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 template<typename ShapeType>
23 (
24  const dictionary& dict
25 )
26 {
27  if(!insertion::readInsertionDict(dict)) return false;
28 
29  regions_.clear();
30 
31  if( !this->isActive() )
32  {
33  return true;
34  }
35 
36  wordList regionDicNames = dict.dictionaryKeywords();
37 
38  for(auto& name:regionDicNames)
39  {
40  REPORT(2)<<"reading insertion region "<< greenText(name)<<endREPORT;
41  regions_.push_backSafe(dict.subDict(name), shapes_);
42  }
43 
44  return true;
45 }
46 
47 template<typename ShapeType>
49 (
50  dictionary& dict
51 )const
52 {
53  if( !insertion::writeInsertionDict(dict) ) return false;
54 
55  if( !this->isActive() ) return true;
56 
57  ForAll(i,regions_)
58  {
59  auto& rgnDict = dict.subDictOrCreate(regions_[i].name());
60 
61  if( !regions_[i].write(rgnDict) )
62  {
63  return false;
64  }
65  }
66 
67  return true;
68 }
69 
70 template<typename ShapeType>
72  particles& prtcl,
73  const ShapeType& shapes)
74 :
75  insertion(prtcl),
76  shapes_(shapes)
77 {
78 
79 
80 }
81 
82 template<typename ShapeType>
84  fileSystem file,
85  particles& prtcl,
86  const ShapeType& shapes)
87 :
88  Insertion(prtcl, shapes)
89 {
90  dictionary inDict(file.fileName(), file);
91 
92  if(!readInsertionDict(inDict))
93  {
94  fatalErrorInFunction<< "could not read from file "<<
95  file<<endl;
96  fatalExit;
97  }
98 }
99 
100 
101 template<typename ShapeType>
103 (
104  real currentTime,
105  real dt
106 )
107 {
108  if(!isActive()) return true;
109 
110 
111  ForAll(i,regions_)
112  {
113  bool insertionOccured = false;
114  auto& rgn = regions_[i];
115  if( rgn.insertionTime(currentTime, dt) )
116  {
117 
118  realx3Vector pos;
119  wordVector shapes;
120  if( rgn.insertParticles(currentTime, dt, shapes, pos, insertionOccured) )
121  {
122 
123  if(insertionOccured)
124  {
125  REPORT(0)<<"\nParticle insertion from "<< greenText(rgn.name())<<endREPORT;
126  REPORT(1)<< cyanText(pos.size()) << " new particles is being inserted at Time: "<<
127  cyanText(currentTime) <<" s."<<endREPORT;
128 
129  if(!particles_.insertParticles(pos, shapes, rgn.setFields()))
130  {
132  " Cannot add "<< pos.size() << " particles from region "<< rgn.name() <<
133  " to particles. \n";
134  return false;
135  }
136  REPORT(1)<<"Total number of particles inserted from this region is "<<
137  cyanText(rgn.totalInserted())<<'\n'<<endREPORT;
138  }
139  else
140  {
141  continue;
142  }
143 
144  }
145  else
146  {
147  if(insertionOccured)
148  {
149  yWARNING<< "\n fewer number of particles are inserted from region "<< rgn.name() <<
150  " than expected. You may stop the simulation to change settings."<<endyWARNING;
151  continue;
152  }
153  else
154  {
156  " error in inserting particles from region "<< rgn.name()<<endl;
157  return false;
158  }
159 
160  }
161  }
162 
163  }
164 
165  return true;
166 }
167 
168 
169 template<typename ShapeType>
171 (
172  iIstream& is
173 )
174 {
175 
176  // create an empty dictionary
177  dictionary dict(is.name(), true);
178 
179  if(!dict.read(is))
180  {
181  ioErrorInFile( is.name(), is.lineNumber() )<<
182  " error in reading "<< insertionFile__ << "dictionary from file."<<endl;
183  return false;
184  }
185 
186  if(!readInsertionDict(dict))
187  {
189  " error in reading from dictionary "<<dict.globalName()<<endl;
190  return false;
191  }
192 
193  return true;
194 }
195 
196 template<typename ShapeType>
198 (
199  iOstream& os
200 )const
201 {
202 
203  dictionary dict(insertionFile__,true);
204 
205  if(! writeInsertionDict(dict) )
206  {
208  " error in writing to " << dict.globalName()<<endl;
209  return false;
210  }
211 
212  if( !dict.write(os) )
213  {
214  ioErrorInFile(os.name(), os.lineNumber())<<
215  " erro in writing to "<< os.name()<<endl;
216  return false;
217  }
218 
219  return true;
220 }
pFlow::List< word >
endREPORT
#define endREPORT
Definition: streams.hpp:41
pFlow::real
float real
Definition: builtinTypes.hpp:46
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::fileSystem::fileName
word fileName() const
Definition: fileSystem.cpp:96
pFlow::Insertion::insertParticles
bool insertParticles(real currentTime, real dt)
Definition: Insertion.cpp:103
pFlow::insertionFile__
const char * insertionFile__
Definition: vocabs.hpp:40
REPORT
#define REPORT(n)
Definition: streams.hpp:40
pFlow::Insertion::read
virtual bool read(iIstream &is) override
Definition: Insertion.cpp:171
pFlow::dictionary::write
virtual bool write(iOstream &os) const
Definition: dictionary.cpp:780
cyanText
#define cyanText(text)
Definition: streams.hpp:34
pFlow::Insertion::Insertion
Insertion(particles &prtcl, const ShapeType &shapes)
Definition: Insertion.cpp:71
pFlow::dictionary::read
virtual bool read(iIstream &is)
Definition: dictionary.cpp:759
pFlow::dictionary::globalName
virtual word globalName() const
Definition: dictionary.cpp:349
pFlow::dictionary::subDictOrCreate
dictionary & subDictOrCreate(const word &keyword)
Definition: dictionary.cpp:634
pFlow::Vector::size
auto size() const
Definition: Vector.hpp:299
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
greenText
#define greenText(text)
Definition: streams.hpp:32
pFlow::dictionary::dictionaryKeywords
wordList dictionaryKeywords() const
Definition: dictionary.cpp:721
pFlow::fileSystem
Definition: fileSystem.hpp:63
pFlow::Insertion::write
virtual bool write(iOstream &os) const override
Definition: Insertion.cpp:198
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::particles
Definition: particles.hpp:33
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:71
pFlow::Insertion::writeInsertionDict
bool writeInsertionDict(dictionary &dict) const
Definition: Insertion.cpp:49
pFlow::IOstream::name
virtual const word & name() const
Definition: IOstream.cpp:31
pFlow::dictionary::subDict
dictionary & subDict(const word &keyword)
Definition: dictionary.cpp:547
endyWARNING
#define endyWARNING
Definition: streams.hpp:45
pFlow::Insertion::readInsertionDict
bool readInsertionDict(const dictionary &dict)
Definition: Insertion.cpp:23
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
yWARNING
#define yWARNING
Definition: streams.hpp:44
pFlow::Vector< realx3 >
pFlow::Insertion
Definition: Insertion.hpp:35
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::dictionary
Definition: dictionary.hpp:38
pFlow::insertion
Definition: insertion.hpp:33