# PhasicFlow: src/phasicFlow/containers/List/List/ListI.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.

ListI.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.
-----------------------------------------------------------------------------*/
template<typename T>
auto pFlow::List<T>::pos
(
size_t i,
bool noError
)
{
if( i >= size() )
{
if(noError)
{
return std::end(*this);
}
else
{
fatalErrorInFunction<<
"out of range access to list element. \n";
fatalExit;
}
}
auto iter = listType::begin();
std::advance(iter, i);
return iter;
}
template<typename T>
const auto pFlow::List<T>::pos
(
size_t i,
bool noError
)const
{
if( i >= size() )
{
if(noError)
{
return std::end(*this);
}
else
{
fatalErrorInFunction<<
"out of range access to list element. \n";
fatalExit;
}
}
auto iter = listType::cbegin();
std::advance(iter, i);
return iter;
}
template<typename T>
inline pFlow::int32 pFlow::List<T>::countElement
(
const T& elm
) const
{
return std::count( listType::begin(), listType::end(), elm);
}
template<typename T>
inline size_t pFlow::List<T>::size()const
{
return listType::size();
}
template<typename T>
inline T& pFlow::List<T>::operator[]
(
size_t i
)
{
return *pos(i);
}
template<typename T>
inline const T& pFlow::List<T>::operator[]
(
size_t i
)const
{
return *pos(i);
}
template<typename T>
inline typename pFlow::List<T>::const_iterator pFlow::List<T>::find
(
const T& val
) const
{
return std::find(this->begin(),this->end(), val);
}
template<typename T>
inline typename pFlow::List<T>::iterator pFlow::List<T>::find
(
const T& val
)
{
return std::find(this->begin(),this->end(), val);
}
template<typename T>
pFlow::int32 pFlow::List<T>::findi(const T& val) const
{
auto pos = find(val);
if( pos == this->end() )return -1;
return static_cast< int32 > (std::distance(this->begin(), pos));
}
template<typename T>
bool pFlow::List<T>::search
(
const T& val
) const
{
if( find(val) == this->end())return false;
return true;
}
template<typename T>
inline void pFlow::List<T>::set(size_t i, const T& val)
{
auto p = pos(i);
*p = val;
}
template<typename T>
inline void pFlow::List<T>::set(size_t i, T&& val)
{
auto p = pos(i);
*p = std::move(val);
}
template<typename T>
inline bool pFlow::List<T>::writeList
(
iOstream& os
) const
{
size_t len = size();
size_t stride = getListStride(len);
// start of List
os << beginListToken();
for(auto elm = listType::begin(); elm!=listType::end(); )
{
os<< *elm++;
for(size_t j=0; j<stride && elm!=listType::end(); j++)
{
os<<spaceToken()<< *elm++;
}
if( elm!=listType::end() )
os<<newLineToken();
}
os<< endListToken();
//os.check(FUNCTION_NAME);
return os.check(FUNCTION_NAME);
}
template<typename T>
inline bool pFlow::List<T>::readList
(
iIstream& is
)
{
// first clear the list
listType::clear();
is.fatalCheck(FUNCTION_NAME);
token firstToken(is);
if( firstToken.isPunctuation() ) // start of list
{
if(firstToken != beginListToken() )
{
ioErrorInFile(is.name(), is.lineNumber())
<< "expected token "<< token::BEGIN_LIST
<< " but found "<< firstToken ;
return false;
}
token lastToken(is);
is.fatalCheck(FUNCTION_NAME);
while
( !(
lastToken.isPunctuation()
&& lastToken == token::END_LIST
)
)
{
is.putBack(lastToken);
T val;
is >> val;
listType::push_back(val);
is >> lastToken;
is.fatalCheck(FUNCTION_NAME);
}
}
else
{
ioErrorInFile(is.name(), is.lineNumber())
<< "expected token "<< beginListToken()
<< " but found "<< firstToken ;
return false;
}
return is.fatalCheck(FUNCTION_NAME);
}
template<typename T>
inline pFlow::iOstream& pFlow::operator << (iOstream& os, const List<T>& lst )
{
if(!lst.writeList(os))
{
fatalExit;
}
return os;
}
template<typename T>
inline pFlow::iIstream& pFlow::operator >>(iIstream& is, List<T>& lst)
{
if( !lst.readList(is) )
{
fatalExit;
}
return is;
}
count
auto count(const Vector< T, Allocator > &vec, const T &val)
pFlow::List
Definition: List.hpp:39
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::List::set
void set(size_t i, const T &val)
Definition: ListI.hpp:144
pFlow::find
int64 find(Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:69
pFlow::token::isPunctuation
bool isPunctuation() const
Token is PUNCTUATION.
Definition: tokenI.hpp:444
pFlow::List::search
bool search(const T &val) const
Definition: ListI.hpp:134
pFlow::List::const_iterator
typename listType::const_iterator const_iterator
Definition: List.hpp:52
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::List::find
const_iterator find(const T &val) const
Definition: ListI.hpp:108
pFlow::newLineToken
token newLineToken()
Definition: token.hpp:533
pFlow::List::countElement
int32 countElement(const T &elm) const
Definition: ListI.hpp:74
pFlow::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.cpp:42
pFlow::List::findi
int32 findi(const T &val) const
Definition: ListI.hpp:125
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::int32
int int32
Definition: builtinTypes.hpp:50
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::List::iterator
typename listType::iterator iterator
Definition: List.hpp:50
pFlow::beginListToken
token beginListToken()
Definition: token.hpp:508
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::spaceToken
token spaceToken()
Definition: token.hpp:528
pFlow::IOstream::name
virtual const word & name() const
Return the name of the stream.
Definition: IOstream.cpp:31
pFlow::List::writeList
bool writeList(iOstream &os) const
Definition: ListI.hpp:160
pFlow::endListToken
token endListToken()
Definition: token.hpp:503
pFlow::List::size
size_t size() const
Definition: ListI.hpp:82
pFlow::List::readList
bool readList(iIstream &is)
Definition: ListI.hpp:194
pFlow::List::pos
auto pos(size_t i, bool noError=false)
Definition: ListI.hpp:23
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
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59