# PhasicFlow: src/phasicFlow/streams/iStream/iIstreamI.hpp 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.

iIstreamI.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.
-----------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * templates * * * * * * * * * * * * * * * * *//
template<typename T>
bool pFlow::iIstream::findKeywordAndVal(const word& keyword, T& val, bool checkEndStatement)
{
if( findToken(keyword) )
{
iIstream& is = *this;
is >> val;
if( checkEndStatement )
{
token next(is);
if( !next.good() || !next.isEndStatement() )
{
return false;
}
}
}
else
{
return false;
}
return true;
}
template<typename T>
T pFlow::iIstream::lookupData
(
const word& keyword
)
{
T val;
if( !findKeywordAndVal(keyword, val) )
{
ioErrorInFile( name(), lineNumber() )<<
" error in finding keyword "<< keyword <<" and value next to it.";
fatalExit;
}
return val;
}
template<typename T>
T pFlow::iIstream::lookupDataOrSet(const word& keyword, const T& setVal)
{
T val;
if(!findKeywordAndVal(keyword, val))
{
val = setVal;
}
return val;
}
template<typename T>
bool pFlow::iIstream::nextData(const word& keyword, T& data)
{
token next;
if( !eof() && good() )
{
read(next);
if(next.error())
{
ioErrorInFile(name(), lineNumber());
return false;
}
if( !next.isWord() )
{
ioErrorInFile(name(), lineNumber())<<
" expected word token.";
return false;
}
if(next.wordToken() != keyword)
{
ioErrorInFile(name(), lineNumber())<<
" expected keyword "<< keyword << " but found "<<next.wordToken()<<endl;
return false;
}
iIstream& is = *this;
is >> data;
read(next);
if( !next.good() || !next.isEndStatement() )
{
ioErrorInFile(name(),lineNumber())<<
" expected ; but found "<< next<<endl;
return false;
}
return true;
}
return false;
}
// * * * * * * * * * * * * * * IO operations * * * * * * * * * * * * * * * * *//
inline pFlow::iIstream& pFlow::operator>>(iIstream& is, word & w)
{
token t(is);
if (!t.good())
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Bad token - could not get word/string value";
fatalExit;
is.setBad();
return is;
}
if (t.isString())
{
w = t.stringToken();
}
else if(t.isWord() )
{
w = t.wordToken();
}
else
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Wrong token type - expected word/string value, found "
<< t;
fatalExit;
is.setBad();
return is;
}
is.check(FUNCTION_NAME);
return is;
}
inline pFlow::iIstream& pFlow::operator>>( iIstream& is, int64& val)
{
token t(is);
if (!t.good())
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Bad token - could not get int64 value";
fatalExit;
is.setBad();
return is;
}
if (t.isNumber())
{
val = t.number();
}
else
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Wrong token type - expected int64 value, found "
<< t;
fatalExit;
is.setBad();
return is;
}
is.check(FUNCTION_NAME);
return is;
}
inline pFlow::iIstream& pFlow::operator>>( iIstream& is, int32& val)
{
int64 lval(0);
is>>lval;
val = static_cast< int32 >(lval);
return is;
}
inline pFlow::iIstream& pFlow::operator>>( iIstream& is, int8& val)
{
int64 lval(0);
is>>lval;
val = static_cast< int8 >(lval);
return is;
}
inline pFlow::iIstream& pFlow::operator>>( iIstream& is, uint64& val)
{
int64 lval(0);
is>>lval;
val = static_cast< uint64 >(lval);
return is;
}
inline pFlow::iIstream& pFlow::operator>>( iIstream& is, uint32& val)
{
int64 lval(0);
is>>lval;
val = static_cast< uint32 >(lval);
return is;
}
inline pFlow::iIstream& pFlow::operator>>( iIstream& is, uint8& val)
{
int64 lval(0);
is>>lval;
val = static_cast< uint8 >(lval);
return is;
}
inline pFlow::iIstream& pFlow::operator>>( iIstream& is, float& val)
{
token t(is);
if (!t.good())
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Bad token - could not get float value";
fatalExit;
is.setBad();
return is;
}
if (t.isNumber())
{
val = t.number();
}
else
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Wrong token type - expected float value, found "
<< t;
fatalExit;
is.setBad();
return is;
}
is.check(FUNCTION_NAME);
return is;
}
inline pFlow::iIstream& pFlow::operator>>( iIstream& is, double& val)
{
token t(is);
if (!t.good())
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Bad token - could not get double value";
fatalExit;
is.setBad();
return is;
}
if (t.isNumber())
{
val = t.number();
}
else
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Wrong token type - expected double value, found "
<< t;
fatalExit;
is.setBad();
return is;
}
is.check(FUNCTION_NAME);
return is;
}
inline pFlow::iIstream& pFlow::operator>>( iIstream& is, size_t& val)
{
token t(is);
if (!t.good())
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Bad token - could not get double value";
fatalExit;
is.setBad();
return is;
}
if (t.isNumber())
{
val = static_cast<size_t>(t.number());
}
else
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Wrong token type - expected double value, found "
<< t;
fatalExit;
is.setBad();
return is;
}
is.check(FUNCTION_NAME);
return is;
}
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
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::token
Token class based on OpenFOAM stream, with some modifications/simplifications to be tailored to our n...
Definition: token.hpp:44
pFlow::token::stringToken
const word & stringToken() const
Return const reference to the string contents.
Definition: tokenI.hpp:642
pFlow::token::error
bool error() const
Token is ERROR.
Definition: tokenI.hpp:402
pFlow::token::good
bool good() const
True if token is not UNDEFINED or ERROR.
Definition: tokenI.hpp:390
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::token::number
real number() const
Return int64, float or double value.
Definition: tokenI.hpp:586
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:52
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::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.cpp:42
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
pFlow::iIstream::nextData
bool nextData(const word &keyword, T &data)
read the data next to keword keyword data; check the keyword is correct or not
Definition: iIstreamI.hpp:81
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::IOstream::setBad
void setBad()
Set stream to be bad.
Definition: IOstream.hpp:274
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::IOstream::name
virtual const word & name() const
Return the name of the stream.
Definition: IOstream.cpp:31
pFlow::iIstream::lookupData
T lookupData(const word &keyword)
lookup for keyword and data; fatalExit if fails
Definition: iIstreamI.hpp:52
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Report an error in file operation with supplied fileName and lineNumber.
Definition: error.hpp:87
pFlow::uint64
unsigned long long int uint64
Definition: builtinTypes.hpp:58
pFlow::int8
signed char int8
Definition: builtinTypes.hpp:48
pFlow::IOstream::lineNumber
int32 lineNumber() const
Const access to the current stream line number.
Definition: IOstream.hpp:223
pFlow::iIstream::findToken
virtual bool findToken(const word &w)
search for all tokesn and find the first word token tbat matchs w
Definition: iIstream.cpp:84
pFlow::token::isNumber
bool isNumber() const
Token is int, float or duble.
Definition: tokenI.hpp:580
pFlow::token::isEndStatement
bool isEndStatement() const
Token is end statement.
Definition: tokenI.hpp:449
pFlow::uint8
unsigned char uint8
Definition: builtinTypes.hpp:54
pFlow::token::wordToken
const word & wordToken() const
Return const reference to the word contents.
Definition: tokenI.hpp:618
pFlow::token::isString
bool isString() const
Token is STRING, VARIABLE or VERBATIM string.
Definition: tokenI.hpp:633
pFlow::token::isWord
bool isWord() const
Token is word or DIRECTIVE word.
Definition: tokenI.hpp:602