opm-simulators
dgfvanguard.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_VANGUARD_HH
28 #define EWOMS_DGF_GRID_VANGUARD_HH
29 
30 #include <dune/grid/io/file/dgfparser/dgfparser.hh>
31 #include <dune/grid/common/mcmgmapper.hh>
32 
37 
38 #include <memory>
39 #include <string>
40 #include <vector>
41 
42 namespace Opm {
43 
48 template <class TypeTag>
49 class DgfVanguard : public BaseVanguard<TypeTag>
50 {
56 
57  using GridPointer = std::unique_ptr<Grid>;
58 
59 public:
63  static void registerParameters()
64  {
65  Parameters::Register<Parameters::GridFile>
66  ("The file name of the DGF file to load");
67  Parameters::Register<Parameters::GridGlobalRefinements>
68  ("The number of global refinements of the grid "
69  "executed after it was loaded");
70  }
71 
75  explicit DgfVanguard(Simulator& simulator)
76  : ParentType(simulator)
77  {
78  const std::string dgfFileName = Parameters::Get<Parameters::GridFile>();
79  const unsigned numRefinments = Parameters::Get<Parameters::GridGlobalRefinements>();
80 
81  {
82  // create DGF GridPtr from a dgf file
83  Dune::GridPtr<Grid> dgfPointer(dgfFileName);
84 
85  // this is only implemented for 2d currently
86  addFractures_(dgfPointer);
87 
88  // store pointer to dune grid
89  gridPtr_.reset(dgfPointer.release());
90  }
91 
92  if (numRefinments > 0) {
93  gridPtr_->globalRefine(static_cast<int>(numRefinments));
94  }
95 
96  this->finalizeInit_();
97  }
98 
102  Grid& grid()
103  { return *gridPtr_; }
104 
108  const Grid& grid() const
109  { return *gridPtr_; }
110 
118  void loadBalance()
119  { gridPtr_->loadBalance(); }
120 
127  { return fractureMapper_; }
128 
135  { return fractureMapper_; }
136 
137 protected:
138  void addFractures_(Dune::GridPtr<Grid>& dgfPointer)
139  {
140  using LevelGridView = typename Grid::LevelGridView;
141 
142  // check if fractures are available (only 2d currently)
143  if (dgfPointer.nofParameters(static_cast<int>(Grid::dimension)) == 0) {
144  return;
145  }
146 
147  LevelGridView gridView = dgfPointer->levelGridView(/*level=*/0);
148  const unsigned edgeCodim = Grid::dimension - 1;
149 
150  using VertexMapper = Dune::MultipleCodimMultipleGeomTypeMapper<LevelGridView>;
151  VertexMapper vertexMapper(gridView, Dune::mcmgVertexLayout());
152 
153  // first create a map of the dune to ART vertex indices
154  for (const auto& element: elements(gridView)) {
155  const auto& refElem =
156  Dune::ReferenceElements<Scalar, Grid::dimension>::general(element.type());
157 
158  const int edges = refElem.size(edgeCodim);
159  for (int edge = 0; edge < edges; ++edge) {
160  const int vertices = refElem.size(edge, edgeCodim, Grid::dimension);
161  std::vector<unsigned> vertexIndices;
162  vertexIndices.reserve(Grid::dimension);
163  for (int vx = 0; vx < vertices; ++vx) {
164  // get local vertex number from edge
165  const int localVx = refElem.subEntity(edge, edgeCodim, vx, Grid::dimension);
166 
167  // get vertex
168  const auto vertex = element.template subEntity<Grid::dimension>(localVx);
169 
170  // if vertex has parameter 1 insert as a fracture vertex
171  if (dgfPointer.parameters(vertex)[0] > 0) {
172  vertexIndices.push_back(
173  static_cast<unsigned>(vertexMapper.subIndex(element,
174  static_cast<int>(localVx),
175  Grid::dimension)));
176  }
177  }
178  // if 2 vertices have been found with flag 1 insert a fracture edge
179  if (static_cast<int>(vertexIndices.size()) == Grid::dimension) {
180  fractureMapper_.addFractureEdge(vertexIndices[0], vertexIndices[1]);
181  }
182  }
183  }
184  }
185 
186 private:
187  GridPointer gridPtr_;
188  FractureMapper fractureMapper_;
189 };
190 
191 } // namespace Opm
192 
193 #endif
Stores the topology of fractures.
Definition: fracturemapper.hh:40
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(...))
Definition: propertysystem.hh:233
const Grid & grid() const
Returns a reference to the grid.
Definition: dgfvanguard.hh:108
Stores the topology of fractures.
This file provides the infrastructure to retrieve run-time parameters.
const GridView & gridView() const
Returns a reference to the grid view to be used.
Definition: basevanguard.hh:70
Provides a simulator vanguard which creates a grid by parsing a Dune Grid Format (DGF) file...
Definition: dgfvanguard.hh:49
Provides the base class for most (all?) simulator vanguards.
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
DgfVanguard(Simulator &simulator)
Load the grid from the file.
Definition: dgfvanguard.hh:75
static void registerParameters()
Register all run-time parameters for the DGF simulator vanguard.
Definition: dgfvanguard.hh:63
void loadBalance()
Distributes the grid on all processes of a parallel computation.
Definition: dgfvanguard.hh:118
FractureMapper & fractureMapper()
Returns the fracture mapper.
Definition: dgfvanguard.hh:126
Grid & grid()
Returns a reference to the grid.
Definition: dgfvanguard.hh:102
The Opm property system, traits with inheritance.
const FractureMapper & fractureMapper() const
Returns the fracture mapper.
Definition: dgfvanguard.hh:134
Provides the base class for most (all?) simulator vanguards.
Definition: basevanguard.hh:49
void addFractureEdge(unsigned vertexIdx1, unsigned vertexIdx2)
Marks an edge as having a fracture.
Definition: fracturemapper.hh:66