mirror of
https://github.com/PhasicFlow/phasicFlow.git
synced 2025-06-12 16:26:23 +00:00
timers modefied
This commit is contained in:
@ -77,18 +77,24 @@ bool pFlow::Timer::write(iOstream& os, bool subTree)const
|
||||
|
||||
if(lvl==0)
|
||||
os<<greenColor<<boldChar;
|
||||
else if(master())
|
||||
os<<yellowColor;
|
||||
|
||||
|
||||
os<<name_;
|
||||
|
||||
if(timerActive())
|
||||
if(master())
|
||||
os<<" execution time (s): total ("<<
|
||||
totalTime()<<"), av. ("<<
|
||||
averageTime()<<").";
|
||||
else
|
||||
os<<" execution time (s): total ("<<
|
||||
cyanText(totalTime())<<"), av. ("<<
|
||||
cyanText(averageTime())<<").";
|
||||
auto tt = accTimersTotal();
|
||||
if(abs(tt)>smallValue)
|
||||
{
|
||||
os<<" execution time (s): total ("<<
|
||||
tt<<")";
|
||||
|
||||
if(!master())
|
||||
{
|
||||
os<<", av. ("<<
|
||||
averageTime()<<").";
|
||||
}
|
||||
}
|
||||
|
||||
os<<defaultColor;
|
||||
os<<'\n';
|
||||
|
@ -109,31 +109,40 @@ public:
|
||||
accTime_ += lastTime_;
|
||||
}
|
||||
|
||||
inline
|
||||
bool timerActive()const
|
||||
{
|
||||
return numIteration_!=0;
|
||||
}
|
||||
|
||||
inline
|
||||
real lastTime()const
|
||||
{
|
||||
return lastTime_;
|
||||
}
|
||||
|
||||
inline
|
||||
real totalTime()const
|
||||
{
|
||||
return accTime_;
|
||||
}
|
||||
|
||||
inline
|
||||
real averageTime()const
|
||||
{
|
||||
|
||||
return accTime_/max(numIteration_, 1);
|
||||
}
|
||||
|
||||
virtual
|
||||
real accTimersTotal()const
|
||||
{
|
||||
return totalTime();
|
||||
}
|
||||
|
||||
//// - IO operations
|
||||
|
||||
virtual bool write(iOstream& os, bool subTree)const;
|
||||
|
||||
|
||||
virtual bool read(iIstream& is)
|
||||
{
|
||||
|
@ -21,6 +21,27 @@ Licence:
|
||||
|
||||
#include "Timers.hpp"
|
||||
|
||||
pFlow::real pFlow::Timers::accTimersTotal()const
|
||||
{
|
||||
// first this timer
|
||||
real total = 0;
|
||||
if(this->timerActive()) total += this->totalTime();
|
||||
|
||||
for(const auto tmr:timers_)
|
||||
{
|
||||
if(tmr -> master())
|
||||
{
|
||||
total += dynamic_cast<const Timers*>(tmr)->accTimersTotal();
|
||||
}
|
||||
else if(tmr->timerActive())
|
||||
{
|
||||
total += tmr->totalTime();
|
||||
}
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
bool pFlow::Timers::write(iOstream& os, bool subTree)const
|
||||
{
|
||||
|
@ -30,7 +30,7 @@ namespace pFlow
|
||||
|
||||
class Timers
|
||||
:
|
||||
public Timer
|
||||
public pFlow::Timer
|
||||
{
|
||||
protected:
|
||||
|
||||
@ -93,6 +93,8 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
real accTimersTotal()const override;
|
||||
|
||||
virtual bool write(iOstream& os, bool subTree = true)const;
|
||||
|
||||
|
||||
|
@ -100,6 +100,19 @@ pFlow::timeControl::timeControl(
|
||||
checkForOutputToFile();
|
||||
}
|
||||
|
||||
bool pFlow::timeControl::finalTime()const
|
||||
{
|
||||
if( currentTime_ >= endTime_ ) return true;
|
||||
if( abs(currentTime_-endTime_) < 0.5*dt_ )return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool pFlow::timeControl::reachedStopAt()const
|
||||
{
|
||||
if( currentTime_ >= stopAt_ ) return true;
|
||||
if( abs(currentTime_-stopAt_) < 0.5*dt_ )return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void pFlow::timeControl::checkForOutputToFile()
|
||||
{
|
||||
|
@ -152,18 +152,9 @@ public:
|
||||
return currentIter_;
|
||||
}
|
||||
|
||||
bool finalTime()const
|
||||
{
|
||||
if( currentTime_ >= endTime_ ) return true;
|
||||
if( abs(currentTime_-endTime_) < 0.5*dt_ )return true;
|
||||
return false;
|
||||
}
|
||||
bool reachedStopAt()const
|
||||
{
|
||||
if( currentTime_ >= stopAt_ ) return true;
|
||||
if( abs(currentTime_-stopAt_) < 0.5*dt_ )return true;
|
||||
return false;
|
||||
}
|
||||
bool finalTime()const;
|
||||
|
||||
bool reachedStopAt()const;
|
||||
|
||||
bool outputToFile()const
|
||||
{
|
||||
|
@ -237,33 +237,39 @@ bool pFlow::systemControl::operator ++(int)
|
||||
|
||||
// skip writing to file for the first iteration
|
||||
//output<< "time()++"<<endl;
|
||||
auto finished = time()++;
|
||||
|
||||
writeToFileTimer_.start();
|
||||
if(time().currentIter() != 0)
|
||||
{
|
||||
//- save the results to file
|
||||
if( !time().write() )
|
||||
{
|
||||
fatalErrorInFunction;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( time().finalTime() )
|
||||
{
|
||||
if( !time().write() )
|
||||
{
|
||||
fatalErrorInFunction;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
writeToFileTimer_.end();
|
||||
auto finished = time()++;
|
||||
|
||||
//output<< "after finalTime()"<<endl;
|
||||
if(!finished)
|
||||
{
|
||||
writeToFileTimer_.start();
|
||||
//if(time().currentIter() != 0 )
|
||||
{
|
||||
//- save the results to file
|
||||
if( !time().write() )
|
||||
{
|
||||
fatalErrorInFunction;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
writeToFileTimer_.end();
|
||||
|
||||
if( time().timersReportTime() &&
|
||||
if( time().timersReportTime() &&
|
||||
timersReport() )
|
||||
{
|
||||
timers_.write(output, true);
|
||||
}
|
||||
|
||||
}
|
||||
else if (time().finalTime())
|
||||
{
|
||||
writeToFileTimer_.start();
|
||||
if( !time().write() )
|
||||
{
|
||||
fatalErrorInFunction;
|
||||
return false;
|
||||
}
|
||||
writeToFileTimer_.end();
|
||||
|
||||
timers_.write(output, true);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user