OGS
TimeStep.h
Go to the documentation of this file.
1
13#pragma once
14
15#include <cstddef>
16
17namespace NumLib
18{
27class TimeStep final
28{
29public:
34 explicit TimeStep(double current_time)
35 : _previous(current_time),
36 _current(current_time),
39 {
40 }
41
48 TimeStep(double previous_time, double current_time, std::size_t n)
49 : _previous(previous_time),
50 _current(current_time),
53 {
54 }
55
57 TimeStep(const TimeStep& src) = default;
58
60 TimeStep& operator=(const TimeStep& src) = default;
61
63 TimeStep& operator+=(const double dt)
64 {
66 _current += dt;
67 _dt = dt;
69 return *this;
70 }
71
73 bool operator<(TimeStep const& ts) const
74 {
75 return (_current < ts._current);
76 }
78 bool operator<=(TimeStep const& ts) const
79 {
80 return (_current <= ts._current);
81 }
83 bool operator==(TimeStep const& ts) const
84 {
85 return (_current == ts._current);
86 }
88 double previous() const { return _previous; }
90 double current() const { return _current; }
92 double dt() const { return _dt; }
94 std::size_t timeStepNumber() const { return _time_step_number; }
95
96 void setAccepted(bool const accepted) { _is_accepted = accepted; }
97 bool isAccepted() const { return _is_accepted; }
98
99private:
101 double _previous;
103 double _current;
105 double _dt;
107 std::size_t _time_step_number;
109 bool _is_accepted = true;
110};
111
112inline void updateTimeSteps(double const dt, TimeStep& previous_timestep,
113 TimeStep& current_timestep)
114{
115 previous_timestep = current_timestep;
116 current_timestep += dt;
117}
118
119} // namespace NumLib
Time step object.
Definition TimeStep.h:28
double current() const
return current time step
Definition TimeStep.h:90
double _current
current time step
Definition TimeStep.h:103
void setAccepted(bool const accepted)
Definition TimeStep.h:96
TimeStep(const TimeStep &src)=default
copy a time step
TimeStep & operator+=(const double dt)
increment time step
Definition TimeStep.h:63
bool operator<(TimeStep const &ts) const
compare current time
Definition TimeStep.h:73
bool isAccepted() const
Definition TimeStep.h:97
TimeStep & operator=(const TimeStep &src)=default
copy a time step
bool operator<=(TimeStep const &ts) const
compare current time
Definition TimeStep.h:78
double dt() const
time step size from _previous
Definition TimeStep.h:92
std::size_t timeStepNumber() const
the time step number
Definition TimeStep.h:94
double _previous
previous time step
Definition TimeStep.h:101
TimeStep(double previous_time, double current_time, std::size_t n)
Definition TimeStep.h:48
bool operator==(TimeStep const &ts) const
compare current time
Definition TimeStep.h:83
TimeStep(double current_time)
Definition TimeStep.h:34
std::size_t _time_step_number
the number of time steps
Definition TimeStep.h:107
bool _is_accepted
is the timestep accepted
Definition TimeStep.h:109
double _dt
time step size
Definition TimeStep.h:105
double previous() const
return previous time step
Definition TimeStep.h:88
void updateTimeSteps(double const dt, TimeStep &previous_timestep, TimeStep &current_timestep)
Definition TimeStep.h:112