# PhasicFlow: src/phasicFlow/Timer/Timer.hpp Source File

Timer.hpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __Timerr_hpp__
#define __Timerr_hpp__
#include <chrono>
#include "types.hpp"
namespace pFlow
{
// forward
class Timers;
class Timer
{
protected:
using timer = std::chrono::high_resolution_clock;
// - name for the timer
word name_ = "noNameTimer";
// start time
timer::time_point start_;
// number of times start() and end() are called
int32 numIteration_ = 0;
// sum of time duratios (in seconds) between all start() and end() calls
real accTime_ = 0.0;
//
real lastTime_ = 0.0;
Timers* parrent_ = nullptr;
public:
TypeInfo("Timer");
Timer(){}
Timer(const word name)
:
name_(name)
{}
Timer(const word name, Timers* parrent);
const word& name()const
{
return name_;
}
virtual ~Timer();
virtual void removeParrent()
{
parrent_ = nullptr;
}
virtual int32 level()const;
virtual bool master()const
{
return false;
}
void start()
{
start_ = timer::now();
}
void end()
{
auto end = timer::now();
lastTime_ = std::chrono::duration_cast
< std::chrono::duration<real> >(end - start_).count();
numIteration_++;
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();
}
virtual bool write(iOstream& os, bool subTree)const;
virtual bool read(iIstream& is)
{
return true;
}
};
inline iOstream& operator<<(iOstream& os, const Timer& t)
{
t.write(os, false);
return os;
}
inline iIstream& operator>>(iIstream& is, Timer& t)
{
return is;
}
}
#endif //__Timer_hpp__
pFlow::Timer::averageTime
real averageTime() const
Definition: Timer.hpp:131
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::Timer::start
void start()
Definition: Timer.hpp:97
pFlow::Timer::name_
word name_
Definition: Timer.hpp:46
types.hpp
pFlow::Timer::totalTime
real totalTime() const
Definition: Timer.hpp:125
pFlow::Timer::removeParrent
virtual void removeParrent()
Definition: Timer.hpp:84
pFlow::Timer::numIteration_
int32 numIteration_
Definition: Timer.hpp:52
pFlow::Timer::write
virtual bool write(iOstream &os, bool subTree) const
Definition: Timer.cpp:52
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::Timers
Definition: Timers.hpp:33
pFlow::Timer::start_
timer::time_point start_
Definition: Timer.hpp:49
pFlow::Timer::Timer
Timer()
Definition: Timer.hpp:66
pFlow
Definition: demComponent.hpp:28
pFlow::Timer::lastTime
real lastTime() const
Definition: Timer.hpp:119
pFlow::Timer::parrent_
Timers * parrent_
Definition: Timer.hpp:60
pFlow::Timer::end
void end()
Definition: Timer.hpp:102
pFlow::Timer::~Timer
virtual ~Timer()
Definition: Timer.cpp:35
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::Timer::lastTime_
real lastTime_
Definition: Timer.hpp:58
pFlow::Timer
Definition: Timer.hpp:39
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::Timer::Timer
Timer(const word name)
Definition: Timer.hpp:68
pFlow::count
auto count(const Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:26
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::Timer::level
virtual int32 level() const
Definition: Timer.cpp:43
pFlow::max
T max(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:164
pFlow::Timer::accTime_
real accTime_
Definition: Timer.hpp:55
pFlow::Timer::name
const word & name() const
Definition: Timer.hpp:77
pFlow::Timer::master
virtual bool master() const
Definition: Timer.hpp:92
pFlow::Timer::accTimersTotal
virtual real accTimersTotal() const
Definition: Timer.hpp:138
pFlow::Timer::read
virtual bool read(iIstream &is)
Definition: Timer.hpp:147
pFlow::Timer::timer
std::chrono::high_resolution_clock timer
Definition: Timer.hpp:43
pFlow::Timer::TypeInfo
TypeInfo("Timer")
pFlow::Timer::timerActive
bool timerActive() const
Definition: Timer.hpp:113
pFlow::iOstream
Definition: iOstream.hpp:53