cuttingSurfaceBaseSelection.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) 2018-2019 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "cuttingSurfaceBase.H"
29#include "polyMesh.H"
30
31// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
32
34(
35 const word callerName,
36 const boundBox& meshBounds,
37 const boundBox& userBounds
38)
39{
40 // User bounding-box does not overlap with (global) mesh!
41 if (userBounds.valid() && !userBounds.overlaps(meshBounds))
42 {
44 << nl << callerName
45 << " : Bounds " << userBounds
46 << " do not overlap the mesh bounding box " << meshBounds
47 << nl << endl;
48 }
49}
50
51
53(
54 const polyMesh& mesh,
55 const boundBox& userBounds,
56 const wordRes& zoneNames,
57 boundBox& meshBounds
58)
59{
60 bitSet cellsToSelect;
61
62 // Zones requested and in use?
63 const bool hasZones =
65 (
66 (-1 != mesh.cellZones().findIndex(zoneNames)),
68 );
69
70 if (hasZones)
71 {
72 cellsToSelect = mesh.cellZones().selection(zoneNames);
73 }
74
75
76 // Subset the zoned cells with the userBounds.
77 // For a full mesh, use the bounds to define the cell selection.
78
79 // If there are zones cells, use them to build the effective mesh
80 // bound box.
81 // Note that for convenience we use cell centres here instead of
82 // cell points, since it will only be used for checking.
83
84
85 meshBounds = mesh.bounds(); // Use the regular mesh bounding box
86
87 const auto& cellCentres = static_cast<const fvMesh&>(mesh).C();
88
89 if (userBounds.empty())
90 {
91 // No bounds restriction, but may need effective mesh
92 // bounding-box for later checks
93
94 if (hasZones)
95 {
96 meshBounds.clear();
97
98 for (const label celli : cellsToSelect)
99 {
100 const point& cc = cellCentres[celli];
101
102 meshBounds.add(cc);
103 }
104
105 meshBounds.reduce();
106 }
107 }
108 else if (hasZones)
109 {
110 // Subset zoned cells with the user bounding-box
111
112 for (const label celli : cellsToSelect)
113 {
114 const point& cc = cellCentres[celli];
115
116 meshBounds.add(cc);
117
118 if (!userBounds.contains(cc))
119 {
120 cellsToSelect.unset(celli);
121 }
122 }
123
124 meshBounds.reduce();
125 }
126 else
127 {
128 // Create cell selection from user bounding-box
129
130 const label len = mesh.nCells();
131
132 cellsToSelect.resize(len);
133
134 for (label celli=0; celli < len; ++celli)
135 {
136 const point& cc = cellCentres[celli];
137
138 if (userBounds.contains(cc))
139 {
140 cellsToSelect.set(celli);
141 }
142 }
143 }
144
145 return cellsToSelect;
146}
147
148
150(
151 const polyMesh& mesh,
152 const boundBox& userBounds,
153 const wordRes& zoneNames,
154 const word callerName,
155 const bool warn
156)
157{
158 boundBox meshBounds;
159
160 bitSet cellsToSelect =
162 (
163 mesh, userBounds, zoneNames, meshBounds
164 );
165
166 if (warn)
167 {
168 checkOverlap(callerName, meshBounds, userBounds);
169 }
170
171 return cellsToSelect;
172}
173
174
175// ************************************************************************* //
Graphite solid properties.
Definition: C.H:53
void resize(const label numElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
Definition: PackedListI.H:409
bitSet selection(const labelUList &zoneIds) const
Definition: ZoneMesh.C:605
label findIndex(const wordRe &key) const
Zone index for the first match, return -1 if not found.
Definition: ZoneMesh.C:497
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
void set(const bitSet &bitset)
Set specified bits from another bitset.
Definition: bitSetI.H:590
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:64
bool valid() const
Bounding box is non-inverted.
Definition: boundBoxI.H:76
bool overlaps(const boundBox &bb) const
Overlaps/touches boundingBox?
Definition: boundBoxI.H:221
void reduce()
Parallel reduction of min/max values.
Definition: boundBox.C:184
bool contains(const point &pt) const
Contains point? (inside or on edge)
Definition: boundBoxI.H:271
bool empty() const
Bounding box is inverted, contains no points.
Definition: boundBoxI.H:62
void add(const boundBox &bb)
Extend to include the second box.
Definition: boundBoxI.H:191
void clear()
Clear bounding box and make it an inverted box.
Definition: boundBoxI.H:184
static void checkOverlap(const word callerName, const boundBox &meshBounds, const boundBox &userBounds)
Check and warn if bounding boxes do not intersect.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:462
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:504
label nCells() const noexcept
Number of mesh cells.
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
#define WarningInFunction
Report a warning using Foam::Warning.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53