# PhasicFlow: src/phasicFlow/types/basicTypes/Logical.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.

Logical.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 "Logical.hpp"
#include "error.hpp"
#include "iIstream.hpp"
#include "iOstream.hpp"
pFlow::Logical::Logical(const word& l)
{
if (!evaluteWord(l, s_, yesNoSet_))
{
fatalErrorInFunction << " invalid input for Logical: " << l << endl;
fatalExit;
}
}
pFlow::Logical::Logical(const char* ch)
: Logical(word(ch))
{
}
bool
pFlow::Logical::evaluteWord(const word& l, bool& b, int& yesNoSet)
{
auto Ul = toUpper(l);
for (int i = 0; i < 4; ++i)
{
if (toUpper(YesNo__[i][0]) == Ul)
{
b = true;
yesNoSet = i;
return true;
}
else if (toUpper(YesNo__[i][1]) == Ul)
{
b = false;
yesNoSet = i;
return true;
}
}
yesNoSet = 0;
return false;
}
bool
pFlow::Logical::read(iIstream& is)
{
token t(is);
word w;
if (!t.good())
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Bad token - could not get Logical value";
is.setBad();
return false;
}
if (t.isString())
{
w = t.stringToken();
}
else if (t.isWord())
{
w = t.wordToken();
}
else
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Wrong token type - expected Logical value, found " << t;
is.setBad();
return false;
}
return evaluteWord(w, s_, yesNoSet_);
}
bool
pFlow::Logical::write(iOstream& os) const
{
if (s_)
{
os << YesNo__[yesNoSet_][0];
}
else
{
os << YesNo__[yesNoSet_][1];
}
return os.check(FUNCTION_NAME);
}
pFlow::iIstream&
pFlow::operator>>(iIstream& is, Logical& L)
{
if (!L.read(is))
{
fatalExit;
}
return is;
}
pFlow::iOstream&
pFlow::operator<<(iOstream& os, const Logical& L)
{
if (!L.write(os))
{
fatalExit;
}
return os;
}
pFlow::Logical::evaluteWord
static bool evaluteWord(const word &l, bool &b, int &yesNoSet)
Definition: Logical.cpp:41
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::stringToken
const word & stringToken() const
Return const reference to the string contents.
Definition: tokenI.hpp:642
pFlow::token::good
bool good() const
True if token is not UNDEFINED or ERROR.
Definition: tokenI.hpp:390
pFlow::toUpper
word toUpper(const word &inStr)
convert a word to all caps
Definition: bTypesFunctions.cpp:43
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.cpp:42
pFlow::Logical::write
bool write(iOstream &os) const
Definition: Logical.cpp:97
Logical.hpp
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::Logical::read
bool read(iIstream &is)
Definition: Logical.cpp:65
pFlow::Logical::s_
bool s_
bool value
Definition: Logical.hpp:44
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::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
pFlow::Logical
Holds a bool value and converts strings to bool.
Definition: Logical.hpp:39
pFlow::Logical::Logical
Logical()=default
Default constructor.
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Report an error in file operation with supplied fileName and lineNumber.
Definition: error.hpp:87
pFlow::IOstream::lineNumber
int32 lineNumber() const
Const access to the current stream line number.
Definition: IOstream.hpp:223
iOstream.hpp
pFlow::Logical::yesNoSet_
int yesNoSet_
Set numbe of of Yes or No.
Definition: Logical.hpp:47
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::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
error.hpp