00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef OPM_GRIDINIT_HEADER_INCLUDED
00021 #define OPM_GRIDINIT_HEADER_INCLUDED
00022
00023 #include <opm/parser/eclipse/Deck/Deck.hpp>
00024 #include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
00025 #include <opm/core/grid/GridManager.hpp>
00026
00027 #if HAVE_OPM_GRID
00028 #include <dune/grid/polyhedralgrid.hh>
00029 #include <dune/grid/CpGrid.hpp>
00030 #endif
00031
00032
00033 namespace Opm
00034 {
00035
00039 template <class Grid>
00040 class GridInit
00041 {
00042 public:
00044 GridInit(const EclipseState&, const std::vector<double>&)
00045 {
00046 OPM_THROW(std::logic_error, "Found no specialization for GridInit for the requested Grid class.");
00047 }
00048 };
00049
00050
00052 template <>
00053 class GridInit<UnstructuredGrid>
00054 {
00055 public:
00057 GridInit(const EclipseState& eclipse_state, const std::vector<double>& porv)
00058 : grid_manager_(eclipse_state.getInputGrid(), porv)
00059 {
00060 }
00062 const UnstructuredGrid& grid()
00063 {
00064 return *grid_manager_.c_grid();
00065 }
00066 private:
00067 GridManager grid_manager_;
00068 };
00069
00070
00071 #if HAVE_OPM_GRID
00073 template < int dim, int dimworld >
00074 class GridInit< Dune::PolyhedralGrid< dim, dimworld > >
00075 {
00076 public:
00077 typedef Dune::PolyhedralGrid< dim, dimworld > Grid;
00079 GridInit(const EclipseState& eclipse_state, const std::vector<double>& porv)
00080 : grid_manager_(eclipse_state.getInputGrid(), porv),
00081 grid_( *grid_manager_.c_grid() )
00082 {
00083 }
00084
00086 const Grid& grid()
00087 {
00088 return grid_;
00089 }
00090 private:
00091 GridManager grid_manager_;
00092 Grid grid_;
00093 };
00094
00095
00097 template <>
00098 class GridInit<Dune::CpGrid>
00099 {
00100 public:
00101 GridInit()
00102 {
00103 gridSelfManaged_ = false;
00104 }
00105
00107 GridInit(const EclipseState& eclipse_state, const std::vector<double>& porv)
00108 {
00109 gridSelfManaged_ = true;
00110
00111 grid_ = new Dune::CpGrid;
00112 grid_->processEclipseFormat(eclipse_state.getInputGrid(), false, false, false, porv);
00113 }
00114
00115 ~GridInit()
00116 {
00117 if (gridSelfManaged_)
00118 delete grid_;
00119 }
00120
00122 Dune::CpGrid& grid()
00123 {
00124 return *grid_;
00125 }
00126
00128 void setGrid(Dune::CpGrid& newGrid)
00129 {
00130 gridSelfManaged_ = false;
00131 grid_ = &newGrid;
00132 }
00133
00134 private:
00135 Dune::CpGrid* grid_;
00136 bool gridSelfManaged_;
00137 };
00138 #endif // HAVE_OPM_GRID
00139
00140
00141 }
00142
00143 #endif // OPM_GRIDINIT_HEADER_INCLUDED