20#ifndef OPM_ADAPTIVE_TIME_STEPPING_IMPL_HPP
21#define OPM_ADAPTIVE_TIME_STEPPING_IMPL_HPP
24#ifndef OPM_ADAPTIVE_TIME_STEPPING_HPP
26#include <opm/simulators/timestepping/AdaptiveTimeStepping.hpp>
27#include <opm/simulators/timestepping/AdaptiveSimulatorTimer.hpp>
30#include <dune/common/timer.hh>
31#include <dune/istl/istlexception.hh>
33#include <opm/common/Exceptions.hpp>
34#include <opm/common/ErrorMacros.hpp>
35#include <opm/common/OpmLog/OpmLog.hpp>
37#include <opm/grid/utility/StopWatch.hpp>
39#include <opm/input/eclipse/Schedule/Tuning.hpp>
41#include <opm/input/eclipse/Units/Units.hpp>
42#include <opm/input/eclipse/Units/UnitSystem.hpp>
46#include <opm/simulators/timestepping/EclTimeSteppingParams.hpp>
54#include <boost/date_time/posix_time/posix_time.hpp>
55#include <fmt/format.h>
56#include <fmt/ranges.h>
64template<
class TypeTag>
65AdaptiveTimeStepping<TypeTag>::
66AdaptiveTimeStepping(
const UnitSystem& unit_system,
68 const double max_next_tstep,
69 const bool terminal_output
72 ,
restart_factor_{Parameters::Get<Parameters::SolverRestartFactor<Scalar>>()}
73 ,
growth_factor_{Parameters::Get<Parameters::SolverGrowthFactor<Scalar>>()}
74 ,
max_growth_{Parameters::Get<Parameters::SolverMaxGrowth<Scalar>>()}
76 Parameters::Get<Parameters::SolverMaxTimeStepInDays<Scalar>>() * 24 * 60 * 60}
78 unit_system.to_si(UnitSystem::measure::time,
79 Parameters::Get<Parameters::SolverMinTimeStep<Scalar>>())}
81 Parameters::Get<Parameters::SolverContinueOnConvergenceFailure>()}
83 ,
solver_verbose_{Parameters::Get<Parameters::SolverVerbosity>() > 0 && terminal_output}
84 ,
timestep_verbose_{Parameters::Get<Parameters::TimeStepVerbosity>() > 0 && terminal_output}
86 (max_next_tstep <= 0 ? Parameters::Get<Parameters::InitialTimeStepInDays>()
87 : max_next_tstep) * 24 * 60 * 60}
90 Parameters::Get<Parameters::TimeStepAfterEventInDays<Scalar>>() * 24 * 60 * 60}
93 Parameters::Get<Parameters::MinTimeStepBeforeShuttingProblematicWellsInDays>() * unit::day}
105template<
class TypeTag>
106AdaptiveTimeStepping<TypeTag>::
107AdaptiveTimeStepping(
double max_next_tstep,
108 const Tuning& tuning,
109 const UnitSystem& unit_system,
111 const bool terminal_output
121 ,
solver_verbose_{Parameters::Get<Parameters::SolverVerbosity>() > 0 && terminal_output}
122 ,
timestep_verbose_{Parameters::Get<Parameters::TimeStepVerbosity>() > 0 && terminal_output}
124 max_next_tstep <= 0 ? Parameters::Get<Parameters::InitialTimeStepInDays>() * 24 * 60 * 60
130 Parameters::Get<Parameters::MinTimeStepBeforeShuttingProblematicWellsInDays>() * unit::day}
136template<
class TypeTag>
148 switch (this->time_step_control_type_) {
149 case TimeStepControlType::HardCodedTimeStep:
150 result = castAndComp<HardcodedTimeStepControl>(rhs);
152 case TimeStepControlType::PIDAndIterationCount:
153 result = castAndComp<PIDAndIterationCountTimeStepControl>(rhs);
155 case TimeStepControlType::SimpleIterationCount:
156 result = castAndComp<SimpleIterationCountTimeStepControl>(rhs);
158 case TimeStepControlType::PID:
159 result = castAndComp<PIDTimeStepControl>(rhs);
161 case TimeStepControlType::General3rdOrder:
162 result = castAndComp<General3rdOrderController>(rhs);
178 this->min_time_step_before_shutting_problematic_wells_ ==
182template<
class TypeTag>
187 registerEclTimeSteppingParameters<Scalar>();
188 detail::registerAdaptiveParameters();
192template<
class TypeTag>
193template <
class Solver>
201 SubStepper<Solver> sub_stepper{
202 *
this, simulator_timer, solver, is_event, tuning_updater,
204 return sub_stepper.run();
207template<
class TypeTag>
208template<
class Serializer>
213 serializer(this->time_step_control_type_);
214 switch (this->time_step_control_type_) {
215 case TimeStepControlType::HardCodedTimeStep:
216 allocAndSerialize<HardcodedTimeStepControl>(serializer);
218 case TimeStepControlType::PIDAndIterationCount:
219 allocAndSerialize<PIDAndIterationCountTimeStepControl>(serializer);
221 case TimeStepControlType::SimpleIterationCount:
222 allocAndSerialize<SimpleIterationCountTimeStepControl>(serializer);
224 case TimeStepControlType::PID:
225 allocAndSerialize<PIDTimeStepControl>(serializer);
227 case TimeStepControlType::General3rdOrder:
228 allocAndSerialize<General3rdOrderController>(serializer);
231 serializer(this->restart_factor_);
232 serializer(this->growth_factor_);
233 serializer(this->max_growth_);
234 serializer(this->max_time_step_);
235 serializer(this->min_time_step_);
236 serializer(this->ignore_convergence_failure_);
237 serializer(this->solver_restart_max_);
238 serializer(this->solver_verbose_);
239 serializer(this->timestep_verbose_);
240 serializer(this->suggested_next_timestep_);
241 serializer(this->full_timestep_initially_);
242 serializer(this->timestep_after_event_);
243 serializer(this->use_newton_iteration_);
244 serializer(this->min_time_step_before_shutting_problematic_wells_);
247template<
class TypeTag>
255template<
class TypeTag>
260 return serializationTestObject_<HardcodedTimeStepControl>();
263template<
class TypeTag>
268 return serializationTestObject_<PIDTimeStepControl>();
271template<
class TypeTag>
276 return serializationTestObject_<PIDAndIterationCountTimeStepControl>();
279template<
class TypeTag>
284 return serializationTestObject_<SimpleIterationCountTimeStepControl>();
287template<
class TypeTag>
292 return serializationTestObject_<General3rdOrderController>();
296template<
class TypeTag>
304template<
class TypeTag>
312template<
class TypeTag>
317 return *this->time_step_control_;
321template<
class TypeTag>
328 if (max_next_tstep > 0) {
333template<
class TypeTag>
336updateTUNING(
double max_next_tstep,
const Tuning& tuning)
350template<
class TypeTag>
351template<
class T,
class Serializer>
356 if (!serializer.isSerializing()) {
357 this->time_step_control_ = std::make_unique<T>();
359 serializer(*
static_cast<T*
>(this->time_step_control_.get()));
362template<
class TypeTag>
368 const T* lhs =
static_cast<const T*
>(this->time_step_control_.get());
369 const T* rhs =
static_cast<const T*
>(Rhs.time_step_control_.get());
373template<
class TypeTag>
380 if (this->suggested_next_timestep_ < 0) {
381 this->suggested_next_timestep_ = this->restart_factor_ * original_time_step;
384 if (this->full_timestep_initially_) {
385 this->suggested_next_timestep_ = original_time_step;
389 if (is_event && this->timestep_after_event_ > 0) {
390 this->suggested_next_timestep_ = this->timestep_after_event_;
394template<
class TypeTag>
395template<
class Controller>
403 result.growth_factor_ = 2.0;
404 result.max_growth_ = 3.0;
405 result.max_time_step_ = 4.0;
406 result.min_time_step_ = 5.0;
407 result.ignore_convergence_failure_ =
true;
408 result.solver_restart_max_ = 6;
409 result.solver_verbose_ =
true;
410 result.timestep_verbose_ =
true;
411 result.suggested_next_timestep_ = 7.0;
412 result.full_timestep_initially_ =
true;
413 result.use_newton_iteration_ =
true;
414 result.min_time_step_before_shutting_problematic_wells_ = 9.0;
415 result.time_step_control_type_ = Controller::Type;
416 result.time_step_control_ =
417 std::make_unique<Controller>(Controller::serializationTestObject());
426template<
class TypeTag>
428init_(
const UnitSystem& unitSystem)
430 std::tie(time_step_control_type_,
432 use_newton_iteration_) = detail::createController(unitSystem);
434 if (this->growth_factor_ < 1.0) {
435 OPM_THROW(std::runtime_error,
436 "Growth factor cannot be less than 1.");
446template<
class TypeTag>
447template<
class Solver>
453 const TuningUpdateCallback& tuning_updater)
454 : adaptive_time_stepping_{adaptive_time_stepping}
455 , simulator_timer_{simulator_timer}
457 , is_event_{is_event}
458 , tuning_updater_{tuning_updater}
462template<
class TypeTag>
463template<
class Solver>
468 return adaptive_time_stepping_;
471template<
class TypeTag>
472template<
class Solver>
477#ifdef RESERVOIR_COUPLING_ENABLED
478 if (isReservoirCouplingSlave_() && reservoirCouplingSlave_().activated()) {
479 return runStepReservoirCouplingSlave_();
481 else if (isReservoirCouplingMaster_() && reservoirCouplingMaster_().activated()) {
482 return runStepReservoirCouplingMaster_();
485 return runStepOriginal_();
488 return runStepOriginal_();
496#ifdef RESERVOIR_COUPLING_ENABLED
497template<
class TypeTag>
498template<
class Solver>
503 return this->solver_.model().simulator().reservoirCouplingMaster() !=
nullptr;
506template<
class TypeTag>
507template<
class Solver>
512 return this->solver_.model().simulator().reservoirCouplingSlave() !=
nullptr;
516template<
class TypeTag>
517template<
class Solver>
522 this->adaptive_time_stepping_.maybeModifySuggestedTimeStepAtBeginningOfReportStep_(
523 original_time_step, this->is_event_
530template<
class TypeTag>
531template<
class Solver>
536 return this->tuning_updater_(elapsed, substep_length, sub_step_number);
539template<
class TypeTag>
540template<
class Solver>
548template <
class TypeTag>
549template <
class Solver>
554 const auto elapsed = this->simulator_timer_.simulationTimeElapsed();
555 const auto original_time_step = this->simulator_timer_.currentStepLength();
556 const auto report_step = this->simulator_timer_.reportStepNum();
557 maybeUpdateTuning_(elapsed, suggestedNextTimestep_(), 0);
558 maybeModifySuggestedTimeStepAtBeginningOfReportStep_(original_time_step);
561 this->simulator_timer_.startDateTime(),
564 suggestedNextTimestep_(),
568 SubStepIteration<Solver> substepIteration{*
this, substep_timer, original_time_step,
true};
569 return substepIteration.run();
572#ifdef RESERVOIR_COUPLING_ENABLED
573template <
class TypeTag>
574template <
class Solver>
579 return *(this->solver_.model().simulator().reservoirCouplingMaster());
583#ifdef RESERVOIR_COUPLING_ENABLED
584template <
class TypeTag>
585template <
class Solver>
590 return *(this->solver_.model().simulator().reservoirCouplingSlave());
594#ifdef RESERVOIR_COUPLING_ENABLED
625template <
class TypeTag>
626template <
class Solver>
632 const double original_time_step = this->simulator_timer_.currentStepLength();
633 double current_time{this->simulator_timer_.simulationTimeElapsed()};
634 double step_end_time = current_time + original_time_step;
635 auto current_step_length = original_time_step;
636 auto report_step_idx = this->simulator_timer_.currentStepNum();
637 if (report_step_idx == 0 && iteration == 0) {
638 reservoirCouplingMaster_().initTimeStepping();
642 reservoirCouplingMaster_().maybeReceiveActivationHandshakeFromSlaves(current_time);
644 reservoirCouplingMaster_().sendDontTerminateSignalToSlaves();
645 reservoirCouplingMaster_().receiveNextReportDateFromSlaves();
646 bool start_of_report_step = (iteration == 0);
647 if (start_of_report_step) {
648 reservoirCouplingMaster_().initStartOfReportStep(report_step_idx);
650 current_step_length = reservoirCouplingMaster_().maybeChopSubStep(
651 current_step_length, current_time);
652 auto num_active = reservoirCouplingMaster_().numActivatedSlaves();
653 OpmLog::info(fmt::format(
654 "\nChoosing next sync time between master and {} active slave {}: {:.2f} days",
655 num_active, (num_active == 1 ?
"process" :
"processes"),
656 current_step_length / unit::day
658 reservoirCouplingMaster_().sendNextTimeStepToSlaves(current_step_length);
659 if (start_of_report_step) {
660 maybeUpdateTuning_(current_time, suggestedNextTimestep_(), 0);
661 maybeModifySuggestedTimeStepAtBeginningOfReportStep_(current_step_length);
664 this->simulator_timer_.startDateTime(),
667 suggestedNextTimestep_(),
668 this->simulator_timer_.reportStepNum(),
672 current_time + current_step_length, step_end_time
677 reservoirCouplingMaster_().setFirstSubstepOfSyncTimestep(
true);
681 reservoirCouplingMaster_().setNeedsSlaveDataReceive(
true);
682 SubStepIteration<Solver> substepIteration{*
this, substep_timer, current_step_length, final_step};
683 const auto sub_steps_report = substepIteration.run();
684 report += sub_steps_report;
685 current_time += current_step_length;
695#ifdef RESERVOIR_COUPLING_ENABLED
696template <
class TypeTag>
697template <
class Solver>
703 const double original_time_step = this->simulator_timer_.currentStepLength();
704 double current_time{this->simulator_timer_.simulationTimeElapsed()};
705 double step_end_time = current_time + original_time_step;
707 auto report_step_idx = this->simulator_timer_.currentStepNum();
708 if (report_step_idx == 0 && iteration == 0) {
709 reservoirCouplingSlave_().initTimeStepping();
712 bool start_of_report_step = (iteration == 0);
713 if (reservoirCouplingSlave_().maybeReceiveTerminateSignalFromMaster()) {
717 reservoirCouplingSlave_().sendNextReportDateToMasterProcess();
718 const auto timestep = reservoirCouplingSlave_().receiveNextTimeStepFromMaster();
719 if (start_of_report_step) {
720 maybeUpdateTuning_(current_time, suggestedNextTimestep_(), 0);
721 maybeModifySuggestedTimeStepAtBeginningOfReportStep_(timestep);
724 this->simulator_timer_.startDateTime(),
727 suggestedNextTimestep_(),
728 this->simulator_timer_.reportStepNum(),
732 current_time + timestep, step_end_time
737 reservoirCouplingSlave_().setFirstSubstepOfSyncTimestep(
true);
738 SubStepIteration<Solver> substepIteration{*
this, substep_timer, timestep, final_step};
739 const auto sub_steps_report = substepIteration.run();
740 report += sub_steps_report;
741 current_time += timestep;
752template <
class TypeTag>
753template <
class Solver>
767template<
class TypeTag>
768template<
class Solver>
772 const double original_time_step,
774 : substepper_{substepper}
775 , substep_timer_{substep_timer}
776 , original_time_step_{original_time_step}
777 , final_step_{final_step}
778 , adaptive_time_stepping_{substepper.getAdaptiveTimerStepper()}
782template <
class TypeTag>
783template <
class Solver>
788 auto& simulator = solver_().model().simulator();
789 auto& problem = simulator.problem();
795 while (!this->substep_timer_.done()) {
799 maybeUpdateTuningAndTimeStep_();
801 const double dt = this->substep_timer_.currentStepLength();
802 if (timeStepVerbose_()) {
803 detail::logTimer(this->substep_timer_);
806 maybeUpdateLastSubstepOfSyncTimestep_(dt);
807 auto substep_report = runSubStep_();
808 markFirstSubStepAsFinished_();
810 if (substep_report.converged || checkContinueOnUnconvergedSolution_(dt)) {
811 Dune::Timer perfTimer;
814 problem.setSubStepReport(substep_report);
815 auto& full_report = adaptive_time_stepping_.report();
816 full_report += substep_report;
817 problem.setSimulationReport(full_report);
818 problem.endTimeStep();
819 substep_report.pre_post_time += perfTimer.stop();
821 report += substep_report;
823 ++this->substep_timer_;
825 const int iterations = getNumIterations_(substep_report);
826 auto dt_estimate = timeStepControlComputeEstimate_(
827 dt, iterations, this->substep_timer_);
829 assert(dt_estimate > 0);
830 dt_estimate = maybeRestrictTimeStepGrowth_(dt, dt_estimate, restarts);
833 maybeReportSubStep_(substep_report);
834 if (this->final_step_ && this->substep_timer_.done()) {
839 report.success.output_write_time += writeOutput_();
843 setTimeStep_(dt_estimate);
845 report.success.converged = this->substep_timer_.done();
846 this->substep_timer_.setLastStepFailed(
false);
849 report += substep_report;
850 this->substep_timer_.setLastStepFailed(
true);
851 checkTimeStepMaxRestartLimit_(restarts);
853 double new_time_step = restartFactor_() * dt;
854 if (substep_report.time_step_rejected) {
857 const double temp_time_step = std::sqrt(safetyFactor * tol / solver_().model().relativeChange()) * dt;
858 if (temp_time_step < dt) {
859 new_time_step = temp_time_step;
862 checkTimeStepMinLimit_(new_time_step);
863 bool wells_shut =
false;
864 if (new_time_step > minTimeStepBeforeClosingWells_()) {
865 chopTimeStep_(new_time_step);
867 wells_shut = chopTimeStepOrCloseFailingWells_(new_time_step);
876 problem.setNextTimeStepSize(this->substep_timer_.currentStepLength());
878 updateSuggestedNextStep_();
888template<
class TypeTag>
889template<
class Solver>
894 const bool continue_on_uncoverged_solution = ignoreConvergenceFailure_() && dt <= minTimeStep_();
895 if (continue_on_uncoverged_solution && solverVerbose_()) {
897 const auto msg = fmt::format(
898 "Solver failed to converge but timestep {} is smaller or equal to {}\n"
899 "which is the minimum threshold given by option --solver-min-time-step\n",
902 OpmLog::problem(msg);
904 return continue_on_uncoverged_solution;
907template<
class TypeTag>
908template<
class Solver>
915 if (restarts >= solverRestartMax_()) {
916 const auto msg = fmt::format(
917 fmt::runtime(
"Solver failed to converge after cutting timestep {} times."), restarts
919 if (solverVerbose_()) {
923 throw TimeSteppingBreakdown{msg};
927template<
class TypeTag>
928template<
class Solver>
933 using Meas = UnitSystem::measure;
936 if (new_time_step < minTimeStep_()) {
937 std::string msg =
"Solver failed to converge after cutting timestep to ";
939 const UnitSystem& unit_system = solver_().model().simulator().vanguard().eclState().getDeckUnitSystem();
941 "{:.3E} {}\nwhich is the minimum threshold given by the TUNING keyword\n",
942 unit_system.from_si(Meas::time, minTimeStep_()),
943 unit_system.name(Meas::time)
948 "{:.3E} DAYS\nwhich is the minimum threshold given by option --solver-min-time-step\n",
949 minTimeStep_() / 86400.0
952 if (solverVerbose_()) {
956 throw TimeSteppingBreakdown{msg};
960template<
class TypeTag>
961template<
class Solver>
966 setTimeStep_(new_time_step);
967 if (solverVerbose_()) {
968 const auto msg = fmt::format(fmt::runtime(
"{}\nTimestep chopped to {} days\n"),
969 this->cause_of_failure_,
970 unit::convert::to(this->substep_timer_.currentStepLength(), unit::day));
971 OpmLog::problem(msg);
975template<
class TypeTag>
976template<
class Solver>
981 bool wells_shut =
false;
988 const bool requireRepeatedFailures =
989 new_time_step > (minTimeStepBeforeClosingWells_() * restartFactor_() * restartFactor_());
990 const std::set<std::string> failing_wells =
991 detail::consistentlyFailingWells(solver_().model().stepReports(), requireRepeatedFailures);
993 if (failing_wells.empty()) {
995 chopTimeStep_(new_time_step);
998 std::vector<std::string> shut_wells;
999 for (
const auto& well : failing_wells) {
1000 const bool was_shut =
1001 solver_().model().wellModel().forceShutWellByName(well,
1002 this->substep_timer_.simulationTimeElapsed(),
1005 shut_wells.push_back(well);
1009 if (shut_wells.empty()) {
1010 for (
const auto& well : failing_wells) {
1011 const bool was_shut =
1012 solver_().model().wellModel().forceShutWellByName(well,
1013 this->substep_timer_.simulationTimeElapsed(),
1016 shut_wells.push_back(well);
1021 if (shut_wells.empty()) {
1022 chopTimeStep_(new_time_step);
1025 if (solverVerbose_()) {
1026 const std::string msg =
1027 fmt::format(fmt::runtime(
"\nProblematic well(s) were shut: {}"
1028 "(retrying timestep)\n"),
1029 fmt::join(shut_wells,
" "));
1030 OpmLog::problem(msg);
1037template<
class TypeTag>
1038template<
class Solver>
1039boost::posix_time::ptime
1043 return simulatorTimer_().currentDateTime();
1046template<
class TypeTag>
1047template<
class Solver>
1052 if (useNewtonIteration_()) {
1053 return substep_report.total_newton_iterations;
1056 return substep_report.total_linear_iterations;
1060template<
class TypeTag>
1061template<
class Solver>
1069template<
class TypeTag>
1070template<
class Solver>
1078template<
class TypeTag>
1079template<
class Solver>
1084 return this->substepper_.isReservoirCouplingMaster_();
1087template<
class TypeTag>
1088template<
class Solver>
1093 return this->substepper_.isReservoirCouplingSlave_();
1096template<
class TypeTag>
1097template<
class Solver>
1102#ifdef RESERVOIR_COUPLING_ENABLED
1106 if (isReservoirCouplingMaster_()) {
1107 reservoirCouplingMaster_().setFirstSubstepOfSyncTimestep(
false);
1109 else if (isReservoirCouplingSlave_()) {
1110 reservoirCouplingSlave_().setFirstSubstepOfSyncTimestep(
false);
1116template<
class TypeTag>
1117template<
class Solver>
1125template<
class TypeTag>
1126template<
class Solver>
1131 if (timeStepVerbose_()) {
1132 std::ostringstream ss;
1133 substep_report.reportStep(ss);
1134 OpmLog::info(ss.str());
1138template<
class TypeTag>
1139template<
class Solver>
1145 dt_estimate = std::min(dt_estimate,
double(maxGrowth_() * dt));
1146 assert(dt_estimate > 0);
1149 dt_estimate = std::min(growthFactor_() * dt, dt_estimate);
1156template<
class TypeTag>
1157template<
class Solver>
1162#ifdef RESERVOIR_COUPLING_ENABLED
1167 if (isReservoirCouplingSlave_()) {
1169 this->substep_timer_.simulationTimeElapsed() + dt,
1170 this->substep_timer_.totalTime()
1172 reservoirCouplingSlave_().setLastSubstepOfSyncTimestep(is_last);
1180template<
class TypeTag>
1181template<
class Solver>
1192 const auto old_value = suggestedNextTimestep_();
1193 if (this->substepper_.maybeUpdateTuning_(this->substep_timer_.simulationTimeElapsed(),
1194 this->substep_timer_.currentStepLength(),
1195 this->substep_timer_.currentStepNum()))
1202 setTimeStep_(suggestedNextTimestep_());
1203 setSuggestedNextStep_(old_value);
1207template<
class TypeTag>
1208template<
class Solver>
1216template<
class TypeTag>
1217template<
class Solver>
1225#ifdef RESERVOIR_COUPLING_ENABLED
1226template<
class TypeTag>
1227template<
class Solver>
1232 return this->substepper_.reservoirCouplingMaster_();
1235template<
class TypeTag>
1236template<
class Solver>
1241 return this->substepper_.reservoirCouplingSlave_();
1245template<
class TypeTag>
1246template<
class Solver>
1254template<
class TypeTag>
1255template<
class Solver>
1262 auto handleFailure = [
this, &substep_report]
1263 (
const std::string& failure_reason,
const std::exception& e,
bool log_exception =
true)
1265 substep_report = solver_().failureReport();
1266 this->cause_of_failure_ = failure_reason;
1267 if (log_exception && solverVerbose_()) {
1268 OpmLog::debug(std::string(
"Caught Exception: ") + e.what());
1273 substep_report = solver_().step(this->substep_timer_, &this->adaptive_time_stepping_.timeStepControl());
1274 if (solverVerbose_()) {
1276 OpmLog::debug(
"Overall linear iterations used: "
1277 + std::to_string(substep_report.total_linear_iterations));
1280 catch (
const TooManyIterations& e) {
1281 handleFailure(
"Solver convergence failure - Iteration limit reached", e);
1283 catch (
const TimeSteppingBreakdown& e) {
1284 handleFailure(e.what(), e);
1286 catch (
const ConvergenceMonitorFailure& e) {
1287 handleFailure(
"Convergence monitor failure", e,
false);
1289 catch (
const LinearSolverProblem& e) {
1290 handleFailure(
"Linear solver convergence failure", e);
1292 catch (
const NumericalProblem& e) {
1293 handleFailure(
"Solver convergence failure - Numerical problem encountered", e);
1295 catch (
const std::runtime_error& e) {
1296 handleFailure(
"Runtime error encountered", e);
1298 catch (
const Dune::ISTLError& e) {
1299 handleFailure(
"ISTL error - Time step too large", e);
1301 catch (
const Dune::MatrixBlockError& e) {
1302 handleFailure(
"Matrix block error", e);
1305 return substep_report;
1308template<
class TypeTag>
1309template<
class Solver>
1314 this->substep_timer_.provideTimeStepEstimate(dt_estimate);
1317template<
class TypeTag>
1318template<
class Solver>
1323 return this->substepper_.solver_;
1327template<
class TypeTag>
1328template<
class Solver>
1336template<
class TypeTag>
1337template<
class Solver>
1345template <
class TypeTag>
1346template <
class Solver>
1351 return this->substepper_.simulator_timer_;
1354template <
class TypeTag>
1355template <
class Solver>
1363template<
class TypeTag>
1364template<
class Solver>
1365boost::posix_time::ptime
1369 return simulatorTimer_().startDateTime();
1372template <
class TypeTag>
1373template <
class Solver>
1381template <
class TypeTag>
1382template <
class Solver>
1389 const SolutionTimeErrorSolverWrapper<Solver> relative_change{solver_()};
1391 dt, iterations, relative_change, substepTimer);
1394template <
class TypeTag>
1395template <
class Solver>
1410template <
class TypeTag>
1411template <
class Solver>
1416 auto suggested_next_step = this->substep_timer_.currentStepLength();
1417 if (! std::isfinite(suggested_next_step)) {
1418 suggested_next_step = this->original_time_step_;
1420 if (timeStepVerbose_()) {
1421 std::ostringstream ss;
1422 this->substep_timer_.report(ss);
1423 ss <<
"Suggested next step size = "
1424 << unit::convert::to(suggested_next_step, unit::day) <<
" (days)" << std::endl;
1425 OpmLog::debug(ss.str());
1427 setSuggestedNextStep_(suggested_next_step);
1430template <
class TypeTag>
1431template <
class Solver>
1439template <
class TypeTag>
1440template <
class Solver>
1445 time::StopWatch perf_timer;
1447 auto& problem = solver_().model().simulator().problem();
1448 problem.writeOutput(
true);
1449 return perf_timer.secsSinceStart();
1456template<
class TypeTag>
1457template<
class Solver>
1464template<
class TypeTag>
1465template<
class Solver>
1466double AdaptiveTimeStepping<TypeTag>::SolutionTimeErrorSolverWrapper<Solver>::relativeChange()
const
1469 return solver_.model().relativeChange();
Simulation timer for adaptive time stepping.
Definition AdaptiveSimulatorTimer.hpp:41
Adaptive time-stepping coordinator for the black-oil simulator.
Definition AdaptiveTimeStepping.hpp:93
double max_growth_
factor that limits the maximum growth of a time step
Definition AdaptiveTimeStepping.hpp:422
double max_time_step_
maximal allowed time step size in days
Definition AdaptiveTimeStepping.hpp:423
bool solver_verbose_
solver verbosity
Definition AdaptiveTimeStepping.hpp:427
int solver_restart_max_
how many restart of solver are allowed
Definition AdaptiveTimeStepping.hpp:426
double timestep_after_event_
suggested size of timestep after an event
Definition AdaptiveTimeStepping.hpp:431
void setSuggestedNextStep(const double x)
Set the suggested length for the next substep [s].
Definition AdaptiveTimeStepping_impl.hpp:299
double suggestedNextStep() const
Current suggested length for the next substep [s].
Definition AdaptiveTimeStepping_impl.hpp:307
bool ignore_convergence_failure_
continue instead of stop when minimum time step is reached
Definition AdaptiveTimeStepping.hpp:425
void updateTUNING(double max_next_tstep, const Tuning &tuning)
Apply TUNING keyword parameters.
Definition AdaptiveTimeStepping_impl.hpp:336
std::function< bool(double elapsed, double substep_length, int sub_step_number)> TuningUpdateCallback
Callback invoked at the start of each substep to apply TUNING, NEXTSTEP (via ACTIONX),...
Definition AdaptiveTimeStepping.hpp:117
double suggested_next_timestep_
suggested size of next timestep
Definition AdaptiveTimeStepping.hpp:429
TimeStepControlType time_step_control_type_
type of time step control object
Definition AdaptiveTimeStepping.hpp:418
bool full_timestep_initially_
beginning with the size of the time step from data file
Definition AdaptiveTimeStepping.hpp:430
SimulatorReport step(const SimulatorTimer &simulator_timer, Solver &solver, const bool is_event, const TuningUpdateCallback &tuning_updater)
Run one report step by orchestrating adaptive substepping.
Definition AdaptiveTimeStepping_impl.hpp:196
double growth_factor_
factor to multiply time step when solver recovered from failed convergence
Definition AdaptiveTimeStepping.hpp:421
double restart_factor_
factor to multiply time step with when solver fails to converge
Definition AdaptiveTimeStepping.hpp:420
double min_time_step_
minimal allowed time step size before throwing
Definition AdaptiveTimeStepping.hpp:424
void updateNEXTSTEP(double max_next_tstep)
Set suggested_next_timestep_ to max_next_tstep iff max_next_tstep > 0.
Definition AdaptiveTimeStepping_impl.hpp:324
TimeStepController time_step_control_
time step control object
Definition AdaptiveTimeStepping.hpp:419
double min_time_step_before_shutting_problematic_wells_
< shut problematic wells when time step size in days are less than this
Definition AdaptiveTimeStepping.hpp:435
bool timestep_verbose_
timestep verbosity
Definition AdaptiveTimeStepping.hpp:428
bool use_newton_iteration_
use newton iteration count for adaptive time step control
Definition AdaptiveTimeStepping.hpp:432
Definition ReservoirCouplingMaster.hpp:38
Definition ReservoirCouplingSlave.hpp:40
Definition SimulatorTimer.hpp:39
TimeStepControlInterface.
Definition TimeStepControlInterface.hpp:51
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:45
This file provides the infrastructure to retrieve run-time parameters.
auto Get(bool errorIfNotRegistered=true)
Retrieve a runtime parameter.
Definition parametersystem.hpp:187
static bool compare_gt_or_eq(double a, double b)
Determines if a is greater than b within the specified tolerance.
Definition ReservoirCoupling.cpp:179
A struct for returning timing data from a simulator to its caller.
Definition SimulatorReport.hpp:34
Definition SimulatorReport.hpp:122