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  Copyright (C) 2012-2013 by Andreas Lauser
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 2 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
25 #ifndef EWOMS_DGF_GRID_MANAGER_HH
26 #define EWOMS_DGF_GRID_MANAGER_HH
27 
28 #include <dune/grid/io/file/dgfparser/dgfparser.hh>
30 
34 
35 
36 #include <type_traits>
37 #include <string>
38 
39 namespace Ewoms {
40 namespace Properties {
41 NEW_PROP_TAG(Grid);
42 NEW_PROP_TAG(GridFile);
43 NEW_PROP_TAG(GridManager);
44 NEW_PROP_TAG(GridGlobalRefinements);
45 NEW_PROP_TAG(Scalar);
46 NEW_PROP_TAG(Simulator);
47 } // namespace Properties
48 
52 template <class TypeTag>
53 class DgfGridManager : public BaseGridManager<TypeTag>
54 {
56  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
57  typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
58  typedef typename GET_PROP_TYPE(TypeTag, Grid) Grid;
60 
61  typedef std::unique_ptr< Grid > GridPointer;
62 
63 public:
67  static void registerParameters()
68  {
69  EWOMS_REGISTER_PARAM(TypeTag, std::string, GridFile,
70  "The file name of the DGF file to load");
71  EWOMS_REGISTER_PARAM(TypeTag, unsigned, GridGlobalRefinements,
72  "The number of global refinements of the grid "
73  "executed after it was loaded");
74  }
75 
79  DgfGridManager(Simulator &simulator)
80  : ParentType(simulator)
81  {
82  const std::string dgfFileName = EWOMS_GET_PARAM(TypeTag, std::string, GridFile);
83  unsigned numRefinments = EWOMS_GET_PARAM(TypeTag, unsigned, GridGlobalRefinements);
84 
85  {
86  // create DGF GridPtr from a dgf file
87  Dune::GridPtr< Grid > dgfPointer( dgfFileName );
88 
89  // this is only implemented for 2d currently
90  addFractures_( dgfPointer );
91 
92  // store pointer to dune grid
93  gridPtr_.reset( dgfPointer.release() );
94  }
95 
96  if (numRefinments > 0)
97  gridPtr_->globalRefine(numRefinments);
98 
99  this->finalizeInit_();
100  }
101 
105  Grid& grid()
106  { return *gridPtr_; }
107 
111  const Grid& grid() const
112  { return *gridPtr_; }
113 
121  void loadBalance()
122  { gridPtr_->loadBalance(); }
123 
129  FractureMapper &fractureMapper()
130  { return fractureMapper_; }
131 
137  const FractureMapper &fractureMapper() const
138  { return fractureMapper_; }
139 
140 protected:
141  void addFractures_( Dune::GridPtr< Grid >& dgfPointer )
142  {
143  // check if fractures are available (only 2d currently)
144  if( dgfPointer.nofParameters( int(Grid::dimension) ) > 0 )
145  {
146  typedef typename Grid::LevelGridView GridView;
147 #if DUNE_VERSION_NEWER(DUNE_GRID,2,3)
148  GridView gridView = dgfPointer->levelGridView( 0 );
149 #else
150  GridView gridView = dgfPointer->levelView( 0 );
151 #endif
152 
153  // first create a map of the dune to ART vertex indices
154  typedef Dune::MultipleCodimMultipleGeomTypeMapper<GridView,
155  Dune::MCMGVertexLayout> ElementMapper;
156 
157  const int edgeCodim = Grid::dimension - 1;
158 
159  ElementMapper elementMapper( gridView );
160  const auto endIt = gridView.template end< 0 > ();
161  for( auto eIt = gridView.template begin< 0 >(); eIt != endIt; ++eIt )
162  {
163  const auto& element = *eIt;
164 #if DUNE_VERSION_NEWER(DUNE_GRID,2,3)
165  const auto& refElem =
166  Dune::ReferenceElements< Scalar, Grid::dimension >::general( element.type() );
167 #else
168  const auto& refElem =
169  Dune::GenericReferenceElements< Scalar, Grid::dimension >::general( element.type() );
170 #endif
171 
172  const int edges = refElem.size( edgeCodim );
173  for( int edge = 0; edge < edges; ++edge )
174  {
175  const int vertices = refElem.size( edge, edgeCodim, Grid::dimension );
176  std::vector< int > vertexIndices;
177  vertexIndices.reserve( Grid::dimension );
178  for( int vx = 0; vx<vertices; ++vx )
179  {
180  // get local vertex number from edge
181  const int localVx = refElem.subEntity( edge, edgeCodim, vx, Grid::dimension );
182 
183 #if DUNE_VERSION_NEWER(DUNE_GRID,2,4)
184  // get vertex
185  const auto vertex = element.template subEntity< Grid::dimension >( localVx );
186 #else
187  // get vertex
188  const auto vertexPtr = element.template subEntity< Grid::dimension >( localVx );
189  const auto& vertex = *vertexPtr ;
190 #endif
191 
192  // if vertex has parameter 1 insert as a fracture vertex
193  if( dgfPointer.parameters( vertex )[ 0 ] > 0 )
194  {
195 #if DUNE_VERSION_NEWER(DUNE_GRID, 2,4)
196  vertexIndices.push_back( elementMapper.subIndex( element, localVx, Grid::dimension ) );
197 #else
198  vertexIndices.push_back( elementMapper.map( element, localVx, Grid::dimension ) );
199 #endif
200  }
201  }
202  // if 2 vertices have been found with flag 1 insert a fracture edge
203  if( int(vertexIndices.size()) == Grid::dimension )
204  {
205  fractureMapper_.addFractureEdge(vertexIndices[ 0 ], vertexIndices[ 1 ] );
206  }
207  }
208  }
209  }
210  }
211 
212 private:
213  GridPointer gridPtr_;
214  FractureMapper fractureMapper_;
215 };
216 
217 } // namespace Ewoms
218 
219 #endif
Provides a grid manager which reads Dune Grid Format (DGF) files.
Definition: dgfgridmanager.hh:53
void finalizeInit_()
Definition: basegridmanager.hh:84
static void registerParameters()
Register all run-time parameters for the grid manager.
Definition: dgfgridmanager.hh:67
const Grid & grid() const
Returns a reference to the grid.
Definition: dgfgridmanager.hh:111
void loadBalance()
Distributes the grid on all processes of a parallel computation.
Definition: dgfgridmanager.hh:121
Stores the topology of fractures.
Definition: fracturemapper.hh:40
void addFractureEdge(int vertexIdx1, int vertexIdx2)
Marks an edge as having a fracture.
Definition: fracturemapper.hh:72
NEW_PROP_TAG(Grid)
The type of the DUNE grid.
Stores the topology of fractures.
This file provides the infrastructure to retrieve run-time parameters.
Provides the base class for most (all?) grid managers.
Definition: basegridmanager.hh:51
void addFractures_(Dune::GridPtr< Grid > &dgfPointer)
Definition: dgfgridmanager.hh:141
FractureMapper & fractureMapper()
Returns the fracture mapper.
Definition: dgfgridmanager.hh:129
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:73
GridView & gridView()
Returns a reference to the grid view to be used.
Definition: basegridmanager.hh:66
Definition: baseauxiliarymodule.hh:35
#define EWOMS_REGISTER_PARAM(TypeTag, ParamType, ParamName, Description)
Register a run-time parameter.
Definition: parametersystem.hh:64
Grid & grid()
Returns a reference to the grid.
Definition: dgfgridmanager.hh:105
DgfGridManager(Simulator &simulator)
Load the grid from the file.
Definition: dgfgridmanager.hh:79
Provides the magic behind the eWoms property system.
Provides the base class for most (all?) grid managers.
const FractureMapper & fractureMapper() const
Returns the fracture mapper.
Definition: dgfgridmanager.hh:137
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName)
Retrieve a runtime parameter.
Definition: parametersystem.hh:95