PDRobstacle.H
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-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::PDRobstacle
29
30Description
31 Obstacle definitions for PDR
32
33SourceFiles
34 PDRobstacle.C
35 PDRobstacleIO.C
36 PDRobstacleRead.C
37
38\*---------------------------------------------------------------------------*/
39
40#ifndef PDRobstacle_H
41#define PDRobstacle_H
42
43#include "InfoProxy.H"
44#include "labelPair.H"
45#include "MeshedSurface.H"
46#include "MeshedSurfacesFwd.H"
47#include "boundBox.H"
48#include "DynamicList.H"
49#include "pointField.H"
50#include "volumeType.H"
52
53// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54
55namespace Foam
56{
57
58// Forward Declarations
59class boundBox;
60class PDRobstacle;
64
65namespace vtk
66{
67 class surfaceWriter;
68}
69
70
71/*---------------------------------------------------------------------------*\
72 Class PDRobstacle Declaration
73\*---------------------------------------------------------------------------*/
75class PDRobstacle
76{
77public:
78
79 //- Obstacle types (legacy numbering)
80 enum legacyTypes
81 {
82 NONE = 0,
87 CUBOID = 6,
95 IGNITION = 41,
96 MESH_PLANE = 46,
97 IGNORE = 200
98 };
99
100
101 // Static Data Members
102
103 //- The max blowoff pressure [bar]
104 // Primarily to catch accidental input in Pa or mbar
105 static constexpr int maxBlowoffPressure = 10;
106
107
108 // Data Members
109
110 //- The group-id
111 label groupId;
112
113 //- The obstacle type-id
114 int typeId;
115
116 //- The x/y/z orientation (0,1,2)
118
119 //- Bias for position sorting
120 scalar sortBias;
121
122 //- The obstacle location.
123 // Lower corner for boxes, end-centre for cylinders
124 point pt;
125
126 //- The obstacle dimensions (for boxes)
127 vector span;
128
129 // Accessors for cylinders and diagonal blocks
131 inline scalar dia() const { return span[vector::X]; }
132 inline scalar theta() const { return span[vector::Y]; }
133 inline scalar len() const { return span[vector::Z]; }
135 inline scalar& dia() { return span[vector::X]; }
136 inline scalar& theta() { return span[vector::Y]; }
137 inline scalar& len() { return span[vector::Z]; }
138
139 union
141 scalar wa;
143 scalar blowoff_press;
144 };
145 union
147 scalar wb;
148 scalar blowoff_time;
149 };
150 scalar vbkge;
151 scalar xbkge;
152 scalar ybkge;
153 scalar zbkge;
154
155 union
158 int inlet_dirn;
159 };
161 string identifier;
162
163public:
164
165 // Constructors
166
167 //- Construct zero-initialized
168 PDRobstacle();
169
170 //- Read construct as named dictionary
171 explicit PDRobstacle(Istream& is);
172
173
174 // Member Function Selectors
177 (
178 void,
180 read,
182 (
183 PDRobstacle& obs,
184 const dictionary& dict
185 ),
186 (obs, dict)
187 );
188
189
190 // Static Member Functions
191
192 //- Read obstacle files and add to the lists
193 // \return the total volume
194 static scalar legacyReadFiles
195 (
196 const fileName& obsFileDir,
197 const wordList& obsFileNames,
198 const boundBox& meshBb,
199 // output
201 DynamicList<PDRobstacle>& cylinders
202 );
203
204 //- Read obstacle files and set the lists
205 // \return the total volume
206 static scalar readFiles
207 (
208 const fileName& obsFileDir,
209 const wordList& obsFileNames,
210 const boundBox& meshBb,
211 // output
213 DynamicList<PDRobstacle>& cylinders
214 );
215
216
217 // Member Functions
218
219 //- Read name / dictionary
220 bool read(Istream& is);
221
222 //- Read the 'name' identifier if present
223 void readProperties(const dictionary& dict);
224
225 //- Obstacle position accessors
226 inline scalar x() const { return pt.x(); }
227 inline scalar y() const { return pt.y(); }
228 inline scalar z() const { return pt.z(); }
229 inline scalar& x() { return pt.x(); }
230 inline scalar& y() { return pt.y(); }
231 inline scalar& z() { return pt.z(); }
232
233
234 //- Is obstacle type id cylinder-like?
235 inline static bool isCylinder(const label id);
236
237 //- Is obstacle cylinder-like?
238 inline bool isCylinder() const;
239
240 //- Reset to a zero obstacle
241 void clear();
242
243 //- Scale obstacle dimensions by specified scaling factor
244 // Zero and negative factors are ignored
245 void scale(const scalar factor);
246
247 //- Volume of the obstacle
248 scalar volume() const;
249
250 //- True if the obstacle is considered to be too small
251 bool tooSmall(const scalar minWidth) const;
252
253 //- Set values from single-line, multi-column format.
254 // The only input format, but termed 'legacy' since it may
255 // be replaced in the near future.
256 // \return false if the scanning failed or if the obstacle type
257 // is not supported (or no longer supported)
258 bool setFromLegacy
259 (
260 const int groupTypeId,
261 const string& buffer,
262 const label lineNo = -1,
263 const word& inputFile = word::null
264 );
265
266 //- Trim obstacle to ensure it is within the specified bounding box
267 //- and return the intersection type.
268 // Returns UNKNOWN for unknown types and invalid bounding boxes
269 volumeType trim(const boundBox& bb);
270
271 //- Surface (points, faces) representation
272 meshedSurface surface() const;
273
274 //- Add pieces to vtp output
275 static label addPieces
276 (
277 vtk::surfaceWriter& surfWriter,
278 const UList<PDRobstacle>& list,
279 label pieceId = 0
280 );
281
282 //- Generate multi-piece VTK (vtp) file of obstacles
283 static void generateVtk
284 (
285 const fileName& outputDir,
286 const UList<PDRobstacle>& obslist,
287 const UList<PDRobstacle>& cyllist
288 );
289
290
291 // IOstream Operators
292
293 //- Return info proxy.
295 {
296 return *this;
297 }
299 friend Istream& operator>>(Istream& is, PDRobstacle& obs);
300};
301
302
303// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
304
305// Global Operators
306
307//- Compare according to x0 position
308bool operator<(const PDRobstacle& a, const PDRobstacle& b);
309
310//- For list output, assert that no obstacles are identical
311inline bool operator!=(const PDRobstacle& a, const PDRobstacle& b)
312{
313 return true;
314}
315
316
317// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
319namespace PDRlegacy
320{
321
322/*---------------------------------------------------------------------------*\
323 Class obstacleGrouping Declaration
324\*---------------------------------------------------------------------------*/
325
326//- Locations for each instance of an obstacle group.
328:
329 public DynamicList<point>
330{
331 //- Number of obstacles counted
332 label nObstacle_;
333
334 //- Number of cylinder-like obstacles counted
335 label nCylinder_;
336
337
338public:
339
340 //- Construct null
342 :
343 nObstacle_(0),
344 nCylinder_(0)
345 {}
346
347 //- Construct with one location (instance)
348 explicit obstacleGrouping(const vector& origin)
349 :
351 {
352 append(origin);
353 }
354
355 //- Clear obstacle count and locations
356 void clear()
357 {
358 nObstacle_ = 0;
359 nCylinder_ = 0;
361 }
362
363 //- Increment the number of obstacles
364 void addObstacle()
365 {
366 ++nObstacle_;
367 }
368
369 //- Increment the number of cylinder-like obstacles
370 void addCylinder()
371 {
372 ++nCylinder_;
373 }
374
375 //- The number of obstacles
376 label nObstacle() const
377 {
378 return nObstacle_;
379 }
380
381 //- The number of cylinder-like obstacles
382 label nCylinder() const
383 {
384 return nCylinder_;
385 }
386
387 //- The number of locations x number of obstacles
388 label nTotalObstacle() const
389 {
390 return size() * nObstacle_;
391 }
392
393 //- The number of locations x number of cylinder-like obstacles
394 label nTotalCylinder() const
395 {
396 return size() * nCylinder_;
397 }
398
399 //- The number of locations x number of obstacles
400 label nTotal() const
401 {
402 return size() * (nObstacle_ + nCylinder_);
403 }
404
405 //- Add a location
407
408 //- Add a location
409 void append(const scalar x, const scalar y, const scalar z)
410 {
411 append(point(x, y, z));
412 }
413};
414
415
416// Service Functions
417
418//- Read obstacle files, do counting only.
419// \return nObstacle, nCylinder read
421(
422 const fileName& obsFileDir,
423 const wordList& obsFileNames,
425);
426
427
428//- Read obstacle files and add to the lists
429// \return the total volume
431(
432 const fileName& obsFileDir,
433 const wordList& obsFileNames,
434 const Map<obstacleGrouping>& groups,
435 const boundBox& meshBb,
436 // output
438 DynamicList<PDRobstacle>& cylinders
439);
440
441
442// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
443
444} // End namespace PDRlegacy
445
446
447// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
448
449// Global Operators
450
451//- Locations for each instance of an obstacle group.
452inline Ostream& operator<<
453(
454 Ostream& os,
455 const PDRlegacy::obstacleGrouping& group
456)
457{
459 << group.size() << token::SPACE
460 << group.nObstacle() << token::SPACE
461 << group.nCylinder() << token::END_LIST;
462
463 return os;
464}
465
466
467// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
468
469} // End namespace Foam
470
471// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
472
473#include "PDRobstacleI.H"
474
475// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
476
477#endif
478
479// ************************************************************************* //
scalar y
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:391
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:52
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Locations for each instance of an obstacle group.
Definition: PDRobstacle.H:329
void addCylinder()
Increment the number of cylinder-like obstacles.
Definition: PDRobstacle.H:369
label nObstacle() const
The number of obstacles.
Definition: PDRobstacle.H:375
void addObstacle()
Increment the number of obstacles.
Definition: PDRobstacle.H:363
label nTotalObstacle() const
The number of locations x number of obstacles.
Definition: PDRobstacle.H:387
label nCylinder() const
The number of cylinder-like obstacles.
Definition: PDRobstacle.H:381
void append(const scalar x, const scalar y, const scalar z)
Add a location.
Definition: PDRobstacle.H:408
obstacleGrouping(const vector &origin)
Construct with one location (instance)
Definition: PDRobstacle.H:347
label nTotal() const
The number of locations x number of obstacles.
Definition: PDRobstacle.H:399
void clear()
Clear obstacle count and locations.
Definition: PDRobstacle.H:355
label nTotalCylinder() const
The number of locations x number of cylinder-like obstacles.
Definition: PDRobstacle.H:393
Obstacle definitions for PDR.
Definition: PDRobstacle.H:75
scalar volume() const
Volume of the obstacle.
static label addPieces(vtk::surfaceWriter &surfWriter, const UList< PDRobstacle > &list, label pieceId=0)
Add pieces to vtp output.
scalar sortBias
Bias for position sorting.
Definition: PDRobstacle.H:119
bool isCylinder() const
Is obstacle cylinder-like?
Definition: PDRobstacleI.H:40
point pt
The obstacle location.
Definition: PDRobstacle.H:123
PDRobstacle(Istream &is)
Read construct as named dictionary.
direction orient
The x/y/z orientation (0,1,2)
Definition: PDRobstacle.H:116
scalar x() const
Obstacle position accessors.
Definition: PDRobstacle.H:225
scalar y() const
Definition: PDRobstacle.H:226
scalar z() const
Definition: PDRobstacle.H:227
bool setFromLegacy(const int groupTypeId, const string &buffer, const label lineNo=-1, const word &inputFile=word::null)
Set values from single-line, multi-column format.
volumeType trim(const boundBox &bb)
scalar theta() const
Definition: PDRobstacle.H:131
scalar len() const
Definition: PDRobstacle.H:132
declareMemberFunctionSelectionTable(void, PDRobstacle, read, dictionary,(PDRobstacle &obs, const dictionary &dict),(obs, dict))
static void generateVtk(const fileName &outputDir, const UList< PDRobstacle > &obslist, const UList< PDRobstacle > &cyllist)
Generate multi-piece VTK (vtp) file of obstacles.
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.
bool tooSmall(const scalar minWidth) const
True if the obstacle is considered to be too small.
meshedSurface surface() const
Surface (points, faces) representation.
label groupId
The group-id.
Definition: PDRobstacle.H:110
void readProperties(const dictionary &dict)
Read the 'name' identifier if present.
friend Istream & operator>>(Istream &is, PDRobstacle &obs)
scalar & theta()
Definition: PDRobstacle.H:135
void clear()
Reset to a zero obstacle.
scalar dia() const
Definition: PDRobstacle.H:130
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.
static constexpr int maxBlowoffPressure
The max blowoff pressure [bar].
Definition: PDRobstacle.H:104
scalar & len()
Definition: PDRobstacle.H:136
vector span
The obstacle dimensions (for boxes)
Definition: PDRobstacle.H:126
bool read(Istream &is)
Read name / dictionary.
InfoProxy< PDRobstacle > info() const
Return info proxy.
Definition: PDRobstacle.H:293
legacyTypes
Obstacle types (legacy numbering)
Definition: PDRobstacle.H:80
@ OLD_BLOWOFF
ignored (old)
Definition: PDRobstacle.H:90
@ IGNITION
ignored (old)
Definition: PDRobstacle.H:94
@ OLD_INLET
ignored (old)
Definition: PDRobstacle.H:89
@ NONE
Placeholder.
Definition: PDRobstacle.H:81
int typeId
The obstacle type-id.
Definition: PDRobstacle.H:113
void scale(const scalar factor)
Scale obstacle dimensions by specified scaling factor.
PDRobstacle()
Construct zero-initialized.
scalar & dia()
Definition: PDRobstacle.H:134
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
label size() const noexcept
The number of elements in the UList.
Definition: UListI.H:420
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:64
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A class for handling file names.
Definition: fileName.H:76
Base class for surface writers.
@ BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155
@ END_LIST
End list [isseparator].
Definition: token.H:156
@ SPACE
Space [isspace].
Definition: token.H:125
An enumeration wrapper for classification of a location as being inside/outside of a volume.
Definition: volumeType.H:61
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
Macros to ease declaration of member function selection tables.
#define declareMemberFunctionSelectionTable(returnType, baseType, funcName, argNames, argList, parListUnused)
Declare a run-time member-function selection (variables and adder classes)
labelPair readObstacleFiles(const fileName &obsFileDir, const wordList &obsFileNames, Map< obstacleGrouping > &groups)
Read obstacle files, do counting only.
Namespace for OpenFOAM.
bool operator!=(const eddy &a, const eddy &b)
Definition: eddy.H:239
vector point
Point is a vector.
Definition: point.H:43
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Istream & operator>>(Istream &, directionInfo &)
uint8_t direction
Definition: direction.H:56
bool operator<(const IOstreamOption::versionNumber &a, const IOstreamOption::versionNumber &b) noexcept
Version A older than B.
List< treeBoundBox > meshBb(1, treeBoundBox(boundBox(coarseMesh.points(), false)).extend(rndGen, 1e-3))
dictionary dict
volScalarField & b
Definition: createFields.H:27