All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
structuredgridmanager.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_STRUCTURED_GRID_MANAGER_HH
28 #define EWOMS_STRUCTURED_GRID_MANAGER_HH
29 
33 
34 #include <dune/grid/yaspgrid.hh>
35 #include <dune/grid/io/file/dgfparser/dgfyasp.hh>
36 
37 #if HAVE_DUNE_ALUGRID
38 #include <dune/alugrid/grid.hh>
39 #include <dune/alugrid/dgf.hh>
40 #endif
41 
42 #include <dune/common/fvector.hh>
43 #include <dune/common/version.hh>
44 
45 #include <vector>
46 #include <memory>
47 
48 namespace Ewoms {
49 
50 template <class TypeTag>
52 
53 namespace Properties {
55 
56 // declare the properties required by the for the lens grid manager
57 NEW_PROP_TAG(Grid);
58 NEW_PROP_TAG(Scalar);
59 
60 NEW_PROP_TAG(DomainSizeX);
61 NEW_PROP_TAG(DomainSizeY);
62 NEW_PROP_TAG(DomainSizeZ);
63 
64 NEW_PROP_TAG(CellsX);
65 NEW_PROP_TAG(CellsY);
66 NEW_PROP_TAG(CellsZ);
67 
68 NEW_PROP_TAG(GridGlobalRefinements);
69 
70 // GRIDDIM is only set by the finger problem
71 #ifndef GRIDDIM
72 static const int dim = 2;
73 #else
74 static const int dim = GRIDDIM;
75 #endif
76 
77 // set the Grid and GridManager properties
78 #if HAVE_DUNE_ALUGRID
79 SET_TYPE_PROP(StructuredGridManager, Grid, Dune::ALUGrid< dim, dim, Dune::cube, Dune::nonconforming >);
80 #else
81 SET_TYPE_PROP(StructuredGridManager, Grid, Dune::YaspGrid< dim >);
82 #endif
83 
85 } // namespace Properties
86 
92 template <class TypeTag>
93 class StructuredGridManager : public BaseGridManager<TypeTag>
94 {
95  typedef BaseGridManager<TypeTag> ParentType;
96  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
97  typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
98  typedef typename GET_PROP_TYPE(TypeTag, Grid) Grid;
99 
100  typedef std::unique_ptr<Grid> GridPointer;
101 
102  static const int dim = Grid::dimension;
103 
104 public:
108  static void registerParameters()
109  {
110  EWOMS_REGISTER_PARAM(TypeTag, unsigned, GridGlobalRefinements,
111  "The number of global refinements of the grid "
112  "executed after it was loaded");
113  EWOMS_REGISTER_PARAM(TypeTag, Scalar, DomainSizeX,
114  "The size of the domain in x direction");
115  EWOMS_REGISTER_PARAM(TypeTag, unsigned, CellsX,
116  "The number of intervalls in x direction");
117  if (dim > 1) {
118  EWOMS_REGISTER_PARAM(TypeTag, Scalar, DomainSizeY,
119  "The size of the domain in y direction");
120  EWOMS_REGISTER_PARAM(TypeTag, unsigned, CellsY,
121  "The number of intervalls in y direction");
122  }
123  if (dim > 2) {
124  EWOMS_REGISTER_PARAM(TypeTag, Scalar, DomainSizeZ,
125  "The size of the domain in z direction");
126  EWOMS_REGISTER_PARAM(TypeTag, unsigned, CellsZ,
127  "The number of intervalls in z direction");
128  }
129  }
130 
135  : ParentType(simulator)
136  {
137  Dune::FieldVector<int, dim> cellRes;
138 
139  typedef double GridScalar;
140  Dune::FieldVector<GridScalar, dim> upperRight;
141  Dune::FieldVector<GridScalar, dim> lowerLeft( 0 );
142 
143  upperRight[0] = EWOMS_GET_PARAM(TypeTag, Scalar, DomainSizeX);
144  upperRight[1] = EWOMS_GET_PARAM(TypeTag, Scalar, DomainSizeY);
145 
146  cellRes[0] = EWOMS_GET_PARAM(TypeTag, unsigned, CellsX);
147  cellRes[1] = EWOMS_GET_PARAM(TypeTag, unsigned, CellsY);
148  if (dim == 3) {
149  upperRight[2] = EWOMS_GET_PARAM(TypeTag, Scalar, DomainSizeZ);
150  cellRes[2] = EWOMS_GET_PARAM(TypeTag, unsigned, CellsZ);
151  }
152 
153  std::stringstream dgffile;
154  dgffile << "DGF" << std::endl;
155  dgffile << "INTERVAL" << std::endl;
156  dgffile << lowerLeft << std::endl;
157  dgffile << upperRight << std::endl;
158  dgffile << cellRes << std::endl;
159  dgffile << "#" << std::endl;
160  dgffile << "GridParameter" << std::endl;
161  dgffile << "overlap 1" << std::endl;
162  dgffile << "#" << std::endl;
163  dgffile << "Simplex" << std::endl;
164  dgffile << "#" << std::endl;
165 
166  // use DGF parser to create a grid from interval block
167  gridPtr_.reset( Dune::GridPtr< Grid >( dgffile ).release() );
168 
169  unsigned numRefinements = EWOMS_GET_PARAM(TypeTag, unsigned, GridGlobalRefinements);
170  gridPtr_->globalRefine(static_cast<int>(numRefinements));
171 
172  this->finalizeInit_();
173  }
174 
178  Grid& grid()
179  { return *gridPtr_; }
180 
184  const Grid& grid() const
185  { return *gridPtr_; }
186 
187 private:
188  GridPointer gridPtr_;
189 };
190 
191 } // namespace Ewoms
192 
193 #endif
Provides the base class for most (all?) grid managers.
Grid & grid()
Return a reference to the grid object.
Definition: structuredgridmanager.hh:178
Helper class for grid instantiation of the lens problem.
Definition: structuredgridmanager.hh:51
#define NEW_TYPE_TAG(...)
Define a new type tag.
Definition: propertysystem.hh:169
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
static void registerParameters()
Register all run-time parameters for the grid manager.
Definition: structuredgridmanager.hh:108
StructuredGridManager(Simulator &simulator)
Create the grid for the lens problem.
Definition: structuredgridmanager.hh:134
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
#define SET_TYPE_PROP(EffTypeTagName, PropTagName,...)
Set a property which defines a type.
Definition: propertysystem.hh:377
const Grid & grid() const
Return a constant reference to the grid object.
Definition: structuredgridmanager.hh:184