Loading...
Searching...
No Matches
AdaptiveTimeStepping.hpp
/*
*/
#ifndef OPM_ADAPTIVE_TIME_STEPPING_HPP
#define OPM_ADAPTIVE_TIME_STEPPING_HPP
#include <opm/models/utils/basicproperties.hh>
#include <opm/models/utils/propertysystem.hh>
#include <opm/simulators/timestepping/AdaptiveSimulatorTimer.hpp>
#include <opm/simulators/timestepping/SimulatorReport.hpp>
#include <opm/simulators/timestepping/SimulatorTimer.hpp>
#include <opm/simulators/timestepping/TimeStepControl.hpp>
#include <opm/simulators/timestepping/TimeStepControlInterface.hpp>
#if HAVE_MPI
#define RESERVOIR_COUPLING_ENABLED
#endif
#ifdef RESERVOIR_COUPLING_ENABLED
#include <opm/simulators/flow/ReservoirCoupling.hpp>
#include <opm/simulators/flow/ReservoirCouplingMaster.hpp>
#include <opm/simulators/flow/ReservoirCouplingSlave.hpp>
#endif
#include <functional>
#include <memory>
#include <set>
#include <string>
#include <tuple>
#include <vector>
namespace Opm::Parameters {
struct SolverContinueOnConvergenceFailure { static constexpr bool value = false; };
struct SolverMaxRestarts { static constexpr int value = 10; };
struct SolverVerbosity { static constexpr int value = 1; };
struct TimeStepVerbosity { static constexpr int value = 1; };
struct InitialTimeStepInDays { static constexpr double value = 1.0; };
struct FullTimeStepInitially { static constexpr bool value = false; };
struct TimeStepControl { static constexpr auto value = "pid+newtoniteration"; };
struct TimeStepControlTolerance { static constexpr double value = 1e-1; };
struct TimeStepControlTargetIterations { static constexpr int value = 30; };
struct TimeStepControlTargetNewtonIterations { static constexpr int value = 8; };
struct TimeStepControlDecayRate { static constexpr double value = 0.75; };
struct TimeStepControlGrowthRate { static constexpr double value = 1.25; };
struct TimeStepControlDecayDampingFactor { static constexpr double value = 1.0; };
struct TimeStepControlGrowthDampingFactor { static constexpr double value = 3.2; };
struct TimeStepControlFileName { static constexpr auto value = "timesteps"; };
struct MinTimeStepBeforeShuttingProblematicWellsInDays { static constexpr double value = 0.01; };
struct MinTimeStepBasedOnNewtonIterations { static constexpr double value = 0.0; };
struct TimeStepControlSafetyFactor { static constexpr double value = 0.8; };
struct TimeStepControlRejectCompletedStep { static constexpr bool value = false; };
struct TimeStepControlToleranceTestVersion { static constexpr auto value = "standard"; };
struct TimeStepControlMaxReductionTimeStep { static constexpr double value = 0.1; };
struct TimeStepControlParameters { static constexpr auto value = "0.125;0.25;0.125;0.75;0.25"; };
} // namespace Opm::Parameters
namespace Opm {
struct Tuning;
class UnitSystem;
struct StepReport;
namespace detail {
void logTimer(const AdaptiveSimulatorTimer& substep_timer);
std::set<std::string>
consistentlyFailingWells(const std::vector<StepReport>& sr,
bool requireRepeatedFailures);
void registerAdaptiveParameters();
std::tuple<TimeStepControlType, std::unique_ptr<TimeStepControlInterface>, bool>
createController(const UnitSystem& unitSystem);
}
template<class TypeTag>
class AdaptiveTimeStepping
{
public:
using TuningUpdateCallback = std::function<bool(const double, const double, const int)>;
private:
using Scalar = GetPropType<TypeTag, Properties::Scalar>;
template <class Solver>
class SolutionTimeErrorSolverWrapper : public RelativeChangeInterface
{
public:
explicit SolutionTimeErrorSolverWrapper(const Solver& solver);
double relativeChange() const;
private:
const Solver& solver_;
};
// Forward declaration of SubStepIteration
template <class Solver> class SubStepIteration;
template <class Solver>
class SubStepper {
public:
SubStepper(AdaptiveTimeStepping<TypeTag>& adaptive_time_stepping,
const SimulatorTimer& simulator_timer,
Solver& solver,
const bool is_event,
const TuningUpdateCallback& tuning_updater);
AdaptiveTimeStepping<TypeTag>& getAdaptiveTimerStepper();
SimulatorReport run();
friend class SubStepIteration<Solver>;
private:
bool isReservoirCouplingMaster_() const;
bool isReservoirCouplingSlave_() const;
void maybeModifySuggestedTimeStepAtBeginningOfReportStep_(const double originalTimeStep);
bool maybeUpdateTuning_(double elapsed, double dt, int sub_step_number) const;
double maxTimeStep_() const;
SimulatorReport runStepOriginal_();
#ifdef RESERVOIR_COUPLING_ENABLED
ReservoirCouplingMaster& reservoirCouplingMaster_();
ReservoirCouplingSlave& reservoirCouplingSlave_();
SimulatorReport runStepReservoirCouplingMaster_();
SimulatorReport runStepReservoirCouplingSlave_();
#endif
double suggestedNextTimestep_() const;
AdaptiveTimeStepping<TypeTag>& adaptive_time_stepping_;
const SimulatorTimer& simulator_timer_;
Solver& solver_;
const bool is_event_;
const TuningUpdateCallback& tuning_updater_;
};
template <class Solver>
class SubStepIteration {
public:
SubStepIteration(SubStepper<Solver>& substepper,
AdaptiveSimulatorTimer& substep_timer,
const double original_time_step,
const bool final_step);
SimulatorReport run();
private:
bool checkContinueOnUnconvergedSolution_(double dt) const;
void checkTimeStepMaxRestartLimit_(const int restarts) const;
void checkTimeStepMinLimit_(const double new_time_step) const;
void chopTimeStep_(const double new_time_step);
bool chopTimeStepOrCloseFailingWells_(const double new_time_step);
boost::posix_time::ptime currentDateTime_() const;
int getNumIterations_(const SimulatorReportSingle& substep_report) const;
double growthFactor_() const;
bool ignoreConvergenceFailure_() const;
void maybeReportSubStep_(SimulatorReportSingle substep_report) const;
double maybeRestrictTimeStepGrowth_(const double dt,
double dt_estimate,
const int restarts) const;
void maybeUpdateTuningAndTimeStep_();
double maxGrowth_() const;
double minTimeStepBeforeClosingWells_() const;
double minTimeStep_() const;
double restartFactor_() const;
SimulatorReportSingle runSubStep_();
int solverRestartMax_() const;
double suggestedNextTimestep_() const;
void setSuggestedNextStep_(double step);
void setTimeStep_(double dt_estimate);
Solver& solver_() const;
bool solverVerbose_() const;
const SimulatorTimer& simulatorTimer_() const;
boost::posix_time::ptime startDateTime_() const;
double timeStepControlComputeEstimate_(const double dt,
const int iterations,
const AdaptiveSimulatorTimer& substepTimer) const;
bool timeStepVerbose_() const;
void updateSuggestedNextStep_();
bool useNewtonIteration_() const;
double writeOutput_() const;
SubStepper<Solver>& substepper_;
AdaptiveSimulatorTimer& substep_timer_;
const double original_time_step_;
const bool final_step_;
std::string cause_of_failure_;
AdaptiveTimeStepping<TypeTag>& adaptive_time_stepping_;
};
public:
AdaptiveTimeStepping() = default;
AdaptiveTimeStepping(const UnitSystem& unitSystem,
const SimulatorReport& full_report,
const double max_next_tstep = -1.0,
const bool terminalOutput = true);
AdaptiveTimeStepping(double max_next_tstep,
const Tuning& tuning,
const UnitSystem& unitSystem,
const SimulatorReport& full_report,
const bool terminalOutput = true);
bool operator==(const AdaptiveTimeStepping<TypeTag>& rhs);
static void registerParameters();
void setSuggestedNextStep(const double x);
double suggestedNextStep() const;
const TimeStepControlInterface& timeStepControl() const;
template <class Solver>
SimulatorReport step(const SimulatorTimer& simulator_timer,
Solver& solver,
const bool is_event,
const TuningUpdateCallback& tuning_updater);
void updateTUNING(double max_next_tstep, const Tuning& tuning);
void updateNEXTSTEP(double max_next_tstep);
template<class Serializer>
void serializeOp(Serializer& serializer);
SimulatorReport& report();
static AdaptiveTimeStepping<TypeTag> serializationTestObjectHardcoded();
static AdaptiveTimeStepping<TypeTag> serializationTestObjectPID();
static AdaptiveTimeStepping<TypeTag> serializationTestObjectPIDIt();
static AdaptiveTimeStepping<TypeTag> serializationTestObjectSimple();
static AdaptiveTimeStepping<TypeTag> serializationTestObject3rdOrder();
private:
void maybeModifySuggestedTimeStepAtBeginningOfReportStep_(const double original_time_step,
const bool is_event);
template<class Controller>
static AdaptiveTimeStepping<TypeTag> serializationTestObject_();
template<class T, class Serializer>
void allocAndSerialize(Serializer& serializer);
template<class T>
bool castAndComp(const AdaptiveTimeStepping<TypeTag>& Rhs) const;
protected:
void init_(const UnitSystem& unitSystem);
using TimeStepController = std::unique_ptr<TimeStepControlInterface>;
TimeStepControlType time_step_control_type_{TimeStepControlType::PIDAndIterationCount};
TimeStepController time_step_control_{};
double restart_factor_{};
double growth_factor_{};
double max_growth_{};
double max_time_step_{};
double min_time_step_{};
bool ignore_convergence_failure_{false};
int solver_restart_max_{};
bool solver_verbose_{false};
bool timestep_verbose_{false};
double suggested_next_timestep_{};
bool full_timestep_initially_{false};
double timestep_after_event_{};
bool use_newton_iteration_{false};
double min_time_step_before_shutting_problematic_wells_{};
// We store a copy of the full simulator run report for output purposes,
// so it can be updated and passed to the summary writing code every
// substep (not just every report step).
SimulatorReport report_{};
};
} // namespace Opm
#include <opm/simulators/timestepping/AdaptiveTimeStepping_impl.hpp>
#endif // OPM_ADAPTIVE_TIME_STEPPING_HPP
basicproperties.hh
Defines a type tags and some fundamental properties all models.
Opm::AdaptiveSimulatorTimer
Simulation timer for adaptive time stepping.
Definition AdaptiveSimulatorTimer.hpp:41
Opm::AdaptiveTimeStepping::max_growth_
double max_growth_
factor that limits the maximum growth of a time step
Definition AdaptiveTimeStepping.hpp:252
Opm::AdaptiveTimeStepping::max_time_step_
double max_time_step_
maximal allowed time step size in days
Definition AdaptiveTimeStepping.hpp:253
Opm::AdaptiveTimeStepping::solver_verbose_
bool solver_verbose_
solver verbosity
Definition AdaptiveTimeStepping.hpp:257
Opm::AdaptiveTimeStepping::solver_restart_max_
int solver_restart_max_
how many restart of solver are allowed
Definition AdaptiveTimeStepping.hpp:256
Opm::AdaptiveTimeStepping::timestep_after_event_
double timestep_after_event_
suggested size of timestep after an event
Definition AdaptiveTimeStepping.hpp:261
Opm::AdaptiveTimeStepping::ignore_convergence_failure_
bool ignore_convergence_failure_
continue instead of stop when minimum time step is reached
Definition AdaptiveTimeStepping.hpp:255
Opm::AdaptiveTimeStepping::suggested_next_timestep_
double suggested_next_timestep_
suggested size of next timestep
Definition AdaptiveTimeStepping.hpp:259
Opm::AdaptiveTimeStepping::time_step_control_type_
TimeStepControlType time_step_control_type_
type of time step control object
Definition AdaptiveTimeStepping.hpp:248
Opm::AdaptiveTimeStepping::full_timestep_initially_
bool full_timestep_initially_
beginning with the size of the time step from data file
Definition AdaptiveTimeStepping.hpp:260
Opm::AdaptiveTimeStepping::step
SimulatorReport step(const SimulatorTimer &simulator_timer, Solver &solver, const bool is_event, const TuningUpdateCallback &tuning_updater)
step method that acts like the solver::step method in a sub cycle of time steps
Definition AdaptiveTimeStepping_impl.hpp:202
Opm::AdaptiveTimeStepping::growth_factor_
double growth_factor_
factor to multiply time step when solver recovered from failed convergence
Definition AdaptiveTimeStepping.hpp:251
Opm::AdaptiveTimeStepping::restart_factor_
double restart_factor_
factor to multiply time step with when solver fails to converge
Definition AdaptiveTimeStepping.hpp:250
Opm::AdaptiveTimeStepping::min_time_step_
double min_time_step_
minimal allowed time step size before throwing
Definition AdaptiveTimeStepping.hpp:254
Opm::AdaptiveTimeStepping::time_step_control_
TimeStepController time_step_control_
time step control object
Definition AdaptiveTimeStepping.hpp:249
Opm::AdaptiveTimeStepping::min_time_step_before_shutting_problematic_wells_
double min_time_step_before_shutting_problematic_wells_
< shut problematic wells when time step size in days are less than this
Definition AdaptiveTimeStepping.hpp:265
Opm::AdaptiveTimeStepping::timestep_verbose_
bool timestep_verbose_
timestep verbosity
Definition AdaptiveTimeStepping.hpp:258
Opm::AdaptiveTimeStepping::use_newton_iteration_
bool use_newton_iteration_
use newton iteration count for adaptive time step control
Definition AdaptiveTimeStepping.hpp:262
Opm::RelativeChangeInterface
RelativeChangeInterface.
Definition TimeStepControlInterface.hpp:34
Opm::RelativeChangeInterface::relativeChange
virtual double relativeChange() const =0
Opm::ReservoirCouplingMaster
Definition ReservoirCouplingMaster.hpp:35
Opm::ReservoirCouplingSlave
Definition ReservoirCouplingSlave.hpp:35
Opm::SimulatorTimer
Definition SimulatorTimer.hpp:39
Opm::TimeStepControlInterface
TimeStepControlInterface.
Definition TimeStepControlInterface.hpp:51
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
Opm::GetPropType
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
propertysystem.hh
The Opm property system, traits with inheritance.
Opm::Parameters::FullTimeStepInitially
Definition AdaptiveTimeStepping.hpp:38
Opm::Parameters::InitialTimeStepInDays
Definition AdaptiveTimeStepping.hpp:37
Opm::Parameters::MinTimeStepBasedOnNewtonIterations
Definition AdaptiveTimeStepping.hpp:49
Opm::Parameters::MinTimeStepBeforeShuttingProblematicWellsInDays
Definition AdaptiveTimeStepping.hpp:48
Opm::Parameters::SolverContinueOnConvergenceFailure
Definition AdaptiveTimeStepping.hpp:33
Opm::Parameters::SolverMaxRestarts
Definition AdaptiveTimeStepping.hpp:34
Opm::Parameters::SolverVerbosity
Definition AdaptiveTimeStepping.hpp:35
Opm::Parameters::TimeStepControlDecayDampingFactor
Definition AdaptiveTimeStepping.hpp:45
Opm::Parameters::TimeStepControlDecayRate
Definition AdaptiveTimeStepping.hpp:43
Opm::Parameters::TimeStepControlFileName
Definition AdaptiveTimeStepping.hpp:47
Opm::Parameters::TimeStepControlGrowthDampingFactor
Definition AdaptiveTimeStepping.hpp:46
Opm::Parameters::TimeStepControlGrowthRate
Definition AdaptiveTimeStepping.hpp:44
Opm::Parameters::TimeStepControlMaxReductionTimeStep
Definition AdaptiveTimeStepping.hpp:53
Opm::Parameters::TimeStepControlParameters
Definition AdaptiveTimeStepping.hpp:54
Opm::Parameters::TimeStepControlRejectCompletedStep
Definition AdaptiveTimeStepping.hpp:51
Opm::Parameters::TimeStepControlSafetyFactor
Definition AdaptiveTimeStepping.hpp:50
Opm::Parameters::TimeStepControlTargetIterations
Definition AdaptiveTimeStepping.hpp:41
Opm::Parameters::TimeStepControlTargetNewtonIterations
Definition AdaptiveTimeStepping.hpp:42
Opm::Parameters::TimeStepControlToleranceTestVersion
Definition AdaptiveTimeStepping.hpp:52
Opm::Parameters::TimeStepControlTolerance
Definition AdaptiveTimeStepping.hpp:40
Opm::Parameters::TimeStepControl
Definition AdaptiveTimeStepping.hpp:39
Opm::Parameters::TimeStepVerbosity
Definition AdaptiveTimeStepping.hpp:36
Opm::SimulatorReportSingle
A struct for returning timing data from a simulator to its caller.
Definition SimulatorReport.hpp:34
Opm::SimulatorReport
Definition SimulatorReport.hpp:122
Opm::StepReport
Definition ConvergenceReport.hpp:460