OGS
TimeStep.h
Go to the documentation of this file.
1
13#pragma once
14
15#include <cstddef>
16#include <limits>
17
18#include "Time.h"
19
20namespace NumLib
21{
30class TimeStep final
31{
32public:
37 explicit TimeStep(Time const& current_time)
38 : _previous(current_time),
39 _current(current_time),
40 _dt(0.0),
42 {
43 }
44
51 TimeStep(Time const& previous_time, Time const& current_time, std::size_t n)
52 : _previous(previous_time),
53 _current(current_time),
54 _dt(_current() - _previous()),
56 {
57 }
58
60 TimeStep(const TimeStep& src) = default;
61
63 TimeStep& operator=(const TimeStep& src) = default;
64
66 TimeStep& operator+=(const double dt)
67 {
69 _current += dt;
70 _dt = dt;
72 return *this;
73 }
74
76 Time previous() const { return _previous; }
78 Time current() const { return _current; }
80 double dt() const { return _dt; }
82 std::size_t timeStepNumber() const { return _time_step_number; }
83
84 void setAccepted(bool const accepted) { _is_accepted = accepted; }
85 bool isAccepted() const { return _is_accepted; }
86
87private:
93 double _dt;
95 std::size_t _time_step_number;
97 bool _is_accepted = true;
98};
99
100inline void updateTimeSteps(double const dt, TimeStep& previous_timestep,
101 TimeStep& current_timestep)
102{
103 previous_timestep = current_timestep;
104 current_timestep += dt;
105}
106
107} // namespace NumLib
Time step object.
Definition TimeStep.h:31
void setAccepted(bool const accepted)
Definition TimeStep.h:84
TimeStep(const TimeStep &src)=default
copy a time step
TimeStep & operator+=(const double dt)
increment time step
Definition TimeStep.h:66
Time _current
current time step
Definition TimeStep.h:91
Time current() const
return current time step
Definition TimeStep.h:78
bool isAccepted() const
Definition TimeStep.h:85
TimeStep & operator=(const TimeStep &src)=default
copy a time step
Time _previous
previous time step
Definition TimeStep.h:89
Time previous() const
return previous time step
Definition TimeStep.h:76
double dt() const
time step size from _previous
Definition TimeStep.h:80
std::size_t timeStepNumber() const
the time step number
Definition TimeStep.h:82
std::size_t _time_step_number
the number of time steps
Definition TimeStep.h:95
TimeStep(Time const &current_time)
Definition TimeStep.h:37
bool _is_accepted
is the timestep accepted
Definition TimeStep.h:97
double _dt
time step size
Definition TimeStep.h:93
TimeStep(Time const &previous_time, Time const &current_time, std::size_t n)
Definition TimeStep.h:51
void updateTimeSteps(double const dt, TimeStep &previous_timestep, TimeStep &current_timestep)
Definition TimeStep.h:100