# PhasicFlow: utilities/Utilities/readControlDict.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.

readControlDict.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 "readControlDict.hpp"
#include "iFstream.hpp"
#include "timeFolder.hpp"
pFlow::word pFlow::readControlDict::convertTimeToName(
const real t,
const int32 precision)const
{
std::ostringstream buf;
if( formatType_ == "general")
buf.setf(ios_base::fmtflags(0), ios_base::floatfield);
else if(formatType_ == "scientific")
buf.setf(ios_base::fmtflags(ios_base::scientific), ios_base::floatfield);
else if(formatType_ == "fixed")
buf.setf(ios_base::fmtflags(ios_base::fixed), ios_base::floatfield);
else
{
fatalErrorInFunction<<"the timeFormat is not correct, it should be "
" (genral, scientific, fixe) but you supplied "<< formatType_<<endl;
fatalExit;
}
buf.precision(precision);
buf << t;
return buf.str();
}
bool pFlow::readControlDict::read()
{
iFstream cdFile(cdPath_);
word startFrom;
if( !cdFile.findTokenAndNextSilent("startFrom", startFrom))
{
startFrom = "latestTime";
}
if(startFrom == "startTime")
{
if(!cdFile.findKeywordAndVal("startTime", startTime_ ))
{
fatalErrorInFunction<<"Could not read startTime from file "<< cdPath_<<endl;
return false;
}
}
else
{
timeFolder folders(rootPath_);
if(startFrom == "firstTime")
{
startTime_ = folders.startTime();
}
else if( startFrom == "latestTime")
{
startTime_ = folders.endTime();
}
else
{
fatalErrorInFunction<<
"expected firstTime, latestTime, or startTime in front of StartFrom, "<<endl<<
"but found "<<startFrom<<endl;
return false;
}
}
if(!cdFile.findKeywordAndVal("endTime", endTime_ ))
{
fatalErrorInFunction<<
"Could not read endTime from file "<< cdPath_<<endl;
return false;
}
if(!cdFile.findKeywordAndVal("writeInterval", saveInterval_))
{
fatalErrorInFunction<<
"Could not read writeInterval from file "<< cdPath_<<endl;
return false;
}
formatType_ = cdFile.lookupDataOrSet<word>("timeFormat", "general");
precision_ = cdFile.lookupDataOrSet("timePrecision", 6);
return true;
}
pFlow::readControlDict::readControlDict(
const fileSystem& rootPath,
const fileSystem& cdPath)
:
rootPath_(rootPath),
cdPath_(cdPath)
{
if(!read())
{
fatalExit;
}
}
pFlow::fixed
IOstream & fixed(IOstream &io)
Definition: IOstream.hpp:329
pFlow::iIstream::findTokenAndNextSilent
virtual bool findTokenAndNextSilent(const word &w, word &nextW, int32 limitLine=100)
Definition: iIstream.cpp:203
pFlow::scientific
IOstream & scientific(IOstream &io)
Definition: IOstream.hpp:335
pFlow::iIstream::lookupDataOrSet
T lookupDataOrSet(const word &keyword, const T &setVal)
lookup for keyword and data; set to setVal if lookup fails.
Definition: iIstreamI.hpp:68
pFlow::real
float real
Definition: builtinTypes.hpp:45
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::iIstream::findKeywordAndVal
bool findKeywordAndVal(const word &keyword, T &val, bool checkEndStatement=true)
find a pair of keyword and data terminated by ; keyword data; return false if keyword does not exist ...
Definition: iIstreamI.hpp:24
pFlow::iFstream
Input file stream for reading binary or ascii data from a file.
Definition: iFstream.hpp:37
pFlow::timeFolder::startTime
real startTime() const
Definition: timeFolder.hpp:105
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::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::readControlDict::formatType_
word formatType_
Definition: readControlDict.hpp:45
pFlow::timeFolder::endTime
real endTime() const
Definition: timeFolder.hpp:111
readControlDict.hpp
iFstream.hpp
pFlow::readControlDict::read
bool read()
Definition: readControlDict.cpp:47
pFlow::readControlDict::readControlDict
readControlDict(const fileSystem &rootPath=defaultRootPath, const fileSystem &cdPath=defaultCDPath)
Definition: readControlDict.cpp:109
pFlow::readControlDict::convertTimeToName
word convertTimeToName(const real t, const int32 precision) const
Definition: readControlDict.cpp:24
timeFolder.hpp
pFlow::timeFolder
Definition: timeFolder.hpp:32