Version: SMASH-3.1
smash::CustomClock Class Reference

#include <clock.h>

Clock with explicitly defined time steps.

Definition at line 404 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 internal times of two clocks. More...
 
bool operator< (double time) const
 Compares the internal time of the clock against a fixed time. More...
 
bool operator> (double time) const
 Compares the internal time of the clock against a fixed time. More...
 
virtual ~Clock ()=default
 

Protected Member Functions

double present_internal_time () const override
 For the CustomClock, the internal time is basically by design the same as what the current_time() method returns. More...
 

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

411  : custom_times_(times) {
412  std::sort(custom_times_.begin(), custom_times_.end());
413  counter_ = -1;
414  }
Representation counter_
Internally used to count the number of time steps.
Definition: clock.h:185
std::vector< double > custom_times_
Vector of times where output is generated.
Definition: clock.h:469

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

419  {
420  if (counter_ == -1) {
421  // current time before the first output should be the starting time
422  return start_time_;
423  } else if (counter_ < -1) {
424  throw std::runtime_error("Trying to access undefined zeroth output time");
425  } else {
426  return custom_times_[counter_];
427  }
428  }
double start_time_
Starting time of the simulation.
Definition: clock.h:471

◆ next_time()

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

Returns
the time of the next time step

Implements smash::Clock.

Definition at line 430 of file clock.h.

430 { 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 431 of file clock.h.

431  {
432  return next_time() - current_time();
433  }
double next_time() const override
Definition: clock.h:430
double current_time() const override
Definition: clock.h:419

◆ 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 simulation
[in]is_output_clockwhether this is an output clock rather than a lab clock

Implements smash::Clock.

Definition at line 434 of file clock.h.

434  {
435  counter_ = -1;
436  start_time_ = start_time;
437  }

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

444  {
445  std::remove_if(custom_times_.begin(), custom_times_.end(),
446  [start_time](double t) {
447  if (t <= start_time) {
448  logg[LClock].warn("Removing custom output time ", t,
449  " fm since it is earlier than the "
450  "starting time of the simulation");
451  return true;
452  } else {
453  return false;
454  }
455  });
456  }

◆ present_internal_time()

double smash::CustomClock::present_internal_time ( ) const
inlineoverrideprotectedvirtual

For the CustomClock, the internal time is basically by design the same as what the current_time() method returns.

Returns
the same as current_time does.

Implements smash::Clock.

Definition at line 465 of file clock.h.

465 { return current_time(); }

Member Data Documentation

◆ custom_times_

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

Vector of times where output is generated.

Definition at line 469 of file clock.h.

◆ start_time_

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

Starting time of the simulation.

Definition at line 471 of file clock.h.


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