Version: SMASH-3.3
smash::CustomClock Class Reference

#include <clock.h>

Clock with explicitly defined time steps.

Definition at line 405 of file clock.h.

Inheritance diagram for smash::CustomClock:
smash::Clock

Public Member Functions

 CustomClock (std::vector< double > times)
 Initialises a custom clock with explicitly given output times. More...
 
double current_time () const override
 
double next_time () const override
 
double timestep_duration () const override
 
void reset (double start_time, bool) override
 Reset the clock to the starting time of the simulation. More...
 
void remove_times_in_past (double start_time) override
 Remove all custom times before start_time. More...
 
- Public Member Functions inherited from smash::Clock
Clockoperator++ ()
 Advances the clock by one tick. More...
 
Clockoperator+= (Representation advance_several_timesteps)
 Advances the clock by an arbitrary number of ticks. More...
 
bool operator< (const Clock &rhs) const
 Compares the internal times of two clocks. More...
 
bool operator< (double time) const
 Compares the internal time of the clock against a fixed time. More...
 
bool operator> (double time) const
 Compares the internal time of the clock against a fixed time. More...
 
virtual ~Clock ()=default
 

Protected Member Functions

double present_internal_time () const override
 For the CustomClock, the internal time is basically by design the same as what the current_time() method returns. More...
 

Private Attributes

std::vector< double > custom_times_
 Vector of times where output is generated. More...
 
double start_time_ = 0.
 Starting time of the simulation. More...
 

Additional Inherited Members

- Public Types inherited from smash::Clock
using Representation = std::int64_t
 The type used for counting ticks/time. More...
 
- Protected Attributes inherited from smash::Clock
Representation counter_ = 0
 Internally used to count the number of time steps. More...
 

Constructor & Destructor Documentation

◆ CustomClock()

smash::CustomClock::CustomClock ( std::vector< double >  times)
inlineexplicit

Initialises a custom clock with explicitly given output times.

Parameters
[in]timesvector of desired output times

Definition at line 412 of file clock.h.

412  : custom_times_(times) {
413  std::sort(custom_times_.begin(), custom_times_.end());
414  counter_ = -1;
415  }
Representation counter_
Internally used to count the number of time steps.
Definition: clock.h:186
std::vector< double > custom_times_
Vector of times where output is generated.
Definition: clock.h:498

Member Function Documentation

◆ current_time()

double smash::CustomClock::current_time ( ) const
inlineoverridevirtual
Returns
The start time if the clock has never been ticked or the current time otherwise.
Exceptions
std::out_of_rangeif the clock has ticked beyond the last time.
std::runtime_errorif the clock has an internal broken state.

Implements smash::Clock.

Definition at line 423 of file clock.h.

423  {
424  if (counter_ == -1) {
425  // current time before the first output should be the starting time
426  return start_time_;
427  } else if (counter_ < -1) {
428  throw std::runtime_error(
429  "Trying to access time of clock in invalid state.");
430  } else {
431  return custom_times_.at(counter_);
432  }
433  }
double start_time_
Starting time of the simulation.
Definition: clock.h:500

◆ next_time()

double smash::CustomClock::next_time ( ) const
inlineoverridevirtual
Returns
The next custom time.
Exceptions
std::out_of_rangeif the clock has ticked beyond last time.

Implements smash::Clock.

Definition at line 439 of file clock.h.

439 { return custom_times_.at(counter_ + 1); }

◆ timestep_duration()

double smash::CustomClock::timestep_duration ( ) const
inlineoverridevirtual

Returns
the duration of the current time step

Implements smash::Clock.

Definition at line 442 of file clock.h.

442  {
443  return next_time() - current_time();
444  }
double next_time() const override
Definition: clock.h:439
double current_time() const override
Definition: clock.h:423

◆ reset()

void smash::CustomClock::reset ( double  start_time,
bool   
)
inlineoverridevirtual

Reset the clock to the starting time of the simulation.

Parameters
[in]start_timestarting time of the simulation
Note
The second bool parameter is irrelevant and unused here.

Implements smash::Clock.

Definition at line 453 of file clock.h.

453  {
454  counter_ = -1;
455  start_time_ = start_time;
456  }

◆ remove_times_in_past()

void smash::CustomClock::remove_times_in_past ( double  start_time)
inlineoverridevirtual

Remove all custom times before start_time.

Parameters
[in]start_timestarting time of the simulation

Implements smash::Clock.

Definition at line 463 of file clock.h.

463  {
464  custom_times_.erase(
465  std::remove_if(
466  custom_times_.begin(), custom_times_.end(),
467  [start_time](double t) {
468  if (t < start_time) {
469  logg[LClock].warn("Removing custom output time ", t,
470  " fm since it is earlier than the "
471  "starting time of the simulation");
472  return true;
473  } else if (t == start_time) {
474  logg[LClock].debug(
475  "The start time ", t,
476  " fm has to be removed from the 'custom_times_' vector "
477  "since it will be otherwise considered twice in the actual "
478  "output time steps");
479  return true;
480  } else {
481  return false;
482  }
483  }),
484  custom_times_.end());
485  }
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:40
static constexpr int LClock
Definition: clock.h:26

◆ present_internal_time()

double smash::CustomClock::present_internal_time ( ) const
inlineoverrideprotectedvirtual

For the CustomClock, the internal time is basically by design the same as what the current_time() method returns.

Returns
the same as current_time does.

Implements smash::Clock.

Definition at line 494 of file clock.h.

494 { return current_time(); }

Member Data Documentation

◆ custom_times_

std::vector<double> smash::CustomClock::custom_times_
private

Vector of times where output is generated.

Definition at line 498 of file clock.h.

◆ start_time_

double smash::CustomClock::start_time_ = 0.
private

Starting time of the simulation.

Definition at line 500 of file clock.h.


The documentation for this class was generated from the following file: