Time2Finish Class Reference

Estimates the total time, in seconds, left to reach the end of any simulation. First, the class needs to be initialized by calling set. After the class is initialized, an estimate of the total remaining time of the simulation can be found by calling getTime2Finish. The estimate is based on rate at which the simulation time progressed since initialization. More...

#include <MercuryTime.h>

Public Member Functions

 Time2Finish (Mdouble t, Mdouble tMax)
 Initialises the variable start with the current value of clock ticks, the current time and the final time of the simulation. More...
 
Mdouble getTime2Finish (Mdouble t)
 Estimates the total time, in seconds, left to reach the end of any simulation. After the class is initialized, an estimate of the total remaining time of the simulation can be found by calling getTime2Finish. The estimate is based on rate at which the simulation time progressed since initialization. More...
 
std::string getFinishTime (Mdouble t)
 Returns the estimated finish time based on the amount of time left to finish. More...
 

Private Attributes

clock_t startTime_
 Stores the current number of clock ticks at the start. More...
 
Mdouble time_
 Stores the simulation time (DPM units) More...
 
Mdouble timeMax_
 Stores the total simulation time (DPM units) More...
 

Detailed Description

Estimates the total time, in seconds, left to reach the end of any simulation. First, the class needs to be initialized by calling set. After the class is initialized, an estimate of the total remaining time of the simulation can be found by calling getTime2Finish. The estimate is based on rate at which the simulation time progressed since initialization.

E.g., assume that the class has been initialized at simulation time 0, with final time 10. Then, getTime2Finish is called after 1 hour at simulation time 2. Since the code required 0.5 hours per simulation time unit and there are 8 simulation time units left, it is likely to finish in 4 hours.

Constructor & Destructor Documentation

◆ Time2Finish()

Time2Finish::Time2Finish ( Mdouble  t,
Mdouble  tMax 
)
inline

Initialises the variable start with the current value of clock ticks, the current time and the final time of the simulation.

Parameters
[in]tcurrent simulation time.
[in]tMaxtotal simulation time for which the simulation is set to run.
119  {
120  startTime_ = clock();
121  time_ = t;
122  timeMax_ = tMax;
123  }
Mdouble timeMax_
Stores the total simulation time (DPM units)
Definition: MercuryTime.h:191
clock_t startTime_
Stores the current number of clock ticks at the start.
Definition: MercuryTime.h:185
Mdouble time_
Stores the simulation time (DPM units)
Definition: MercuryTime.h:188
t
Definition: plotPSD.py:36

References startTime_, plotPSD::t, time_, and timeMax_.

Member Function Documentation

◆ getFinishTime()

std::string Time2Finish::getFinishTime ( Mdouble  t)
inline

Returns the estimated finish time based on the amount of time left to finish.

Parameters
[in]tcurrent simulation time
Returns
time of the day, in hours, at which the simulation is predicted to end
163  {
164  // gets the estimated time left to finish.
165  Mdouble time2Finish = getTime2Finish(t);
166 
167  // adds to the estimated time to current time and also type-casting Mdouble to time_t.
168  time_t finish = time(nullptr) + time2Finish;
169 
170  std::stringstream ss;
171 
172  //write estimated end time
173  ss << ctime(&finish);
174 
175  //decrement put pointer by one to avoid line break
176  ss.seekp((long) ss.tellp() - 1);
177 
178  //write time to finish
179  ss << " (" << time2Finish / 3600 << "h)";
180  return ss.str();
181  }
double Mdouble
Definition: GeneralDefine.h:13
Mdouble getTime2Finish(Mdouble t)
Estimates the total time, in seconds, left to reach the end of any simulation. After the class is ini...
Definition: MercuryTime.h:138

References getTime2Finish(), and plotPSD::t.

◆ getTime2Finish()

Mdouble Time2Finish::getTime2Finish ( Mdouble  t)
inline

Estimates the total time, in seconds, left to reach the end of any simulation. After the class is initialized, an estimate of the total remaining time of the simulation can be found by calling getTime2Finish. The estimate is based on rate at which the simulation time progressed since initialization.

E.g., assume that the class has been initialized at simulation time 0, with final time 10. Then, getTime2Finish is called after 1 hour at simulation time 2. Since the code required 0.5 hours per simulation time unit and there are 8 simulation time units left, it is likely to finish in 4 hours.

Parameters
[in]tcurrent simulation time.
Returns
Mdouble time, in seconds, left to reach the end of any simulation
139  {
140  clock_t finish = clock();
141  Mdouble elapsedTime = (Mdouble(finish) - Mdouble(startTime_)) / CLOCKS_PER_SEC;
142 
143  if (fabs(time_ - t) < 1.e-9)
144  {
145  logger(WARN, "Choose an other value for t");
146  return 0;
147  }
148  else
149  {
150  Mdouble time2Finish = elapsedTime * (timeMax_ - time_) / (t - time_);
151  startTime_ = finish;
152  time_ = t;
153  return time2Finish;
154  }
155  }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ WARN
Real fabs(const Real &a)
Definition: boostmultiprec.cpp:117

References boost::multiprecision::fabs(), logger, startTime_, plotPSD::t, time_, timeMax_, and WARN.

Referenced by getFinishTime().

Member Data Documentation

◆ startTime_

clock_t Time2Finish::startTime_
private

Stores the current number of clock ticks at the start.

Referenced by getTime2Finish(), and Time2Finish().

◆ time_

Mdouble Time2Finish::time_
private

Stores the simulation time (DPM units)

Referenced by getTime2Finish(), and Time2Finish().

◆ timeMax_

Mdouble Time2Finish::timeMax_
private

Stores the total simulation time (DPM units)

Referenced by getTime2Finish(), and Time2Finish().


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