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

vibratingMotion.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 "vibratingMotion.hpp"
#include "dictionary.hpp"
#include "vocabs.hpp"
bool pFlow::vibratingMotion::readDictionary
(
const dictionary& dict
)
{
auto motionModel = dict.getVal<word>("motionModel");
if(motionModel != "vibratingMotion")
{
fatalErrorInFunction<<
" motionModel should be vibratingMotion, but found "
<< motionModel <<endl;
return false;
}
auto& motionInfo = dict.subDict("vibratingMotionInfo");
auto compNames = motionInfo.dictionaryKeywords();
components_.reserve(compNames.size()+1);
components_.clear();
componentName_.clear();
for(auto& cName: compNames)
{
auto& compDict = motionInfo.subDict(cName);
if(auto compPtr = makeUnique<vibrating>(compDict); compPtr)
{
components_.push_back(compPtr());
componentName_.push_back(cName);
}
else
{
fatalErrorInFunction<<
"could not read vibrating motion from "<< compDict.globalName()<<endl;
return false;
}
}
if( !componentName_.search("none") )
{
components_.push_back
(
vibrating()
);
componentName_.push_back("none");
}
components_.syncViews();
numComponents_ = components_.size();
return true;
}
bool pFlow::vibratingMotion::writeDictionary
(
dictionary& dict
)const
{
dict.add("motionModel", "vibratingMotion");
auto& motionInfo = dict.subDictOrCreate("vibratingMotionInfo");
ForAll(i, components_)
{
auto& compDict = motionInfo.subDictOrCreate(componentName_[i]);
if( !components_.hostVectorAll()[i].write(compDict))
{
fatalErrorInFunction<<
" error in writing motion compoonent "<< componentName_[i] << " to dicrionary "
<< motionInfo.globalName()<<endl;
return false;
}
}
return true;
}
pFlow::vibratingMotion::vibratingMotion()
{}
pFlow::vibratingMotion::vibratingMotion
(
const dictionary& dict
)
{
if(! readDictionary(dict) )
{
fatalExit;
}
}
bool pFlow::vibratingMotion::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::vibratingMotion::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
pFlow::vibratingMotion::read
FUNCTION_H bool read(iIstream &is)
Read from input stream is.
Definition: vibratingMotion.cpp:127
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::vibrating
Vibrating model for a wall.
Definition: vibrating.hpp:65
pFlow::dictionary::write
virtual bool write(iOstream &os) const
Definition: dictionary.cpp:780
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::dictionary::dictionaryKeywords
wordList dictionaryKeywords() const
Definition: dictionary.cpp:721
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::vibratingMotion::readDictionary
bool readDictionary(const dictionary &dict)
Read from a dictionary.
Definition: vibratingMotion.cpp:27
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
dictionary.hpp
vibratingMotion.hpp
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:71
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::vibratingMotion::writeDictionary
bool writeDictionary(dictionary &dict) const
Write to a dictionary.
Definition: vibratingMotion.cpp:88
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
pFlow::vibratingMotion::vibratingMotion
FUNCTION_H vibratingMotion()
Empty.
Definition: vibratingMotion.cpp:112
vocabs.hpp
pFlow::vibratingMotion::write
FUNCTION_H bool write(iOstream &os) const
Write to output stream os.
Definition: vibratingMotion.cpp:148
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::dictionary
Definition: dictionary.hpp:38