www.cemf.ir
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 "vocabs.hpp"
23 #include "commandLine.hpp"
24 #include "positionParticles.hpp"
25 #include "pointStructure.hpp"
26 #include "setFields.hpp"
27 #include "systemControl.hpp"
28 #include "baseShapeNames.hpp"
29 
30 //#include "readControlDict.hpp"
31 
32 int main( int argc, char* argv[] )
33 {
34 
35  pFlow::commandLine cmds(
36  "createParticles",
37  "Read the dictionary createParticles and create particles"
38  " based on the two sub-dictionaries positionParticles and setFields.\n"
39  "First executes positionParticles and then setFields, except "
40  "otherwise selected in the command line.");
41 
42 
43  bool positionOnly = false;
44  cmds.add_flag(
45  "--positionParticles-only",
46  positionOnly,
47  "Exectue the positionParticles part only and store the created "
48  "pointStructure in the time folder.");
49 
50  bool setOnly = false;
51  cmds.add_flag("--setFields-only",
52  setOnly,
53  "Exectue the setFields part only. Read the pointStructure from "
54  "time folder and setFields and save the result in the same time folder.");
55 
56  bool isCoupling = false;
57  cmds.add_flag(
58  "-c,--coupling",
59  isCoupling,
60  "Is this a fluid-particle coupling simulation");
61 
62  if(!cmds.parse(argc, argv)) return 0;
63 
64  if(setOnly && positionOnly)
65  {
66  ERR<<
67  "Options --positionParticles-only and --setFields-only cannot be used simeltanuously. \n"<<END_ERR;
68  return 1;
69  }
70 
71 // this should be palced in each main
72 #include "initialize_Control.hpp"
73 
74  pFlow::fileDictionary cpDict("particlesDict", Control.settings().path());
75 
76 
77  pFlow::uniquePtr<pFlow::pointStructure> pStructPtr = nullptr;
78 
79 
80  if(!setOnly)
81  {
82 
83  // position particles based on the dict content
84  REPORT(0)<< "Positioning points . . . \n"<<END_REPORT;
85  auto pointPosition = pFlow::positionParticles::create(Control, cpDict.subDict("positionParticles"));
86 
87  pFlow::fileSystem pStructPath = Control.time().path()+pFlow::pointStructureFile__;
88 
89  auto finalPos = pointPosition().getFinalPosition();
90 
91  pStructPtr = pFlow::makeUnique<pFlow::pointStructure>(Control, finalPos);
92 
93 
94  REPORT(1)<< "Created pStruct with "<< pStructPtr().size() << " points and capacity "<<
95  pStructPtr().capacity()<<" . . ."<< END_REPORT;
96 
97  }
98  else
99  {
100  // read the content of pStruct from 0/pStructure
101  pStructPtr = pFlow::makeUnique<pFlow::pointStructure>(Control);
102 
103  }
104 
106 
107  if(!positionOnly)
108  {
109 
110  auto& pStruct = pStructPtr();
111 
112  auto& sfDict = cpDict.subDict("setFields");
113 
114  pFlow::setFieldList defValueList(sfDict.subDict("defaultValue"));
115 
116  for(auto& sfEntry: defValueList)
117  {
118  if( auto Ptr = sfEntry.setPointFieldDefaultValueNewAll( pStruct, true); Ptr)
119  {
120  allObjects.push_back(std::move(Ptr));
121  }
122  else
123  {
124  ERR<< "\n error occured in setting default value fields.\n"<<END_ERR;
125  return 1;
126  }
127  }
128 
130 
131  auto& selectorsDict = sfDict.subDict("selectors");
132 
133  auto selNames = selectorsDict.dictionaryKeywords();
134 
135  for(auto name: selNames)
136  {
137  REPORT(1)<< "Applying selector " << Green_Text(name) <<END_REPORT;
138 
139  if(
140  !applySelector(Control, pStruct, selectorsDict.subDict(name))
141  )
142  {
143  ERR<<"\n error occured in setting selector. \n"<<END_ERR;
144  return 1;
145  }
147  }
148  }
149 
150  Control.clearIncludeExclude();
151  Control.addExclude("shapeName");
152 
153  pFlow::uint64PointField_H shapeHash
154  (
156  (
157  "shapeHash",
158  "",
161  ),
162  pStructPtr(),
163  0u
164  );
165 
166  pFlow::uint32PointField_H shapeIndex
167  (
169  (
170  "shapeIndex",
171  "",
174  ),
175  pStructPtr(),
176  0u
177  );
178 
179  pFlow::baseShapeNames shapes(
181  &Control.caseSetup()
182  );
183 
184  auto& shapeName = Control.time().template lookupObject<pFlow::wordPointField_H>("shapeName");
185 
186  REPORT(0)<< "Converting shapeName field to shapeIndex field"<<END_REPORT;
187 
188  auto shapeName_D = shapeName.deviceView();
189  auto shapeHash_D = shapeHash.deviceView();
190  auto shapeIndex_D = shapeIndex.deviceView();
191 
192  REPORT(1)<<"List of shape names in "<<shapes.globalName()<<
193  " is: "<<Green_Text(shapes.shapeNameList())<<END_REPORT;
194 
195  ForAll(i, shapeHash)
196  {
197  if(pFlow::uint32 index; shapes.shapeNameToIndex(shapeName_D[i], index))
198  {
199  shapeHash_D[i] = shapes.hashes()[index];
200  shapeIndex_D[i] = index;
201  }
202  else
203  {
204  fatalErrorInFunction<<"Found shape name "<< Yellow_Text(shapeName_D[i])<<
205  "in shapeName field. But the list of shape names in file "<<
206  shapes.globalName()<<" is : \n"<<
207  shapes.shapeNames()<<pFlow::endl;
208  }
209  }
210 
211  if( !Control.time().write(true))
212  {
214  "ERRor in writing to file. \n ";
215  return 1;
216  }
217  REPORT(0)<< Green_Text("\nFinished successfully.\n")<<END_REPORT;
218 
219 
220 // this should be palced in each main
221 #include "finalize.hpp"
222 
223  return 0;
224 }
initialize_Control.hpp
Green_Text
#define Green_Text(text)
Definition: iOstream.hpp:42
pFlow::List
Definition: List.hpp:39
pFlow::baseShapeNames::hashes
const auto & hashes() const
Definition: baseShapeNames.hpp:87
END_ERR
#define END_ERR
Definition: streams.hpp:47
REPORT
#define REPORT(n)
Definition: streams.hpp:39
pFlow::baseShapeNames::shapeNames
const wordVector & shapeNames() const
Definition: baseShapeNames.hpp:73
ERR
#define ERR
Definition: streams.hpp:46
systemControl.hpp
pFlow::baseShapeNames
Definition: baseShapeNames.hpp:33
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::baseShapeNames::shapeNameList
wordList shapeNameList() const
Definition: baseShapeNames.hpp:79
baseShapeNames.hpp
pFlow::commandLine
Definition: commandLine.hpp:36
pFlow::dictionary::globalName
virtual word globalName() const
global name of entry, separated with dots
Definition: dictionary.cpp:356
pFlow::objectFile::WRITE_ALWAYS
@ WRITE_ALWAYS
Definition: objectFile.hpp:43
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
Yellow_Text
#define Yellow_Text(text)
Definition: iOstream.hpp:40
pFlow::fileSystem
Manages file pathes, manupulate and combines them.
Definition: fileSystem.hpp:71
pFlow::pointField
Definition: pointField.hpp:33
pFlow::pointStructureFile__
const char *const pointStructureFile__
Definition: vocabs.hpp:42
pFlow::commandLine::parse
bool parse(int argc, char **argv)
Definition: commandLine.cpp:50
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::setFieldList
Definition: setFieldList.hpp:32
pFlow::output
Ostream output
pFlow::baseShapeNames::shapeNameToIndex
bool shapeNameToIndex(const word &name, uint32 &index) const
Definition: baseShapeNames.hpp:100
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:75
pFlow::shapeFile__
const char *const shapeFile__
Definition: vocabs.hpp:41
END_REPORT
#define END_REPORT
Definition: streams.hpp:40
pFlow::objectFile
Definition: objectFile.hpp:30
pFlow::dictionary::subDict
dictionary & subDict(const word &keyword)
ref to a subdictioanry fatalExit if not found
Definition: dictionary.cpp:560
pStruct
auto & pStruct
Definition: setPointStructure.hpp:24
pFlow::positionParticles::create
static uniquePtr< positionParticles > create(systemControl &control, const dictionary &dict)
Definition: positionParticles.cpp:128
pFlow::objectFile::READ_NEVER
@ READ_NEVER
Definition: objectFile.hpp:37
pFlow::fileDictionary
Definition: fileDictionary.hpp:29
pFlow::uniquePtr
Definition: uniquePtr.hpp:42
main
int main(int argc, char *argv[])
Definition: particlesPhasicFlow.cpp:32
pFlow::applySelector
bool applySelector(systemControl &control, const pointStructure &pStruct, const dictionary &selDict)
Definition: setFields.hpp:34
vocabs.hpp
setFields.hpp
positionParticles.hpp
commandLine.hpp
pointStructure.hpp
Control
auto & Control
Definition: initialize_Control.hpp:47
pFlow::internalField::deviceView
auto deviceView() const
Definition: internalField.hpp:97
finalize.hpp