All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
SimulatorBase.hpp
1 //===========================================================================
2 //
3 // File: SimulatorBase.hpp
4 //
5 // Created: Tue Aug 11 15:01:48 2009
6 //
7 // Author(s): Atgeirr F Rasmussen <atgeirr@sintef.no>
8 // Bård Skaflestad <bard.skaflestad@sintef.no>
9 //
10 // $Date$
11 //
12 // $Revision$
13 //
14 //===========================================================================
15 
16 /*
17  Copyright 2009, 2010 SINTEF ICT, Applied Mathematics.
18  Copyright 2009, 2010 Statoil ASA.
19 
20  This file is part of The Open Reservoir Simulator Project (OpenRS).
21 
22  OpenRS is free software: you can redistribute it and/or modify
23  it under the terms of the GNU General Public License as published by
24  the Free Software Foundation, either version 3 of the License, or
25  (at your option) any later version.
26 
27  OpenRS is distributed in the hope that it will be useful,
28  but WITHOUT ANY WARRANTY; without even the implied warranty of
29  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  GNU General Public License for more details.
31 
32  You should have received a copy of the GNU General Public License
33  along with OpenRS. If not, see <http://www.gnu.org/licenses/>.
34 */
35 
36 #ifndef OPENRS_SIMULATORBASE_HEADER
37 #define OPENRS_SIMULATORBASE_HEADER
38 
39 
40 #include <opm/core/utility/parameters/ParameterGroup.hpp>
41 
42 #include <opm/core/utility/SparseVector.hpp>
43 #include <opm/core/utility/SparseTable.hpp>
44 #include <opm/parser/eclipse/Units/Units.hpp>
45 
46 #include <dune/grid/common/Volumes.hpp>
47 #include <dune/grid/CpGrid.hpp>
48 
49 #include <opm/porsol/common/GridInterfaceEuler.hpp>
50 #include <opm/porsol/common/ReservoirPropertyCapillary.hpp>
51 #include <opm/porsol/common/BoundaryConditions.hpp>
52 #include <opm/porsol/common/setupGridAndProps.hpp>
53 #include <opm/porsol/common/setupBoundaryConditions.hpp>
54 #include <opm/porsol/common/SimulatorUtilities.hpp>
55 
56 #include <opm/porsol/euler/EulerUpstream.hpp>
57 #include <opm/porsol/euler/ImplicitCapillarity.hpp>
58 
59 #include <opm/porsol/mimetic/MimeticIPEvaluator.hpp>
60 #include <opm/porsol/mimetic/IncompFlowSolverHybrid.hpp>
61 
62 
63 #include <opm/common/utility/platform_dependent/disable_warnings.h>
64 
65 #include <boost/lexical_cast.hpp>
66 #include <dune/grid/yaspgrid.hh>
67 
68 #include <opm/common/utility/platform_dependent/reenable_warnings.h>
69 
70 
71 #include <fstream>
72 #include <iterator>
73 #include <iostream>
74 
75 
76 namespace Opm
77 {
78 
79 
80 
81 
85  template <class SimTraits>
87  {
88  public:
89 
93  : simulation_steps_(1),
94  stepsize_(1.0), // init() expects units of days! Yes, but now the meaning of stepsize_ changes
95  // from days (here) to seconds (after init()). Solution to that?
96  residual_tolerance_(1e-8),
97  linsolver_verbosity_(1),
98  linsolver_type_(1)
99  {
100  }
101 
104  void init(const Opm::ParameterGroup& param)
105  {
106  initControl(param);
107  initGridAndProps(param);
108  initInitialConditions(param);
109  initBoundaryConditions(param);
110  initSources(param);
111  initSolvers(param);
112 
113  // Write any unused parameters.
114  std::cout << "==================== Unused parameters: ====================\n";
115  param.displayUsage();
116  std::cout << "================================================================\n";
117  }
118 
119  protected:
120  typedef Dune::CpGrid GridType;
121  enum { Dimension = GridType::dimension };
122  typedef Dune::FieldVector<double, Dimension> Vector;
123  typedef typename SimTraits::template ResProp<Dimension>::Type ResProp;
124  typedef GridInterfaceEuler<GridType> GridInterface;
125  typedef GridInterface::CellIterator CellIter;
126  typedef CellIter::FaceIterator FaceIter;
127  typedef BasicBoundaryConditions<true, true> BCs;
128  typedef typename SimTraits::template FlowSolver<GridInterface, BCs>::Type FlowSolver;
129  typedef typename SimTraits::template TransportSolver<GridInterface, BCs>::Type TransportSolver;
130 
131  int simulation_steps_;
132  double stepsize_;
133  std::vector<double> init_saturation_;
134  Vector gravity_;
135  double residual_tolerance_;
136  int linsolver_verbosity_;
137  int linsolver_type_;
138 
139  GridType grid_;
140  GridInterface ginterf_;
141  ResProp res_prop_;
142  BCs bcond_;
143  Opm::SparseVector<double> injection_rates_;
144  std::vector<double> injection_rates_psolver_; // Should modify psolver to take SparseVector
145  FlowSolver flow_solver_;
146  TransportSolver transport_solver_;
147 
148 
149  virtual void initControl(const Opm::ParameterGroup& param)
150  {
151  simulation_steps_ = param.getDefault("simulation_steps", simulation_steps_);
152  stepsize_ = Opm::unit::convert::from(param.getDefault("stepsize", stepsize_),
153  Opm::unit::day);
154  }
155 
156  virtual void initGridAndProps(const Opm::ParameterGroup& param)
157  {
158  setupGridAndProps(param, grid_, res_prop_);
159  ginterf_.init(grid_);
160 
161  gravity_[0] = param.getDefault("gx", 0.0);
162  gravity_[1] = param.getDefault("gy", 0.0);
163  gravity_[2] = param.getDefault("gz", 0.0); //Dune::unit::gravity);
164  }
165 
166  virtual void initInitialConditions(const Opm::ParameterGroup& param)
167  {
168  if (param.getDefault("init_saturation_from_file", false)) {
169  std::string filename = param.get<std::string>("init_saturation_filename");
170  std::ifstream satfile(filename.c_str());
171  if (!satfile) {
172  OPM_THROW(std::runtime_error, "Could not open initial saturation file: " << filename);
173  }
174  int num_sats;
175  satfile >> num_sats;
176  if (num_sats != ginterf_.numberOfCells()) {
177  OPM_THROW(std::runtime_error, "Number of saturation values claimed different from number of grid cells: "
178  << num_sats << " vs. " << ginterf_.numberOfCells());
179  }
180  std::istream_iterator<double> beg(satfile);
181  std::istream_iterator<double> end;
182  init_saturation_.assign(beg, end);
183  if (int(init_saturation_.size()) != num_sats) {
184  OPM_THROW(std::runtime_error, "Number of saturation values claimed different from actual file content: "
185  << num_sats << " vs. " << init_saturation_.size());
186  }
187  } else {
188  double init_s = param.getDefault("init_saturation", 0.0);
189  init_saturation_.clear();
190  init_saturation_.resize(ginterf_.numberOfCells(), init_s);
191  }
192  }
193 
194  virtual void initBoundaryConditions(const Opm::ParameterGroup& param)
195  {
196  setupBoundaryConditions(param, ginterf_, bcond_);
197  }
198 
199  virtual void initSources(const Opm::ParameterGroup& /* param */)
200  {
201  int nc = ginterf_.numberOfCells();
202  injection_rates_ = Opm::SparseVector<double>(nc);
203  injection_rates_psolver_.resize(nc, 0.0);
204 // injection_rates_.addElement(1.0, 0);
205 // injection_rates_.addElement(-1.0, nc - 1);
206 // injection_rates_psolver_[0] = 1.0;
207 // injection_rates_psolver_[nc - 1] = -1.0;
208  }
209 
210  virtual void initSolvers(const Opm::ParameterGroup& param)
211  {
212  // Initialize flow solver.
213  flow_solver_.init(ginterf_, res_prop_, gravity_, bcond_);
214  residual_tolerance_ = param.getDefault("residual_tolerance", residual_tolerance_);
215  linsolver_verbosity_ = param.getDefault("linsolver_verbosity", linsolver_verbosity_);
216  linsolver_type_ = param.getDefault("linsolver_type", linsolver_type_);
217  //flow_solver_.assembleStatic(ginterf_, res_prop_);
218  // Initialize transport solver.
219  transport_solver_.init(param, ginterf_, res_prop_, bcond_);
220  }
221 
222 
223  };
224 
225 
226 
227 } // namespace Opm
228 
229 
230 
231 #endif // OPENRS_SIMULATORBASE_HEADER
Definition: SimulatorBase.hpp:86
void setupBoundaryConditions(const Opm::ParameterGroup &param, const GridInterface &g, BCs &bcs)
Setup boundary conditions for a simulation.
Definition: setupBoundaryConditions.hpp:51
void setupGridAndProps(const Opm::ParameterGroup &param, Dune::CpGrid &grid, ResProp< 3 > &res_prop)
Definition: setupGridAndProps.hpp:70
SimulatorBase()
Definition: SimulatorBase.hpp:92
void init(const Opm::ParameterGroup &param)
Initialization from parameters.
Definition: SimulatorBase.hpp:104