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 | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Searching and marking zones of the patch.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "PatchTools.H"
30 #include "PackedBoolList.H"
31 #include "boundBox.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 // Finds area, starting at faceI, delimited by borderEdge.
36 // Marks all visited faces (from face-edge-face walk) with currentZone.
37 template
38 <
39  class BoolListType,
40  class Face,
41  template<class> class FaceList,
42  class PointField,
43  class PointType
44 >
45 
46 void
48 (
49  const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
50  const BoolListType& borderEdge,
51  const label faceI,
52  const label currentZone,
53  labelList& faceZone
54 )
55 {
56  const labelListList& faceEdges = p.faceEdges();
57  const labelListList& edgeFaces = p.edgeFaces();
58 
59  // List of faces whose faceZone has been set.
60  labelList changedFaces(1, faceI);
61 
62  while (true)
63  {
64  // Pick up neighbours of changedFaces
65  DynamicList<label> newChangedFaces(2*changedFaces.size());
66 
67  forAll(changedFaces, i)
68  {
69  label faceI = changedFaces[i];
70 
71  const labelList& fEdges = faceEdges[faceI];
72 
73  forAll(fEdges, fEdgeI)
74  {
75  label edgeI = fEdges[fEdgeI];
76 
77  if (!borderEdge[edgeI])
78  {
79  const labelList& eFaceLst = edgeFaces[edgeI];
80 
81  forAll(eFaceLst, j)
82  {
83  label nbrFaceI = eFaceLst[j];
84 
85  if (faceZone[nbrFaceI] == -1)
86  {
87  faceZone[nbrFaceI] = currentZone;
88  newChangedFaces.append(nbrFaceI);
89  }
90  else if (faceZone[nbrFaceI] != currentZone)
91  {
93  << "Zones " << faceZone[nbrFaceI]
94  << " at face " << nbrFaceI
95  << " connects to zone " << currentZone
96  << " at face " << faceI
97  << abort(FatalError);
98  }
99  }
100  }
101  }
102  }
103 
104  if (newChangedFaces.empty())
105  {
106  break;
107  }
108 
109  // transfer from dynamic to normal list
110  changedFaces.transfer(newChangedFaces);
111  }
112 }
113 
114 
115 // Finds areas delimited by borderEdge (or 'real' edges).
116 // Fills faceZone accordingly
117 template
118 <
119  class BoolListType,
120  class Face,
121  template<class> class FaceList,
122  class PointField,
123  class PointType
124 >
125 
128 (
129  const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
130  const BoolListType& borderEdge,
131  labelList& faceZone
132 )
133 {
134  faceZone.setSize(p.size());
135  faceZone = -1;
136 
137  label zoneI = 0;
138  for (label startFaceI = 0; startFaceI < faceZone.size();)
139  {
140  // Find next non-visited face
141  for (; startFaceI < faceZone.size(); ++startFaceI)
142  {
143  if (faceZone[startFaceI] == -1)
144  {
145  faceZone[startFaceI] = zoneI;
146  markZone(p, borderEdge, startFaceI, zoneI, faceZone);
147  zoneI++;
148  break;
149  }
150  }
151  }
152 
153  return zoneI;
154 }
155 
156 
157 
158 // Finds areas delimited by borderEdge (or 'real' edges).
159 // Fills faceZone accordingly
160 template
161 <
162  class BoolListType,
163  class Face,
164  template<class> class FaceList,
165  class PointField,
166  class PointType
167 >
168 
169 void
171 (
172  const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
173  const BoolListType& includeFaces,
174  labelList& pointMap,
176 )
177 {
178  label faceI = 0;
179  label pointI = 0;
180 
181  const List<Face>& localFaces = p.localFaces();
182 
183  faceMap.setSize(localFaces.size());
184  pointMap.setSize(p.nPoints());
185 
186  boolList pointHad(pointMap.size(), false);
187 
188  forAll(p, oldFaceI)
189  {
190  if (includeFaces[oldFaceI])
191  {
192  // Store new faces compact
193  faceMap[faceI++] = oldFaceI;
194 
195  // Renumber labels for face
196  const Face& f = localFaces[oldFaceI];
197 
198  forAll(f, fp)
199  {
200  const label ptLabel = f[fp];
201  if (!pointHad[ptLabel])
202  {
203  pointHad[ptLabel] = true;
204  pointMap[pointI++] = ptLabel;
205  }
206  }
207  }
208  }
209 
210  // Trim
211  faceMap.setSize(faceI);
212  pointMap.setSize(pointI);
213 }
214 
215 
216 template
217 <
218  class Face,
219  template<class> class FaceList,
220  class PointField,
221  class PointType
222 >
224 (
226  boundBox& bb,
227  label& nPoints
228 )
229 {
230  // Unfortunately nPoints constructs meshPoints() so do compact version
231  // ourselves
232  const PointField& points = p.points();
233 
234  PackedBoolList pointIsUsed(points.size());
235 
236  nPoints = 0;
238 
239  forAll(p, faceI)
240  {
241  const Face& f = p[faceI];
242 
243  forAll(f, fp)
244  {
245  label pointI = f[fp];
246  if (pointIsUsed.set(pointI, 1u))
247  {
248  bb.min() = ::Foam::min(bb.min(), points[pointI]);
249  bb.max() = ::Foam::max(bb.max(), points[pointI]);
250  nPoints++;
251  }
252  }
253  }
254 }
255 
256 
257 // ************************************************************************* //
Foam::PackedBoolList
A bit-packed bool list.
Definition: PackedBoolList.H:63
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeFast.C:90
p
p
Definition: pEqn.H:62
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
Foam::boundBox::max
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:60
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::PatchTools::calcBounds
static void calcBounds(const PrimitivePatch< Face, FaceList, PointField, PointType > &p, boundBox &bb, label &nPoints)
Definition: PatchToolsSearch.C:224
Foam::boundBox::invertedBox
static const boundBox invertedBox
A very large inverted boundBox: min/max == +/- VGREAT.
Definition: boundBox.H:79
Foam::PackedBoolList::set
void set(const PackedList< 1 > &)
Set specified bits.
Definition: PackedBoolList.C:169
Foam::PatchTools::subsetMap
static void subsetMap(const PrimitivePatch< Face, FaceList, PointField, PointType > &, const BoolListType &includeFaces, labelList &pointMap, labelList &faceMap)
Determine the mapping for a sub-patch.
Definition: PatchToolsSearch.C:173
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
List::size
int size() const
Definition: ListI.H:83
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
PackedBoolList.H
Foam::PatchTools::markZone
static void markZone(const PrimitivePatch< Face, FaceList, PointField, PointType > &, const BoolListType &borderEdge, const label faceI, const label currentZone, labelList &faceZone)
Fill faceZone with currentZone for every face reachable.
Definition: PatchToolsSearch.C:46
Foam::boundBox::min
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:54
PatchTools.H
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::boolList
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
boundBox.H
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
f
labelList f(nPoints)
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::PatchTools::markZones
static label markZones(const PrimitivePatch< Face, FaceList, PointField, PointType > &, const BoolListType &borderEdge, labelList &faceZone)
Size and fills faceZone with zone of face.
Foam::boundBox
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
List
Definition: Test.C:19
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88