28 double const t_initial,
double const t_end,
double const min_dt,
29 double const max_dt,
double const initial_dt,
31 std::vector<int>&& iter_times_vector,
32 std::vector<double>&& multiplier_vector,
33 std::vector<double>
const& fixed_times_for_output)
35 _iter_times_vector(std::move(iter_times_vector)),
36 _multiplier_vector(std::move(multiplier_vector)),
39 _initial_dt(initial_dt),
40 _multiplier_interpolation_type(multiplier_interpolation_type),
41 _max_iter(_iter_times_vector.empty() ? 0 : _iter_times_vector.back()),
42 _fixed_times_for_output(fixed_times_for_output)
46 OGS_FATAL(
"Vector of iteration numbers must not be empty.");
51 "Vector of iteration numbers must be of the same size as the "
52 "vector of multipliers.");
57 OGS_FATAL(
"Vector of iteration numbers must be sorted.");
62 int const number_iterations,
70 ts_previous = ts_current;
83 if (std::abs(dt - ts_current.
dt()) < std::numeric_limits<double>::epsilon())
103 int const number_iterations,
bool const current_time_step_is_accepted,
104 std::vector<int>
const& nonlinear_iteration_numbers,
105 std::vector<double>
const& multipliers,
108 double multiplier = multipliers.front();
109 switch (multiplier_interpolation_type)
114 nonlinear_iteration_numbers, multipliers,
false);
115 multiplier = pwli.getValue(number_iterations);
116 DBUG(
"Using piecewise linear iteration-based time stepping.");
120 DBUG(
"Using piecewise constant iteration-based time stepping.");
121 for (std::size_t i = 0; i < nonlinear_iteration_numbers.size(); i++)
123 if (number_iterations >= nonlinear_iteration_numbers[i])
125 multiplier = multipliers[i];
131 if (!current_time_step_is_accepted && (multiplier >= 1.0))
133 return *std::min_element(multipliers.begin(), multipliers.end());
155 dt = ts_previous.
dt() *
171 auto fixed_output_time_it = std::find_if(
173 [&ts_current](
auto const fixed_output_time)
174 {
return ts_current.
current()() < fixed_output_time; });
180 if (*fixed_output_time_it < ts_current.
current()() + dt)
183 if (std::abs(*fixed_output_time_it - ts_current.
current()()) >
184 std::numeric_limits<double>::epsilon() * ts_current.
current()())
186 return *fixed_output_time_it - ts_current.
current()();
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the PiecewiseLinearInterpolation class.
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.
Interface of time stepping algorithms.
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