# PhasicFlow: src/phasicFlow/repository/IOobject/IOobject.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.

IOobject.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 "IOobject.hpp"
#include "repository.hpp"
pFlow::IOobject::IOobject
(
const objectFile& objf,
const IOPattern& iop,
repository* owner
)
:
IOfileHeader(objf),
ioPattern_(iop),
owner_(owner)
{
if(owner_&& !owner->addToRepository(this))
{
fatalErrorInFunction<<
"failed to add object "<< objf.name()<<
" to repository "<< owner->name()<<endl;
fatalExit;
}
}
pFlow::IOobject::~IOobject()
{
if(owner_)
{
owner_->removeFromRepository(this);
}
}
pFlow::repository* pFlow::IOobject::releaseOwner
(
bool fromOwner
)
{
auto* old = owner_;
if(old && !fromOwner)
{
old->removeFromRepository(this);
}
owner_ = nullptr;
return old;
}
bool pFlow::IOobject::isIncluded(const word& objName)const
{
if(owner_)
return owner_->isIncluded(objName);
return false;
}
bool pFlow::IOobject::isExcluded(const word& objName)const
{
if(owner_)
return owner_->isExcluded(objName);
return false;
}
bool pFlow::IOobject::readObject(bool rdHdr)
{
if(!implyRead())return true;
if( rdHdr && ioPattern().thisCallRead())
{
if( auto ptrIS = inStream(); ptrIS )
{
if(!readHeader(ptrIS()))return false;
}
else
{
warningInFunction<<
"could not open file " << path() <<endl;
return false;
}
}
if(ioPattern().thisCallRead())
{
if( auto ptrIS = inStream(); ptrIS )
{
if(!readObject(ptrIS(), rdHdr))return false;
}
else
{
warningInFunction<<
"could not open file " << path() <<endl;
return false;
}
}
return true;
}
bool pFlow::IOobject::writeObject() const
{
if(!implyWrite()) return true;
if(ioPattern().thisCallWrite())
{
if( ioPattern().thisProcWriteData())
{
if(auto ptrOS = outStream(); ptrOS )
{
return writeObject(ptrOS());
}
else
{
warningInFunction<<
"error in opening file "<< path() <<endl;
return false;
}
}
else
{
if(auto ptrOS = dummyOutStream(); ptrOS )
{
return writeObject(ptrOS());
}
else
{
warningInFunction<<
"error in opening file "<< path() <<endl;
return false;
}
}
}
return true;
}
bool pFlow::IOobject::readObject(iIstream& is, bool rdHdr)
{
if(rdHdr &&
ioPattern().thisCallRead() &&
!readHeader(is)) return false;
if(ioPattern().thisCallRead())
{
return read(is, ioPattern());
}
else
{
return true;
}
}
bool pFlow::IOobject::writeObject(iOstream& os) const
{
if(this->writeHeader() && ioPattern().thisProcWriteHeader())
{
writeHeader(os, typeName());
}
if(ioPattern().thisCallWrite())
{
return write(os, ioPattern() );
}
else
return true;
}
pFlow::IOobject::isExcluded
bool isExcluded(const word &objName) const override
Definition: IOobject.cpp:76
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
IOobject.hpp
pFlow::IOobject::~IOobject
~IOobject() override
Definition: IOobject.cpp:46
warningInFunction
#define warningInFunction
Report a warning.
Definition: error.hpp:95
pFlow::IOobject::isIncluded
bool isIncluded(const word &objName) const override
Definition: IOobject.cpp:68
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
repository.hpp
pFlow::repository::name
word name() const
Definition: repository.cpp:60
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
pFlow::IOobject::readObject
bool readObject(bool rdHdr=true)
Definition: IOobject.cpp:83
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::objectFile::name
virtual const word & name() const
Definition: objectFile.hpp:101
pFlow::IOobject::IOobject
IOobject(const objectFile &objf, const IOPattern &iop, repository *owner)
Definition: IOobject.cpp:26
pFlow::IOPattern
Definition: IOPattern.hpp:32
pFlow::repository::addToRepository
bool addToRepository(repository *rep)
add repository to this repository return false if the name already exists
Definition: repository.cpp:102
pFlow::objectFile
Definition: objectFile.hpp:30
pFlow::IOobject::releaseOwner
repository * releaseOwner(bool fromOwner=false)
Definition: IOobject.cpp:55
pFlow::repository::removeFromRepository
bool removeFromRepository(repository *rep)
remove rep from the list of repositories
Definition: repository.cpp:118
pFlow::IOfileHeader
Definition: IOfileHeader.hpp:35
pFlow::repository
Definition: repository.hpp:34
pFlow::IOobject::owner_
repository * owner_
Definition: IOobject.hpp:43
pFlow::IOobject::writeObject
bool writeObject() const
Definition: IOobject.cpp:119
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59