www.cemf.ir
Insertion.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 
23 template<typename ShapeType>
25 (
26  dictionary& dict
27 )const
28 {
29 
30  if(!insertion::writeInsertionDict(dict))return false;
31 
32  if( !this->isActive() ) return true;
33 
34  ForAll(i,regions_)
35  {
36  auto& rgnDict = dict.subDictOrCreate(regions_[i].name());
37 
38  if( !regions_[i].write(rgnDict) )
39  {
41  "Error in writing to dictionary "<<rgnDict.globalName()<<endl;
42  return false;
43  }
44  }
45 
46  return true;
47 }
48 
49 template<typename ShapeType>
50 bool
52 {
53  regions_.clear();
54 
55  if( !this->isActive() )
56  {
57  return true;
58  }
59 
60  wordList regionDicNames = this->dictionaryKeywords();
61 
62  for(const auto& name:regionDicNames)
63  {
64  REPORT(2)<<"reading insertion region "<< Green_Text(name)<<END_REPORT;
65 
66  regions_.push_back(makeUnique<InsertionRegion<ShapeType>>(
67  name,
68  *this,
69  shapes_));
70  }
71 
72  return true;
73 
74 }
75 
76 template<typename ShapeType>
78  particles& prtcl,
79  const ShapeType& shapes)
80 :
81  insertion(prtcl),
82  shapes_(shapes)
83 {
84  if(!readInsertionDict())
85  {
87  fatalExit;
88  }
89 }
90 
91 /*template<typename ShapeType>
92 pFlow::Insertion<ShapeType>::Insertion(
93  fileSystem file,
94  particles& prtcl,
95  const ShapeType& shapes)
96 :
97  Insertion(prtcl, shapes)
98 {
99  dictionary inDict(file.fileName(), file);
100 
101  if(!readInsertionDict(inDict))
102  {
103  fatalErrorInFunction<< "could not read from file "<<
104  file<<endl;
105  fatalExit;
106  }
107 }*/
108 
109 
110 template<typename ShapeType>
112 (
113  uint32 iter,
114  real t,
115  real dt
116 )
117 {
118  if(!isActive()) return true;
119 
120 
121  ForAll(i,regions_)
122  {
123  bool insertionOccured = false;
124  auto& rgn = regions_[i];
125  if( rgn.insertionTime(iter, t, dt) )
126  {
127 
128  realx3Vector pos;
129  wordVector shapes;
130  if( rgn.insertParticles(iter, t, dt, shapes, pos, insertionOccured) )
131  {
132 
133  if(insertionOccured)
134  {
135  REPORT(0)<<"\nParticle insertion from "<< Green_Text(rgn.name())<<END_REPORT;
136  REPORT(1)<< Cyan_Text(pos.size()) << " new particles is being inserted at Time: "<<
137  Cyan_Text(t) <<" s."<<END_REPORT;
138 
139  if(!Particles().insertParticles(pos, shapes, rgn.setFieldList()))
140  {
142  " Cannot add "<< pos.size() << " particles from region "<< rgn.name() <<
143  " to particles. \n";
144  return false;
145  }
146  REPORT(1)<<"Total number of particles inserted from this region is "<<
147  Cyan_Text(rgn.totalInserted())<<'\n'<<END_REPORT;
148  }
149  else
150  {
151  continue;
152  }
153 
154  }
155  else
156  {
157  if(insertionOccured)
158  {
159  WARNING<< "\n fewer number of particles are inserted from region "<< rgn.name() <<
160  " than expected. You may stop the simulation to change settings."<<END_WARNING;
161  if(!Particles().insertParticles(pos, shapes, rgn.setFieldList()))
162  {
164  " Cannot add "<< pos.size() << " particles from region "<< rgn.name() <<
165  " to particles. \n";
166  return false;
167  }
168  }
169  else
170  {
172  " error in inserting particles from region "<< rgn.name()<<endl;
173  return false;
174  }
175 
176  }
177  }
178 
179  }
180 
181  return true;
182 }
183 
184 
185 /*template<typename ShapeType>
186 bool pFlow::Insertion<ShapeType>::read
187 (
188  iIstream& is
189 )
190 {
191 
192  // create an empty dictionary
193  dictionary dict(is.name(), true);
194 
195  if(!dict.read(is))
196  {
197  ioErrorInFile( is.name(), is.lineNumber() )<<
198  " error in reading "<< insertionFile__ << "dictionary from file."<<endl;
199  return false;
200  }
201 
202  if(!readInsertionDict(dict))
203  {
204  fatalErrorInFunction<<
205  " error in reading from dictionary "<<dict.globalName()<<endl;
206  return false;
207  }
208 
209  return true;
210 }
211 
212 template<typename ShapeType>
213 bool pFlow::Insertion<ShapeType>::write
214 (
215  iOstream& os
216 )const
217 {
218 
219  dictionary dict(insertionFile__,true);
220 
221  if(! writeInsertionDict(dict) )
222  {
223  fatalErrorInFunction<<
224  " error in writing to " << dict.globalName()<<endl;
225  return false;
226  }
227 
228  if( !dict.write(os) )
229  {
230  ioErrorInFile(os.name(), os.lineNumber())<<
231  " erro in writing to "<< os.name()<<endl;
232  return false;
233  }
234 
235  return true;
236 }*/
Green_Text
#define Green_Text(text)
Definition: iOstream.hpp:42
pFlow::List< word >
pFlow::real
float real
Definition: builtinTypes.hpp:45
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
Cyan_Text
#define Cyan_Text(text)
Definition: iOstream.hpp:44
REPORT
#define REPORT(n)
Definition: streams.hpp:39
pFlow::Insertion::Insertion
Insertion(particles &prtcl, const ShapeType &shapes)
Definition: Insertion.cpp:77
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
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::InsertionRegion
This manages insertion of particles from a region based on the ShapeType.
Definition: InsertionRegion.hpp:42
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::Insertion::writeInsertionDict
bool writeInsertionDict(dictionary &dict) const override
Write to dictionary.
Definition: Insertion.cpp:25
END_WARNING
#define END_WARNING
Definition: streams.hpp:44
pFlow::particles
Definition: particles.hpp:33
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:75
END_REPORT
#define END_REPORT
Definition: streams.hpp:40
pFlow::makeUnique
uniquePtr< T > makeUnique(Args &&... args)
Definition: uniquePtr.hpp:99
pFlow::Insertion::readInsertionDict
bool readInsertionDict()
Definition: Insertion.cpp:51
pFlow::Vector< realx3 >
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
pFlow::Insertion::insertParticles
bool insertParticles(uint32 iter, real t, real dt)
Definition: Insertion.cpp:112
pFlow::insertion
Base class for particle insertion.
Definition: insertion.hpp:35
WARNING
#define WARNING
Definition: streams.hpp:43