Version: SMASH-3.0
smash::CustomClock Class Reference

#include <clock.h>

Clock with explicitly defined time steps.

Definition at line 338 of file clock.h.

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

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 start_time, 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...
 
double start_time_ = 0.
 Starting time of the simulation. 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)
inlineexplicit

Initialises a custom clock with explicitly given output times.

Parameters
[in]timesvector of desired output times

Definition at line 345 of file clock.h.

345  : custom_times_(times) {
346  std::sort(custom_times_.begin(), custom_times_.end());
347  counter_ = -1;
348  }
Representation counter_
Internally used to count the number of time steps.
Definition: clock.h:161
std::vector< double > custom_times_
Vector of times where output is generated.
Definition: clock.h:394

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

353  {
354  if (counter_ == -1) {
355  // current time before the first output should be the starting time
356  return start_time_;
357  } else if (counter_ < -1) {
358  throw std::runtime_error("Trying to access undefined zeroth output time");
359  } else {
360  return custom_times_[counter_];
361  }
362  }
double start_time_
Starting time of the simulation.
Definition: clock.h:396

◆ next_time()

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

Returns
the time of the next time step

Implements smash::Clock.

Definition at line 364 of file clock.h.

364 { return custom_times_[counter_ + 1]; }

◆ timestep_duration()

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

Implements smash::Clock.

Definition at line 365 of file clock.h.

365  {
366  return next_time() - current_time();
367  }
double next_time() const override
Definition: clock.h:364
double current_time() const override
Definition: clock.h:353

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

368  {
369  counter_ = -1;
370  start_time_ = start_time;
371  }

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

378  {
379  std::remove_if(custom_times_.begin(), custom_times_.end(),
380  [start_time](double t) {
381  if (t <= start_time) {
382  logg[LClock].warn("Removing custom output time ", t,
383  " fm since it is earlier than the "
384  "starting time of the simulation");
385  return true;
386  } else {
387  return false;
388  }
389  });
390  }

Member Data Documentation

◆ custom_times_

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

Vector of times where output is generated.

Definition at line 394 of file clock.h.

◆ start_time_

double smash::CustomClock::start_time_ = 0.
private

Starting time of the simulation.

Definition at line 396 of file clock.h.


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