GridInit.hpp
1 /*
2  Copyright 2015 SINTEF ICT, Applied Mathematics.
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 3 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 
20 #ifndef OPM_GRIDINIT_HEADER_INCLUDED
21 #define OPM_GRIDINIT_HEADER_INCLUDED
22 
23 #include <opm/parser/eclipse/Deck/Deck.hpp>
24 #include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
25 #include <opm/core/grid/GridManager.hpp>
26 
27 #if HAVE_OPM_GRID
28 #include <dune/grid/polyhedralgrid.hh>
29 #include <dune/grid/CpGrid.hpp>
30 #endif
31 
32 
33 namespace Opm
34 {
35 
39  template <class Grid>
40  class GridInit
41  {
42  public:
44  GridInit(const EclipseState&, const std::vector<double>&)
45  {
46  OPM_THROW(std::logic_error, "Found no specialization for GridInit for the requested Grid class.");
47  }
48  };
49 
50 
52  template <>
53  class GridInit<UnstructuredGrid>
54  {
55  public:
57  GridInit(const EclipseState& eclipse_state, const std::vector<double>& porv)
58  : grid_manager_(eclipse_state.getInputGrid(), porv)
59  {
60  }
62  const UnstructuredGrid& grid()
63  {
64  return *grid_manager_.c_grid();
65  }
66  private:
67  GridManager grid_manager_;
68  };
69 
70 
71 #if HAVE_OPM_GRID
72  template < int dim, int dimworld >
74  class GridInit< Dune::PolyhedralGrid< dim, dimworld > >
75  {
76  public:
77  typedef Dune::PolyhedralGrid< dim, dimworld > Grid;
79  GridInit(const EclipseState& eclipse_state, const std::vector<double>& porv)
80  : grid_manager_(eclipse_state.getInputGrid(), porv),
81  grid_( *grid_manager_.c_grid() )
82  {
83  }
84 
86  const Grid& grid()
87  {
88  return grid_;
89  }
90  private:
91  GridManager grid_manager_;
92  Grid grid_;
93  };
94 
95 
97  template <>
98  class GridInit<Dune::CpGrid>
99  {
100  public:
101  GridInit()
102  {
103  gridSelfManaged_ = false;
104  }
105 
107  GridInit(const EclipseState& eclipse_state, const std::vector<double>& porv)
108  {
109  gridSelfManaged_ = true;
110 
111  grid_ = new Dune::CpGrid;
112  grid_->processEclipseFormat(eclipse_state.getInputGrid(), false, false, false, porv);
113  }
114 
115  ~GridInit()
116  {
117  if (gridSelfManaged_)
118  delete grid_;
119  }
120 
122  Dune::CpGrid& grid()
123  {
124  return *grid_;
125  }
126 
128  void setGrid(Dune::CpGrid& newGrid)
129  {
130  gridSelfManaged_ = false;
131  grid_ = &newGrid;
132  }
133 
134  private:
135  Dune::CpGrid* grid_;
136  bool gridSelfManaged_;
137  };
138 #endif // HAVE_OPM_GRID
139 
140 
141 } // namespace Opm
142 
143 #endif // OPM_GRIDINIT_HEADER_INCLUDED
Definition: ISTLSolver.hpp:44
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: AdditionalObjectDeleter.hpp:22
const UnstructuredGrid & grid()
Access the created grid.
Definition: GridInit.hpp:62
GridInit(const EclipseState &, const std::vector< double > &)
Initialize from a deck and/or an eclipse state and (logical cartesian) specified pore volumes...
Definition: GridInit.hpp:44
A class intended to give a generic interface to initializing and accessing UnstructuredGrid and CpGri...
Definition: GridInit.hpp:40
GridInit(const EclipseState &eclipse_state, const std::vector< double > &porv)
Initialize from a deck and/or an eclipse state and (logical cartesian) specified pore volumes...
Definition: GridInit.hpp:57