Version: SMASH-3.0
smash::Clock Class Referenceabstract

#include <clock.h>

Clock tracks the time in the simulation.

The basic unit is 1 fm in natural units which correspond to \(\frac{10^{-15}}{299\,792\,458}\,\mathrm{s} \approx 0.33\cdot10^{-23}\,\mathrm{s}\) in the international system of units. The resolution of the clock is \(0.000001\,\mathrm{fm}=10^{-6}\,\mathrm{fm}\), i.e. only multiples of \(0.000001\,\mathrm{fm}\) are internally representable.

Potential usage for adapting time steps:

UniformClock labtime(0., 0.1, end_time_);
UniformClock endtime(10., 0., end_time_);
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 73 of file clock.h.

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

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

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

106  {
107  // guard against overflow:
108  if (counter_ >= std::numeric_limits<Representation>::max() - 1) {
109  throw std::overflow_error("Too many timesteps, clock overflow imminent");
110  }
111  ++counter_;
112  return *this;
113  }
Representation counter_
Internally used to count the number of time steps.
Definition: clock.h:161

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

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

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

137  {
138  return current_time() < rhs.current_time();
139  }
virtual double current_time() const =0

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

146 { return current_time() < time; }

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

153 { return current_time() > time; }

Member Data Documentation

◆ counter_

Representation smash::Clock::counter_ = 0
protected

Internally used to count the number of time steps.

Definition at line 161 of file clock.h.


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