OGS 6.1.0-1721-g6382411ad
IterationNumberBasedTimeStepping.cpp
Go to the documentation of this file.
1 
14 
15 #include <algorithm>
16 #include <cassert>
17 #include <cmath>
18 #include <limits>
19 #include <utility>
20 
21 namespace NumLib
22 {
24  double const t_initial, double const t_end, double const min_dt,
25  double const max_dt, double const initial_dt,
26  std::vector<int>&& iter_times_vector,
27  std::vector<double>&& multiplier_vector)
28  : TimeStepAlgorithm(t_initial, t_end),
29  _iter_times_vector(std::move(iter_times_vector)),
30  _multiplier_vector(std::move(multiplier_vector)),
31  _min_dt(min_dt),
32  _max_dt(max_dt),
33  _initial_dt(initial_dt),
34  _max_iter(_iter_times_vector.empty() ? 0 : _iter_times_vector.back())
35 {
36  if (_iter_times_vector.empty())
37  {
38  OGS_FATAL("Vector of iteration numbers must not be empty.");
39  }
40  if (_iter_times_vector.size() != _multiplier_vector.size())
41  {
42  OGS_FATAL(
43  "Vector of iteration numbers must be of the same size as the "
44  "vector of multipliers.");
45  }
46  if (!std::is_sorted(std::begin(_iter_times_vector),
47  std::end(_iter_times_vector)))
48  {
49  OGS_FATAL("Vector of iteration numbers must be sorted.");
50  }
51 }
52 
53 bool IterationNumberBasedTimeStepping::next(double const /*solution_error*/,
54  int const number_iterations)
55 {
56  _iter_times = number_iterations;
57 
58  // check current time step
59  if (std::abs(_ts_current.current() - end()) <
60  std::numeric_limits<double>::epsilon())
61  {
62  return false;
63  }
64 
65  // confirm current time and move to the next if accepted
66  if (accepted())
67  {
69  _dt_vector.push_back(_ts_current.dt());
70  }
71  else
72  {
74  }
75 
76  // prepare the next time step info
79 
80  return true;
81 }
82 
84  int const number_iterations) const
85 {
86  double multiplier = std::numeric_limits<double>::quiet_NaN();
87  for (std::size_t i = 0; i < _iter_times_vector.size(); i++)
88  {
89  if (number_iterations >= _iter_times_vector[i])
90  {
91  multiplier = _multiplier_vector[i];
92  }
93  }
94  return multiplier;
95 }
96 
98 {
99  double dt = 0.0;
100 
101  // In first time step and first non-linear iteration take the initial dt.
102  if (_ts_prev.steps() == 0 && _iter_times == 0)
103  {
104  dt = _initial_dt;
105  }
106  else
107  {
108  // Attention: for the first time step and second iteration the
109  // ts_prev.dt is 0 and 0*multiplier is the next dt, which will be
110  // clamped to the minimum dt.
112  }
113 
114  dt = std::min(std::max(dt, _min_dt), _max_dt);
115 
116  double const t_next = dt + _ts_prev.current();
117  if (t_next > end())
118  {
119  dt = end() - _ts_prev.current();
120  }
121 
122  return dt;
123 }
124 
126 {
127  return _iter_times <= _max_iter;
128 }
129 } // namespace NumLib
double dt() const
time step size from _previous
Definition: TimeStep.h:110
const double _min_dt
The minimum allowed time step size.
int _iter_times
The number of nonlinear iterations.
Interface of time stepping algorithms.
std::size_t steps() const
the number of time _steps
Definition: TimeStep.h:112
std::vector< double > _dt_vector
a vector of time step sizes
double findMultiplier(int number_iterations) const
Find a multiplier for the given number of iterations.
TimeStep _ts_current
current time step information
double end() const
return the end of time steps
bool next(double solution_error, int number_iterations) override
double getNextTimeStepSize() const
Calculate the next time step size.
const int _max_iter
The maximum allowed iteration number to accept current time step.
IterationNumberBasedTimeStepping(double const t_initial, double const t_end, double const min_dt, double const max_dt, double const initial_dt, std::vector< int > &&iter_times_vector, std::vector< double > &&multiplier_vector)
TimeStep _ts_prev
previous time step information
double current() const
return current time step
Definition: TimeStep.h:108
const double _max_dt
The maximum allowed time step size.
#define OGS_FATAL(fmt,...)
Definition: Error.h:71
bool accepted() const override
return if current time step is accepted or not
const std::vector< double > _multiplier_vector
This vector stores the multiplier coefficients.