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 -------------------------------------------------------------------------------
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.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)),
67  andOp<bool>()
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 =
161  cuttingSurfaceBase::cellSelection
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 // ************************************************************************* //
Foam::PackedList::resize
void resize(const label numElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
Definition: PackedListI.H:409
Foam::boundBox::reduce
void reduce()
Parallel reduction of min/max values.
Definition: boundBox.C:184
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::bitSet::set
void set(const bitSet &bitset)
Set specified bits from another bitset.
Definition: bitSetI.H:574
Foam::cuttingSurfaceBase::checkOverlap
static void checkOverlap(const word callerName, const boundBox &meshBounds, const boundBox &userBounds)
Check and warn if bounding boxes do not intersect.
Definition: cuttingSurfaceBaseSelection.C:34
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::cuttingSurfaceBase::cellSelection
static bitSet cellSelection(const polyMesh &mesh, const boundBox &userBounds, const wordRes &zoneNames, boundBox &meshBounds)
Define cell selection from bounding-box and zones.
Definition: cuttingSurfaceBaseSelection.C:53
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
C
volScalarField & C
Definition: readThermalProperties.H:102
Foam::boundBox::overlaps
bool overlaps(const boundBox &bb) const
Overlaps/touches boundingBox?
Definition: boundBoxI.H:221
cuttingSurfaceBase.H
Foam::andOp
Definition: ops.H:233
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam::boundBox::empty
bool empty() const
Bounding box is inverted, contains no points.
Definition: boundBoxI.H:62
Foam::boundBox::clear
void clear()
Clear bounding box and make it an inverted box.
Definition: boundBoxI.H:184
Foam::boundBox::contains
bool contains(const point &pt) const
Contains point? (inside or on edge)
Definition: boundBoxI.H:271
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::Vector< scalar >
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Foam::boundBox::valid
bool valid() const
Bounding box is non-inverted.
Definition: boundBoxI.H:76
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::boundBox::add
void add(const boundBox &bb)
Extend to include the second box.
Definition: boundBoxI.H:191