vibratingMotion.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 "vibratingMotion.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 != "vibratingMotion")
35  {
37  " motionModel should be vibratingMotion, but found "
38  << motionModel <<endl;
39  return false;
40  }
41 
42  auto& motionInfo = dict.subDict("vibratingMotionInfo");
43  auto compNames = motionInfo.dictionaryKeywords();
44 
45  components_.reserve(compNames.size()+1);
46 
47 
48  components_.clear();
49  componentName_.clear();
50 
51 
52  for(auto& cName: compNames)
53  {
54  auto& compDict = motionInfo.subDict(cName);
55 
56  if(auto compPtr = makeUnique<vibrating>(compDict); compPtr)
57  {
58  components_.push_back(compPtr());
59  componentName_.push_back(cName);
60  }
61  else
62  {
64  "could not read vibrating motion from "<< compDict.globalName()<<endl;
65  return false;
66  }
67  }
68 
69 
70 
71  if( !componentName_.search("none") )
72  {
73  components_.push_back
74  (
75  vibrating()
76  );
77  componentName_.push_back("none");
78  }
79 
80  components_.syncViews();
81  numComponents_ = components_.size();
82 
83 
84  return true;
85 }
86 
88 (
89  dictionary& dict
90 )const
91 {
92  dict.add("motionModel", "vibratingMotion");
93 
94  auto& motionInfo = dict.subDictOrCreate("vibratingMotionInfo");
95 
96  ForAll(i, components_)
97  {
98 
99  auto& compDict = motionInfo.subDictOrCreate(componentName_[i]);
100  if( !components_.hostVectorAll()[i].write(compDict))
101  {
103  " error in writing motion compoonent "<< componentName_[i] << " to dicrionary "
104  << motionInfo.globalName()<<endl;
105  return false;
106  }
107  }
108 
109  return true;
110 }
111 
113 {}
114 
116 (
117  const dictionary& dict
118 )
119 {
120  if(! readDictionary(dict) )
121  {
122  fatalExit;
123  }
124 }
125 
127 (
128  iIstream& is
129 )
130 {
131  // create an empty file dictionary
132  dictionary motionInfo(motionModelFile__, true);
133 
134  // read dictionary from stream
135  if( !motionInfo.read(is) )
136  {
137  ioErrorInFile(is.name(), is.lineNumber()) <<
138  " error in reading dictionray " << motionModelFile__ <<" from file. \n";
139  return false;
140  }
141 
142  if( !readDictionary(motionInfo) ) return false;
143 
144  return true;
145 }
146 
148 (
149  iOstream& os
150 )const
151 {
152  // create an empty file dictionary
153  dictionary motionInfo(motionModelFile__, true);
154 
155  if( !writeDictionary(motionInfo))
156  {
157  return false;
158  }
159 
160  if( !motionInfo.write(os) )
161  {
162  ioErrorInFile( os.name(), os.lineNumber() )<<
163  " error in writing dictionray to file. \n";
164  return false;
165  }
166  return true;
167 }
pFlow::motionModelFile__
const char * motionModelFile__
Definition: vocabs.hpp:45
pFlow::vibratingMotion::read
FUNCTION_H bool read(iIstream &is)
Definition: vibratingMotion.cpp:127
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::vibrating
Definition: vibrating.hpp:36
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::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
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::vibratingMotion::readDictionary
bool readDictionary(const dictionary &dict)
Definition: vibratingMotion.cpp:27
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
dictionary.hpp
vibratingMotion.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
pFlow::dictionary::getVal
T getVal(const word &keyword) const
Definition: dictionary.hpp:309
pFlow::vibratingMotion::writeDictionary
bool writeDictionary(dictionary &dict) const
Definition: vibratingMotion.cpp:88
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
pFlow::vibratingMotion::vibratingMotion
FUNCTION_H vibratingMotion()
Definition: vibratingMotion.cpp:112
vocabs.hpp
pFlow::vibratingMotion::write
FUNCTION_H bool write(iOstream &os) const
Definition: vibratingMotion.cpp:148
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::dictionary
Definition: dictionary.hpp:38