Version: SMASH-1.7
smash::CustomClock Class Reference

#include <clock.h>

Clock with explicitly defined time steps.

Definition at line 314 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

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

321  : custom_times_(times) {
322  std::sort(custom_times_.begin(), custom_times_.end());
323  counter_ = -1;
324  }
std::vector< double > custom_times_
Vector of times where output is generated.
Definition: clock.h:363
Representation counter_
Internally used to count the number of time steps.
Definition: clock.h:156

Member Function Documentation

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

329  {
330  if (counter_ < 0) {
331  throw std::runtime_error("Trying to access undefined zeroth output time");
332  }
333  return custom_times_[counter_];
334  }
std::vector< double > custom_times_
Vector of times where output is generated.
Definition: clock.h:363
Representation counter_
Internally used to count the number of time steps.
Definition: clock.h:156
double smash::CustomClock::next_time ( ) const
inlineoverridevirtual

Returns
the time of the next time step

Implements smash::Clock.

Definition at line 336 of file clock.h.

336 { return custom_times_[counter_ + 1]; }
std::vector< double > custom_times_
Vector of times where output is generated.
Definition: clock.h:363
Representation counter_
Internally used to count the number of time steps.
Definition: clock.h:156
double smash::CustomClock::timestep_duration ( ) const
inlineoverridevirtual
Returns
the duration of the current time step

Implements smash::Clock.

Definition at line 337 of file clock.h.

337  {
338  return next_time() - current_time();
339  }
double next_time() const override
Definition: clock.h:336
double current_time() const override
Definition: clock.h:329

Here is the call graph for this function:

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

340 { counter_ = -1; }
Representation counter_
Internally used to count the number of time steps.
Definition: clock.h:156
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 347 of file clock.h.

347  {
348  std::remove_if(
349  custom_times_.begin(), custom_times_.end(), [start_time](double t) {
350  if (t <= start_time) {
351  logger<LogArea::Clock>().warn("Removing custom output time ", t,
352  " fm since it is earlier than the "
353  "starting time of the simulation");
354  return true;
355  } else {
356  return false;
357  }
358  });
359  }
std::vector< double > custom_times_
Vector of times where output is generated.
Definition: clock.h:363

Member Data Documentation

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

Vector of times where output is generated.

Definition at line 363 of file clock.h.


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