# PhasicFlow: src/phasicFlow/containers/Field/Field.cpp Source File

Field.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.
-----------------------------------------------------------------------------*/
template<template<class, class> class VectorField, class T, class PropType>
bool pFlow::Field<VectorField, T, PropType>::readUniform
(
iIstream& is,
size_t len,
bool readLength
)
{
size_t flen = 0;
if( readLength )
{
is>>flen;
if(is.bad() || is.eof() )
{
ioErrorInFile( is.name(), is.lineNumber() ) <<
"expected integer value to specify field length \n";
return false;
}
}
else
{
flen = len;
}
// create a vector with one element and read it in
T bF;
is >> bF;
VectorType::assign(flen, bF);
// read end statement char ;
is.readEndStatement("readField");
return true;
}
template<template<class, class> class VectorField, class T, class PropType>
bool pFlow::Field<VectorField, T, PropType>::readNonUniform
(
iIstream& is,
size_t len
)
{
size_t flen = 0;
is >> flen;
if(is.bad() || is.eof() )
{
ioErrorInFile( is.name(), is.lineNumber() ) <<
" expected integer value to specify field length \n";
return false;
}
if( len!=0 && flen != len )
{
ioErrorInFile( is.name(), is.lineNumber() ) <<
" expected "<< len <<" as the field length but found "<< flen <<" \n";
return false;
}
this->clear();
VectorType::read(is);
is.readEndStatement("readField");
if( this->size() != flen )
{
ioErrorInFile( is.name(), is.lineNumber() ) <<
" expected " << flen << " elements, but supplied "<<
this->size() << " elements in file "<< is.name() <<endl;
return false;
}
return true;
}
template<template<class, class> class VectorField, class T, class PropType>
bool pFlow::Field<VectorField, T, PropType>::readField
(
iIstream& is,
const size_t len,
bool readLength
)
{
if( !is.findToken(fieldKey_) )
{
ioErrorInFile( is.name(), is.lineNumber() ) <<
" error in searching for filedkey " << fieldKey_<<endl;
return false;
}
word fieldU;
is >> fieldU;
if(is.bad() || is.eof())
{
ioErrorInFile( is.name(), is.lineNumber()) <<
" error in reading keyword from file.";
return false;
}
if( fieldU == uniform__ )
{
return readUniform(is, len, readLength);
}
else if( fieldU == nonUniform__ )
{
return readNonUniform(is, len);
}
else
{
ioErrorInFile( is.name(), is.lineNumber() ) <<
"unknown keyword, expected uniform/nonUniform, but found " <<
fieldU << endl;
return false;
}
return true;
}
template<template<class, class> class VectorField, class T, class PropType>
bool pFlow::Field<VectorField, T, PropType>::readField
(
iIstream& is
)
{
return readField(is, 0, true);
}
template<template<class, class> class VectorField, class T, class PropType>
bool pFlow::Field<VectorField, T, PropType>::writeField(iOstream& os)const
{
os.writeWordKeyword(fieldKey_) << nonUniform__<<endl;
os<< this->size()<<endl;
VectorType::write(os);
os.endEntry();
return true;
}
pFlow::IOstream::eof
bool eof() const
Definition: IOstream.hpp:156
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::iIstream::readEndStatement
char readEndStatement(const char *funcName)
Definition: iIstream.cpp:324
pFlow::uniform__
const char * uniform__
Definition: vocabs.hpp:52
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::nonUniform__
const char * nonUniform__
Definition: vocabs.hpp:53
pFlow::Field::readNonUniform
bool readNonUniform(iIstream &is, size_t len)
Definition: Field.cpp:62
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::IOstream::bad
bool bad() const
Definition: IOstream.hpp:168
pFlow::iOstream::endEntry
virtual iOstream & endEntry()
Definition: iOstream.cpp:97
pFlow::IOstream::name
virtual const word & name() const
Definition: IOstream.cpp:31
pFlow::Field::readField
bool readField(iIstream &is, const size_t len, bool readLength=true)
Definition: Field.cpp:104
pFlow::Field::readUniform
bool readUniform(iIstream &is, size_t len, bool readLength=true)
Definition: Field.cpp:23
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
pFlow::iIstream::findToken
virtual bool findToken(const word &w)
Definition: iIstream.cpp:60
pFlow::Field::writeField
bool writeField(iOstream &os) const
Definition: Field.cpp:163
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::iOstream::writeWordKeyword
virtual iOstream & writeWordKeyword(const word &kw)
Definition: iOstream.cpp:41