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::motionModelFile__
const char * motionModelFile__
Definition: vocabs.hpp:45
pFlow::List< word >
pFlow::multiRotatingAxisMotion::readDictionary
bool readDictionary(const dictionary &dict)
Definition: multiRotatingAxisMotion.cpp:27
pFlow::real
float real
Definition: builtinTypes.hpp:46
fatalExit
#define fatalExit
Definition: error.hpp:57
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::multiRotatingAxisMotion::write
FUNCTION_H bool write(iOstream &os) const
Definition: multiRotatingAxisMotion.cpp:219
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
FUNCTION_H
#define FUNCTION_H
Definition: pFlowMacros.hpp:58
n
int32 n
Definition: NBSCrossLoop.hpp:24
pFlow::multiRotatingAxis
Definition: multiRotatingAxis.hpp:36
pFlow::iIstream
Definition: iIstream.hpp:33
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::multiRotatingAxisMotion::writeDictionary
bool writeDictionary(dictionary &dict) const
Definition: multiRotatingAxisMotion.cpp:139
pFlow::multiRotatingAxisMotion::move
FUNCTION_H bool move(real t, real dt)
Definition: multiRotatingAxisMotion.cpp:178
dictionary.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
sort
void sort(Vector< T, Allocator > &vec)
pFlow::multiRotatingAxisMotion::read
FUNCTION_H bool read(iIstream &is)
Definition: multiRotatingAxisMotion.cpp:198
pFlow::dictionary::getVal
T getVal(const word &keyword) const
Definition: dictionary.hpp:309
pFlow::multiRotatingAxisMotion::multiRotatingAxisMotion
FUNCTION_H multiRotatingAxisMotion()
Definition: multiRotatingAxisMotion.cpp:163
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
multiRotatingAxisMotion.hpp
vocabs.hpp
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::dictionary
Definition: dictionary.hpp:38