opm-simulators
SimulatorFullyImplicit.hpp
1 /*
2  Copyright 2013, 2015, 2020 SINTEF Digital, Mathematics and Cybernetics.
3  Copyright 2015 Andreas Lauser
4  Copyright 2017 IRIS
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #ifndef OPM_SIMULATOR_FULLY_IMPLICIT_HEADER_INCLUDED
23 #define OPM_SIMULATOR_FULLY_IMPLICIT_HEADER_INCLUDED
24 
25 #include <opm/common/ErrorMacros.hpp>
26 #include <opm/simulators/flow/rescoup/ReservoirCouplingEnabled.hpp>
27 
28 #ifdef RESERVOIR_COUPLING_ENABLED
29 #include <opm/input/eclipse/Schedule/ResCoup/ReservoirCouplingInfo.hpp>
30 #include <opm/input/eclipse/Schedule/ResCoup/MasterGroup.hpp>
31 #include <opm/input/eclipse/Schedule/ResCoup/Slaves.hpp>
32 #include <opm/simulators/flow/rescoup/ReservoirCouplingMaster.hpp>
33 #include <opm/simulators/flow/rescoup/ReservoirCouplingSlave.hpp>
34 #include <opm/common/Exceptions.hpp>
35 #endif
36 
37 #include <opm/grid/utility/StopWatch.hpp>
38 
39 #include <opm/simulators/aquifers/BlackoilAquiferModel.hpp>
40 #include <opm/simulators/flow/NonlinearSystemBlackOilReservoir.hpp>
41 #include <opm/simulators/flow/BlackoilModelParameters.hpp>
42 #include <opm/simulators/flow/ConvergenceOutputConfiguration.hpp>
43 #include <opm/simulators/flow/ExtraConvergenceOutputThread.hpp>
44 #include <opm/simulators/flow/NonlinearSolver.hpp>
45 #include <opm/simulators/flow/SimulatorConvergenceOutput.hpp>
46 #include <opm/simulators/flow/SimulatorReportBanners.hpp>
47 #include <opm/simulators/flow/SimulatorSerializer.hpp>
48 #include <opm/simulators/timestepping/AdaptiveTimeStepping.hpp>
49 #include <opm/simulators/timestepping/ConvergenceReport.hpp>
50 #include <opm/simulators/wells/WellState.hpp>
51 
52 #if HAVE_HDF5
53 #include <opm/simulators/utils/HDF5Serializer.hpp>
54 #endif
55 
56 #include <array>
57 #include <memory>
58 #include <string>
59 #include <vector>
60 
61 namespace Opm::Parameters {
62 
63 struct EnableAdaptiveTimeStepping { static constexpr bool value = true; };
64 struct OutputExtraConvergenceInfo { static constexpr auto* value = "none"; };
65 struct SaveStep { static constexpr auto* value = ""; };
66 struct SaveFile { static constexpr auto* value = ""; };
67 struct LoadFile { static constexpr auto* value = ""; };
68 struct LoadStep { static constexpr int value = -1; };
69 struct Slave { static constexpr bool value = false; };
70 
71 } // namespace Opm::Parameters
72 
73 namespace Opm::detail {
74 
75 void registerSimulatorParameters();
76 
80 void logTuning(const Tuning& tuning);
81 
82 }
83 
84 namespace Opm {
85 
112 template<class TypeTag>
114 {
115 protected:
116  struct MPI_Comm_Deleter;
117 public:
122  using BlackoilIndices = GetPropType<TypeTag, Properties::Indices>;
126  using MaterialLawParams = GetPropType<TypeTag, Properties::MaterialLawParams>;
130 
132  static constexpr bool enablePolymer = getPropValue<TypeTag, Properties::EnablePolymer>();
133  using PolymerModule = BlackOilPolymerModule<TypeTag, enablePolymer>;
134  static constexpr bool enableBioeffects = getPropValue<TypeTag, Properties::EnableBioeffects>();
135  using BioeffectsModule = BlackOilBioeffectsModule<TypeTag, enableBioeffects>;
136 
138  using ModelParameters = typename Model::ModelParameters;
139  using SolverParameters = typename Solver::SolverParameters;
141 
151  explicit SimulatorFullyImplicit(Simulator& simulator);
152 
154  ~SimulatorFullyImplicit() override;
155 
166  static void registerParameters();
167 
168 #ifdef RESERVOIR_COUPLING_ENABLED
169 
181  SimulatorReport run(SimulatorTimer& timer, int argc, char** argv);
182 
194  bool checkRunningAsReservoirCouplingMaster();
195 
209  void init(const SimulatorTimer& timer, int argc, char** argv);
210 #else
211 
220 
229  void init(const SimulatorTimer& timer);
230 #endif
231 
245  void updateTUNING(const Tuning& tuning);
246 
254  void updateTUNINGDP(const TuningDp& tuning_dp);
255 
273  bool runStep(SimulatorTimer& timer);
274 
283 
284  const Grid& grid() const { return simulator_.vanguard().grid(); }
285 
289  template<class Serializer>
290  void serializeOp(Serializer& serializer);
291 
292  const Model& model() const { return solver_->model(); }
293 
294 protected:
296  void loadState(HDF5Serializer& serializer, const std::string& groupName) override;
297 
299  void saveState(HDF5Serializer& serializer, const std::string& groupName) const override;
300 
303  std::array<std::string,5> getHeader() const override;
304 
306  const std::vector<int>& getCellMapping() const override {
307  return simulator_.vanguard().globalCell();
308  }
309 
318  std::unique_ptr<Solver> createSolver(WellModel& wellModel);
319 
320  const EclipseState& eclState() const { return simulator_.vanguard().eclState(); }
321 
322  const Schedule& schedule() const { return simulator_.vanguard().schedule(); }
323 
324  bool isRestart() const { return eclState().getInitConfig().restartRequested(); }
325 
326  WellModel& wellModel_() { return simulator_.problem().wellModel(); }
327 
328  const WellModel& wellModel_() const { return simulator_.problem().wellModel(); }
329 
330 #ifdef RESERVOIR_COUPLING_ENABLED
331 
342  void handleSlaveTerminated_();
343 #endif
344 
346  Simulator& simulator_;
347 
349  ModelParameters modelParam_;
350 
352  SolverParameters solverParam_;
353 
355  std::unique_ptr<Solver> solver_;
356 
359 
362 
364  std::unique_ptr<time::StopWatch> solverTimer_;
365 
367  std::unique_ptr<time::StopWatch> totalTimer_;
368 
370  std::unique_ptr<TimeStepper> adaptiveTimeStepping_;
371 
374 
375 #ifdef RESERVOIR_COUPLING_ENABLED
376  bool slaveMode_{false};
378 
380  std::unique_ptr<ReservoirCouplingMaster<Scalar>> reservoirCouplingMaster_{nullptr};
381 
383  std::unique_ptr<ReservoirCouplingSlave<Scalar>> reservoirCouplingSlave_{nullptr};
384 #endif
385 
388 };
389 
390 } // namespace Opm
391 
392 #include <opm/simulators/flow/SimulatorFullyImplicit_impl.hpp>
393 
394 #endif // OPM_SIMULATOR_FULLY_IMPLICIT_HEADER_INCLUDED
A nonlinear solver class suitable for general fully-implicit models, as well as pressure, transport and sequential models.
Definition: NonlinearSolver.hpp:96
Definition: SimulatorFullyImplicit.hpp:63
Definition: SimulatorFullyImplicit.hpp:65
Definition: alignedallocator.hh:32
Definition: SimulatorFullyImplicit.hpp:64
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
std::unique_ptr< Solver > solver_
Built lazily on the first runStep call; reused thereafter.
Definition: SimulatorFullyImplicit.hpp:355
void updateTUNINGDP(const TuningDp &tuning_dp)
Apply a TUNINGDP keyword to the cached model parameters.
Definition: SimulatorFullyImplicit_impl.hpp:256
Top-level driver for a fully implicit flow simulation.
Definition: SimulatorFullyImplicit.hpp:113
std::unique_ptr< TimeStepper > adaptiveTimeStepping_
Set iff adaptive time stepping is enabled.
Definition: SimulatorFullyImplicit.hpp:370
Definition: NonlinearSolver.hpp:79
SimulatorSerializer serializer_
OPMRST save / load.
Definition: SimulatorFullyImplicit.hpp:387
SimulatorConvergenceOutput convergence_output_
Background thread for INFOSTEP / INFOITER files.
Definition: SimulatorFullyImplicit.hpp:373
bool runStep(SimulatorTimer &timer)
Advance the simulation by one report step.
Definition: SimulatorFullyImplicit_impl.hpp:279
Definition: SimulatorFullyImplicit.hpp:67
Adaptive time-stepping coordinator for the black-oil simulator.
Definition: AdaptiveTimeStepping.hpp:92
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
Definition: blackoilnewtonmethodparams.hpp:31
std::unique_ptr< time::StopWatch > totalTimer_
Wall-clock for the entire simulation.
Definition: SimulatorFullyImplicit.hpp:367
Class for (de-)serializing using HDF5.
Definition: HDF5Serializer.hpp:37
Definition: SimulatorFullyImplicit.hpp:68
Definition: SimulatorFullyImplicit.hpp:69
Simulator & simulator_
Surrounding eWoms simulator; observed, not owned.
Definition: SimulatorFullyImplicit.hpp:346
SolverParameters solverParam_
Cached nonlinear-solver parameters.
Definition: SimulatorFullyImplicit.hpp:352
SimulatorReport run(SimulatorTimer &timer)
Run the entire simulation to completion.
Definition: SimulatorFullyImplicit_impl.hpp:109
Class handling convergence history output for a simulator.
Definition: SimulatorConvergenceOutput.hpp:43
bool terminalOutput_
Emit high-level progress to std::cout (rank 0 only).
Definition: SimulatorFullyImplicit.hpp:358
std::unique_ptr< Solver > createSolver(WellModel &wellModel)
Build the Solver used during the current report step.
Definition: SimulatorFullyImplicit_impl.hpp:600
void saveState(HDF5Serializer &serializer, const std::string &groupName) const override
Save this simulator&#39;s data block to an OPMRST file via HDF5.
Definition: SimulatorFullyImplicit_impl.hpp:575
const std::vector< int > & getCellMapping() const override
Local-to-global cell index mapping.
Definition: SimulatorFullyImplicit.hpp:306
~SimulatorFullyImplicit() override
Ends the convergence-output thread cleanly on all ranks.
Definition: SimulatorFullyImplicit_impl.hpp:78
Class handling simulator serialization.
Definition: SimulatorSerializer.hpp:55
std::unique_ptr< time::StopWatch > solverTimer_
Wall-clock for the current report step&#39;s solve.
Definition: SimulatorFullyImplicit.hpp:364
ModelParameters modelParam_
Cached model parameters; mutated by TUNING / TUNINGDP application.
Definition: SimulatorFullyImplicit.hpp:349
std::array< std::string, 5 > getHeader() const override
Return the OPMRST header tuple: product name, module version, compile timestamp, deck case name...
Definition: SimulatorFullyImplicit_impl.hpp:586
SimulatorReport report_
Aggregated report across the entire simulation.
Definition: SimulatorFullyImplicit.hpp:361
SimulatorFullyImplicit(Simulator &simulator)
Construct from the surrounding eWoms Simulator.
Definition: SimulatorFullyImplicit_impl.hpp:46
Definition: SimulatorFullyImplicit.hpp:66
static void registerParameters()
Register all parameters consumed by this class and its major collaborators.
Definition: SimulatorFullyImplicit_impl.hpp:87
void updateTUNING(const Tuning &tuning)
Apply a TUNING keyword to the cached model parameters.
Definition: SimulatorFullyImplicit_impl.hpp:240
void serializeOp(Serializer &serializer)
Serialize the parts of this class needed for OPMRST round-tripping (the surrounding simulator state...
Definition: SimulatorFullyImplicit_impl.hpp:554
Definition: SimulatorReport.hpp:121
void loadState(HDF5Serializer &serializer, const std::string &groupName) override
Load this simulator&#39;s data block from an OPMRST file via HDF5.
Definition: SimulatorFullyImplicit_impl.hpp:564
Definition: SimulatorTimer.hpp:38
Abstract interface for simulator serialization ops.
Definition: SimulatorSerializer.hpp:36
SimulatorReport finalize()
Stop the timers and emit the final OPMRST output.
Definition: SimulatorFullyImplicit_impl.hpp:531
void init(const SimulatorTimer &timer)
One-shot setup performed before the first runStep.
Definition: SimulatorFullyImplicit_impl.hpp:204