rotatingAxisMotion.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 #include "rotatingAxisMotion.hpp"
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 != "rotatingAxisMotion")
35  {
37  " motionModel should be rotatingAxisMotion, but found "
38  << motionModel <<endl;
39  return false;
40  }
41 
42  auto& motionInfo = dict.subDict("rotatingAxisMotionInfo");
43  auto axisNames = motionInfo.dictionaryKeywords();
44 
45  axis_.reserve(axisNames.size()+1);
46 
47 
48  axis_.clear();
49  axisName_.clear();
50 
51 
52  for(auto& aName: axisNames)
53  {
54  auto& axDict = motionInfo.subDict(aName);
55 
56  if(auto axPtr = makeUnique<rotatingAxis>(axDict); axPtr)
57  {
58  axis_.push_back(axPtr());
59  axisName_.push_back(aName);
60  }
61  else
62  {
64  "could not read rotating axis from "<< axDict.globalName()<<endl;
65  return false;
66  }
67  }
68 
69 
70 
71  if( !axisName_.search("none") )
72  {
73  axis_.push_back
74  (
76  realx3(0.0,0.0,0.0),
77  realx3(1.0,0.0,0.0),
78  0.0
79  )
80  );
81  axisName_.push_back("none");
82  }
83 
84  axis_.syncViews();
85  numAxis_ = axis_.size();
86 
87  return true;
88 }
89 
91 (
92  dictionary& dict
93 )const
94 {
95  dict.add("motionModel", "rotatingAxisMotion");
96 
97  auto& motionInfo = dict.subDictOrCreate("rotatingAxisMotionInfo");
98 
99  ForAll(i, axis_)
100  {
101 
102  auto& axDict = motionInfo.subDictOrCreate(axisName_[i]);
103  if( !axis_.hostVectorAll()[i].write(axDict))
104  {
106  " error in writing axis "<< axisName_[i] << " to dicrionary "
107  << motionInfo.globalName()<<endl;
108  return false;
109  }
110  }
111 
112  return true;
113 }
114 
116 {}
117 
119 (
120  const dictionary& dict
121 )
122 {
123  if(! readDictionary(dict) )
124  {
125  fatalExit;
126  }
127 }
128 
130 (
131  iIstream& is
132 )
133 {
134  // create an empty file dictionary
135  dictionary motionInfo(motionModelFile__, true);
136 
137  // read dictionary from stream
138  if( !motionInfo.read(is) )
139  {
140  ioErrorInFile(is.name(), is.lineNumber()) <<
141  " error in reading dictionray " << motionModelFile__ <<" from file. \n";
142  return false;
143  }
144 
145  if( !readDictionary(motionInfo) ) return false;
146 
147  return true;
148 }
149 
151 (
152  iOstream& os
153 )const
154 {
155  // create an empty file dictionary
156  dictionary motionInfo(motionModelFile__, true);
157 
158  if( !writeDictionary(motionInfo))
159  {
160  return false;
161  }
162 
163  if( !motionInfo.write(os) )
164  {
165  ioErrorInFile( os.name(), os.lineNumber() )<<
166  " error in writing dictionray to file. \n";
167  return false;
168  }
169  return true;
170 }
pFlow::motionModelFile__
const char * motionModelFile__
Definition: vocabs.hpp:45
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::rotatingAxisMotion::write
FUNCTION_H bool write(iOstream &os) const
Definition: rotatingAxisMotion.cpp:151
pFlow::dictionary::write
virtual bool write(iOstream &os) const
Definition: dictionary.cpp:780
pFlow::rotatingAxisMotion::rotatingAxisMotion
FUNCTION_H rotatingAxisMotion()
Definition: rotatingAxisMotion.cpp:115
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::rotatingAxisMotion::writeDictionary
bool writeDictionary(dictionary &dict) const
Definition: rotatingAxisMotion.cpp:91
pFlow::realx3
triple< real > realx3
Definition: types.hpp:48
pFlow::dictionary::dictionaryKeywords
wordList dictionaryKeywords() const
Definition: dictionary.cpp:721
pFlow::iIstream
Definition: iIstream.hpp:33
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::rotatingAxis
Definition: rotatingAxis.hpp:35
dictionary.hpp
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:71
pFlow::rotatingAxisMotion::read
FUNCTION_H bool read(iIstream &is)
Definition: rotatingAxisMotion.cpp:130
rotatingAxisMotion.hpp
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::rotatingAxisMotion::readDictionary
bool readDictionary(const dictionary &dict)
Definition: rotatingAxisMotion.cpp:27
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
vocabs.hpp
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::dictionary
Definition: dictionary.hpp:38