# PhasicFlow: src/phasicFlow/repository/Time/timeControl.cpp Source File

timeControl.cpp
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.
-----------------------------------------------------------------------------*/
#include "timeControl.hpp"
#include "dictionary.hpp"
bool pFlow::timeControl::screenReport()const
{
return screenReportInterval_.isMember(currentIter_);
}
pFlow::timeControl::timeControl
(
const dictionary& dict
)
:
dt_
(
dict.getVal<real>("dt")
),
startTime_
(
dict.getVal<real>("startTime")
),
endTime_
(
dict.getVal<real>("endTime")
),
stopAt_(endTime_),
currentTime_(startTime_),
saveInterval_
(
dict.getVal<real>("saveInterval")
),
lastSaved_(startTime_),
currentIter_(0),
timePrecision_
(
dict.getValOrSet("timePrecision", 4)
),
timersReportInterval_
(
startTime_,
dict.getValOrSet("timersReportInterval", 0.04)
)
{
checkForOutputToFile();
}
pFlow::timeControl::timeControl(
dictionary& dict,
real startTime,
real endTime,
real saveInterval,
word startTimeName)
:
dt_
(
dict.getVal<real>("dt")
),
startTime_(startTime),
endTime_(endTime),
stopAt_(endTime_),
currentTime_(startTime_),
saveInterval_(saveInterval),
lastSaved_(startTime_),
currentIter_(0),
timePrecision_
(
dict.getValOrSet("timePrecision", 4)
),
managedExternaly_(true),
timeName_(startTimeName),
timersReportInterval_
(
startTime_,
dict.getValOrSet("timersReportInterval", 0.04)
)
{
checkForOutputToFile();
}
pFlow::word pFlow::timeControl::timeName()const
{
if(managedExternaly_)
return timeName_;
else
return currentTimeWord();
}
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()
{
bool save = false;
if(managedExternaly_)
{
if( abs(currentTime_-writeTime_) < 0.5*dt_)
{
save = true;
lastSaved_ = currentTime_;
}
}
else
{
if ( abs(currentTime_ - lastSaved_ - saveInterval_) < 0.5 * dt_ )
{
lastSaved_ = currentTime_;
save = true;
}
else if( abs(currentTime_ - lastSaved_) < min( pow(10.0,-1.0*timePrecision_), 0.5 *dt_) )
{
lastSaved_ = currentTime_;
save = true;
}
}
outputToFile_ = save;
}
bool pFlow::timeControl::timersReportTime()const
{
if(currentIter_<=1)return false;
return timersReportInterval_.isMember(currentTime_, dt_);
}
void pFlow::timeControl::setSaveTimeFolder(
bool saveToFile,
const word& timeName)
{
if(managedExternaly_)
{
outputToFile_ = saveToFile;
timeName_ = timeName;
}
}
bool pFlow::timeControl::operator ++(int)
{
if( reachedStopAt() ) return false;
// increament iteration number
currentIter_++;
currentTime_ += dt_;
if(screenReport() && !managedExternaly_)
{
REPORT(0)<<"Time (s): "<<cyanText( currentTimeWord() )<<endREPORT;
}
// switch outputToFile_ on/off
checkForOutputToFile();
return true;
}
endREPORT
#define endREPORT
Definition: streams.hpp:41
pFlow::dictionary::getValOrSet
T getValOrSet(const word &keyword, const T &setVal) const
Definition: dictionary.hpp:325
pFlow::timeControl::timersReportTime
bool timersReportTime() const
Definition: timeControl.cpp:157
pFlow::real
float real
Definition: builtinTypes.hpp:46
REPORT
#define REPORT(n)
Definition: streams.hpp:40
pFlow::timeControl::operator++
bool operator++(int)
Definition: timeControl.cpp:174
cyanText
#define cyanText(text)
Definition: streams.hpp:34
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::timeControl::timeName
word timeName() const
Definition: timeControl.cpp:103
timeControl.hpp
pFlow::pow
Vector< T, Allocator > pow(const Vector< T, Allocator > &v, T e)
Definition: VectorMath.hpp:109
dictionary.hpp
pFlow::timeControl::screenReportInterval_
int32StridedRagne screenReportInterval_
Definition: timeControl.hpp:79
pFlow::abs
INLINE_FUNCTION_HD real abs(real x)
Definition: math.hpp:43
pFlow::timeControl::screenReport
bool screenReport() const
Definition: timeControl.cpp:26
pFlow::timeControl::checkForOutputToFile
void checkForOutputToFile()
Definition: timeControl.cpp:125
pFlow::timeControl::finalTime
bool finalTime() const
Definition: timeControl.cpp:111
pFlow::dictionary::getVal
T getVal(const word &keyword) const
Definition: dictionary.hpp:309
pFlow::timeControl::timeControl
timeControl(const dictionary &dict)
Definition: timeControl.cpp:32
pFlow::timeControl::currentIter_
int32 currentIter_
Definition: timeControl.hpp:66
pFlow::stridedRange::isMember
bool isMember(T val, T epsilon=0) const
Definition: stridedRange.hpp:100
pFlow::timeControl::setSaveTimeFolder
void setSaveTimeFolder(bool saveToFile, const word &timeName="wrongTimeFolder")
Definition: timeControl.cpp:163
pFlow::min
T min(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:138
pFlow::dictionary
Definition: dictionary.hpp:38
pFlow::timeControl::reachedStopAt
bool reachedStopAt() const
Definition: timeControl.cpp:118