particlesPhasicFlow.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 #include "positionParticles.hpp"
23 #include "pointStructure.hpp"
24 #include "setFields.hpp"
25 #include "systemControl.hpp"
26 #include "commandLine.hpp"
27 #include "readControlDict.hpp"
28 
29 using pFlow::output;
30 using pFlow::endl;
31 using pFlow::dictionary;
32 using pFlow::uniquePtr;
33 using pFlow::IOobject;
34 using pFlow::objectFile;
35 using pFlow::fileSystem;
39 using pFlow::commandLine;
41 
42 int main( int argc, char* argv[] )
43 {
44 
45  commandLine cmds(
46  "createParticles",
47  "Read the dictionary createParticles and create particles"
48  " based on the two sub-dictionaries positionParticles and setFields.\n"
49  "First executes positionParticles and then setFields, except "
50  "otherwise selected in the command line.");
51 
52 
53  bool positionOnly = false;
54  cmds.add_flag(
55  "--positionParticles-only",
56  positionOnly,
57  "Exectue the positionParticles part only and store the created "
58  "pointStructure in the time folder.");
59 
60  bool setOnly = false;
61  cmds.add_flag("--setFields-only",
62  setOnly,
63  "Exectue the setFields part only. Read the pointStructure from "
64  "time folder and setFields and save the result in the same time folder.");
65 
66  bool isCoupling = false;
67  cmds.add_flag(
68  "-c,--coupling",
69  isCoupling,
70  "Is this a fluid-particle coupling simulation");
71 
72  if(!cmds.parse(argc, argv)) return 0;
73 
74  if(setOnly && positionOnly)
75  {
76  ERR<<
77  "Options --positionParticles-only and --setFields-only cannot be used simeltanuously. \n"<<endERR;
78  return 1;
79  }
80 
81 // this should be palced in each main
82 #include "initialize_Control.hpp"
83 
84  auto objCPDict = IOobject::make<dictionary>
85  (
87  (
88  "particlesDict",
89  Control.settings().path(),
90  objectFile::READ_ALWAYS,
91  objectFile::WRITE_ALWAYS
92  ),
93  "particlesDict",
94  true
95  );
96 
97  auto& cpDict = objCPDict().getObject<dictionary>();
98 
99  pointStructure* pStructPtr = nullptr;
100 
101 
102  if(!setOnly)
103  {
104 
105  // position particles based on the dict content
106  REPORT(0)<< "Positioning points . . . \n"<<endREPORT;
107  auto pointPosition = positionParticles::create(cpDict.subDict("positionParticles"));
108 
109  fileSystem pStructPath = Control.time().path()+pointStructureFile__;
110 
111  auto finalPos = pointPosition().getFinalPosition();
112 
113 
114  auto& pStruct = Control.time().emplaceObject<pointStructure>
115  (
116  objectFile
117  (
119  Control.time().path(),
120  objectFile::READ_NEVER,
121  objectFile::WRITE_ALWAYS
122  ),
123  finalPos
124  );
125 
126  pStructPtr = &pStruct;
127 
128 
129  REPORT(1)<< "Created pStruct with "<< pStruct.size() << " points and capacity "<<
130  pStruct.capacity()<<" . . ."<< endREPORT;
131 
132  REPORT(1)<< "Writing pStruct to " << Control.time().path()+ pointStructureFile__<< endREPORT<<endl<<endl;
133 
134  if( !Control.time().write())
135  {
137  "ERRor in writing to file. \n ";
138  return 1;
139  }
140  }else
141  {
142 
143  auto& pStruct = Control.time().emplaceObject<pointStructure>
144  (
145  objectFile
146  (
148  Control.time().path(),
149  objectFile::READ_NEVER,
150  objectFile::WRITE_ALWAYS
151  )
152  );
153 
154  pStructPtr = &pStruct;
155 
156  }
157 
158 
159 
160  if(!positionOnly)
161  {
162 
163  auto& pStruct = *pStructPtr;
164 
165  auto& sfDict = cpDict.subDict("setFields");
166 
167  setFieldList defValueList(sfDict.subDict("defaultValue"));
168 
169  for(auto& sfEntry: defValueList)
170  {
171  if( !sfEntry.setPointFieldDefaultValueNewAll(Control.time(), pStruct, true))
172  {
173  ERR<< "\n error occured in setting default value fields.\n"<<endERR;
174  return 1;
175  }
176  }
177 
178  output<<endl;
179 
180  auto& selectorsDict = sfDict.subDict("selectors");
181 
182  auto selNames = selectorsDict.dictionaryKeywords();
183 
184  for(auto name: selNames)
185  {
186  REPORT(1)<< "Applying selector " << greenText(name) <<endREPORT;
187 
188  if(
189  !applySelector(Control, pStruct, selectorsDict.subDict(name))
190  )
191  {
192  ERR<<"\n error occured in setting selector. \n"<<endERR;
193  return 1;
194  }
195  output<<endl;
196  }
197  }
198 
199  Control.time().write(true);
200  REPORT(0)<< greenText("\nFinished successfully.\n")<<endREPORT;
201 
202 
203 // this should be palced in each main
204 #include "finalize.hpp"
205 
206  return 0;
207 }
208 
209 
210 
211 /*
212 uniquePtr<IOobject> pStructObj{nullptr};
213 
214  if(!setOnly)
215  {
216 
217  // position particles based on the dict content
218  REPORT(0)<< "Positioning points . . . \n"<<endREPORT;
219  auto pointPosition = positionParticles::create(cpDict.subDict("positionParticles"));
220 
221  fileSystem pStructPath = Control.time().path()+pointStructureFile__;
222 
223  auto finalPos = pointPosition().getFinalPosition();
224 
225 
226  pStructObj = IOobject::make<pointStructure>
227  (
228  objectFile
229  (
230  pointStructureFile__,
231  Control.time().path(),
232  objectFile::READ_NEVER,
233  objectFile::WRITE_ALWAYS
234  ),
235  finalPos
236  );
237 
238  auto& pSruct = pStructObj().getObject<pointStructure>();
239 
240  REPORT(1)<< "Created pStruct with "<< pSruct.size() << " points and capacity "<<
241  pSruct.capacity()<<" . . ."<< endREPORT;
242 
243  REPORT(1)<< "Writing pStruct to " << pStructObj().path() << endREPORT<<endl<<endl;
244 
245  if( !pStructObj().write())
246  {
247  fatalErrorInFunction<<
248  "ERRor in writing to file. \n ";
249  return 1;
250  }
251  }else
252  {
253  pStructObj = IOobject::make<pointStructure>
254  (
255  objectFile
256  (
257  pointStructureFile__,
258  Control.time().path(),
259  objectFile::READ_ALWAYS,
260  objectFile::WRITE_NEVER
261  )
262  );
263  }
264 
265 
266 
267  if(!positionOnly)
268  {
269 
270  auto& pStruct = pStructObj().getObject<pointStructure>();
271 
272  auto& sfDict = cpDict.subDict("setFields");
273 
274  setFieldList defValueList(sfDict.subDict("defaultValue"));
275 
276  for(auto& sfEntry: defValueList)
277  {
278  if( !sfEntry.setPointFieldDefaultValueNewAll(Control.time(), pStruct, true))
279  {
280  ERR<< "\n error occured in setting default value fields.\n"<<endERR;
281  return 1;
282  }
283  }
284 
285  output<<endl;
286 
287  auto& selectorsDict = sfDict.subDict("selectors");
288 
289  auto selNames = selectorsDict.dictionaryKeywords();
290 
291  for(auto name: selNames)
292  {
293  REPORT(1)<< "Applying selector " << greenText(name) <<endREPORT;
294 
295  if(
296  !applySelector(Control, pStruct, selectorsDict.subDict(name))
297  )
298  {
299  ERR<<"\n error occured in setting selector. \n"<<endERR;
300  return 1;
301  }
302  output<<endl;
303  }
304  }
305  */
initialize_Control.hpp
pFlow::pointStructureFile__
const char * pointStructureFile__
Definition: vocabs.hpp:42
endREPORT
#define endREPORT
Definition: streams.hpp:41
REPORT
#define REPORT(n)
Definition: streams.hpp:40
ERR
#define ERR
Definition: streams.hpp:47
systemControl.hpp
pFlow::commandLine
Definition: commandLine.hpp:36
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:320
greenText
#define greenText(text)
Definition: streams.hpp:32
pFlow::IOobject
Definition: IOobject.hpp:35
pFlow::fileSystem
Definition: fileSystem.hpp:63
pFlow::pointStructure
Definition: pointStructure.hpp:44
pFlow::commandLine::parse
bool parse(int argc, char **argv)
Definition: commandLine.cpp:50
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::setFieldList
Definition: setFieldList.hpp:32
pFlow::output
Ostream output
endERR
#define endERR
Definition: streams.hpp:48
pFlow::objectFile
Definition: objectFile.hpp:33
pStruct
auto & pStruct
Definition: setPointStructure.hpp:24
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
pFlow::positionParticles
Definition: positionParticles.hpp:102
main
int main(int argc, char *argv[])
Definition: particlesPhasicFlow.cpp:42
pFlow::applySelector
bool applySelector(systemControl &control, const pointStructure &pStruct, const dictionary &selDict)
Definition: setFields.hpp:34
readControlDict.hpp
setFields.hpp
positionParticles.hpp
commandLine.hpp
pointStructure.hpp
pFlow::dictionary
Definition: dictionary.hpp:38
Control
auto & Control
Definition: initialize_Control.hpp:47
finalize.hpp