Version: SMASH-1.7
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 68 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

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

The type used for counting ticks/time.

Definition at line 71 of file clock.h.

Constructor & Destructor Documentation

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

Here is the caller graph for this function:

Member Function Documentation

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

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

Here is the caller graph for this function:

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:

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

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

Here is the caller graph for this function:

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.

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::CustomClock, and smash::UniformClock.

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 101 of file clock.h.

101  {
102  // guard against overflow:
103  if (counter_ >= std::numeric_limits<Representation>::max() - 1) {
104  throw std::overflow_error("Too many timesteps, clock overflow imminent");
105  }
106  ++counter_;
107  return *this;
108  }
Representation counter_
Internally used to count the number of time steps.
Definition: clock.h:156
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 118 of file clock.h.

118  {
119  if (counter_ >= std::numeric_limits<Representation>::max() -
120  advance_several_timesteps) {
121  throw std::overflow_error("Too many timesteps, clock overflow imminent");
122  }
123  counter_ += advance_several_timesteps;
124  return *this;
125  }
Representation counter_
Internally used to count the number of time steps.
Definition: clock.h:156
bool smash::Clock::operator< ( const Clock rhs) const
inline

Compares the times between two clocks.

Parameters
[in]rhsThe other clock.

Definition at line 132 of file clock.h.

132  {
133  return current_time() < rhs.current_time();
134  }
virtual double current_time() const =0

Here is the call graph for this function:

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 141 of file clock.h.

141 { return current_time() < time; }
virtual double current_time() const =0

Here is the call graph for this function:

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 148 of file clock.h.

148 { return current_time() > time; }
virtual double current_time() const =0

Here is the call graph for this function:

Member Data Documentation

Representation smash::Clock::counter_ = 0
protected

Internally used to count the number of time steps.

Definition at line 156 of file clock.h.


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