# PhasicFlow: src/phasicFlow/dictionary/entry/iEntry.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.

iEntry.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.
-----------------------------------------------------------------------------*/
// based on OpenFOAM dictionary, with some modifications/simplifications
// to be tailored to our needs
#include "iEntry.hpp"
#include "dictionary.hpp"
#include "dataEntry.hpp"
#include "error.hpp"
#include "iOstream.hpp"
#include "iIstream.hpp"
bool pFlow::iEntry::readKeyword
(
iIstream &is,
word& keyword,
token& tok
)
{
while
(
!is.read(tok).bad() &&
!is.eof() &&
tok.good()
)
{
if(tok == token::END_STATEMENT) continue;
if( tok.isWord())
{
keyword = tok.wordToken();
return true;
}
else
{
return false;
}
}
return false;
}
bool pFlow::iEntry::createEntry
(
dictionary& parDict,
iIstream& is,
bool hasBlockToken
)
{
is.fatalCheck(FUNCTION_NAME);
// reads tokens one-by-one
word key;
token nextTok;
if( auto isKey = iEntry::readKeyword(is, key, nextTok ); isKey )
{
//output<< key << " "<<nextTok <<endl;
is.read(nextTok);
if( is.eof() || is.bad() || !nextTok.good() )
{
ioErrorInFile(is.name(), is.lineNumber())<<
"expecting a valid token after keyword " << key << endl;
fatalExit;
}
// output<< nextTok<<endl;
is.putBack(nextTok);
if( nextTok == token::BEGIN_BLOCK )
{
uniquePtr<iEntry> ptr = makeUnique<dictionary>(key, parDict, is);
if( !parDict.addPtr(key, ptr ))
{
fatalErrorInFunction <<
"unable to add dicrionary " << key <<
" to dictionary " << parDict.globalName() <<endl;
fatalExit;
}
}
else
{
uniquePtr<iEntry> ptr = makeUnique<dataEntry>(key, parDict, is);
if( !parDict.addPtr(key, ptr ) )
{
fatalErrorInFunction <<
"unable to add dataEntry " << key <<
" to dictionary " << parDict.globalName() <<endl;
fatalExit;
}
}
}
else
{
if( nextTok.good() )
{
if(hasBlockToken)
{
if(nextTok != token::END_BLOCK )
{
ioErrorInFile(is.name(), is.lineNumber())<<
"expecting a } but found "<< nextTok <<endl;
fatalExit;
}else
{
return false;
}
}else
{
ioErrorInFile(is.name(), is.lineNumber())<<
"not expecting " << nextTok <<endl;
return false;
}
}
else if( !is.eof())
{
ioErrorInFile(is.name(), is.lineNumber())<<
"error in reading next token. \n";
fatalExit;
}
}
return true;
}
bool pFlow::iEntry::writeKeyword
(
iOstream& os
)const
{
os.writeWordKeyword(keyword_);
os.fatalCheck("pFlow::iEntry::writeKeyword");
return true;
}
pFlow::iOstream& pFlow::operator << (iOstream& os, const iEntry& e)
{
if(!e.write(os))
{
ioErrorInFile(os.name(), os.lineNumber())<<
"Error in wrting to file \n";
fatalExit;
}
return os;
}
pFlow::iIstream& pFlow::operator >> (iIstream& is, iEntry& e)
{
if( !e.read(is))
{
ioErrorInFile(is.name(), is.lineNumber())<<
"Error in reading from file \n";
fatalExit;
}
return is;
}
pFlow::IOstream::eof
bool eof() const
Return true if end of input seen.
Definition: IOstream.hpp:192
pFlow::iIstream::read
virtual iIstream & read(token &)=0
Return next token from stream.
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
iIstream.hpp
pFlow::token::good
bool good() const
True if token is not UNDEFINED or ERROR.
Definition: tokenI.hpp:390
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::dictionary::globalName
virtual word globalName() const
global name of entry, separated with dots
Definition: dictionary.cpp:356
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::iEntry::write
virtual bool write(iOstream &os) const =0
write to stream
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
pFlow::iEntry::read
virtual bool read(iIstream &is)=0
read from stream
pFlow::IOstream::bad
bool bad() const
Return true if stream is corrupted.
Definition: IOstream.hpp:204
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::iEntry::createEntry
static bool createEntry(dictionary &parDict, iIstream &is, bool hasBlockToken=false)
create an entry (dataEntry or dictionary) from stream
Definition: iEntry.cpp:64
dictionary.hpp
pFlow::iIstream::putBack
void putBack(const token &tok)
Put back token Only a single put back is permitted.
Definition: iIstream.cpp:23
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::IOstream::fatalCheck
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.cpp:48
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::IOstream::name
virtual const word & name() const
Return the name of the stream.
Definition: IOstream.cpp:31
iEntry.hpp
pFlow::dictionary::addPtr
bool addPtr(const word &keyword, uniquePtr< iEntry > &etry, bool warning=true)
add a pointer entry (dictionary/dataEntry) replaces this entry with existing one and issue a warning
Definition: dictionary.cpp:386
pFlow::iEntry::writeKeyword
bool writeKeyword(iOstream &os) const
Definition: iEntry.cpp:154
pFlow::uniquePtr
Definition: uniquePtr.hpp:42
dataEntry.hpp
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Report an error in file operation with supplied fileName and lineNumber.
Definition: error.hpp:87
pFlow::iEntry::readKeyword
static bool readKeyword(iIstream &is, word &keyword, token &tok)
read a keyword from stream
Definition: iEntry.cpp:32
pFlow::iEntry
Interface calss for data entry and dictionary
Definition: iEntry.hpp:42
pFlow::IOstream::lineNumber
int32 lineNumber() const
Const access to the current stream line number.
Definition: IOstream.hpp:223
iOstream.hpp
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::token::wordToken
const word & wordToken() const
Return const reference to the word contents.
Definition: tokenI.hpp:618
pFlow::iOstream::writeWordKeyword
virtual iOstream & writeWordKeyword(const word &kw)
Write the keyword followed by an appropriate indentation.
Definition: iOstream.cpp:48
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::token::isWord
bool isWord() const
Token is word or DIRECTIVE word.
Definition: tokenI.hpp:602
error.hpp