10 #ifndef SRC_INCLUDE_SMASH_CLOCK_H_
11 #define SRC_INCLUDE_SMASH_CLOCK_H_
25 static constexpr
int LClock = LogArea::Clock::id;
90 virtual void reset(
double start_time,
const bool is_output_clock) = 0;
108 if (
counter_ >= std::numeric_limits<Representation>::max() - 1) {
109 throw std::overflow_error(
"Too many timesteps, clock overflow imminent");
124 if (
counter_ >= std::numeric_limits<Representation>::max() -
125 advance_several_timesteps) {
126 throw std::overflow_error(
"Too many timesteps, clock overflow imminent");
128 counter_ += advance_several_timesteps;
200 UniformClock(
const double time,
const double dt,
const double time_end)
205 throw std::range_error(
"No negative time increment allowed");
226 throw std::overflow_error(
"Too many timesteps, clock overflow imminent");
251 throw std::range_error(
"No negative time increment allowed");
264 void reset(
const double start_time,
const bool is_output_clock)
override {
266 if (is_output_clock) {
270 reset_time = start_time;
290 template <
typename T>
291 typename std::enable_if<std::is_floating_point<T>::value,
Clock&>::type
293 if (big_timestep < 0.) {
294 throw std::range_error(
"The clock cannot be turned back.");
308 if (
counter_ >= std::numeric_limits<Representation>::max() -
309 advance_several_timesteps) {
310 throw std::overflow_error(
"Too many timesteps, clock overflow imminent");
312 counter_ += advance_several_timesteps;
358 throw std::runtime_error(
"Trying to access undefined zeroth output time");
368 void reset(
double start_time,
bool)
override {
380 [start_time](
double t) {
381 if (t <= start_time) {
382 logg[LClock].warn(
"Removing custom output time ", t,
383 " fm since it is earlier than the "
384 "starting time of the simulation");
396 double start_time_ = 0.;
Clock tracks the time in the simulation.
bool operator<(double time) const
Compares the time of the clock against a fixed time.
bool operator<(const Clock &rhs) const
Compares the times between two clocks.
std::int64_t Representation
The type used for counting ticks/time.
virtual double current_time() const =0
virtual double timestep_duration() const =0
Representation counter_
Internally used to count the number of time steps.
bool operator>(double time) const
Compares the time of the clock against a fixed time.
Clock & operator++()
Advances the clock by one tick.
virtual void reset(double start_time, const bool is_output_clock)=0
reset the clock to the starting time of the simulation
virtual double next_time() const =0
virtual void remove_times_in_past(double start_time)=0
Remove output times before the starting time of the simulation if this is a custom clock.
Clock & operator+=(Representation advance_several_timesteps)
Advances the clock by an arbitrary number of ticks.
Clock with explicitly defined time steps.
double next_time() const override
CustomClock(std::vector< double > times)
Initialises a custom clock with explicitly given output times.
double start_time_
Starting time of the simulation.
void remove_times_in_past(double start_time) override
Remove all custom times before start_time.
std::vector< double > custom_times_
Vector of times where output is generated.
void reset(double start_time, bool) override
reset the clock to the starting time of the simulation
double timestep_duration() const override
double current_time() const override
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
static constexpr int LClock