This commit is contained in:
Håkon Hægland 2025-02-14 15:55:49 +00:00 committed by GitHub
commit 86f7de1301
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 77 additions and 124 deletions

View File

@ -13,6 +13,7 @@
#include <opm/models/utils/basicproperties.hh> #include <opm/models/utils/basicproperties.hh>
#include <opm/models/utils/propertysystem.hh> #include <opm/models/utils/propertysystem.hh>
#include <opm/simulators/flow/NonlinearSolver.hpp>
#include <opm/simulators/timestepping/AdaptiveSimulatorTimer.hpp> #include <opm/simulators/timestepping/AdaptiveSimulatorTimer.hpp>
#include <opm/simulators/timestepping/SimulatorReport.hpp> #include <opm/simulators/timestepping/SimulatorReport.hpp>
#include <opm/simulators/timestepping/SimulatorTimer.hpp> #include <opm/simulators/timestepping/SimulatorTimer.hpp>
@ -79,8 +80,11 @@ template<class TypeTag>
class AdaptiveTimeStepping class AdaptiveTimeStepping
{ {
private: private:
using Model = GetPropType<TypeTag, Properties::Model>;
using Scalar = GetPropType<TypeTag, Properties::Scalar>; using Scalar = GetPropType<TypeTag, Properties::Scalar>;
template <class Solver> using Solver = NonlinearSolver<TypeTag, Model>;
using Simulator = GetPropType<TypeTag, Properties::Simulator>;
class SolutionTimeErrorSolverWrapper : public RelativeChangeInterface class SolutionTimeErrorSolverWrapper : public RelativeChangeInterface
{ {
public: public:
@ -91,25 +95,21 @@ private:
const Solver& solver_; const Solver& solver_;
}; };
// Forward declaration of SubStepIteration class SubStepIteration;
// TODO: This forward declaration is not enough for GCC version 9.4.0 (released June 2021),
// but it works fine with GCC version 13.2.0 (released July 2023).
template <class Solver> class SubStepIteration;
template <class Solver>
class SubStepper { class SubStepper {
public: public:
SubStepper( SubStepper(
AdaptiveTimeStepping<TypeTag>& adaptive_time_stepping, AdaptiveTimeStepping<TypeTag>& adaptive_time_stepping,
Solver &solver,
const SimulatorTimer& simulator_timer, const SimulatorTimer& simulator_timer,
Solver& solver,
const bool is_event, const bool is_event,
const std::function<bool(const double, const double, const int)>& tuning_updater const std::function<bool(const double, const double, const int)>& tuning_updater
); );
AdaptiveTimeStepping<TypeTag>& getAdaptiveTimerStepper(); AdaptiveTimeStepping<TypeTag>& getAdaptiveTimerStepper();
SimulatorReport run(); SimulatorReport run();
friend class AdaptiveTimeStepping<TypeTag>::template SubStepIteration<Solver>; friend class AdaptiveTimeStepping<TypeTag>::SubStepIteration;
private: private:
bool isReservoirCouplingMaster_() const; bool isReservoirCouplingMaster_() const;
@ -127,17 +127,17 @@ private:
double suggestedNextTimestep_() const; double suggestedNextTimestep_() const;
AdaptiveTimeStepping<TypeTag>& adaptive_time_stepping_; AdaptiveTimeStepping<TypeTag>& adaptive_time_stepping_;
const SimulatorTimer& simulator_timer_;
Solver& solver_; Solver& solver_;
const SimulatorTimer& simulator_timer_;
const bool is_event_; const bool is_event_;
const std::function<bool(double elapsed, double dt, int sub_step_number)>& tuning_updater_; const std::function<bool(double elapsed, double dt, int sub_step_number)>& tuning_updater_;
Simulator& simulator_;
}; };
template <class Solver>
class SubStepIteration { class SubStepIteration {
public: public:
SubStepIteration( SubStepIteration(
SubStepper<Solver>& substepper, SubStepper& substepper,
AdaptiveSimulatorTimer& substep_timer, AdaptiveSimulatorTimer& substep_timer,
const double original_time_step, const double original_time_step,
const bool final_step const bool final_step
@ -179,7 +179,7 @@ private:
bool useNewtonIteration_() const; bool useNewtonIteration_() const;
double writeOutput_() const; double writeOutput_() const;
SubStepper<Solver>& substepper_; SubStepper& substepper_;
AdaptiveSimulatorTimer& substep_timer_; AdaptiveSimulatorTimer& substep_timer_;
const double original_time_step_; const double original_time_step_;
const bool final_step_; const bool final_step_;
@ -209,10 +209,10 @@ public:
void setReservoirCouplingMaster(ReservoirCouplingMaster *reservoir_coupling_master); void setReservoirCouplingMaster(ReservoirCouplingMaster *reservoir_coupling_master);
void setReservoirCouplingSlave(ReservoirCouplingSlave *reservoir_coupling_slave); void setReservoirCouplingSlave(ReservoirCouplingSlave *reservoir_coupling_slave);
#endif #endif
void setSuggestedNextStep(const double x); void setSuggestedNextStep(const double x);
double suggestedNextStep() const; double suggestedNextStep() const;
template <class Solver>
SimulatorReport step(const SimulatorTimer& simulator_timer, SimulatorReport step(const SimulatorTimer& simulator_timer,
Solver& solver, Solver& solver,
const bool is_event, const bool is_event,

View File

@ -189,13 +189,13 @@ setReservoirCouplingSlave(ReservoirCouplingSlave *reservoir_coupling_slave)
} }
#endif #endif
/** \brief step method that acts like the solver::step method /** \brief step method that acts like the solver::step method
in a sub cycle of time steps in a sub cycle of time steps
\param tuningUpdater Function used to update TUNING parameters before each \param tuningUpdater Function used to update TUNING parameters before each
time step. ACTIONX might change tuning. time step. ACTIONX might change tuning.
*/ */
template<class TypeTag> template<class TypeTag>
template <class Solver>
SimulatorReport SimulatorReport
AdaptiveTimeStepping<TypeTag>:: AdaptiveTimeStepping<TypeTag>::
step(const SimulatorTimer& simulator_timer, step(const SimulatorTimer& simulator_timer,
@ -207,8 +207,8 @@ step(const SimulatorTimer& simulator_timer,
)> tuning_updater )> tuning_updater
) )
{ {
SubStepper<Solver> sub_stepper{ SubStepper sub_stepper{
*this, simulator_timer, solver, is_event, tuning_updater, *this, solver, simulator_timer, is_event, tuning_updater,
}; };
return sub_stepper.run(); return sub_stepper.run();
} }
@ -426,12 +426,11 @@ init_(const UnitSystem& unitSystem)
************************************************/ ************************************************/
template<class TypeTag> template<class TypeTag>
template<class Solver> AdaptiveTimeStepping<TypeTag>::SubStepper::
AdaptiveTimeStepping<TypeTag>::SubStepper<Solver>::
SubStepper( SubStepper(
AdaptiveTimeStepping<TypeTag>& adaptive_time_stepping, AdaptiveTimeStepping<TypeTag>& adaptive_time_stepping,
const SimulatorTimer& simulator_timer,
Solver& solver, Solver& solver,
const SimulatorTimer& simulator_timer,
const bool is_event, const bool is_event,
const std::function<bool(const double /*current_time*/, const std::function<bool(const double /*current_time*/,
const double /*dt*/, const double /*dt*/,
@ -440,26 +439,25 @@ SubStepper(
) )
: adaptive_time_stepping_{adaptive_time_stepping} : adaptive_time_stepping_{adaptive_time_stepping}
, simulator_timer_{simulator_timer}
, solver_{solver} , solver_{solver}
, simulator_timer_{simulator_timer}
, is_event_{is_event} , is_event_{is_event}
, tuning_updater_{tuning_updater} , tuning_updater_{tuning_updater}
, simulator_{solver.model().simulator()}
{ {
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
AdaptiveTimeStepping<TypeTag>& AdaptiveTimeStepping<TypeTag>&
AdaptiveTimeStepping<TypeTag>::SubStepper<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepper::
getAdaptiveTimerStepper() getAdaptiveTimerStepper()
{ {
return adaptive_time_stepping_; return adaptive_time_stepping_;
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
SimulatorReport SimulatorReport
AdaptiveTimeStepping<TypeTag>::SubStepper<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepper::
run() run()
{ {
#ifdef RESERVOIR_COUPLING_ENABLED #ifdef RESERVOIR_COUPLING_ENABLED
@ -483,27 +481,24 @@ run()
template<class TypeTag> template<class TypeTag>
template<class Solver>
bool bool
AdaptiveTimeStepping<TypeTag>::SubStepper<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepper::
isReservoirCouplingMaster_() const isReservoirCouplingMaster_() const
{ {
return this->adaptive_time_stepping_.reservoir_coupling_master_ != nullptr; return this->simulator_.reservoirCouplingMaster() != nullptr;
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
bool bool
AdaptiveTimeStepping<TypeTag>::SubStepper<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepper::
isReservoirCouplingSlave_() const isReservoirCouplingSlave_() const
{ {
return this->adaptive_time_stepping_.reservoir_coupling_slave_ != nullptr; return this->simulator_.reservoirCouplingSlave() != nullptr;
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
void void
AdaptiveTimeStepping<TypeTag>::SubStepper<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepper::
maybeModifySuggestedTimeStepAtBeginningOfReportStep_(const double original_time_step) maybeModifySuggestedTimeStepAtBeginningOfReportStep_(const double original_time_step)
{ {
this->adaptive_time_stepping_.maybeModifySuggestedTimeStepAtBeginningOfReportStep_( this->adaptive_time_stepping_.maybeModifySuggestedTimeStepAtBeginningOfReportStep_(
@ -515,27 +510,24 @@ maybeModifySuggestedTimeStepAtBeginningOfReportStep_(const double original_time_
// It has to be called for each substep since TUNING might have been changed for next sub step due // It has to be called for each substep since TUNING might have been changed for next sub step due
// to ACTIONX (via NEXTSTEP) or WCYCLE keywords. // to ACTIONX (via NEXTSTEP) or WCYCLE keywords.
template<class TypeTag> template<class TypeTag>
template<class Solver>
bool bool
AdaptiveTimeStepping<TypeTag>::SubStepper<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepper::
maybeUpdateTuning_(double elapsed, double dt, int sub_step_number) const maybeUpdateTuning_(double elapsed, double dt, int sub_step_number) const
{ {
return this->tuning_updater_(elapsed, dt, sub_step_number); return this->tuning_updater_(elapsed, dt, sub_step_number);
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
double double
AdaptiveTimeStepping<TypeTag>::SubStepper<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepper::
maxTimeStep_() const maxTimeStep_() const
{ {
return this->adaptive_time_stepping_.max_time_step_; return this->adaptive_time_stepping_.max_time_step_;
} }
template <class TypeTag> template <class TypeTag>
template <class Solver>
SimulatorReport SimulatorReport
AdaptiveTimeStepping<TypeTag>::SubStepper<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepper::
runStepOriginal_() runStepOriginal_()
{ {
auto elapsed = this->simulator_timer_.simulationTimeElapsed(); auto elapsed = this->simulator_timer_.simulationTimeElapsed();
@ -552,29 +544,27 @@ runStepOriginal_()
report_step, report_step,
maxTimeStep_() maxTimeStep_()
}; };
SubStepIteration<Solver> substepIteration{*this, substep_timer, original_time_step, /*final_step=*/true}; SubStepIteration substepIteration{*this, substep_timer, original_time_step, /*final_step=*/true};
return substepIteration.run(); return substepIteration.run();
} }
#ifdef RESERVOIR_COUPLING_ENABLED #ifdef RESERVOIR_COUPLING_ENABLED
template <class TypeTag> template <class TypeTag>
template <class Solver>
ReservoirCouplingMaster& ReservoirCouplingMaster&
AdaptiveTimeStepping<TypeTag>::SubStepper<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepper::
reservoirCouplingMaster_() reservoirCouplingMaster_()
{ {
return *adaptive_time_stepping_.reservoir_coupling_master_; return *(this->simulator_.reservoirCouplingMaster());
} }
#endif #endif
#ifdef RESERVOIR_COUPLING_ENABLED #ifdef RESERVOIR_COUPLING_ENABLED
template <class TypeTag> template <class TypeTag>
template <class Solver>
ReservoirCouplingSlave& ReservoirCouplingSlave&
AdaptiveTimeStepping<TypeTag>::SubStepper<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepper::
reservoirCouplingSlave_() reservoirCouplingSlave_()
{ {
return *this->adaptive_time_stepping_.reservoir_coupling_slave_; return *(this->simulator_.reservoirCouplingSlave());
} }
#endif #endif
@ -610,9 +600,8 @@ reservoirCouplingSlave_()
// report step. // report step.
template <class TypeTag> template <class TypeTag>
template <class Solver>
SimulatorReport SimulatorReport
AdaptiveTimeStepping<TypeTag>::SubStepper<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepper::
runStepReservoirCouplingMaster_() runStepReservoirCouplingMaster_()
{ {
bool substep_done = false; bool substep_done = false;
@ -644,7 +633,7 @@ runStepReservoirCouplingMaster_()
bool final_step = ReservoirCoupling::Seconds::compare_gt_or_eq( bool final_step = ReservoirCoupling::Seconds::compare_gt_or_eq(
current_time + current_step_length, step_end_time current_time + current_step_length, step_end_time
); );
SubStepIteration<Solver> substepIteration{*this, substep_timer, current_step_length, final_step}; SubStepIteration substepIteration{*this, substep_timer, current_step_length, final_step};
auto sub_steps_report = substepIteration.run(); auto sub_steps_report = substepIteration.run();
report += sub_steps_report; report += sub_steps_report;
current_time += current_step_length; current_time += current_step_length;
@ -659,9 +648,8 @@ runStepReservoirCouplingMaster_()
#ifdef RESERVOIR_COUPLING_ENABLED #ifdef RESERVOIR_COUPLING_ENABLED
template <class TypeTag> template <class TypeTag>
template <class Solver>
SimulatorReport SimulatorReport
AdaptiveTimeStepping<TypeTag>::SubStepper<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepper::
runStepReservoirCouplingSlave_() runStepReservoirCouplingSlave_()
{ {
bool substep_done = false; bool substep_done = false;
@ -688,7 +676,7 @@ runStepReservoirCouplingSlave_()
bool final_step = ReservoirCoupling::Seconds::compare_gt_or_eq( bool final_step = ReservoirCoupling::Seconds::compare_gt_or_eq(
current_time + timestep, step_end_time current_time + timestep, step_end_time
); );
SubStepIteration<Solver> substepIteration{*this, substep_timer, timestep, final_step}; SubStepIteration substepIteration{*this, substep_timer, timestep, final_step};
auto sub_steps_report = substepIteration.run(); auto sub_steps_report = substepIteration.run();
report += sub_steps_report; report += sub_steps_report;
current_time += timestep; current_time += timestep;
@ -704,9 +692,8 @@ runStepReservoirCouplingSlave_()
#endif #endif
template <class TypeTag> template <class TypeTag>
template <class Solver>
double double
AdaptiveTimeStepping<TypeTag>::SubStepper<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepper::
suggestedNextTimestep_() const suggestedNextTimestep_() const
{ {
return this->adaptive_time_stepping_.suggestedNextStep(); return this->adaptive_time_stepping_.suggestedNextStep();
@ -719,10 +706,9 @@ suggestedNextTimestep_() const
************************************************/ ************************************************/
template<class TypeTag> template<class TypeTag>
template<class Solver> AdaptiveTimeStepping<TypeTag>::SubStepIteration::
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>::
SubStepIteration( SubStepIteration(
SubStepper<Solver>& substepper, SubStepper& substepper,
AdaptiveSimulatorTimer& substep_timer, AdaptiveSimulatorTimer& substep_timer,
const double original_time_step, const double original_time_step,
bool final_step bool final_step
@ -736,9 +722,8 @@ SubStepIteration(
} }
template <class TypeTag> template <class TypeTag>
template <class Solver>
SimulatorReport SimulatorReport
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
run() run()
{ {
auto& simulator = solver_().model().simulator(); auto& simulator = solver_().model().simulator();
@ -824,9 +809,8 @@ run()
template<class TypeTag> template<class TypeTag>
template<class Solver>
bool bool
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
checkContinueOnUnconvergedSolution_(double dt) const checkContinueOnUnconvergedSolution_(double dt) const
{ {
bool continue_on_uncoverged_solution = ignoreConvergenceFailure_() && dt <= minTimeStep_(); bool continue_on_uncoverged_solution = ignoreConvergenceFailure_() && dt <= minTimeStep_();
@ -843,9 +827,8 @@ checkContinueOnUnconvergedSolution_(double dt) const
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
void void
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
checkTimeStepMaxRestartLimit_(const int restarts) const checkTimeStepMaxRestartLimit_(const int restarts) const
{ {
// If we have restarted (i.e. cut the timestep) too // If we have restarted (i.e. cut the timestep) too
@ -863,9 +846,8 @@ checkTimeStepMaxRestartLimit_(const int restarts) const
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
void void
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
checkTimeStepMinLimit_(const int new_time_step) const checkTimeStepMinLimit_(const int new_time_step) const
{ {
// If we have restarted (i.e. cut the timestep) too // If we have restarted (i.e. cut the timestep) too
@ -885,9 +867,8 @@ checkTimeStepMinLimit_(const int new_time_step) const
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
void void
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
chopTimeStep_(const double new_time_step) chopTimeStep_(const double new_time_step)
{ {
setTimeStep_(new_time_step); setTimeStep_(new_time_step);
@ -900,9 +881,8 @@ chopTimeStep_(const double new_time_step)
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
bool bool
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
chopTimeStepOrCloseFailingWells_(const int new_time_step) chopTimeStepOrCloseFailingWells_(const int new_time_step)
{ {
bool wells_shut = false; bool wells_shut = false;
@ -956,18 +936,16 @@ chopTimeStepOrCloseFailingWells_(const int new_time_step)
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
boost::posix_time::ptime boost::posix_time::ptime
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
currentDateTime_() const currentDateTime_() const
{ {
return simulatorTimer_().currentDateTime(); return simulatorTimer_().currentDateTime();
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
int int
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
getNumIterations_(const SimulatorReportSingle &substep_report) const getNumIterations_(const SimulatorReportSingle &substep_report) const
{ {
if (useNewtonIteration_()) { if (useNewtonIteration_()) {
@ -979,36 +957,32 @@ getNumIterations_(const SimulatorReportSingle &substep_report) const
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
double double
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
growthFactor_() const growthFactor_() const
{ {
return this->adaptive_time_stepping_.growth_factor_; return this->adaptive_time_stepping_.growth_factor_;
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
bool bool
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
ignoreConvergenceFailure_() const ignoreConvergenceFailure_() const
{ {
return adaptive_time_stepping_.ignore_convergence_failure_; return adaptive_time_stepping_.ignore_convergence_failure_;
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
double double
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
maxGrowth_() const maxGrowth_() const
{ {
return this->adaptive_time_stepping_.max_growth_; return this->adaptive_time_stepping_.max_growth_;
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
void void
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
maybeReportSubStep_(SimulatorReportSingle substep_report) const maybeReportSubStep_(SimulatorReportSingle substep_report) const
{ {
if (timeStepVerbose_()) { if (timeStepVerbose_()) {
@ -1019,9 +993,8 @@ maybeReportSubStep_(SimulatorReportSingle substep_report) const
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
double double
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
maybeRestrictTimeStepGrowth_(const double dt, double dt_estimate, const int restarts) const maybeRestrictTimeStepGrowth_(const double dt, double dt_estimate, const int restarts) const
{ {
// limit the growth of the timestep size by the growth factor // limit the growth of the timestep size by the growth factor
@ -1039,9 +1012,8 @@ maybeRestrictTimeStepGrowth_(const double dt, double dt_estimate, const int rest
// It has to be called for each substep since TUNING might have been changed for next sub step due // It has to be called for each substep since TUNING might have been changed for next sub step due
// to ACTIONX (via NEXTSTEP) or WCYCLE keywords. // to ACTIONX (via NEXTSTEP) or WCYCLE keywords.
template<class TypeTag> template<class TypeTag>
template<class Solver>
void void
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
maybeUpdateTuningAndTimeStep_() maybeUpdateTuningAndTimeStep_()
{ {
// TODO: This function is currently only called if NEXTSTEP is activated from ACTIONX or // TODO: This function is currently only called if NEXTSTEP is activated from ACTIONX or
@ -1066,36 +1038,32 @@ maybeUpdateTuningAndTimeStep_()
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
double double
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
minTimeStepBeforeClosingWells_() const minTimeStepBeforeClosingWells_() const
{ {
return this->adaptive_time_stepping_.min_time_step_before_shutting_problematic_wells_; return this->adaptive_time_stepping_.min_time_step_before_shutting_problematic_wells_;
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
double double
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
minTimeStep_() const minTimeStep_() const
{ {
return this->adaptive_time_stepping_.min_time_step_; return this->adaptive_time_stepping_.min_time_step_;
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
double double
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
restartFactor_() const restartFactor_() const
{ {
return this->adaptive_time_stepping_.restart_factor_; return this->adaptive_time_stepping_.restart_factor_;
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
SimulatorReportSingle SimulatorReportSingle
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
runSubStep_() runSubStep_()
{ {
SimulatorReportSingle substep_report; SimulatorReportSingle substep_report;
@ -1147,18 +1115,16 @@ runSubStep_()
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
void void
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
setTimeStep_(double dt_estimate) setTimeStep_(double dt_estimate)
{ {
this->substep_timer_.provideTimeStepEstimate(dt_estimate); this->substep_timer_.provideTimeStepEstimate(dt_estimate);
} }
template<class TypeTag> template<class TypeTag>
template<class Solver> typename AdaptiveTimeStepping<TypeTag>::Solver&
Solver& AdaptiveTimeStepping<TypeTag>::SubStepIteration::
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>::
solver_() const solver_() const
{ {
return this->substepper_.solver_; return this->substepper_.solver_;
@ -1166,75 +1132,67 @@ solver_() const
template<class TypeTag> template<class TypeTag>
template<class Solver>
int int
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
solverRestartMax_() const solverRestartMax_() const
{ {
return this->adaptive_time_stepping_.solver_restart_max_; return this->adaptive_time_stepping_.solver_restart_max_;
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
void void
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
setSuggestedNextStep_(double step) setSuggestedNextStep_(double step)
{ {
this->adaptive_time_stepping_.setSuggestedNextStep(step); this->adaptive_time_stepping_.setSuggestedNextStep(step);
} }
template <class TypeTag> template <class TypeTag>
template <class Solver>
const SimulatorTimer& const SimulatorTimer&
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
simulatorTimer_() const simulatorTimer_() const
{ {
return this->substepper_.simulator_timer_; return this->substepper_.simulator_timer_;
} }
template <class TypeTag> template <class TypeTag>
template <class Solver>
bool bool
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
solverVerbose_() const solverVerbose_() const
{ {
return this->adaptive_time_stepping_.solver_verbose_; return this->adaptive_time_stepping_.solver_verbose_;
} }
template<class TypeTag> template<class TypeTag>
template<class Solver>
boost::posix_time::ptime boost::posix_time::ptime
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
startDateTime_() const startDateTime_() const
{ {
return simulatorTimer_().startDateTime(); return simulatorTimer_().startDateTime();
} }
template <class TypeTag> template <class TypeTag>
template <class Solver>
double double
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
suggestedNextTimestep_() const suggestedNextTimestep_() const
{ {
return this->adaptive_time_stepping_.suggestedNextStep(); return this->adaptive_time_stepping_.suggestedNextStep();
} }
template <class TypeTag> template <class TypeTag>
template <class Solver>
double double
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
timeStepControlComputeEstimate_(const double dt, const int iterations, double elapsed) const timeStepControlComputeEstimate_(const double dt, const int iterations, double elapsed) const
{ {
// create object to compute the time error, simply forwards the call to the model // create object to compute the time error, simply forwards the call to the model
SolutionTimeErrorSolverWrapper<Solver> relative_change{solver_()}; SolutionTimeErrorSolverWrapper relative_change{solver_()};
return this->adaptive_time_stepping_.time_step_control_->computeTimeStepSize( return this->adaptive_time_stepping_.time_step_control_->computeTimeStepSize(
dt, iterations, relative_change, elapsed); dt, iterations, relative_change, elapsed);
} }
template <class TypeTag> template <class TypeTag>
template <class Solver>
bool bool
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
timeStepVerbose_() const timeStepVerbose_() const
{ {
return this->adaptive_time_stepping_.timestep_verbose_; return this->adaptive_time_stepping_.timestep_verbose_;
@ -1248,9 +1206,8 @@ timeStepVerbose_() const
// (and the begginning of each report step). Note that the WCYCLE keyword can also update the // (and the begginning of each report step). Note that the WCYCLE keyword can also update the
// suggested time step via the maybeUpdateTuning_() method. // suggested time step via the maybeUpdateTuning_() method.
template <class TypeTag> template <class TypeTag>
template <class Solver>
void void
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
updateSuggestedNextStep_() updateSuggestedNextStep_()
{ {
auto suggested_next_step = this->substep_timer_.currentStepLength(); auto suggested_next_step = this->substep_timer_.currentStepLength();
@ -1268,18 +1225,16 @@ updateSuggestedNextStep_()
} }
template <class TypeTag> template <class TypeTag>
template <class Solver>
bool bool
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
useNewtonIteration_() const useNewtonIteration_() const
{ {
return this->adaptive_time_stepping_.use_newton_iteration_; return this->adaptive_time_stepping_.use_newton_iteration_;
} }
template <class TypeTag> template <class TypeTag>
template <class Solver>
double double
AdaptiveTimeStepping<TypeTag>::SubStepIteration<Solver>:: AdaptiveTimeStepping<TypeTag>::SubStepIteration::
writeOutput_() const writeOutput_() const
{ {
time::StopWatch perf_timer; time::StopWatch perf_timer;
@ -1294,16 +1249,14 @@ writeOutput_() const
* **********************************************/ * **********************************************/
template<class TypeTag> template<class TypeTag>
template<class Solver> AdaptiveTimeStepping<TypeTag>::SolutionTimeErrorSolverWrapper::SolutionTimeErrorSolverWrapper(
AdaptiveTimeStepping<TypeTag>::SolutionTimeErrorSolverWrapper<Solver>::SolutionTimeErrorSolverWrapper(
const Solver& solver const Solver& solver
) )
: solver_{solver} : solver_{solver}
{} {}
template<class TypeTag> template<class TypeTag>
template<class Solver> double AdaptiveTimeStepping<TypeTag>::SolutionTimeErrorSolverWrapper::relativeChange() const
double AdaptiveTimeStepping<TypeTag>::SolutionTimeErrorSolverWrapper<Solver>::relativeChange() const
{ {
// returns: || u^n+1 - u^n || / || u^n+1 || // returns: || u^n+1 - u^n || / || u^n+1 ||
return solver_.model().relativeChange(); return solver_.model().relativeChange();