# PhasicFlow: src/phasicFlow/repository/systemControl/systemControl.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.

systemControl.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 "systemControl.hpp"
#include "Lists.hpp"
#include "error.hpp"
#include "iOstream.hpp"
#include "types.hpp"
#include "vocabs.hpp"
bool pFlow::systemControl::readIncludeExclue(const dictionary& dict)
{
if (dict.containsDataEntry("includeObjects"))
{
wordList incld = dict.getVal<wordList>("includeObjects");
for (auto& nm : incld)
{
includeList_.insert(nm);
}
}
if (dict.containsDataEntry("excludeObjects"))
{
wordList excld = dict.getVal<wordList>("excludeObjects");
for (auto& nm : excld)
{
excludeList_.insert(nm);
}
}
return true;
}
pFlow::word pFlow::systemControl::getRunName(const fileSystem& path)
{
// gets the canonical form of path
word wPath = path.canonical().wordPath() + "/";
auto first = wPath.find_first_of('/');
auto last = wPath.find_last_of('/');
if (first == word::npos)
{
fatalErrorInFunction << "path is empty \n";
fatalExit;
}
if (last == wPath.size() - 1)
{
wPath = wPath.substr(0, last);
last = wPath.find_last_of('/');
}
word rName = wPath.substr(last + 1);
return rName;
}
pFlow::word pFlow::systemControl::getTopFolder(const fileSystem& path)
{
// gets the canonical form of path
word wPath = path.canonical().wordPath();
auto first = wPath.find_first_of('/');
auto last = wPath.find_last_of('/');
if (first == word::npos)
{
fatalErrorInFunction << "path is empty \n";
fatalExit;
}
if (last == wPath.size() - 1)
{
wPath = wPath.substr(0, last);
last = wPath.find_last_of('/');
}
word tFolder = wPath.substr(0, last);
return tFolder;
}
pFlow::systemControl::systemControl(const fileSystem path)
: repository(
"systemControl",
path, // local path
nullptr // no owner
),
runName_(getRunName(path)),
topLevelFolder_(getTopFolder(path)),
settingsDict_(makeUnique<fileDictionary>(
objectFile(
settingsFile__,
settingsFolder__,
objectFile::READ_ALWAYS,
objectFile::WRITE_NEVER
),
this
)),
Time_(this, settingsDict_()),
settings_(
makeUnique<repository>(settingsRepository__, settingsFolder__, this)
),
caseSetup_(
makeUnique<repository>(caseSetupRepository__, caseSetupFolder__, this)
),
libs_(settingsDict_()),
outFilePrecision_(
settingsDict_().getValOrSet("outFilePrecision", static_cast<uint64>(6))
),
timers_(runName_),
timersReport_(settingsDict_().getValOrSet("timersReport", Logical("Yes"))),
writeToFileTimer_("Write to file", &timers_)
{
readIncludeExclue(settingsDict_());
}
pFlow::systemControl::systemControl(
const real startTime,
const real endTime,
const real saveInterval,
const word startTimeName,
const fileSystem path
)
: repository(
"systemControl",
path, // local path
nullptr // no owner
),
runName_(getRunName(path)),
topLevelFolder_(getTopFolder(path)),
settingsDict_(makeUnique<fileDictionary>(
objectFile(
settingsFile__,
settingsFolder__,
objectFile::READ_ALWAYS,
objectFile::WRITE_NEVER
),
this
)),
Time_(
this,
settingsDict_(),
startTime,
endTime,
saveInterval,
startTimeName
),
settings_(
makeUnique<repository>(settingsRepository__, settingsFolder__, this)
),
caseSetup_(
makeUnique<repository>(caseSetupRepository__, caseSetupFolder__, this)
),
libs_(settingsDict_()),
externalTimeControl_(true),
timers_(runName_),
timersReport_(settingsDict_->getValOrSet("timersReport", Logical("Yes"))),
writeToFileTimer_("Write to file", &timers_)
{
readIncludeExclue(settingsDict_());
}
bool pFlow::systemControl::operator++(int)
{
auto toContinue = time()++;
if (toContinue)
{
writeToFileTimer_.start();
// if(time().currentIter() != 0 )
{
//- save the results to file
if (!time().write())
{
fatalErrorInFunction;
return false;
}
}
writeToFileTimer_.end();
if (time().timersReportTime() && timersReport())
{
timers_.write(mOutput, true);
}
}
else if (time().finalTime())
{
writeToFileTimer_.start();
if (!time().write())
{
fatalErrorInFunction;
return false;
}
writeToFileTimer_.end();
timers_.write(mOutput, true);
}
return toContinue;
}
pFlow::List< word >
pFlow::fileSystem::canonical
fileSystem canonical() const
Canonical path of this (it should exist)
Definition: fileSystem.cpp:149
pFlow::real
float real
Definition: builtinTypes.hpp:45
Lists.hpp
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::mOutput
masterOstream mOutput
types.hpp
systemControl.hpp
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::systemControl::readIncludeExclue
bool readIncludeExclue(const dictionary &dict)
Definition: systemControl.cpp:28
pFlow::caseSetupRepository__
const char *const caseSetupRepository__
Definition: vocabs.hpp:31
pFlow::settingsFolder__
const char *const settingsFolder__
Definition: vocabs.hpp:28
pFlow::systemControl::settingsDict_
uniquePtr< fileDictionary > settingsDict_
settingsDict fileDictionary
Definition: systemControl.hpp:54
pFlow::dictionary::containsDataEntry
bool containsDataEntry(const word &name) const
check if a data entry exist
Definition: dictionary.cpp:761
pFlow::fileSystem
Manages file pathes, manupulate and combines them.
Definition: fileSystem.hpp:71
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::systemControl::getTopFolder
static word getTopFolder(const fileSystem &path)
Definition: systemControl.cpp:75
pFlow::systemControl::systemControl
systemControl(const fileSystem path=CWD())
Definition: systemControl.cpp:100
pFlow::systemControl::getRunName
static word getRunName(const fileSystem &path)
Definition: systemControl.cpp:50
pFlow::objectFile
Definition: objectFile.hpp:30
pFlow::makeUnique
uniquePtr< T > makeUnique(Args &&... args)
Definition: uniquePtr.hpp:99
pFlow::dictionary::getVal
T getVal(const word &keyword) const
get the value of data entry
Definition: dictionary.hpp:379
pFlow::systemControl::operator++
bool operator++(int)
Definition: systemControl.cpp:182
pFlow::Logical
Holds a bool value and converts strings to bool.
Definition: Logical.hpp:39
pFlow::caseSetupFolder__
const char *const caseSetupFolder__
Definition: vocabs.hpp:30
pFlow::fileDictionary
Definition: fileDictionary.hpp:29
pFlow::uint64
unsigned long long int uint64
Definition: builtinTypes.hpp:58
pFlow::systemControl::includeList_
wordSet includeList_
Definition: systemControl.hpp:82
pFlow::repository
Definition: repository.hpp:34
pFlow::systemControl::excludeList_
wordSet excludeList_
Definition: systemControl.hpp:84
iOstream.hpp
pFlow::fileSystem::wordPath
word wordPath() const
Path in word type.
Definition: fileSystem.hpp:160
pFlow::settingsRepository__
const char *const settingsRepository__
Definition: vocabs.hpp:29
vocabs.hpp
pFlow::settingsFile__
const char *const settingsFile__
Definition: vocabs.hpp:38
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
error.hpp