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