Loading...
Searching...
No Matches
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);
104}
105
106
107template<class BoolListType, class FaceList, class PointField>
108Foam::label
110(
111 const PrimitivePatch<FaceList, PointField>& p,
112 const BoolListType& borderEdge,
113 labelList& faceZone
114)
115{
116 faceZone.setSize(p.size());
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;
191 bb.reset();
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:68
void append(const T &val)
Copy append an element to the end of this list.
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition List.C:347
void setSize(label n)
Alias for resize().
Definition List.H:536
void clear()
Clear the list, i.e. set size to zero.
Definition ListI.H:133
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 List is empty (ie, size() is zero).
Definition UList.H:701
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
labelList sortedToc() const
The indices of the on bits as a sorted labelList.
Definition bitSetI.H:441
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
void add(const boundBox &bb)
Extend to include the second box.
Definition boundBoxI.H:323
void reset()
Reset to an inverted box.
Definition boundBoxI.H:295
A subset of mesh faces organised as a primitive patch.
Definition faceZone.H:63
volScalarField & p
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
const pointField & points
label nPoints
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
List< labelList > labelListList
List of labelList.
Definition labelList.H:38
List< label > labelList
A List of labels.
Definition List.H:62
errorManip< error > abort(error &err)
Definition errorManip.H:139
GeometricField< Type, pointPatchField, pointMesh > PointField
A point field for a given type.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
labelList f(nPoints)
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299