PDRsetFields.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016 Shell Research Ltd.
9  Copyright (C) 2019-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Applications
28  PDRsetFields
29 
30 Description
31  Preparation of fields for PDRFoam
32 
33 SourceFiles
34  PDRsetFields.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #include "argList.H"
39 #include "Time.H"
40 #include "IOdictionary.H"
41 
42 #include "PDRsetFields.H"
43 #include "PDRlegacy.H"
44 #include "PDRutils.H"
45 #include "IOmanip.H"
46 
47 using namespace Foam;
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 // Main program:
51 
52 int main(int argc, char* argv[])
53 {
55  (
56  "Processes a set of geometrical obstructions to determine the"
57  " equivalent blockage effects when setting cases for PDRFoam"
58  );
61 
63  (
64  "time",
65  "time",
66  "Specify a time"
67  );
68 
69  argList::addOption("dict", "file", "Alternative PDRsetFieldsDict");
70 
72  (
73  "legacy",
74  "Force use of legacy obstacles table"
75  );
76 
78  (
79  "dry-run",
80  "Read obstacles and write VTK only"
81  );
82 
83  #include "setRootCase.H"
84  #include "createTime.H"
85 
86  const word dictName("PDRsetFieldsDict");
88 
89  Info<< "Reading " << dictIO.name() << nl << endl;
90 
91  IOdictionary setFieldsDict(dictIO);
92 
93  const bool dryrun = args.found("dry-run");
94 
95  const fileName& casepath = runTime.globalPath();
96 
97  pars.timeName = "0";
99 
100  // Program parameters (globals)
101  pars.read(setFieldsDict);
102 
103  if (args.found("legacy"))
104  {
105  pars.legacyObsSpec = true;
106  }
107 
108  // Always have the following:
109  // 0 = blockedFaces patch (no wall functions)
110  // 1 = mergingFaces patch
111  // 2 = wallFaces patch
112 
115 
116  for
117  (
118  PDRpatchDef::predefined predef :
119  {
123  }
124  )
125  {
126  patches[predef] = PDRpatchDef::names[predef];
127  }
128 
129 
130  // Dimensions and grid points for i-j-k domain
131  PDRblock pdrBlock;
132 
133  if (pars.legacyMeshSpec)
134  {
135  PDRlegacy::read_mesh_spec(casepath, pdrBlock);
136  }
137  else
138  {
139  IOdictionary iodict
140  (
141  IOobject
142  (
143  "PDRblockMeshDict",
144  runTime.system(),
145  runTime,
148  )
149  );
150 
151  pdrBlock.read(iodict);
152 
153  #ifdef FULLDEBUG
154  PDRlegacy::print_info(pdrBlock);
155  #endif
156  }
157 
158  // Storage for obstacles and cylinder-like obstacles
159  DynamicList<PDRobstacle> obstacles, cylinders;
160 
161  // Read in obstacles
162  const scalar volObstacles =
163  (
166  (
168  pdrBlock.bounds(),
169  obstacles,
170  cylinders
171  )
173  (
175  pdrBlock.bounds(),
176  obstacles,
177  cylinders
178  )
179  );
180 
181 
182  PDRobstacle::generateVtk(casepath/"VTK", obstacles, cylinders);
183 
184  if (dryrun)
185  {
186  Info<< nl
187  << "dry-run: stopping after reading/writing obstacles" << nl
188  << "\nEnd\n" << nl;
189  return 0;
190  }
191 
192 
193  // Bookkeeping of the ranges within the obstacle list
194 
195  // Original blockage at the start
196  const labelRange origBlocks(0, obstacles.size());
197 
198  // Intersection blockage
199  labelRange interBlocks(origBlocks.after(), 0);
200 
201  scalar volSubtract = 0;
202 
203  // Do binary intersections between blocks and cylinders (or diag-beam)
204  // by creating -ve blocks at the overlap
205 
206  labelRange int1Blocks(origBlocks.after(), 0);
207 
208  if (pars.overlaps % 2 > 0)
209  {
210  Info<< " block/cylinder intersections" << endl;
211 
212  label nblocked = obstacles.size();
213 
214  volSubtract += block_cylinder_overlap(obstacles, origBlocks, cylinders);
215 
216  nblocked = (obstacles.size() - nblocked);
217 
218  interBlocks += nblocked;
219  int1Blocks += nblocked;
220  }
221 
222  // Do binary intersections between blocks
223  // by creating -ve blocks at the overlap
224 
225  labelRange int2Blocks(int1Blocks.after(), 0);
226  if (pars.overlaps % 4 > 1)
227  {
228  Info<< " block/block intersections" << endl;
229 
230  label nblocked = obstacles.size();
231 
232  volSubtract += block_overlap(obstacles, origBlocks, 1.0);
233 
234  nblocked = (obstacles.size() - nblocked);
235 
236  interBlocks += nblocked;
237  int2Blocks += nblocked;
238  }
239 
240  // Correct for triple intersections
241  // by looking for overlaps between the -ve blocks just created
242 
243  labelRange int3Blocks(int2Blocks.after(), 0);
244  if (pars.overlaps % 8 > 3)
245  {
246  Info<< " triple intersections" << endl;
247 
248  label nblocked = obstacles.size();
249 
250  volSubtract += block_overlap(obstacles, interBlocks, 1.0/3.0);
251 
252  nblocked = (obstacles.size() - nblocked);
253 
254  interBlocks += nblocked;
255  int3Blocks += nblocked;
256  }
257 
258 
259  // The field arrays, in one structure pass around easily
260  PDRarrays arr(pdrBlock);
261 
262  Info<< "Apply blockage" << endl;
263 
264  // Create blockage and count arrays by working through
265  // real and extra blocks and cylinders
266 
267  // User-defined negative blocks. Use "sign" to distinguish
268  if (origBlocks.size())
269  {
270  Info<< " negative blocks: " << origBlocks.size() << nl;
271 
272  for (const PDRobstacle& obs : obstacles[origBlocks])
273  {
274  arr.addBlockage(obs, patches, -1);
275  }
276  }
277 
278  // Do the intersection blocks positive and negative
279  // These are done first so that negative area blockage cancels positive
280 
281  if (interBlocks.size())
282  {
283  Info<< " blocks " << interBlocks.size() << nl;
284 
285  for (const PDRobstacle& obs : obstacles[interBlocks])
286  {
287  arr.addBlockage(obs, patches, 0);
288  }
289  }
290 
291  // The positive real bocks
292  if (origBlocks.size())
293  {
294  Info<< " positive blocks: " << origBlocks.size() << nl;
295 
296  for (const PDRobstacle& obs : obstacles[origBlocks])
297  {
298  arr.addBlockage(obs, patches, 1);
299  }
300  }
301 
302  // The cylinders
303  if (cylinders.size())
304  {
305  Info<< " cylinders: " << cylinders.size() << nl;
306 
307  for (const PDRobstacle& obs : cylinders)
308  {
309  arr.addCylinder(obs);
310  }
311  }
312 
313  // Calculation of the fields of drag, turbulence
314  // generation and combustion enhancement
315 
316  arr.blockageSummary();
317 
318  // Mapping of OpenFOAM cells/faces to i-j-k indices
319  PDRmeshArrays meshIdx;
321 
322  meshIdx.read(runTime, pdrBlock);
323 
324  PDRarrays::calculateAndWrite(arr, meshIdx, casepath, patches);
325 
326  Info<< nl
327  << setw(6) << origBlocks.size() << " blocks and "
328  << cylinders.size() << " cylinders/diagonal blocks" << nl;
329 
330  Info<< setw(6) << int2Blocks.size()
331  << " intersections amongst blocks" << nl;
332 
333  Info<< setw(6) << int1Blocks.size()
334  << " intersections between blocks and cyl/beams" << nl;
335 
336  Info<< setw(6) << int1Blocks.size()
337  << "/3 triple intersections" << nl;
338 
339  Info<< "Volume of obstacles read in: " << volObstacles
340  << ", volume of intersections: " << volSubtract << nl;
341 
342  Info<< nl << "After corrections:" << nl;
343  arr.blockageSummary();
344 
345  Info<< nl << "\nEnd\n" << endl;
346 
347  return 0;
348 }
349 
350 
351 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
PDRsetFields.H
Preparation of fields for PDRFoam.
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobjectI.H:70
Foam::PDRparams::timeName
word timeName
Definition: PDRparams.H:63
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::PDRpatchDef::NUM_PREDEFINED
Definition: PDRpatchDef.H:64
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
setSystemRunTimeDictionaryIO.H
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
Foam::pars
Foam::PDRparams pars
Globals for program parameters (ugly hack)
block_overlap
scalar block_overlap(DynamicList< PDRobstacle > &blocks, const labelRange &range, const scalar multiplier=1.0)
Calculate block/block overlaps.
Foam::PDRparams::legacyObsSpec
bool legacyObsSpec
Definition: PDRparams.H:67
Foam::argList::addNote
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:413
dictName
const word dictName("blockMeshDict")
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::PDRpatchDef::WALL_PATCH
Definition: PDRpatchDef.H:62
Foam::argList::readIfPresent
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
Definition: argListI.H:302
Foam::PDRblock::bounds
const boundBox & bounds() const
The mesh bounding box.
Definition: PDRblockI.H:164
PDRutils.H
Foam::PDRpatchDef::names
static const Enum< predefined > names
Names for predefined types.
Definition: PDRpatchDef.H:68
PDRlegacy.H
Foam::PDRlegacy::read_mesh_spec
void read_mesh_spec(const fileName &casepath, PDRblock &pdrBlock)
Foam::PDRarrays::calculateAndWrite
static void calculateAndWrite(PDRarrays &arr, const PDRmeshArrays &meshIndexing, const fileName &casepath, const UList< PDRpatchDef > &patches)
Foam::PDRlegacy::print_info
void print_info(const PDRblock &block)
Foam::PDRparams::read
void read(const dictionary &dict)
Read program parameters from dictionary.
Foam::PDRparams::legacyMeshSpec
bool legacyMeshSpec
Definition: PDRparams.H:66
Foam::argList::noFunctionObjects
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
Definition: argList.C:454
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
argList.H
Foam::PDRarrays
Work array definitions for PDR fields.
Definition: PDRarrays.H:63
Foam::PDRobstacle::legacyReadFiles
static scalar legacyReadFiles(const fileName &obsFileDir, const wordList &obsFileNames, const boundBox &meshBb, DynamicList< PDRobstacle > &blocks, DynamicList< PDRobstacle > &cylinders)
Read obstacle files and add to the lists.
IOmanip.H
Istream and Ostream manipulators taking arguments.
Foam::labelRange
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:58
Foam::PDRpatchDef::BLOCKED_FACE
Definition: PDRpatchDef.H:60
Foam::PDRobstacle::readFiles
static scalar readFiles(const fileName &obsFileDir, const wordList &obsFileNames, const boundBox &meshBb, DynamicList< PDRobstacle > &blocks, DynamicList< PDRobstacle > &cylinders)
Read obstacle files and set the lists.
dictIO
IOobject dictIO
Definition: setConstantMeshDictionaryIO.H:1
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::setw
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
Foam::PDRblock
A single block x-y-z rectilinear mesh addressable as i,j,k with simplified creation....
Definition: PDRblock.H:149
Foam::PtrList::resize
void resize(const label newLen)
Adjust size of PtrList.
Definition: PtrList.C:103
Foam::PDRparams::gridPointTol
scalar gridPointTol
Definition: PDRparams.H:92
Foam::PDRmeshArrays::read
void read(const Time &runTime, const PDRblock &pdrBlock)
Read OpenFOAM mesh and determine i-j-k indices for faces/cells.
Foam::PDRparams::obsfile_dir
fileName obsfile_dir
Definition: PDRparams.H:61
Foam::argList::addBoolOption
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition: argList.C:325
IOdictionary.H
Time.H
setRootCase.H
Foam::TimePaths::system
const word & system() const
Return system name.
Definition: TimePathsI.H:94
Foam::PDRparams::overlaps
int overlaps
Flag to control which overlap calculations are performed.
Definition: PDRparams.H:90
Foam::PDRparams::obsfile_names
wordList obsfile_names
Definition: PDRparams.H:62
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::PDRobstacle
Obstacle definitions for PDR.
Definition: PDRobstacle.H:74
createTime.H
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:121
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::TimePaths::globalPath
fileName globalPath() const
Return global path for the case.
Definition: TimePathsI.H:72
Foam::PDRmeshArrays
OpenFOAM/PDRblock addressing information.
Definition: PDRmeshArrays.H:65
Foam::PDRobstacle::generateVtk
static void generateVtk(const fileName &outputDir, const UList< PDRobstacle > &obslist, const UList< PDRobstacle > &cyllist)
Generate multi-piece VTK (vtp) file of obstacles.
Foam::PDRpatchDef::MERGING_PATCH
Definition: PDRpatchDef.H:61
block_cylinder_overlap
scalar block_cylinder_overlap(DynamicList< PDRobstacle > &blocks, const labelRange &range, const UList< PDRobstacle > &cylinders)
Calculate block/cylinder overlaps.
Foam::PDRmeshArrays::gridPointRelTol
static scalar gridPointRelTol
Relative tolerance when matching grid points. Default = 0.02.
Definition: PDRmeshArrays.H:70
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:491
Foam::argList::addOption
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
Definition: argList.C:336
args
Foam::argList args(argc, argv)
Foam::PDRblock::read
bool read(const dictionary &dict)
Read dictionary.
Definition: PDRblock.C:556
Foam::PDRpatchDef::predefined
predefined
Patch predefines.
Definition: PDRpatchDef.H:58
Foam::argList::found
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:157