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 -------------------------------------------------------------------------------
10 License
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  }
138  }
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 // ************************************************************************* //
label findIndex(const wordRe &key) const
Zone index for the first match, return -1 if not found.
Definition: ZoneMesh.C:601
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
static bitSet cellSelection(const polyMesh &mesh, const boundBox &userBounds, const wordRes &zoneNames, boundBox &meshBounds)
Define cell selection from bounding-box and zones.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
bool returnReduceAnd(const bool value, const label comm=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
dynamicFvMesh & mesh
static void checkOverlap(const word callerName, const boundBox &meshBounds, const boundBox &userBounds)
Check and warn if bounding boxes do not intersect.
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:137
A class for handling words, derived from Foam::string.
Definition: word.H:63
volScalarField & C
vector point
Point is a vector.
Definition: point.H:37
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
#define WarningInFunction
Report a warning using Foam::Warning.
label nCells() const noexcept
Number of mesh cells.
bool good() const
Bounding box is non-inverted.
Definition: boundBoxI.H:156
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:678
bitSet selection(const labelUList &zoneIds) const
Return all elements (cells, faces, points) contained in the listed zones.
Definition: ZoneMesh.C:706
const boundBox & bounds() const noexcept
Return mesh bounding box.
Definition: polyMesh.H:616
bool overlaps(const boundBox &bb) const
Overlaps/touches boundingBox?
Definition: boundBoxI.H:439