www.cemf.ir
MotionModel.cpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 
22 template<typename Model, typename Component>
23 inline
25 {
26  if( auto i = componentNames_.findi(name); i == -1)
27  {
28  return false;
29  }
30  else
31  {
32  indx = static_cast<uint32>(i);
33  return true;
34  }
35 
36 }
37 
38 template<typename Model, typename Component>
39 inline
41 {
42  if(i < numComponents_ )
43  {
44  name = componentNames_[i];
45  return true;
46  }
47  else
48  {
49  return false;
50  }
51 }
52 
53 template<typename Model, typename Component>
54 inline
56 (
57  const dictionary& dict
58 )
59 {
60 
61  auto modelName = dict.getVal<word>("motionModel");
62 
63  if(modelName != getTypeName<ModelComponent>())
64  {
66  " motionModel should be "<< Yellow_Text(getTypeName<ModelComponent>())<<
67  ", but found "<< Yellow_Text(modelName)<<endl;
68  return false;
69  }
70 
71  auto& motionInfo = dict.subDict(modelName+"Info");
72  auto compNames = motionInfo.dictionaryKeywords();
73 
74  Vector<ModelComponent> components(
75  "Read::modelComponent",
76  compNames.size()+1,
77  0,
78  RESERVE());
79 
80  componentNames_.clear();
81 
82 
83  for(auto& cName: compNames)
84  {
85  auto& compDict = motionInfo.subDict(cName);
86 
87  if(auto compPtr = makeUnique<ModelComponent>(compDict); compPtr)
88  {
89  components.push_back(compPtr());
90  componentNames_.push_back(cName);
91  }
92  }
93 
94  if( !componentNames_.search("none") )
95  {
96  components.push_back
97  (
98  impl_noneComponent()
99  );
100  componentNames_.push_back("none");
101  }
102 
103  motionComponents_.assign(components);
104  numComponents_ = motionComponents_.size();
105 
106  return true;
107 }
108 
109 
110 template<typename Model, typename Component>
111 inline
113 (
114  dictionary& dict
115 )const
116 {
117  word modelName = getTypeName<ModelComponent>();
118 
119  dict.add("motionModel", modelName );
120 
121  auto modelDictName = modelName+"Info";
122 
123  auto& motionInfo = dict.subDictOrCreate(modelDictName);
124  auto hostComponents = motionComponents_.hostView();
125 
126  ForAll(i, motionComponents_)
127  {
128 
129  auto& axDict = motionInfo.subDictOrCreate(componentNames_[i]);
130  if( !hostComponents[i].write(axDict))
131  {
133  " error in writing axis "<< componentNames_[i] << " to dicrionary "
134  << motionInfo.globalName()<<endl;
135  return false;
136  }
137  }
138 
139  return true;
140 }
141 
142 
143 template<typename Model, typename Component>
145 :
146  motionComponents_("motionComponents")
147 {}
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