SimulatorBase.hpp
1 /*
2  Copyright 2013 SINTEF ICT, Applied Mathematics.
3  Copyright 2015 Andreas Lauser
4 
5  This file is part of the Open Porous Media project (OPM).
6 
7  OPM is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  OPM is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with OPM. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef OPM_SIMULATORBASE_HEADER_INCLUDED
22 #define OPM_SIMULATORBASE_HEADER_INCLUDED
23 
24 #include <opm/material/densead/Math.hpp>
25 #include <opm/autodiff/DuneMatrix.hpp>
26 
27 #include <opm/autodiff/SimulatorFullyImplicitBlackoilOutput.hpp>
28 #include <opm/core/utility/parameters/ParameterGroup.hpp>
29 #include <opm/common/ErrorMacros.hpp>
30 
31 #include <opm/autodiff/GeoProps.hpp>
32 #include <opm/autodiff/BlackoilModel.hpp>
33 #include <opm/autodiff/BlackoilPropsAdFromDeck.hpp>
34 #include <opm/autodiff/WellStateFullyImplicitBlackoil.hpp>
36 
37 #include <opm/core/grid.h>
38 #include <opm/core/wells.h>
39 #include <opm/core/well_controls.h>
40 #include <opm/core/pressure/flow_bc.h>
41 
42 #include <opm/core/simulator/SimulatorReport.hpp>
43 #include <opm/simulators/timestepping/SimulatorTimer.hpp>
44 #include <opm/simulators/timestepping/AdaptiveSimulatorTimer.hpp>
45 #include <opm/core/utility/StopWatch.hpp>
46 #include <opm/core/utility/miscUtilities.hpp>
47 #include <opm/core/utility/miscUtilitiesBlackoil.hpp>
48 
49 #include <opm/core/props/rock/RockCompressibility.hpp>
50 
51 #include <opm/core/simulator/BlackoilState.hpp>
52 #include <opm/simulators/timestepping/AdaptiveTimeStepping.hpp>
53 #include <opm/core/transport/reorder/TransportSolverCompressibleTwophaseReorder.hpp>
54 
55 #include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
56 #include <opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp>
57 #include <opm/parser/eclipse/EclipseState/Schedule/Well.hpp>
58 #include <opm/parser/eclipse/EclipseState/Schedule/WellProductionProperties.hpp>
59 
60 
61 #include <boost/filesystem.hpp>
62 #include <boost/lexical_cast.hpp>
63 
64 #include <algorithm>
65 #include <cstddef>
66 #include <cassert>
67 #include <functional>
68 #include <memory>
69 #include <numeric>
70 #include <fstream>
71 #include <iostream>
72 #include <string>
73 #include <unordered_map>
74 #include <utility>
75 #include <vector>
76 
77 namespace Opm
78 {
79 
80  template <class Simulator>
82 
84  template <class Implementation>
86  {
88 
89  public:
90  typedef typename Traits::ReservoirState ReservoirState;
91  typedef typename Traits::WellState WellState;
92  typedef typename Traits::OutputWriter OutputWriter;
93  typedef typename Traits::Grid Grid;
94  typedef typename Traits::Solver Solver;
95  typedef typename Traits::WellModel WellModel;
96 
124  SimulatorBase(const ParameterGroup& param,
125  const Grid& grid,
126  DerivedGeology& geo,
128  const RockCompressibility* rock_comp_props,
130  const double* gravity,
131  const bool disgas,
132  const bool vapoil,
133  std::shared_ptr<EclipseState> eclipse_state,
134  OutputWriter& output_writer,
135  const std::vector<double>& threshold_pressures_by_face,
136  const std::unordered_set<std::string>& defunct_well_names);
137 
144  SimulatorReport run(SimulatorTimer& timer,
145  ReservoirState& state);
146 
147  protected:
148  Implementation& asImpl() { return *static_cast<Implementation*>(this); }
149  const Implementation& asImpl() const { return *static_cast<const Implementation*>(this); }
150 
151  void handleAdditionalWellInflow(SimulatorTimer& timer,
152  WellsManager& wells_manager,
153  WellState& well_state,
154  const Wells* wells);
155 
156  std::unique_ptr<Solver> createSolver(const WellModel& well_model);
157 
158  void
159  computeRESV(const std::size_t step,
160  const Wells* wells,
161  const BlackoilState& x,
162  WellState& xw);
163 
164  void
165  FIPUnitConvert(const UnitSystem& units,
166  std::vector<std::vector<double> >& fip);
167 
168  void
169  FIPUnitConvert(const UnitSystem& units,
170  std::vector<double>& fip);
171 
172  std::vector<double>
173  FIPTotals(const std::vector<std::vector<double> >& fip, const ReservoirState& state);
174 
175  void
176  outputFluidInPlace(const std::vector<double>& oip, const std::vector<double>& cip, const UnitSystem& units, const int reg);
177 
178 
179  void updateListEconLimited(const std::unique_ptr<Solver>& solver,
180  const Schedule& schedule,
181  const int current_step,
182  const Wells* wells,
183  const WellState& well_state,
184  DynamicListEconLimited& list_econ_limited) const;
185 
186  void initHysteresisParams(ReservoirState& state);
187 
188  // Data.
189  typedef RateConverter::
190  SurfaceToReservoirVoidage< BlackoilPropsAdFromDeck::FluidSystem,
191  std::vector<int> > RateConverterType;
192  typedef typename Traits::Model Model;
193  typedef typename Model::ModelParameters ModelParameters;
194  typedef typename Solver::SolverParameters SolverParameters;
195 
196  const ParameterGroup param_;
197  ModelParameters model_param_;
198  SolverParameters solver_param_;
199 
200  // Observed objects.
201  const Grid& grid_;
202  BlackoilPropsAdFromDeck& props_;
203  const RockCompressibility* rock_comp_props_;
204  const double* gravity_;
205  // Solvers
206  DerivedGeology& geo_;
208  // Misc. data
209  std::vector<int> allcells_;
210  const bool has_disgas_;
211  const bool has_vapoil_;
212  bool terminal_output_;
213  // eclipse_state
214  std::shared_ptr<EclipseState> eclipse_state_;
215  // output_writer
216  OutputWriter& output_writer_;
217  RateConverterType rateConverter_;
218  // Threshold pressures.
219  std::vector<double> threshold_pressures_by_face_;
220  // Whether this a parallel simulation or not
221  bool is_parallel_run_;
222  // The names of wells that should be defunct
223  // (e.g. in a parallel run when they are handeled by
224  // a different process)
225  std::unordered_set<std::string> defunct_well_names_;
226  };
227 
228 } // namespace Opm
229 
230 #include "SimulatorBase_impl.hpp"
231 #endif // OPM_SIMULATORBASE_HEADER_INCLUDED
Class collecting all necessary components for a two-phase simulation.
Definition: SimulatorBase.hpp:85
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: AdditionalObjectDeleter.hpp:22
Facility for converting component rates at surface conditions to phase (voidage) rates at reservoir c...
SimulatorBase(const ParameterGroup &param, const Grid &grid, DerivedGeology &geo, BlackoilPropsAdFromDeck &props, const RockCompressibility *rock_comp_props, NewtonIterationBlackoilInterface &linsolver, const double *gravity, const bool disgas, const bool vapoil, std::shared_ptr< EclipseState > eclipse_state, OutputWriter &output_writer, const std::vector< double > &threshold_pressures_by_face, const std::unordered_set< std::string > &defunct_well_names)
Initialise from parameters and objects to observe.
Definition: SimulatorBase_impl.hpp:36
Class containing static geological properties that are derived from grid and petrophysical properties...
Definition: GeoProps.hpp:59
SimulatorReport run(SimulatorTimer &timer, ReservoirState &state)
Run the simulation.
Definition: SimulatorBase_impl.hpp:87
Interface class for (linear) solvers for the fully implicit black-oil system.
Definition: NewtonIterationBlackoilInterface.hpp:31
This class implements the AD-adapted fluid interface for three-phase black-oil.
Definition: BlackoilPropsAdFromDeck.hpp:61
Definition: SimulatorBase.hpp:81
Definition: SimulatorTimer.hpp:34