PatchToolsSearch.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2017-2018 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
27Description
28 Searching and marking zones of the patch.
29
30\*---------------------------------------------------------------------------*/
31
32#include "PatchTools.H"
33#include "bitSet.H"
34#include "boundBox.H"
35
36// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37
38template<class BoolListType, class FaceList, class PointField>
40(
42 const BoolListType& borderEdge,
43 const label facei,
44 const label currentZone,
46)
47{
48 const labelListList& faceEdges = p.faceEdges();
49 const labelListList& edgeFaces = p.edgeFaces();
50
51 // List of faces whose faceZone has been set.
52 labelList changedFaces(1, facei);
53
54 while (true)
55 {
56 // Pick up neighbours of changedFaces
57 DynamicList<label> newChangedFaces(2*changedFaces.size());
58
59 forAll(changedFaces, i)
60 {
61 label facei = changedFaces[i];
62
63 const labelList& fEdges = faceEdges[facei];
64
65 forAll(fEdges, fEdgeI)
66 {
67 label edgeI = fEdges[fEdgeI];
68
69 if (!borderEdge[edgeI])
70 {
71 const labelList& eFaceLst = edgeFaces[edgeI];
72
73 forAll(eFaceLst, j)
74 {
75 label nbrFacei = eFaceLst[j];
76
77 if (faceZone[nbrFacei] == -1)
78 {
79 faceZone[nbrFacei] = currentZone;
80 newChangedFaces.append(nbrFacei);
81 }
82 else if (faceZone[nbrFacei] != currentZone)
83 {
85 << "Zones " << faceZone[nbrFacei]
86 << " at face " << nbrFacei
87 << " connects to zone " << currentZone
88 << " at face " << facei
89 << abort(FatalError);
90 }
91 }
92 }
93 }
94 }
95
96 if (newChangedFaces.empty())
97 {
98 break;
99 }
100
101 // transfer from dynamic to normal list
102 changedFaces.transfer(newChangedFaces);
103 }
104}
105
106
107template<class BoolListType, class FaceList, class PointField>
108Foam::label
110(
112 const BoolListType& borderEdge,
114)
115{
117 faceZone = -1;
118
119 label zoneI = 0;
120 for (label startFacei = 0; startFacei < faceZone.size();)
121 {
122 // Find next non-visited face
123 for (; startFacei < faceZone.size(); ++startFacei)
124 {
125 if (faceZone[startFacei] == -1)
126 {
127 faceZone[startFacei] = zoneI;
128 markZone(p, borderEdge, startFacei, zoneI, faceZone);
129 zoneI++;
130 break;
131 }
132 }
133 }
134
135 return zoneI;
136}
137
138
139template<class BoolListType, class FaceList, class PointField>
140void
142(
144 const BoolListType& includeFaces,
145 labelList& pointMap,
147)
148{
149 const auto& localFaces = p.localFaces();
150
151 faceMap.resize(localFaces.size());
152 pointMap.clear();
153
154 bitSet pointUsed(p.nPoints());
155
156 label facei = 0;
157
158 forAll(localFaces, oldFacei)
159 {
160 if (includeFaces[oldFacei])
161 {
162 // Compact storage for new faces
163 faceMap[facei++] = oldFacei;
164
165 // Local points used by face
166 pointUsed.set(localFaces[oldFacei]);
167 }
168 }
169
170 // The newToOld mappings
171 faceMap.resize(facei);
172 pointMap = pointUsed.sortedToc();
173}
174
175
176template<class FaceList, class PointField>
178(
180 boundBox& bb,
181 label& nPoints
182)
183{
184 // Unfortunately nPoints constructs meshPoints() so do compact version
185 // ourselves
186 const PointField& points = p.points();
187
188 bitSet pointUsed(points.size());
189
190 nPoints = 0;
192
193 for (const auto& f : p)
194 {
195 for (const label pointi : f)
196 {
197 if (pointUsed.set(pointi))
198 {
199 bb.add(points[pointi]);
200 ++nPoints;
201 }
202 }
203 }
204}
205
206
207// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
void transfer(List< T > &list)
Definition: List.C:447
void setSize(const label n)
Alias for resize()
Definition: List.H:218
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:116
static void subsetMap(const PrimitivePatch< FaceList, PointField > &p, const BoolListType &includeFaces, labelList &pointMap, labelList &faceMap)
Determine the mapping for a sub-patch.
static void markZone(const PrimitivePatch< FaceList, PointField > &, const BoolListType &borderEdge, const label facei, const label currentZone, labelList &faceZone)
Fill faceZone with currentZone for every face reachable.
static label markZones(const PrimitivePatch< FaceList, PointField > &, const BoolListType &borderEdge, labelList &faceZone)
Size and fills faceZone with zone of face.
static void calcBounds(const PrimitivePatch< FaceList, PointField > &p, boundBox &bb, label &nPoints)
A list of faces which address into the list of points.
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
labelList sortedToc() const
The indices of the on bits as a sorted labelList.
Definition: bitSetI.H:533
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
static const boundBox invertedBox
A large inverted boundBox: min/max == +/- ROOTVGREAT.
Definition: boundBox.H:86
void add(const boundBox &bb)
Extend to include the second box.
Definition: boundBoxI.H:191
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:67
volScalarField & p
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
const pointField & points
label nPoints
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
labelList f(nPoints)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333