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  uniquePtr<IOobject> pStructObj{nullptr};
100 
101  if(!setOnly)
102  {
103 
104  // position particles based on the dict content
105  REPORT(0)<< "Positioning points . . . \n"<<endREPORT;
106  auto pointPosition = positionParticles::create(cpDict.subDict("positionParticles"));
107 
108  fileSystem pStructPath = Control.time().path()+pointStructureFile__;
109 
110  auto finalPos = pointPosition().getFinalPosition();
111 
112 
113  pStructObj = IOobject::make<pointStructure>
114  (
115  objectFile
116  (
118  Control.time().path(),
119  objectFile::READ_NEVER,
120  objectFile::WRITE_ALWAYS
121  ),
122  finalPos
123  );
124 
125  auto& pSruct = pStructObj().getObject<pointStructure>();
126 
127  REPORT(1)<< "Created pStruct with "<< pSruct.size() << " points and capacity "<<
128  pSruct.capacity()<<" . . ."<< endREPORT;
129 
130  REPORT(1)<< "Writing pStruct to " << pStructObj().path() << endREPORT<<endl<<endl;
131 
132  if( !pStructObj().write())
133  {
135  "ERRor in writing to file. \n ";
136  return 1;
137  }
138  }else
139  {
140  pStructObj = IOobject::make<pointStructure>
141  (
142  objectFile
143  (
145  Control.time().path(),
146  objectFile::READ_ALWAYS,
147  objectFile::WRITE_NEVER
148  )
149  );
150  }
151 
152 
153 
154  if(!positionOnly)
155  {
156 
157  auto& pStruct = pStructObj().getObject<pointStructure>();
158 
159  auto& sfDict = cpDict.subDict("setFields");
160 
161  setFieldList defValueList(sfDict.subDict("defaultValue"));
162 
163  for(auto& sfEntry: defValueList)
164  {
165  if( !sfEntry.setPointFieldDefaultValueNewAll(Control.time(), pStruct, true))
166  {
167  ERR<< "\n error occured in setting default value fields.\n"<<endERR;
168  return 1;
169  }
170  }
171 
172  output<<endl;
173 
174  auto& selectorsDict = sfDict.subDict("selectors");
175 
176  auto selNames = selectorsDict.dictionaryKeywords();
177 
178  for(auto name: selNames)
179  {
180  REPORT(1)<< "Applying selector " << greenText(name) <<endREPORT;
181 
182  if(
183  !applySelector(Control, pStruct, selectorsDict.subDict(name))
184  )
185  {
186  ERR<<"\n error occured in setting selector. \n"<<endERR;
187  return 1;
188  }
189  output<<endl;
190  }
191  }
192 
193  Control.time().write(true);
194  REPORT(0)<< greenText("\nFinished successfully.\n")<<endREPORT;
195 
196 
197 // this should be palced in each main
198 #include "finalize.hpp"
199 
200  return 0;
201 }
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::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
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
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
pointStructure.hpp
pFlow::dictionary
Definition: dictionary.hpp:38
Control
auto & Control
Definition: initialize_Control.hpp:47
finalize.hpp