Version: SMASH-2.0
smash::Clock Class Referenceabstract

#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.

Potential usage for adapting time steps:

UniformClock labtime(0., 0.1);
UniformClock endtime(10., 0.);
while (labtime < endtime) {
// do something
// adapt the timestep size to external circumstances:
if (system_is_very_dense()) {
labtime.set_timestep_duration(labtime.timestep_duration() / 2.);
}
if (system_is_very_dilute()) {
labtime.set_timestep_duration(labtime.timestep_duration() * 2.);
}
// let the clock tick
++labtime;
}

Possible actions for Clock are:

Definition at line 71 of file clock.h.

Inheritance diagram for smash::Clock:
[legend]
Collaboration diagram for smash::Clock:
[legend]

Public Types

using Representation = std::int64_t
 The type used for counting ticks/time. More...
 

Public Member Functions

virtual double timestep_duration () const =0
 
virtual double current_time () const =0
 
virtual double next_time () const =0
 
virtual void reset (double start_time, const bool is_output_clock)=0
 reset the clock to the starting time of the simulation More...
 
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. More...
 
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 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...
 
virtual ~Clock ()=default
 

Protected Attributes

Representation counter_ = 0
 Internally used to count the number of time steps. More...
 

Member Typedef Documentation

◆ Representation

using smash::Clock::Representation = std::int64_t

The type used for counting ticks/time.

Definition at line 74 of file clock.h.

Constructor & Destructor Documentation

◆ ~Clock()

virtual smash::Clock::~Clock ( )
virtualdefault

Member Function Documentation

◆ timestep_duration()

virtual double smash::Clock::timestep_duration ( ) const
pure virtual
Returns
the duration of the current time step

Implemented in smash::CustomClock, and smash::UniformClock.

◆ current_time()

virtual double smash::Clock::current_time ( ) const
pure virtual
Returns
the current time

Implemented in smash::CustomClock, and smash::UniformClock.

Here is the caller graph for this function:

◆ next_time()

virtual double smash::Clock::next_time ( ) const
pure virtual
Returns
the time of the next time step

Implemented in smash::CustomClock, and smash::UniformClock.

◆ reset()

virtual void smash::Clock::reset ( double  start_time,
const bool  is_output_clock 
)
pure virtual

reset the clock to the starting time of the simulation

Parameters
[in]start_timestarting time of the imulation
[in]is_output_clockwhether this is an output clock rather than a lab clock

Implemented in smash::CustomClock, and smash::UniformClock.

◆ remove_times_in_past()

virtual void smash::Clock::remove_times_in_past ( double  start_time)
pure virtual

Remove output times before the starting time of the simulation if this is a custom clock.

Parameters
[in]start_timestarting time of the simulation

Implemented in smash::UniformClock, and smash::CustomClock.

◆ operator++()

Clock& smash::Clock::operator++ ( )
inline

Advances the clock by one tick.

This operator is used as ++clock. The operator clock++ is not implemented deliberately, because that requires a copy of the clock being created.

Definition at line 104 of file clock.h.

104  {
105  // guard against overflow:
106  if (counter_ >= std::numeric_limits<Representation>::max() - 1) {
107  throw std::overflow_error("Too many timesteps, clock overflow imminent");
108  }
109  ++counter_;
110  return *this;
111  }

◆ operator+=()

Clock& smash::Clock::operator+= ( Representation  advance_several_timesteps)
inline

advances the clock by an arbitrary number of ticks.

Parameters
[in]advance_several_timestepsNumber of the timesteps added to the clock
Exceptions
OverflowErrorif the number of the added timesteps exceeds the maximum value.

Definition at line 121 of file clock.h.

121  {
122  if (counter_ >= std::numeric_limits<Representation>::max() -
123  advance_several_timesteps) {
124  throw std::overflow_error("Too many timesteps, clock overflow imminent");
125  }
126  counter_ += advance_several_timesteps;
127  return *this;
128  }

◆ operator<() [1/2]

bool smash::Clock::operator< ( const Clock rhs) const
inline

Compares the times between two clocks.

Parameters
[in]rhsThe other clock.

Definition at line 135 of file clock.h.

135  {
136  return current_time() < rhs.current_time();
137  }
Here is the call graph for this function:

◆ operator<() [2/2]

bool smash::Clock::operator< ( double  time) const
inline

Compares the time of the clock against a fixed time.

Parameters
[in]timeThe other time.

Definition at line 144 of file clock.h.

144 { return current_time() < time; }
Here is the call graph for this function:

◆ operator>()

bool smash::Clock::operator> ( double  time) const
inline

Compares the time of the clock against a fixed time.

Parameters
[in]timeThe other time.

Definition at line 151 of file clock.h.

151 { return current_time() > time; }
Here is the call graph for this function:

Member Data Documentation

◆ counter_

Representation smash::Clock::counter_ = 0
protected

Internally used to count the number of time steps.

Definition at line 159 of file clock.h.


The documentation for this class was generated from the following file:
smash::Clock::counter_
Representation counter_
Internally used to count the number of time steps.
Definition: clock.h:159
smash::Clock::current_time
virtual double current_time() const =0