# PhasicFlow: src/MotionModel/MotionModel/MotionModel.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.

MotionModel.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<typename Model, typename Component>
inline
bool pFlow::MotionModel<Model, Component>::impl_nameToIndex(const word& name, uint32& indx)const
{
if( auto i = componentNames_.findi(name); i == -1)
{
return false;
}
else
{
indx = static_cast< uint32 >(i);
return true;
}
}
template<typename Model, typename Component>
inline
bool pFlow::MotionModel<Model, Component>::impl_indexToName(uint32 i, word& name)const
{
if(i < numComponents_ )
{
name = componentNames_[i];
return true;
}
else
{
return false;
}
}
template<typename Model, typename Component>
inline
bool pFlow::MotionModel<Model, Component>::impl_readDictionary
(
const dictionary& dict
)
{
auto modelName = dict.getVal<word>("motionModel");
if(modelName != getTypeName<ModelComponent>())
{
fatalErrorInFunction<<
" motionModel should be "<< Yellow_Text(getTypeName<ModelComponent>())<<
", but found "<< Yellow_Text(modelName)<<endl;
return false;
}
auto& motionInfo = dict.subDict(modelName+"Info");
auto compNames = motionInfo.dictionaryKeywords();
Vector<ModelComponent> components(
"Read::modelComponent",
compNames.size()+1,
0,
RESERVE());
componentNames_.clear();
for(auto& cName: compNames)
{
auto& compDict = motionInfo.subDict(cName);
if(auto compPtr = makeUnique<ModelComponent>(compDict); compPtr)
{
components.push_back(compPtr());
componentNames_.push_back(cName);
}
}
if( !componentNames_.search("none") )
{
components.push_back
(
impl_noneComponent()
);
componentNames_.push_back("none");
}
motionComponents_.assign(components);
numComponents_ = motionComponents_.size();
return true;
}
template<typename Model, typename Component>
inline
bool pFlow::MotionModel<Model, Component>::impl_writeDictionary
(
dictionary& dict
)const
{
word modelName = getTypeName<ModelComponent>();
dict.add("motionModel", modelName );
auto modelDictName = modelName+"Info";
auto& motionInfo = dict.subDictOrCreate(modelDictName);
auto hostComponents = motionComponents_.hostView();
ForAll(i, motionComponents_)
{
auto& axDict = motionInfo.subDictOrCreate(componentNames_[i]);
if( !hostComponents[i].write(axDict))
{
fatalErrorInFunction<<
" error in writing axis "<< componentNames_[i] << " to dicrionary "
<< motionInfo.globalName()<<endl;
return false;
}
}
return true;
}
template<typename Model, typename Component>
pFlow::MotionModel<Model, Component>::MotionModel()
:
motionComponents_("motionComponents")
{}
pFlow::MotionModel::impl_writeDictionary
bool impl_writeDictionary(dictionary &dict) const
Write to dictionary.
Definition: MotionModel.cpp:113
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::dictionary::subDictOrCreate
dictionary & subDictOrCreate(const word &keyword)
search for a sub-dict with keyword create a new sub-dict if not found and return a ref to it fatalExi...
Definition: dictionary.cpp:647
pFlow::Vector::size
auto size() const
Size of the vector.
Definition: Vector.hpp:265
pFlow::dictionary::add
bool add(const word &keyword, const float &v)
add a float dataEntry
Definition: dictionary.cpp:435
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::MotionModel::impl_readDictionary
bool impl_readDictionary(const dictionary &dict)
Read from dictionary.
Definition: MotionModel.cpp:56
Yellow_Text
#define Yellow_Text(text)
Definition: iOstream.hpp:40
pFlow::MotionModel::MotionModel
MotionModel()
Empty.
Definition: MotionModel.cpp:144
pFlow::dictionary::dictionaryKeywords
wordList dictionaryKeywords() const
return a list of all dictionary (non-null) keywords
Definition: dictionary.cpp:734
RESERVE
Definition: Vector.hpp:40
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::MotionModel::impl_indexToName
bool impl_indexToName(uint32 i, word &name) const
Component index to motion component name.
Definition: MotionModel.cpp:40
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:75
pFlow::dictionary::subDict
dictionary & subDict(const word &keyword)
ref to a subdictioanry fatalExit if not found
Definition: dictionary.cpp:560
pFlow::dictionary::getVal
T getVal(const word &keyword) const
get the value of data entry
Definition: dictionary.hpp:379
pFlow::Vector
Definition: Vector.hpp:48
pFlow::MotionModel::impl_nameToIndex
bool impl_nameToIndex(const word &name, uint32 &idx) const
Name of the compoenent to index of the component.
Definition: MotionModel.cpp:24
pFlow::dictionary
Dictionary holds a set of data entries or sub-dictionaries that are enclosed in a curely braces or ar...
Definition: dictionary.hpp:67