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>;
83 using AquiferModel = GetPropType<TypeTag, Properties::EclAquiferModel>;
86 typedef BlackOilPolymerModule<TypeTag> PolymerModule;
87 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 ebosSimulator_.model().invalidateAndUpdateIntensiveQuantities(0);
154 while (!timer.
done()) {
155 bool continue_looping = runStep(timer);
156 if (!continue_looping)
break;
163 ebosSimulator_.setEpisodeIndex(-1);
166 solverTimer_ = std::make_unique<time::StopWatch>();
167 totalTimer_ = std::make_unique<time::StopWatch>();
168 totalTimer_->start();
171 bool enableAdaptive = EWOMS_GET_PARAM(TypeTag,
bool, EnableAdaptiveTimeStepping);
172 bool enableTUNING = EWOMS_GET_PARAM(TypeTag,
bool, EnableTuning);
173 if (enableAdaptive) {
174 const UnitSystem& unitSystem = this->ebosSimulator_.vanguard().eclState().getUnits();
177 auto max_next_tstep = sched_state.max_next_tstep();
178 adaptiveTimeStepping_ = std::make_unique<TimeStepper>(max_next_tstep,
179 sched_state.tuning(),
180 unitSystem, terminalOutput_);
183 adaptiveTimeStepping_ = std::make_unique<TimeStepper>(unitSystem, terminalOutput_);
189 adaptiveTimeStepping_->setSuggestedNextStep(ebosSimulator_.timeStepSize());
194 bool runStep(SimulatorTimer& timer)
196 if (schedule().exitStatus().has_value()) {
197 if (terminalOutput_) {
198 OpmLog::info(
"Stopping simulation since EXIT was triggered by an action keyword.");
200 report_.success.exit_status = schedule().exitStatus().value();
205 if (terminalOutput_) {
206 std::ostringstream ss;
208 OpmLog::debug(ss.str());
211 if (terminalOutput_) {
212 outputReportStep(timer);
216 if (timer.initialStep()) {
217 Dune::Timer perfTimer;
220 ebosSimulator_.setEpisodeIndex(-1);
221 ebosSimulator_.setEpisodeLength(0.0);
222 ebosSimulator_.setTimeStepSize(0.0);
223 wellModel_().beginReportStep(timer.currentStepNum());
224 ebosSimulator_.problem().writeOutput();
226 report_.success.output_write_time += perfTimer.stop();
230 solverTimer_->start();
232 auto solver = createSolver(wellModel_());
234 ebosSimulator_.startNextEpisode(
235 ebosSimulator_.startTime()
236 + schedule().seconds(timer.currentStepNum()),
237 timer.currentStepLength());
238 ebosSimulator_.setEpisodeIndex(timer.currentStepNum());
239 solver->model().beginReportStep();
240 bool enableTUNING = EWOMS_GET_PARAM(TypeTag,
bool, EnableTuning);
247 if (adaptiveTimeStepping_) {
248 const auto& events = schedule()[timer.currentStepNum()].events();
250 if (events.hasEvent(ScheduleEvents::TUNING_CHANGE)) {
251 const auto& sched_state = schedule()[timer.currentStepNum()];
252 const auto& tuning = sched_state.tuning();
253 const auto& max_next_tstep = sched_state.max_next_tstep();
254 adaptiveTimeStepping_->updateTUNING(max_next_tstep, tuning);
257 bool event = events.hasEvent(ScheduleEvents::NEW_WELL) ||
258 events.hasEvent(ScheduleEvents::INJECTION_TYPE_CHANGED) ||
259 events.hasEvent(ScheduleEvents::WELL_SWITCHED_INJECTOR_PRODUCER) ||
260 events.hasEvent(ScheduleEvents::WELL_STATUS_CHANGE);
261 auto stepReport = adaptiveTimeStepping_->step(timer, *solver, event,
nullptr);
262 report_ += stepReport;
264 ebosSimulator_.problem().setSimulationReport(report_);
267 auto stepReport = solver->step(timer);
268 report_ += stepReport;
269 if (terminalOutput_) {
270 std::ostringstream ss;
271 stepReport.reportStep(ss);
272 OpmLog::info(ss.str());
277 Dune::Timer perfTimer;
279 const double nextstep = adaptiveTimeStepping_ ? adaptiveTimeStepping_->suggestedNextStep() : -1.0;
280 ebosSimulator_.problem().setNextTimeStepSize(nextstep);
281 ebosSimulator_.problem().writeOutput();
282 report_.success.output_write_time += perfTimer.stop();
284 solver->model().endReportStep();
287 solverTimer_->stop();
290 report_.success.solver_time += solverTimer_->secsSinceStart();
295 if (terminalOutput_) {
296 if (!timer.initialStep()) {
298 outputTimestampFIP(timer, eclState().getTitle(), version);
302 if (terminalOutput_) {
304 "Time step took " + std::to_string(solverTimer_->secsSinceStart()) +
" seconds; "
305 "total solver time " + std::to_string(report_.success.solver_time) +
" seconds.";
311 SimulatorReport finalize()
315 Dune::Timer finalOutputTimer;
316 finalOutputTimer.start();
318 ebosSimulator_.problem().finalizeOutput();
319 report_.success.output_write_time += finalOutputTimer.stop();
324 report_.success.total_time = totalTimer_->secsSinceStart();
325 report_.success.converged =
true;
330 const Grid& grid()
const
331 {
return ebosSimulator_.vanguard().grid(); }
335 std::unique_ptr<Solver> createSolver(WellModel& wellModel)
337 auto model = std::make_unique<Model>(ebosSimulator_,
342 return std::make_unique<Solver>(solverParam_, std::move(model));
345 const EclipseState& eclState()
const
346 {
return ebosSimulator_.vanguard().eclState(); }
349 const Schedule& schedule()
const
350 {
return ebosSimulator_.vanguard().schedule(); }
352 bool isRestart()
const
354 const auto& initconfig = eclState().getInitConfig();
355 return initconfig.restartRequested();
358 WellModel& wellModel_()
359 {
return ebosSimulator_.problem().wellModel(); }
361 const WellModel& wellModel_()
const
362 {
return ebosSimulator_.problem().wellModel(); }
365 Simulator& ebosSimulator_;
366 std::unique_ptr<WellConnectionAuxiliaryModule<TypeTag>> wellAuxMod_;
368 ModelParameters modelParam_;
369 SolverParameters solverParam_;
372 PhaseUsage phaseUsage_;
374 bool terminalOutput_;
376 SimulatorReport report_;
377 std::unique_ptr<time::StopWatch> solverTimer_;
378 std::unique_ptr<time::StopWatch> totalTimer_;
379 std::unique_ptr<TimeStepper> adaptiveTimeStepping_;
Definition: AdaptiveTimeSteppingEbos.hpp:237
A model implementation for three-phase black oil.
Definition: BlackoilModelEbos.hpp:156
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:27
std::string moduleVersionName()
Return the version name of the module, for example "2015.10" (for a release branch) or "2016....
Definition: moduleVersion.cpp:34
PhaseUsage phaseUsageFromDeck(const EclipseState &eclipseState)
Looks at presence of WATER, OIL and GAS keywords in state object to determine active phases.
Definition: phaseUsageFromDeck.cpp:145
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:70