20 double const t_initial,
double const t_end,
double const min_dt,
21 double const max_dt,
double const initial_dt,
23 std::vector<int>&& iter_times_vector,
24 std::vector<double>&& multiplier_vector,
25 std::vector<double>
const& fixed_times_for_output)
38 OGS_FATAL(
"Vector of iteration numbers must not be empty.");
43 "Vector of iteration numbers must be of the same size as the "
44 "vector of multipliers.");
49 OGS_FATAL(
"Vector of iteration numbers must be sorted.");
54 int const number_iterations,
62 ts_previous = ts_current;
75 if (std::abs(dt - ts_current.
dt()) < std::numeric_limits<double>::epsilon())
95 int const number_iterations,
bool const current_time_step_is_accepted,
96 std::vector<int>
const& nonlinear_iteration_numbers,
97 std::vector<double>
const& multipliers,
100 double multiplier = multipliers.front();
101 switch (multiplier_interpolation_type)
106 nonlinear_iteration_numbers, multipliers,
false);
107 multiplier = pwli.getValue(number_iterations);
111 auto const& piecewise_constant_interpolation =
113 nonlinear_iteration_numbers, multipliers);
115 piecewise_constant_interpolation.value(number_iterations);
119 if (!current_time_step_is_accepted && (multiplier >= 1.0))
121 return *std::min_element(multipliers.begin(), multipliers.end());
143 dt = ts_previous.
dt() *
159 auto fixed_output_time_it = std::find_if(
161 [&ts_current](
auto const fixed_output_time)
162 {
return ts_current.
current()() < fixed_output_time; });
168 if (*fixed_output_time_it < ts_current.
current()() + dt)
171 if (std::abs(*fixed_output_time_it - ts_current.
current()()) >
172 std::numeric_limits<double>::epsilon() * ts_current.
current()())
174 return *fixed_output_time_it - ts_current.
current()();
IterationNumberBasedTimeStepping(double const t_initial, double const t_end, double const min_dt, double const max_dt, double const initial_dt, MultiplyerInterpolationType const multiplier_interpolation_type, std::vector< int > &&iter_times_vector, std::vector< double > &&multiplier_vector, std::vector< double > const &fixed_times_for_output)
double next(double solution_error, int number_iterations, NumLib::TimeStep &ts_previous, NumLib::TimeStep &ts_current) override
const MultiplyerInterpolationType _multiplier_interpolation_type
Interpolation type for the multiplier.
std::vector< double > const _fixed_times_for_output
double getNextTimeStepSize(NumLib::TimeStep const &ts_previous, NumLib::TimeStep const &ts_current) const
Calculate the next time step size.
const double _max_dt
The maximum allowed time step size.
const std::vector< double > _multiplier_vector
This vector stores the multiplier coefficients.
const std::vector< int > _iter_times_vector
bool canReduceTimestepSize(NumLib::TimeStep const ×tep_previous, NumLib::TimeStep const ×tep_current) const override
Query the timestepper if further time step size reduction is possible.
int _iter_times
The number of nonlinear iterations.
const double _min_dt
The minimum allowed time step size.
const double _initial_dt
Initial time step size.
const int _max_iter
The maximum allowed iteration number to accept current time step.
TimeStepAlgorithm(const double t0, const double t_end)
void setAccepted(bool const accepted)
Time current() const
return current time step
Time previous() const
return previous time step
double dt() const
time step size from _previous
std::size_t timeStepNumber() const
the time step number
double findMultiplier(int const number_iterations, bool const current_time_step_is_accepted, std::vector< int > const &nonlinear_iteration_numbers, std::vector< double > const &multipliers, MultiplyerInterpolationType const multiplier_interpolation_type)
Find a multiplier for the given number of iterations.
bool canReduceTimestepSize(TimeStep const ×tep_previous, TimeStep const ×tep_current, double const min_dt)
MultiplyerInterpolationType