22 #ifndef OPM_SIMULATORFULLYIMPLICITBLACKOILEBOS_HEADER_INCLUDED
23 #define OPM_SIMULATORFULLYIMPLICITBLACKOILEBOS_HEADER_INCLUDED
25 #include <opm/simulators/flow/NonlinearSolverEbos.hpp>
26 #include <opm/simulators/flow/BlackoilModelEbos.hpp>
27 #include <opm/simulators/flow/BlackoilModelParametersEbos.hpp>
28 #include <opm/simulators/wells/WellState.hpp>
29 #include <opm/simulators/aquifers/BlackoilAquiferModel.hpp>
30 #include <opm/simulators/utils/moduleVersion.hpp>
31 #include <opm/simulators/timestepping/AdaptiveTimeSteppingEbos.hpp>
32 #include <opm/grid/utility/StopWatch.hpp>
34 #include <opm/common/ErrorMacros.hpp>
36 namespace Opm::Properties {
38 template<
class TypeTag,
class MyTypeTag>
40 using type = UndefinedProperty;
42 template<
class TypeTag,
class MyTypeTag>
44 using type = UndefinedProperty;
47 template<
class TypeTag>
49 static constexpr
bool value =
true;
51 template<
class TypeTag>
53 static constexpr
bool value =
true;
55 template<
class TypeTag>
57 static constexpr
bool value =
false;
66 const std::string& title,
67 const std::string& version);
70 template<
class TypeTag>
74 using Simulator = GetPropType<TypeTag, Properties::Simulator>;
75 using Grid = GetPropType<TypeTag, Properties::Grid>;
76 using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
77 using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
78 using BlackoilIndices = GetPropType<TypeTag, Properties::Indices>;
79 using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
80 using MaterialLaw = GetPropType<TypeTag, Properties::MaterialLaw>;
81 using SolutionVector = GetPropType<TypeTag, Properties::SolutionVector>;
82 using MaterialLawParams = GetPropType<TypeTag, Properties::MaterialLawParams>;
85 typedef BlackOilPolymerModule<TypeTag> PolymerModule;
86 typedef BlackOilMICPModule<TypeTag> MICPModule;
118 : ebosSimulator_(ebosSimulator)
123 const auto& comm = grid().comm();
124 terminalOutput_ = EWOMS_GET_PARAM(TypeTag,
bool, EnableTerminalOutput);
125 terminalOutput_ = terminalOutput_ && (comm.rank() == 0);
128 static void registerParameters()
130 ModelParameters::registerParameters();
131 SolverParameters::registerParameters();
132 TimeStepper::registerParameters();
134 EWOMS_REGISTER_PARAM(TypeTag,
bool, EnableTerminalOutput,
135 "Print high-level information about the simulation's progress to the terminal");
136 EWOMS_REGISTER_PARAM(TypeTag,
bool, EnableAdaptiveTimeStepping,
137 "Use adaptive time stepping between report steps");
138 EWOMS_REGISTER_PARAM(TypeTag,
bool, EnableTuning,
139 "Honor some aspects of the TUNING keyword.");
152 while (!timer.
done()) {
153 bool continue_looping = runStep(timer);
154 if (!continue_looping)
break;
161 ebosSimulator_.setEpisodeIndex(-1);
164 solverTimer_ = std::make_unique<time::StopWatch>();
165 totalTimer_ = std::make_unique<time::StopWatch>();
166 totalTimer_->start();
169 bool enableAdaptive = EWOMS_GET_PARAM(TypeTag,
bool, EnableAdaptiveTimeStepping);
170 bool enableTUNING = EWOMS_GET_PARAM(TypeTag,
bool, EnableTuning);
171 if (enableAdaptive) {
172 const UnitSystem& unitSystem = this->ebosSimulator_.vanguard().eclState().getUnits();
174 adaptiveTimeStepping_ = std::make_unique<TimeStepper>(schedule()[timer.
currentStepNum()].tuning(),
175 unitSystem, terminalOutput_);
178 adaptiveTimeStepping_ = std::make_unique<TimeStepper>(unitSystem, terminalOutput_);
184 adaptiveTimeStepping_->setSuggestedNextStep(ebosSimulator_.timeStepSize());
189 bool runStep(SimulatorTimer& timer)
191 if (schedule().exitStatus().has_value()) {
192 if (terminalOutput_) {
193 OpmLog::info(
"Stopping simulation since EXIT was triggered by an action keyword.");
195 report_.success.exit_status = schedule().exitStatus().value();
200 if (terminalOutput_) {
201 std::ostringstream ss;
203 OpmLog::debug(ss.str());
206 if (terminalOutput_) {
207 outputReportStep(timer);
211 if (timer.initialStep()) {
212 Dune::Timer perfTimer;
215 ebosSimulator_.setEpisodeIndex(-1);
216 ebosSimulator_.setEpisodeLength(0.0);
217 ebosSimulator_.setTimeStepSize(0.0);
219 wellModel_().beginReportStep(timer.currentStepNum());
220 ebosSimulator_.problem().writeOutput();
222 report_.success.output_write_time += perfTimer.stop();
226 solverTimer_->start();
228 auto solver = createSolver(wellModel_());
230 ebosSimulator_.startNextEpisode(
231 ebosSimulator_.startTime()
232 + schedule().seconds(timer.currentStepNum()),
233 timer.currentStepLength());
234 ebosSimulator_.setEpisodeIndex(timer.currentStepNum());
235 solver->model().beginReportStep();
236 bool enableTUNING = EWOMS_GET_PARAM(TypeTag,
bool, EnableTuning);
243 if (adaptiveTimeStepping_) {
244 const auto& events = schedule()[timer.currentStepNum()].events();
246 if (events.hasEvent(ScheduleEvents::TUNING_CHANGE)) {
247 adaptiveTimeStepping_->updateTUNING(schedule()[timer.currentStepNum()].tuning());
250 bool event = events.hasEvent(ScheduleEvents::NEW_WELL) ||
251 events.hasEvent(ScheduleEvents::INJECTION_TYPE_CHANGED) ||
252 events.hasEvent(ScheduleEvents::WELL_SWITCHED_INJECTOR_PRODUCER) ||
253 events.hasEvent(ScheduleEvents::WELL_STATUS_CHANGE);
254 auto stepReport = adaptiveTimeStepping_->step(timer, *solver, event,
nullptr);
255 report_ += stepReport;
258 auto stepReport = solver->step(timer);
259 report_ += stepReport;
260 if (terminalOutput_) {
261 std::ostringstream ss;
262 stepReport.reportStep(ss);
263 OpmLog::info(ss.str());
268 Dune::Timer perfTimer;
270 const double nextstep = adaptiveTimeStepping_ ? adaptiveTimeStepping_->suggestedNextStep() : -1.0;
271 ebosSimulator_.problem().setNextTimeStepSize(nextstep);
272 ebosSimulator_.problem().writeOutput();
273 report_.success.output_write_time += perfTimer.stop();
275 solver->model().endReportStep();
278 solverTimer_->stop();
281 report_.success.solver_time += solverTimer_->secsSinceStart();
286 if (terminalOutput_) {
287 if (!timer.initialStep()) {
289 outputTimestampFIP(timer, eclState().getTitle(), version);
293 if (terminalOutput_) {
295 "Time step took " + std::to_string(solverTimer_->secsSinceStart()) +
" seconds; "
296 "total solver time " + std::to_string(report_.success.solver_time) +
" seconds.";
302 SimulatorReport finalize()
306 Dune::Timer finalOutputTimer;
307 finalOutputTimer.start();
309 ebosSimulator_.problem().finalizeOutput();
310 report_.success.output_write_time += finalOutputTimer.stop();
315 report_.success.total_time = totalTimer_->secsSinceStart();
316 report_.success.converged =
true;
321 const Grid& grid()
const
322 {
return ebosSimulator_.vanguard().grid(); }
326 std::unique_ptr<Solver> createSolver(WellModel& wellModel)
328 auto model = std::make_unique<Model>(ebosSimulator_,
333 return std::make_unique<Solver>(solverParam_, std::move(model));
336 const EclipseState& eclState()
const
337 {
return ebosSimulator_.vanguard().eclState(); }
340 const Schedule& schedule()
const
341 {
return ebosSimulator_.vanguard().schedule(); }
343 bool isRestart()
const
345 const auto& initconfig = eclState().getInitConfig();
346 return initconfig.restartRequested();
349 WellModel& wellModel_()
350 {
return ebosSimulator_.problem().wellModel(); }
352 const WellModel& wellModel_()
const
353 {
return ebosSimulator_.problem().wellModel(); }
356 Simulator& ebosSimulator_;
357 std::unique_ptr<WellConnectionAuxiliaryModule<TypeTag>> wellAuxMod_;
359 ModelParameters modelParam_;
360 SolverParameters solverParam_;
363 PhaseUsage phaseUsage_;
365 bool terminalOutput_;
367 SimulatorReport report_;
368 std::unique_ptr<time::StopWatch> solverTimer_;
369 std::unique_ptr<time::StopWatch> totalTimer_;
370 std::unique_ptr<TimeStepper> adaptiveTimeStepping_;
Definition: AdaptiveTimeSteppingEbos.hpp:237
Class for handling the blackoil well model.
Definition: BlackoilAquiferModel.hpp:81
A model implementation for three-phase black oil.
Definition: BlackoilModelEbos.hpp:154
Class for handling the blackoil well model.
Definition: BlackoilWellModel.hpp:94
A nonlinear solver class suitable for general fully-implicit models, as well as pressure,...
Definition: NonlinearSolverEbos.hpp:89
a simulator for the blackoil model
Definition: SimulatorFullyImplicitBlackoilEbos.hpp:72
SimulatorReport run(SimulatorTimer &timer)
Run the simulation.
Definition: SimulatorFullyImplicitBlackoilEbos.hpp:148
SimulatorFullyImplicitBlackoilEbos(Simulator &ebosSimulator)
Initialise from parameters and objects to observe.
Definition: SimulatorFullyImplicitBlackoilEbos.hpp:117
Definition: SimulatorTimer.hpp:37
int currentStepNum() const override
Current step number.
Definition: SimulatorTimer.cpp:80
bool done() const override
Return true if op++() has been called numSteps() times.
Definition: SimulatorTimer.cpp:153
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:26
std::string moduleVersionName()
Return the version name of the module, for example "2015.10" (for a release branch) or "2016....
Definition: moduleVersion.cpp:29
PhaseUsage phaseUsageFromDeck(const EclipseState &eclipseState)
Looks at presence of WATER, OIL and GAS keywords in state object to determine active phases.
Definition: phaseUsageFromDeck.cpp:141
Solver parameters for the BlackoilModel.
Definition: BlackoilModelParametersEbos.hpp:327
Definition: NonlinearSolverEbos.hpp:101
Definition: SimulatorFullyImplicitBlackoilEbos.hpp:39
Definition: BlackoilWellModel.hpp:82
Definition: SimulatorFullyImplicitBlackoilEbos.hpp:43
Definition: SimulatorReport.hpp:66