Version: SMASH-1.8
smash::CustomClock Class Reference

#include <clock.h>

Clock with explicitly defined time steps.

Definition at line 316 of file clock.h.

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

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, 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 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
 

Private Attributes

std::vector< double > custom_times_
 Vector of times where output is generated. 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)
inline

Initialises a custom clock with explicitly given output times.

Parameters
[in]timesvector of desired output times

Definition at line 323 of file clock.h.

323  : custom_times_(times) {
324  std::sort(custom_times_.begin(), custom_times_.end());
325  counter_ = -1;
326  }

Member Function Documentation

◆ current_time()

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

Returns
the current time
Exceptions
runtime_errorif the clock has never been advanced

Implements smash::Clock.

Definition at line 331 of file clock.h.

331  {
332  if (counter_ < 0) {
333  throw std::runtime_error("Trying to access undefined zeroth output time");
334  }
335  return custom_times_[counter_];
336  }
Here is the caller graph for this function:

◆ next_time()

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

Returns
the time of the next time step

Implements smash::Clock.

Definition at line 338 of file clock.h.

338 { return custom_times_[counter_ + 1]; }
Here is the caller graph for this function:

◆ timestep_duration()

double smash::CustomClock::timestep_duration ( ) const
inlineoverridevirtual
Returns
the duration of the current time step

Implements smash::Clock.

Definition at line 339 of file clock.h.

339  {
340  return next_time() - current_time();
341  }
Here is the call graph for this function:

◆ reset()

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

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

Implements smash::Clock.

Definition at line 342 of file clock.h.

342 { counter_ = -1; }

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

349  {
350  std::remove_if(custom_times_.begin(), custom_times_.end(),
351  [start_time](double t) {
352  if (t <= start_time) {
353  logg[LClock].warn("Removing custom output time ", t,
354  " fm since it is earlier than the "
355  "starting time of the simulation");
356  return true;
357  } else {
358  return false;
359  }
360  });
361  }

Member Data Documentation

◆ custom_times_

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

Vector of times where output is generated.

Definition at line 365 of file clock.h.


The documentation for this class was generated from the following file:
smash::CustomClock::current_time
double current_time() const override
Definition: clock.h:331
smash::LClock
static constexpr int LClock
Definition: clock.h:24
smash::Clock::counter_
Representation counter_
Internally used to count the number of time steps.
Definition: clock.h:158
smash::logg
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:39
smash::CustomClock::custom_times_
std::vector< double > custom_times_
Vector of times where output is generated.
Definition: clock.h:365
smash::CustomClock::next_time
double next_time() const override
Definition: clock.h:338