All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dgfgridmanager.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_DGF_GRID_MANAGER_HH
28 #define EWOMS_DGF_GRID_MANAGER_HH
29 
30 #include <dune/grid/io/file/dgfparser/dgfparser.hh>
31 #include <dune/grid/common/mcmgmapper.hh>
33 
37 
38 
39 #include <type_traits>
40 #include <string>
41 
42 namespace Ewoms {
43 namespace Properties {
44 NEW_PROP_TAG(Grid);
45 NEW_PROP_TAG(GridFile);
46 NEW_PROP_TAG(GridManager);
47 NEW_PROP_TAG(GridGlobalRefinements);
48 NEW_PROP_TAG(Scalar);
49 NEW_PROP_TAG(Simulator);
50 } // namespace Properties
51 
55 template <class TypeTag>
56 class DgfGridManager : public BaseGridManager<TypeTag>
57 {
59  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
60  typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
61  typedef typename GET_PROP_TYPE(TypeTag, Grid) Grid;
63 
64  typedef std::unique_ptr< Grid > GridPointer;
65 
66 public:
70  static void registerParameters()
71  {
72  EWOMS_REGISTER_PARAM(TypeTag, std::string, GridFile,
73  "The file name of the DGF file to load");
74  EWOMS_REGISTER_PARAM(TypeTag, unsigned, GridGlobalRefinements,
75  "The number of global refinements of the grid "
76  "executed after it was loaded");
77  }
78 
83  : ParentType(simulator)
84  {
85  const std::string dgfFileName = EWOMS_GET_PARAM(TypeTag, std::string, GridFile);
86  unsigned numRefinments = EWOMS_GET_PARAM(TypeTag, unsigned, GridGlobalRefinements);
87 
88  {
89  // create DGF GridPtr from a dgf file
90  Dune::GridPtr< Grid > dgfPointer( dgfFileName );
91 
92  // this is only implemented for 2d currently
93  addFractures_( dgfPointer );
94 
95  // store pointer to dune grid
96  gridPtr_.reset( dgfPointer.release() );
97  }
98 
99  if (numRefinments > 0)
100  gridPtr_->globalRefine(static_cast<int>(numRefinments));
101 
102  this->finalizeInit_();
103  }
104 
108  Grid& grid()
109  { return *gridPtr_; }
110 
114  const Grid& grid() const
115  { return *gridPtr_; }
116 
124  void loadBalance()
125  { gridPtr_->loadBalance(); }
126 
133  { return fractureMapper_; }
134 
141  { return fractureMapper_; }
142 
143 protected:
144  void addFractures_(Dune::GridPtr<Grid>& dgfPointer)
145  {
146  typedef typename Grid::LevelGridView GridView;
147  typedef Dune::MultipleCodimMultipleGeomTypeMapper<GridView, Dune::MCMGVertexLayout> ElementMapper;
148 
149  // check if fractures are available (only 2d currently)
150  if (dgfPointer.nofParameters(static_cast<int>(Grid::dimension)) == 0)
151  return;
152 
153  GridView gridView = dgfPointer->levelGridView(/*level=*/0);
154  const unsigned edgeCodim = Grid::dimension - 1;
155 
156  // first create a map of the dune to ART vertex indices
157  ElementMapper elementMapper(gridView);
158  auto eIt = gridView.template begin</*codim=*/0>();
159  const auto eEndIt = gridView.template end</*codim=*/0>();
160  for (; eIt != eEndIt; ++eIt) {
161  const auto& element = *eIt;
162  const auto& refElem =
163  Dune::ReferenceElements<Scalar, Grid::dimension>::general(element.type());
164 
165  const int edges = refElem.size( edgeCodim );
166  for (int edge = 0; edge < edges; ++edge) {
167  const int vertices = refElem.size(edge, edgeCodim, Grid::dimension);
168  std::vector<unsigned> vertexIndices;
169  vertexIndices.reserve(Grid::dimension);
170  for (int vx = 0; vx < vertices; ++vx) {
171  // get local vertex number from edge
172  const int localVx = refElem.subEntity(edge, edgeCodim, vx, Grid::dimension);
173 
174  // get vertex
175  const auto vertex = element.template subEntity<Grid::dimension>(localVx);
176 
177  // if vertex has parameter 1 insert as a fracture vertex
178  if (dgfPointer.parameters( vertex )[ 0 ] > 0)
179  vertexIndices.push_back(
180  static_cast<unsigned>(elementMapper.subIndex(element,
181  static_cast<int>(localVx),
182  Grid::dimension)));
183  }
184  // if 2 vertices have been found with flag 1 insert a fracture edge
185  if (static_cast<int>(vertexIndices.size()) == Grid::dimension)
186  fractureMapper_.addFractureEdge(vertexIndices[0], vertexIndices[1]);
187  }
188  }
189  }
190 
191 private:
192  GridPointer gridPtr_;
193  FractureMapper fractureMapper_;
194 };
195 
196 } // namespace Ewoms
197 
198 #endif
Grid & grid()
Returns a reference to the grid.
Definition: dgfgridmanager.hh:108
const Grid & grid() const
Returns a reference to the grid.
Definition: dgfgridmanager.hh:114
Stores the topology of fractures.
Provides the base class for most (all?) grid managers.
Stores the topology of fractures.
Definition: fracturemapper.hh:42
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.
const FractureMapper & fractureMapper() const
Returns the fracture mapper.
Definition: dgfgridmanager.hh:140
void loadBalance()
Distributes the grid on all processes of a parallel computation.
Definition: dgfgridmanager.hh:124
FractureMapper & fractureMapper()
Returns the fracture mapper.
Definition: dgfgridmanager.hh:132
const GridView & gridView() const
Returns a reference to the grid view to be used.
Definition: basegridmanager.hh:79
Provides a grid manager which reads Dune Grid Format (DGF) files.
Definition: dgfgridmanager.hh:56
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName)
Retrieve a runtime parameter.
Definition: parametersystem.hh:99
void addFractureEdge(unsigned vertexIdx1, unsigned vertexIdx2)
Marks an edge as having a fracture.
Definition: fracturemapper.hh:74
Provides the magic behind the eWoms property system.
static void registerParameters()
Register all run-time parameters for the grid manager.
Definition: dgfgridmanager.hh:70
DgfGridManager(Simulator &simulator)
Load the grid from the file.
Definition: dgfgridmanager.hh:82
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