Loading...
Searching...
No Matches
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-2022 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.good() && !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 =
64 returnReduceAnd(-1 != mesh.cellZones().findIndex(zoneNames));
65
66 if (hasZones)
67 {
68 cellsToSelect = mesh.cellZones().selection(zoneNames);
69 }
70
71
72 // Subset the zoned cells with the userBounds.
73 // For a full mesh, use the bounds to define the cell selection.
74
75 // If there are zones cells, use them to build the effective mesh
76 // bound box.
77 // Note that for convenience we use cell centres here instead of
78 // cell points, since it will only be used for checking.
79
80
81 meshBounds = mesh.bounds(); // Use the regular mesh bounding box
82
83 const auto& cellCentres = static_cast<const fvMesh&>(mesh).C();
84
85 if (userBounds.empty())
86 {
87 // No bounds restriction, but may need effective mesh
88 // bounding-box for later checks
89
90 if (hasZones)
91 {
92 meshBounds.clear();
93
94 for (const label celli : cellsToSelect)
95 {
96 const point& cc = cellCentres[celli];
97
98 meshBounds.add(cc);
99 }
100
101 meshBounds.reduce();
102 }
103 }
104 else if (hasZones)
105 {
106 // Subset zoned cells with the user bounding-box
107
108 for (const label celli : cellsToSelect)
109 {
110 const point& cc = cellCentres[celli];
111
112 meshBounds.add(cc);
113
114 if (!userBounds.contains(cc))
115 {
116 cellsToSelect.unset(celli);
117 }
118 }
119
120 meshBounds.reduce();
121 }
122 else
123 {
124 // Create cell selection from user bounding-box
125
126 const label len = mesh.nCells();
127
128 cellsToSelect.resize(len);
129
130 for (label celli=0; celli < len; ++celli)
131 {
132 const point& cc = cellCentres[celli];
133
134 if (userBounds.contains(cc))
135 {
136 cellsToSelect.set(celli);
137 }
139 }
140
141 return cellsToSelect;
142}
143
144
146(
147 const polyMesh& mesh,
148 const boundBox& userBounds,
149 const wordRes& zoneNames,
150 const word callerName,
151 const bool warn
152)
153{
154 boundBox meshBounds;
155
156 bitSet cellsToSelect =
158 (
159 mesh, userBounds, zoneNames, meshBounds
160 );
161
162 if (warn)
163 {
164 checkOverlap(callerName, meshBounds, userBounds);
165 }
166
167 return cellsToSelect;
168}
169
170
171// ************************************************************************* //
static const Foam::dimensionedScalar C("", Foam::dimTemperature, 234.5)
void resize(const label numElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
void set(const bitSet &bitset)
Set specified bits from another bitset.
Definition bitSetI.H:502
A bounding box defined in terms of min/max extrema points.
Definition boundBox.H:71
bool overlaps(const boundBox &bb) const
Overlaps/touches boundingBox?
Definition boundBoxI.H:439
void reduce()
Inplace parallel reduction of min/max values, using UPstream::worldComm.
bool contains(const point &pt) const
Contains point? (inside or on edge).
Definition boundBoxI.H:455
bool empty() const
Bounding box is inverted, contains no points.
Definition boundBoxI.H:144
void add(const boundBox &bb)
Extend to include the second box.
Definition boundBoxI.H:323
bool good() const
Bounding box is non-inverted.
Definition boundBoxI.H:156
void clear()
Same as reset() - reset to an inverted box.
Definition boundBox.H:419
static void checkOverlap(const word callerName, const boundBox &meshBounds, const boundBox &userBounds)
Check and warn if bounding boxes do not intersect.
static bitSet cellSelection(const polyMesh &mesh, const boundBox &userBounds, const wordRes &zoneNames, boundBox &meshBounds)
Define cell selection from bounding-box and zones.
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
const boundBox & bounds() const noexcept
Return mesh bounding box.
Definition polyMesh.H:617
label nCells() const noexcept
Number of mesh cells.
A List of wordRe with additional matching capabilities.
Definition wordRes.H:56
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
#define WarningInFunction
Report a warning using Foam::Warning.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
bool returnReduceAnd(const bool value, const int communicator=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
vector point
Point is a vector.
Definition point.H:37
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50