-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtime_handler.h
86 lines (76 loc) · 1.8 KB
/
time_handler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef TIME_HANDLER_H
#define TIME_HANDLER_H
#include <deal.II/base/timer.h>
namespace Adapter
{
using namespace dealii;
/**
* @brief The Time class keeps track of the current time step and
* absolute time values. There are certainly different ways to
* handle this in the solver. However, the class has a function
* @p set_absolute_time(), which allows to set the time variables
* manually during simulation. This is necessary for subcycling
* and allows a more compact notation. This function is also
* used in the @p Adapter class.
*
* The remaining member functions are self-explanatory.
*
*/
class Time
{
public:
Time(const double time_end, const double delta_t)
: timestep(0)
, time_current(0.0)
, time_end(time_end)
, delta_t(delta_t)
{}
virtual ~Time()
{}
double
current() const
{
return time_current;
}
double
end() const
{
return time_end;
}
double
get_delta_t() const
{
return delta_t;
}
unsigned int
get_timestep() const
{
return timestep;
}
/**
* @brief set_absolute_time Allows to set the absolute time manually
*
* @param[in] new_time absolute time value
*/
void
set_absolute_time(const double new_time)
{
// to account for rounding errors
double factor = std::pow(10, 10);
timestep = std::round((new_time / delta_t) * factor) / factor;
time_current = new_time;
}
void
increment()
{
time_current += delta_t;
++timestep;
}
private:
unsigned int timestep;
double time_current;
const double time_end;
const double delta_t;
};
} // namespace Adapter
#endif // TIME_HANDLER_H