10 #ifndef SRC_INCLUDE_SMASH_CLOCK_H_
11 #define SRC_INCLUDE_SMASH_CLOCK_H_
25 static constexpr
int LClock = LogArea::Clock::id;
103 virtual void reset(
double start_time,
bool is_output_clock) = 0;
120 if (
counter_ >= std::numeric_limits<Representation>::max() - 1) {
121 throw std::overflow_error(
"Too many timesteps, clock overflow imminent");
136 if (
counter_ >= std::numeric_limits<Representation>::max() -
137 advance_several_timesteps) {
138 throw std::overflow_error(
"Too many timesteps, clock overflow imminent");
140 counter_ += advance_several_timesteps;
239 throw std::range_error(
"Time increment must be positive and non-zero");
242 throw std::range_error(
243 "The initial time of UniformClock must be smaller than the end time. "
244 "(Attempt to set initial time to " +
245 std::to_string(time) +
" and end time to " +
246 std::to_string(time_end) +
" not possible)");
272 throw std::overflow_error(
"Too many timesteps, clock overflow imminent");
278 return convert(next_point_in_time);
291 logg[
LClock].warn() <<
"UniformClock asked for timestep duration beyond "
292 "end of simulation, returning 0.";
307 throw std::range_error(
"Time increment must be positive and non-zero!");
320 void reset(
double start_time,
bool is_output_clock)
override {
322 if (is_output_clock) {
324 reset_time = std::floor(start_time / delta_t) * delta_t;
326 reset_time = start_time;
346 template <
typename T>
347 typename std::enable_if<std::is_floating_point<T>::value,
Clock&>::type
349 if (big_timestep < 0.) {
350 throw std::range_error(
"The clock cannot be turned back.");
364 if (
counter_ >= std::numeric_limits<Representation>::max() -
365 advance_several_timesteps) {
366 throw std::overflow_error(
"Too many timesteps, clock overflow imminent");
368 counter_ += advance_several_timesteps;
424 throw std::runtime_error(
"Trying to access undefined zeroth output time");
434 void reset(
double start_time,
bool)
override {
446 [start_time](
double t) {
447 if (t <= start_time) {
448 logg[LClock].warn(
"Removing custom output time ", t,
449 " fm since it is earlier than the "
450 "starting time of the simulation");
471 double start_time_ = 0.;
Clock tracks the time in the simulation.
bool operator<(double time) const
Compares the internal time of the clock against a fixed time.
bool operator<(const Clock &rhs) const
Compares the internal times of 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
virtual double present_internal_time() const =0
This function always returns the clock time, even if children might attribute a different behaviour t...
virtual void reset(double start_time, bool is_output_clock)=0
reset the clock to the starting time of the simulation
Representation counter_
Internally used to count the number of time steps.
bool operator>(double time) const
Compares the internal time of the clock against a fixed time.
Clock & operator++()
Advances the clock by one tick.
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 present_internal_time() const override
For the CustomClock, the internal time is basically by design the same as what the current_time() met...
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