# PhasicFlow: src/MotionModel/rotatingAxisMotion/rotatingAxisMotion.cpp Source File

rotatingAxisMotion.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 "rotatingAxisMotion.hpp"
#include "dictionary.hpp"
#include "vocabs.hpp"
bool pFlow::rotatingAxisMotion::readDictionary
(
const dictionary& dict
)
{
auto motionModel = dict.getVal<word>("motionModel");
if(motionModel != "rotatingAxisMotion")
{
fatalErrorInFunction<<
" motionModel should be rotatingAxisMotion, but found "
<< motionModel <<endl;
return false;
}
auto& motionInfo = dict.subDict("rotatingAxisMotionInfo");
auto axisNames = motionInfo.dictionaryKeywords();
axis_.reserve(axisNames.size()+1);
axis_.clear();
axisName_.clear();
for(auto& aName: axisNames)
{
auto& axDict = motionInfo.subDict(aName);
if(auto axPtr = makeUnique<rotatingAxis>(axDict); axPtr)
{
axis_.push_back(axPtr());
axisName_.push_back(aName);
}
else
{
fatalErrorInFunction<<
"could not read rotating axis from "<< axDict.globalName()<<endl;
return false;
}
}
if( !axisName_.search("none") )
{
axis_.push_back
(
rotatingAxis(
realx3(0.0,0.0,0.0),
realx3(1.0,0.0,0.0),
0.0
)
);
axisName_.push_back("none");
}
axis_.syncViews();
numAxis_ = axis_.size();
return true;
}
bool pFlow::rotatingAxisMotion::writeDictionary
(
dictionary& dict
)const
{
dict.add("motionModel", "rotatingAxisMotion");
auto& motionInfo = dict.subDictOrCreate("rotatingAxisMotionInfo");
ForAll(i, axis_)
{
auto& axDict = motionInfo.subDictOrCreate(axisName_[i]);
if( !axis_.hostVectorAll()[i].write(axDict))
{
fatalErrorInFunction<<
" error in writing axis "<< axisName_[i] << " to dicrionary "
<< motionInfo.globalName()<<endl;
return false;
}
}
return true;
}
pFlow::rotatingAxisMotion::rotatingAxisMotion()
{}
pFlow::rotatingAxisMotion::rotatingAxisMotion
(
const dictionary& dict
)
{
if(! readDictionary(dict) )
{
fatalExit;
}
}
bool pFlow::rotatingAxisMotion::read
(
iIstream& is
)
{
// create an empty file dictionary
dictionary motionInfo(motionModelFile__, true);
// read dictionary from stream
if( !motionInfo.read(is) )
{
ioErrorInFile(is.name(), is.lineNumber()) <<
" error in reading dictionray " << motionModelFile__ <<" from file. \n";
return false;
}
if( !readDictionary(motionInfo) ) return false;
return true;
}
bool pFlow::rotatingAxisMotion::write
(
iOstream& os
)const
{
// create an empty file dictionary
dictionary motionInfo(motionModelFile__, true);
if( !writeDictionary(motionInfo))
{
return false;
}
if( !motionInfo.write(os) )
{
ioErrorInFile( os.name(), os.lineNumber() )<<
" error in writing dictionray to file. \n";
return false;
}
return true;
}
pFlow::motionModelFile__
const char * motionModelFile__
Definition: vocabs.hpp:45
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::rotatingAxisMotion::write
FUNCTION_H bool write(iOstream &os) const
Write to output stream os.
Definition: rotatingAxisMotion.cpp:151
pFlow::dictionary::write
virtual bool write(iOstream &os) const
Definition: dictionary.cpp:780
pFlow::rotatingAxisMotion::rotatingAxisMotion
FUNCTION_H rotatingAxisMotion()
Empty.
Definition: rotatingAxisMotion.cpp:115
pFlow::dictionary::read
virtual bool read(iIstream &is)
Definition: dictionary.cpp:759
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::dictionary::subDictOrCreate
dictionary & subDictOrCreate(const word &keyword)
Definition: dictionary.cpp:634
pFlow::dictionary::add
bool add(const word &keyword, const float &v)
Definition: dictionary.cpp:422
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::rotatingAxisMotion::writeDictionary
bool writeDictionary(dictionary &dict) const
Write to dictionary.
Definition: rotatingAxisMotion.cpp:91
pFlow::realx3
triple< real > realx3
Definition: types.hpp:48
pFlow::dictionary::dictionaryKeywords
wordList dictionaryKeywords() const
Definition: dictionary.cpp:721
pFlow::iIstream
Definition: iIstream.hpp:33
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::rotatingAxis
An axis which rotates around itself at specified speed.
Definition: rotatingAxis.hpp:62
dictionary.hpp
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:71
pFlow::rotatingAxisMotion::read
FUNCTION_H bool read(iIstream &is)
Read from input stream is.
Definition: rotatingAxisMotion.cpp:130
rotatingAxisMotion.hpp
pFlow::IOstream::name
virtual const word & name() const
Definition: IOstream.cpp:31
pFlow::dictionary::subDict
dictionary & subDict(const word &keyword)
Definition: dictionary.cpp:547
pFlow::dictionary::getVal
T getVal(const word &keyword) const
Definition: dictionary.hpp:309
pFlow::rotatingAxisMotion::readDictionary
bool readDictionary(const dictionary &dict)
Read from dictionary.
Definition: rotatingAxisMotion.cpp:27
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
vocabs.hpp
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::dictionary
Definition: dictionary.hpp:38