OGS
TimeStepAlgorithm.cpp
Go to the documentation of this file.
1
10#include "TimeStepAlgorithm.h"
11
12#include <algorithm>
13#include <limits>
14
15namespace NumLib
16{
18 double const t, double const dt,
19 std::vector<double> const& fixed_output_times)
20{
21 auto const specific_time = std::upper_bound(
22 std::cbegin(fixed_output_times), std::cend(fixed_output_times), t);
23
24 if (specific_time == std::cend(fixed_output_times))
25 {
26 return dt;
27 }
28
29 double const t_to_specific_time = *specific_time - t;
30 if ((t_to_specific_time > std::numeric_limits<double>::epsilon()) &&
31 (t + dt - *specific_time > 0.0))
32 {
33 return t_to_specific_time;
34 }
35
36 return dt;
37}
38
39bool canReduceTimestepSize(TimeStep const& timestep_previous,
40 TimeStep const& timestep_current,
41 double const min_dt)
42{
43 return !(timestep_current.dt() == min_dt &&
44 timestep_previous.dt() == min_dt);
45}
46} // namespace NumLib
Time step object.
Definition TimeStep.h:28
double dt() const
time step size from _previous
Definition TimeStep.h:92
double possiblyClampDtToNextFixedTime(double const t, double const dt, std::vector< double > const &fixed_output_times)
bool canReduceTimestepSize(TimeStep const &timestep_previous, TimeStep const &timestep_current, double const min_dt)