# PhasicFlow: src/phasicFlow/repository/Time/timeControl.cpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

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 "math.hpp"
#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)
),
performSorting_
(
dict.getValOrSet("performSorting", Logical("No"))
),
sortingInterval_
(
startTime_,
dict.getValOrSet("sortingInterval", static_cast< real >(1.0))
)
{
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)
),
performSorting_
(
dict.getValOrSet("performSorting", Logical("No"))
),
sortingInterval_
(
startTime_,
dict.getValOrSet("sortingInterval", static_cast<real>(1.0))
)
{
checkForOutputToFile();
}
pFlow::real pFlow::timeControl::setTime(real t)
{
real tmp = currentTime_;
currentTime_ = t;
lastSaved_ = t;
checkForOutputToFile();
return tmp;
}
pFlow::word pFlow::timeControl::timeName()const
{
if(managedExternaly_)
return timeName_;
else
return currentTimeWord();
}
bool pFlow::timeControl::finalTime()const
{
if( currentTime_ >= endTime_ ) return true;
if( std::abs(currentTime_-endTime_) < 0.5*dt_ )return true;
return false;
}
bool pFlow::timeControl::reachedStopAt()const
{
if( currentTime_ >= stopAt_ ) return true;
if( std::abs(currentTime_-stopAt_) < 0.5*dt_ )return true;
return false;
}
void pFlow::timeControl::checkForOutputToFile()
{
bool save = false;
if(managedExternaly_)
{
if( std::abs(currentTime_-writeTime_) < 0.5*dt_)
{
save = true;
lastSaved_ = currentTime_;
}
}
else
{
if ( std::abs(currentTime_ - lastSaved_ - saveInterval_) < 0.5 * dt_ )
{
lastSaved_ = currentTime_;
save = true;
}
else if( std::abs(currentTime_ - lastSaved_) < std::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_, 0.55*dt_);
}
bool pFlow::timeControl::sortTime()const
{
return performSorting_()&&sortingInterval_.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): "<<Cyan_Text( currentTimeWord() )<<END_REPORT;
}
// switch outputToFile_ on/off
checkForOutputToFile();
return true;
}
pFlow::dictionary::getValOrSet
T getValOrSet(const word &keyword, const T &setVal) const
get the value of data entry or if not found, set the value to setVal
Definition: dictionary.hpp:415
pFlow::timeControl::timersReportTime
bool timersReportTime() const
Definition: timeControl.cpp:181
pFlow::real
float real
Definition: builtinTypes.hpp:45
Cyan_Text
#define Cyan_Text(text)
Definition: iOstream.hpp:44
REPORT
#define REPORT(n)
Definition: streams.hpp:39
pFlow::timeControl::operator++
bool operator++(int)
Definition: timeControl.cpp:203
pFlow::timeControl::sortTime
bool sortTime() const
Definition: timeControl.cpp:187
pFlow::pow
Vector< T, Allocator > pow(const Vector< T, Allocator > &v1, const Vector< T, Allocator > &v2)
Definition: VectorMath.hpp:89
pFlow::algorithms::KOKKOS::min
INLINE_FUNCTION_H Type min(const Type *first, int32 numElems)
Definition: kokkosAlgorithms.hpp:124
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::timeControl::timeName
word timeName() const
Definition: timeControl.cpp:129
pFlow::timeControl::setTime
real setTime(real t)
Definition: timeControl.cpp:120
timeControl.hpp
dictionary.hpp
pFlow::timeControl::screenReportInterval_
int32StridedRagne screenReportInterval_
Definition: timeControl.hpp:83
pFlow::timeControl::screenReport
bool screenReport() const
Definition: timeControl.cpp:26
pFlow::timeControl::checkForOutputToFile
void checkForOutputToFile()
Definition: timeControl.cpp:151
pFlow::abs
Vector< T, Allocator > abs(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:84
END_REPORT
#define END_REPORT
Definition: streams.hpp:40
pFlow::timeControl::finalTime
bool finalTime() const
Definition: timeControl.cpp:137
pFlow::dictionary::getVal
T getVal(const word &keyword) const
get the value of data entry
Definition: dictionary.hpp:379
pFlow::Logical
Holds a bool value and converts strings to bool.
Definition: Logical.hpp:39
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:110
pFlow::timeControl::setSaveTimeFolder
void setSaveTimeFolder(bool saveToFile, const word &timeName="wrongTimeFolder")
Definition: timeControl.cpp:192
math.hpp
pFlow::dictionary
Dictionary holds a set of data entries or sub-dictionaries that are enclosed in a curely braces or ar...
Definition: dictionary.hpp:67
pFlow::timeControl::reachedStopAt
bool reachedStopAt() const
Definition: timeControl.cpp:144