#include <clock.h>
Clock tracks the time in the simulation.
The basic unit is 1 fm/c = \(1 / 2.99798542 \cdot 10^{-23}\)s \(\approx 0.33 \cdot 10^{-24}\) s. The resolution of the clock is 0.000001 fm/c. I.e. only multiples of 0.000001 fm/c are representable internally.
Possible actions for Clock are:
Clock stores a time step size \(\Delta t\) and a base time \(t_0\) as well as a counter \(n\). The current time is calculated from \(t = t_0 + n \cdot \Delta t\). When \(\Delta t\) is changed, \(t_0\) is reset.
Public Types | |
using | Representation = std::int64_t |
The type used for counting ticks/time. More... | |
Public Member Functions | |
Clock ()=default | |
default initializer: Timestep size is set to 0! More... | |
Clock (const double time, const double dt) | |
Initialize with base time and time step size. More... | |
double | current_time () const |
double | next_time () const |
double | timestep_duration () const |
void | set_timestep_duration (const double dt) |
Sets the time step size (and resets the counter). More... | |
bool | multiple_is_in_next_tick (const double interval) const |
Checks if a multiple of a given interval is reached within the next tick. More... | |
double | next_multiple (const double interval) const |
Returns the next multiple of a given interval. More... | |
void | end_tick_on_multiple (const double interval) |
Set the time step such that it ends on the next multiple of the interval. More... | |
void | reset (const double reset_time) |
Resets the time to a pre-defined value reset_time . More... | |
Clock & | operator++ () |
Advances the clock by one tick ( \(\Delta t\)). More... | |
template<typename T > | |
std::enable_if< std::is_floating_point< T >::value, Clock & >::type | operator+= (T big_timestep) |
Advances the clock by an arbitrary timestep (multiple of 0.000001 fm/c). More... | |
Clock & | operator+= (Representation advance_several_timesteps) |
advances the clock by an arbitrary number of ticks. More... | |
bool | operator< (const Clock &rhs) const |
Compares the times between two clocks. More... | |
bool | operator< (double time) const |
Compares the time of the clock against a fixed time. More... | |
bool | operator> (double time) const |
Compares the time of the clock against a fixed time. More... | |
Static Private Member Functions | |
static Representation | convert (double x) |
Convert a double x into the internal int representation. More... | |
static double | convert (Representation x) |
Convert an internal int value x into the double representation. More... | |
Private Attributes | |
Representation | counter_ = 0 |
Clock tick. More... | |
Representation | timestep_duration_ = 0u |
The time step size \(\Delta t\) in $10^{-3}$ fm. More... | |
Representation | reset_time_ = 0 |
The time of last reset (when counter_ was set to 0). More... | |
Static Private Attributes | |
static constexpr double | resolution = 0.000001 |
Defines the resolution of the clock (i.e. More... | |
static constexpr double | to_double = resolution |
A multiplier transfering the internal integer to the real time. More... | |
static constexpr double | from_double = 1. / resolution |
A multiplier transfering the real time to the internal integer. More... | |
using smash::Clock::Representation = std::int64_t |
|
default |
default initializer: Timestep size is set to 0!
|
inline |
Initialize with base time and time step size.
[in] | time | base time |
[in] | dt | step size |
Definition at line 103 of file clock.h.
|
inline |
Definition at line 110 of file clock.h.
|
inline |
This function is needed, because current_time() + timestep_duration() is not the same as the next tick (numerically; this is due to floating point arithmetic).
Definition at line 120 of file clock.h.
|
inline |
Definition at line 128 of file clock.h.
|
inline |
Sets the time step size (and resets the counter).
[in] | dt | new time step size |
Definition at line 134 of file clock.h.
|
inline |
Checks if a multiple of a given interval is reached within the next tick.
[in] | interval | The interval \(t_i\) at which, for instance, output is expected to happen |
Internally, it checks if \(n\) is the same for this time step as for the next time step. If so, the next multiple is outside the current time step, if not, then the multiple must be within.
Definition at line 158 of file clock.h.
|
inline |
Returns the next multiple of a given interval.
[in] | interval | the given interval |
interval
that is larger than the current time. Definition at line 182 of file clock.h.
|
inline |
Set the time step such that it ends on the next multiple of the interval.
interval | The given interval |
Definition at line 195 of file clock.h.
|
inline |
Resets the time to a pre-defined value reset_time
.
This is the only way of turning the clock back. It is needed so that the time can be adjusted after initialization (different initial conditions may require different starting times).
[in] | reset_time | New time |
Definition at line 216 of file clock.h.
|
inline |
|
inline |
Advances the clock by an arbitrary timestep (multiple of 0.000001 fm/c).
T | type of the timestep |
[in] | big_timestep | Timestep by which the clock is advanced. |
Definition at line 249 of file clock.h.
|
inline |
|
inline |
Compares the times between two clocks.
[in] | rhs | The other clock. |
Definition at line 277 of file clock.h.
|
inline |
|
inline |
|
inlinestaticprivate |
Convert a double x
into the internal int representation.
Definition at line 301 of file clock.h.
|
inlinestaticprivate |
Convert an internal int value x
into the double representation.
Definition at line 305 of file clock.h.
|
staticprivate |
Defines the resolution of the clock (i.e.
the smallest representable time difference).
The value 0.000001 is very well suited because
|
staticprivate |
|
staticprivate |
|
private |
|
private |
|
private |