www.cemf.ir
multiRotatingAxisMotion.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 
22 #include "dictionary.hpp"
23 #include "vocabs.hpp"
24 
25 
27 (
28  const dictionary& dict
29 )
30 {
31 
32  auto motionModel = dict.getVal<word>("motionModel");
33 
34  if(motionModel != "multiRotatingAxisMotion")
35  {
37  " motionModel should be multiRotatingAxisMotion, but found "
38  << motionModel <<endl;
39  return false;
40  }
41 
42  auto& motionInfo = dict.subDict("multiRotatingAxisMotionInfo");
43  auto axisNames = motionInfo.dictionaryKeywords();
44  wordList rotationAxis;
45 
46  // first check if
47 
48 
49  for(auto& aName: axisNames)
50  {
51  auto& axDict = motionInfo.subDict(aName);
52 
53  if(auto axPtr = makeUnique<rotatingAxis>(axDict); axPtr)
54  {
55  rotationAxis.push_back(
56  axDict.getValOrSet<word>("rotationAxis", "none"));
57  }
58  else
59  {
61  "could not read rotating axis from "<< axDict.globalName()<<endl;
62  return false;
63  }
64  }
65 
66  if( !axisNames.search("none") )
67  {
68  axisNames.push_back("none");
69  rotationAxis.push_back("none");
70  }
71 
72  using intPair = std::pair<int32, int32>;
73 
74  std::vector<intPair> numRotAxis;
75 
76  for(size_t i=0; i< axisNames.size(); i++)
77  {
78  word rotAxis = rotationAxis[i];
79  int32 n=0;
80  while(rotAxis != "none")
81  {
82  n++;
83  if(int32 iAxis = axisNames.findi(rotAxis) ; iAxis != -1)
84  {
85  rotAxis = rotationAxis[iAxis];
86  }else
87  {
89  "rotation axis name "<< rotAxis << "is does not exist!"<<endl;
90  return false;
91  }
92 
93  }
94 
95  numRotAxis.push_back({n,i});
96  }
97 
98  auto compareFunc = [](const intPair& a, const intPair& b)
99  { return a.first > b.first; };
100 
101  algorithms::STD::sort(numRotAxis.data(), numRotAxis.size(), compareFunc);
102 
103  sortedIndex_.clear();
104  axisName_.clear();
105 
106 
107  for(auto ax:numRotAxis)
108  {
109  axisName_.push_back(axisNames[ax.second]);
110  sortedIndex_.push_back(ax.second);
111  }
112 
113  numAxis_ = axisName_.size();
114  axis_.clear();
115  axis_.reserve(numAxis_);
116 
117 
118  // create the actual axis vector
119  for(auto& aName: axisName_)
120  {
121  if(aName != "none")
122  {
123  auto& axDict = motionInfo.subDict(aName);
124  axis_.push_back(
125  multiRotatingAxis(this, axDict));
126  }
127  else
128  {
129  axis_.push_back(
130  multiRotatingAxis(this));
131  }
132 
133  }
134 
135  return true;
136 }
137 
139 (
140  dictionary& dict
141 )const
142 {
143  dict.add("motionModel", "multiRotatingAxisMotion");
144 
145  auto& motionInfo = dict.subDictOrCreate("multiRotatingAxisMotionInfo");
146 
147  ForAll(i, axis_)
148  {
149 
150  auto& axDict = motionInfo.subDictOrCreate(axisName_[i]);
151  if( !axis_.hostVectorAll()[i].write(this,axDict))
152  {
154  " error in writing axis "<< axisName_[i] << " to dicrionary "
155  << motionInfo.globalName()<<endl;
156  return false;
157  }
158  }
159 
160  return true;
161 }
162 
164 {}
165 
167 (
168  const dictionary& dict
169 )
170 {
171  if(! readDictionary(dict) )
172  {
173  fatalExit;
174  }
175 }
176 
179 {
180 
181  // every thing is done on host
182  for(int32 i=0; i<numAxis_; i++)
183  {
184  auto& ax = axis_[sortedIndex_[i]];
185  ax.setTime(t);
186  ax.setAxisList(getAxisListPtrHost());
187  ax.move(dt);
188  }
189 
190  // transfer to device
191  axis_.modifyOnHost();
192  axis_.syncViews();
193 
194  return true;
195 }
196 
198 (
199  iIstream& is
200 )
201 {
202  // create an empty file dictionary
203  dictionary motionInfo(motionModelFile__, true);
204 
205  // read dictionary from stream
206  if( !motionInfo.read(is) )
207  {
208  ioErrorInFile(is.name(), is.lineNumber()) <<
209  " error in reading dictionray " << motionModelFile__ <<" from file. \n";
210  return false;
211  }
212 
213  if( !readDictionary(motionInfo) ) return false;
214 
215  return true;
216 }
217 
219 (
220  iOstream& os
221 )const
222 {
223  // create an empty file dictionary
224  dictionary motionInfo(motionModelFile__, true);
225 
226  if( !writeDictionary(motionInfo))
227  {
228  return false;
229  }
230 
231  if( !motionInfo.write(os) )
232  {
233  ioErrorInFile( os.name(), os.lineNumber() )<<
234  " error in writing dictionray to file. \n";
235  return false;
236  }
237  return true;
238 }
pFlow::List< word >
pFlow::multiRotatingAxisMotion::readDictionary
bool readDictionary(const dictionary &dict)
Read from a dictionary.
Definition: multiRotatingAxisMotion.cpp:27
pFlow::real
float real
Definition: builtinTypes.hpp:45
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::dictionary::read
bool read(iIstream &is) override
read from stream
Definition: dictionary.cpp:772
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::multiRotatingAxisMotion::write
FUNCTION_H bool write(iOstream &os) const
Write to output stream os.
Definition: multiRotatingAxisMotion.cpp:219
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::motionModelFile__
const char *const motionModelFile__
Definition: vocabs.hpp:45
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::dictionary::dictionaryKeywords
wordList dictionaryKeywords() const
return a list of all dictionary (non-null) keywords
Definition: dictionary.cpp:734
FUNCTION_H
#define FUNCTION_H
Definition: pFlowMacros.hpp:62
pFlow::multiRotatingAxis
Defines an axis of rotation that rotates around itself and rotates around another axis.
Definition: multiRotatingAxis.hpp:75
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::multiRotatingAxisMotion::writeDictionary
bool writeDictionary(dictionary &dict) const
Write to a dictionary.
Definition: multiRotatingAxisMotion.cpp:139
pFlow::multiRotatingAxisMotion::move
FUNCTION_H bool move(real t, real dt)
Move points.
Definition: multiRotatingAxisMotion.cpp:178
dictionary.hpp
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:75
pFlow::dictionary::write
bool write(iOstream &os) const override
write to stream
Definition: dictionary.cpp:793
pFlow::IOstream::name
virtual const word & name() const
Return the name of the stream.
Definition: IOstream.cpp:31
pFlow::dictionary::subDict
dictionary & subDict(const word &keyword)
ref to a subdictioanry fatalExit if not found
Definition: dictionary.cpp:560
sort
void sort(Vector< T, Allocator > &vec)
pFlow::multiRotatingAxisMotion::read
FUNCTION_H bool read(iIstream &is)
Read from input stream is.
Definition: multiRotatingAxisMotion.cpp:198
pFlow::dictionary::getVal
T getVal(const word &keyword) const
get the value of data entry
Definition: dictionary.hpp:379
n
uint32 n
Definition: NBSLoop.hpp:24
pFlow::multiRotatingAxisMotion::multiRotatingAxisMotion
FUNCTION_H multiRotatingAxisMotion()
Empty constructor.
Definition: multiRotatingAxisMotion.cpp:163
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Report an error in file operation with supplied fileName and lineNumber.
Definition: error.hpp:87
pFlow::IOstream::lineNumber
int32 lineNumber() const
Const access to the current stream line number.
Definition: IOstream.hpp:223
multiRotatingAxisMotion.hpp
vocabs.hpp
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
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