cubegridmanager.hh
Go to the documentation of this file.
1 // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 // vi: set et ts=4 sw=4 sts=4:
3 /*
4  Copyright (C) 2012-2013 by Andreas Lauser
5  Copyright (C) 2012 by Markus Wolff
6 
7  This file is part of the Open Porous Media project (OPM).
8 
9  OPM is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 2 of the License, or
12  (at your option) any later version.
13 
14  OPM is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OPM. If not, see <http://www.gnu.org/licenses/>.
21 */
26 #ifndef EWOMS_CUBE_GRID_MANAGER_HH
27 #define EWOMS_CUBE_GRID_MANAGER_HH
28 
33 
34 #include <dune/grid/utility/structuredgridfactory.hh>
35 
36 #include <dune/common/fvector.hh>
37 
38 #include <memory>
39 
40 namespace Ewoms {
41 namespace Properties {
42 NEW_PROP_TAG(Scalar);
43 NEW_PROP_TAG(Grid);
44 
45 NEW_PROP_TAG(DomainSizeX);
46 NEW_PROP_TAG(DomainSizeY);
47 NEW_PROP_TAG(DomainSizeZ);
48 
49 NEW_PROP_TAG(CellsX);
50 NEW_PROP_TAG(CellsY);
51 NEW_PROP_TAG(CellsZ);
52 
53 NEW_PROP_TAG(GridGlobalRefinements);
54 } // namespace Properties
55 
63 template <class TypeTag>
64 class CubeGridManager : public BaseGridManager<TypeTag>
65 {
67  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
68  typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
69  typedef typename GET_PROP_TYPE(TypeTag, Grid) Grid;
70 
71  typedef Dune::shared_ptr<Grid> GridPointer;
72  typedef typename Grid::ctype CoordScalar;
73  enum { dimWorld = Grid::dimensionworld };
74  typedef Dune::FieldVector<CoordScalar, dimWorld> GlobalPosition;
75 
76 public:
80  static void registerParameters()
81  {
82  EWOMS_REGISTER_PARAM(TypeTag, unsigned, GridGlobalRefinements,
83  "The number of global refinements of the grid "
84  "executed after it was loaded");
85  EWOMS_REGISTER_PARAM(TypeTag, Scalar, DomainSizeX,
86  "The size of the domain in x direction");
87  EWOMS_REGISTER_PARAM(TypeTag, int, CellsX,
88  "The number of intervalls in x direction");
89  if (dimWorld > 1) {
90  EWOMS_REGISTER_PARAM(TypeTag, Scalar, DomainSizeY,
91  "The size of the domain in y direction");
92  EWOMS_REGISTER_PARAM(TypeTag, int, CellsY,
93  "The number of intervalls in y direction");
94  }
95  if (dimWorld > 2) {
96  EWOMS_REGISTER_PARAM(TypeTag, Scalar, DomainSizeZ,
97  "The size of the domain in z direction");
98  EWOMS_REGISTER_PARAM(TypeTag, int, CellsZ,
99  "The number of intervalls in z direction");
100  }
101  }
102 
106  CubeGridManager(Simulator &simulator)
107  : ParentType(simulator)
108  {
109  Dune::array<unsigned int, dimWorld> cellRes;
110  GlobalPosition upperRight(0.0);
111  GlobalPosition lowerLeft(0.0);
112 
113  for (unsigned i = 0; i < dimWorld; ++i)
114  cellRes[i] = 0;
115 
116  upperRight[0] = EWOMS_GET_PARAM(TypeTag, Scalar, DomainSizeX);
117  cellRes[0] = EWOMS_GET_PARAM(TypeTag, int, CellsX);
118  if (dimWorld > 1) {
119  upperRight[1] = EWOMS_GET_PARAM(TypeTag, Scalar, DomainSizeY);
120  cellRes[1] = EWOMS_GET_PARAM(TypeTag, int, CellsY);
121  }
122  if (dimWorld > 2) {
123  upperRight[2] = EWOMS_GET_PARAM(TypeTag, Scalar, DomainSizeZ);
124  cellRes[2] = EWOMS_GET_PARAM(TypeTag, int, CellsZ);
125  }
126 
127  unsigned numRefinements = EWOMS_GET_PARAM(TypeTag, unsigned, GridGlobalRefinements);
128  cubeGrid_ = Dune::StructuredGridFactory<Grid>::createCubeGrid(lowerLeft,
129  upperRight,
130  cellRes);
131  cubeGrid_->globalRefine(numRefinements);
132 
133  this->finalizeInit_();
134  }
135 
139  Grid& grid()
140  { return *cubeGrid_; }
141 
145  const Grid& grid() const
146  { return *cubeGrid_; }
147 
148 protected:
149  GridPointer cubeGrid_;
150 };
151 
152 } // namespace Ewoms
153 
154 #endif
void finalizeInit_()
Definition: basegridmanager.hh:84
static void registerParameters()
Register all run-time parameters for the grid manager.
Definition: cubegridmanager.hh:80
Defines a type tags and some fundamental properties all models.
Grid & grid()
Returns a reference to the grid.
Definition: cubegridmanager.hh:139
NEW_PROP_TAG(Grid)
The type of the DUNE grid.
This file provides the infrastructure to retrieve run-time parameters.
Provides the base class for most (all?) grid managers.
Definition: basegridmanager.hh:51
CubeGridManager(Simulator &simulator)
Create the grid.
Definition: cubegridmanager.hh:106
const Grid & grid() const
Returns a reference to the grid.
Definition: cubegridmanager.hh:145
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:73
Definition: baseauxiliarymodule.hh:35
GridPointer cubeGrid_
Definition: cubegridmanager.hh:149
#define EWOMS_REGISTER_PARAM(TypeTag, ParamType, ParamName, Description)
Register a run-time parameter.
Definition: parametersystem.hh:64
Provides a grid manager which a regular grid made of quadrilaterals.
Definition: cubegridmanager.hh:64
Provides the magic behind the eWoms property system.
Provides the base class for most (all?) grid managers.
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName)
Retrieve a runtime parameter.
Definition: parametersystem.hh:95