MercuryDPM  Beta
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

void set (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.

Definition at line 88 of file MercuryTime.h.

## Member Function Documentation

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

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

Parameters
 [in] t current simulation time
Returns
time of the day, in hours, at which the simulation is predicted to end

Definition at line 142 of file MercuryTime.h.

References getTime2Finish().

143  {
144  // gets the estimated time left to finish.
145  Mdouble time2Finish = getTime2Finish(t);
146
147  // adds to the estimated time to current time and also type-casting Mdouble to time_t.
148  time_t finish = time(nullptr) + time2Finish;
149
150  std::stringstream ss;
151
152  //write estimated end time
153  ss << ctime(&finish);
154
155  //decrement put pointer by one to avoid line break
156  ss.seekp((long) ss.tellp() - 1);
157
158  //write time to finish
159  ss << " (" << time2Finish / 3600 << "h)";
160  return ss.str();
161  }
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:118
double Mdouble
 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] t current simulation time.
Returns
Mdouble time, in seconds, left to reach the end of any simulation

Definition at line 118 of file MercuryTime.h.

References startTime_, time_, and timeMax_.

Referenced by getFinishTime().

119  {
120  clock_t finish = clock();
121  Mdouble elapsedTime = (Mdouble(finish) - Mdouble(startTime_)) / CLOCKS_PER_SEC;
122
123  if (fabs(time_ - t) < 1.e-9)
124  {
125  std::cout << "Choose an other value for t" << std::endl;
126  return 0;
127  }
128  else
129  {
130  Mdouble time2Finish = elapsedTime * (timeMax_ - time_) / (t - time_);
131  startTime_ = finish;
132  time_ = t;
133  return time2Finish;
134  }
135  }
clock_t startTime_
Stores the current number of clock ticks at the start.
Definition: MercuryTime.h:165
Mdouble time_
Stores the simulation time (DPM units)
Definition: MercuryTime.h:168
double Mdouble
Mdouble timeMax_
Stores the total simulation time (DPM units)
Definition: MercuryTime.h:171
 void Time2Finish::set ( 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] t current simulation time. [in] tMax total simulation time for which the simulation is set to run.

Definition at line 98 of file MercuryTime.h.

References startTime_, time_, and timeMax_.

99  {
100  startTime_ = clock();
101  time_ = t;
102  timeMax_ = tMax;
103  }
clock_t startTime_
Stores the current number of clock ticks at the start.
Definition: MercuryTime.h:165
Mdouble time_
Stores the simulation time (DPM units)
Definition: MercuryTime.h:168
Mdouble timeMax_
Stores the total simulation time (DPM units)
Definition: MercuryTime.h:171

## Member Data Documentation

 clock_t Time2Finish::startTime_
private

Stores the current number of clock ticks at the start.

Definition at line 165 of file MercuryTime.h.

Referenced by getTime2Finish(), and set().

 Mdouble Time2Finish::time_
private

Stores the simulation time (DPM units)

Definition at line 168 of file MercuryTime.h.

Referenced by getTime2Finish(), and set().

 Mdouble Time2Finish::timeMax_
private

Stores the total simulation time (DPM units)

Definition at line 171 of file MercuryTime.h.

Referenced by getTime2Finish(), and set().

The documentation for this class was generated from the following file:
{"ft_lang_label":"__label__en","ft_lang_prob":0.85732514,"math_prob":0.96510684,"size":3728,"snap":"2022-27-2022-33","text_gpt3_token_len":848,"char_repetition_ratio":0.18662728,"word_repetition_ratio":0.7013652,"special_character_ratio":0.22505365,"punctuation_ratio":0.15774648,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9689504,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-07-07T08:16:30Z\",\"WARC-Record-ID\":\"<urn:uuid:1ea17352-f115-42b2-bc98-636b46aada51>\",\"Content-Length\":\"33797\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:9b2d33f8-4672-4d20-90e4-061252050e56>\",\"WARC-Concurrent-To\":\"<urn:uuid:e37162b2-5934-41e7-a828-0d1067b0da57>\",\"WARC-IP-Address\":\"149.210.143.222\",\"WARC-Target-URI\":\"http://docs.mercurydpm.org/Beta/d7/d04/classTime2Finish.html\",\"WARC-Payload-Digest\":\"sha1:QREM6NBBNBEEFNOKO2NCHZVKDMRK6TKQ\",\"WARC-Block-Digest\":\"sha1:EFDLWIVMSKXWLHTM35INNGX2G32GDCTY\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656104683708.93_warc_CC-MAIN-20220707063442-20220707093442-00044.warc.gz\"}"}