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-2013 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 (
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  (
94  "PatchTools::markZone"
95  "("
96  "const PrimitivePatch<Face, FaceList, "
97  "PointField, PointType>& p,"
98  "const BoolListType& borderEdge,"
99  "const label faceI,"
100  "const label currentZone,"
101  "labelList& faceZone"
102  ")"
103  )
104  << "Zones " << faceZone[nbrFaceI]
105  << " at face " << nbrFaceI
106  << " connects to zone " << currentZone
107  << " at face " << faceI
108  << abort(FatalError);
109  }
110  }
111  }
112  }
113  }
114 
115  if (newChangedFaces.empty())
116  {
117  break;
118  }
119 
120  // transfer from dynamic to normal list
121  changedFaces.transfer(newChangedFaces);
122  }
123 }
124 
125 
126 // Finds areas delimited by borderEdge (or 'real' edges).
127 // Fills faceZone accordingly
128 template
129 <
130  class BoolListType,
131  class Face,
132  template<class> class FaceList,
133  class PointField,
134  class PointType
135 >
136 
139 (
141  const BoolListType& borderEdge,
142  labelList& faceZone
143 )
144 {
145  faceZone.setSize(p.size());
146  faceZone = -1;
147 
148  label zoneI = 0;
149  for (label startFaceI = 0; startFaceI < faceZone.size();)
150  {
151  // Find next non-visited face
152  for (; startFaceI < faceZone.size(); ++startFaceI)
153  {
154  if (faceZone[startFaceI] == -1)
155  {
156  faceZone[startFaceI] = zoneI;
157  markZone(p, borderEdge, startFaceI, zoneI, faceZone);
158  zoneI++;
159  break;
160  }
161  }
162  }
163 
164  return zoneI;
165 }
166 
167 
168 
169 // Finds areas delimited by borderEdge (or 'real' edges).
170 // Fills faceZone accordingly
171 template
172 <
173  class BoolListType,
174  class Face,
175  template<class> class FaceList,
176  class PointField,
177  class PointType
178 >
179 
180 void
182 (
184  const BoolListType& includeFaces,
185  labelList& pointMap,
186  labelList& faceMap
187 )
188 {
189  label faceI = 0;
190  label pointI = 0;
191 
192  const List<Face>& localFaces = p.localFaces();
193 
194  faceMap.setSize(localFaces.size());
195  pointMap.setSize(p.nPoints());
196 
197  boolList pointHad(pointMap.size(), false);
198 
199  forAll(p, oldFaceI)
200  {
201  if (includeFaces[oldFaceI])
202  {
203  // Store new faces compact
204  faceMap[faceI++] = oldFaceI;
205 
206  // Renumber labels for face
207  const Face& f = localFaces[oldFaceI];
208 
209  forAll(f, fp)
210  {
211  const label ptLabel = f[fp];
212  if (!pointHad[ptLabel])
213  {
214  pointHad[ptLabel] = true;
215  pointMap[pointI++] = ptLabel;
216  }
217  }
218  }
219  }
220 
221  // Trim
222  faceMap.setSize(faceI);
223  pointMap.setSize(pointI);
224 }
225 
226 
227 template
228 <
229  class Face,
230  template<class> class FaceList,
231  class PointField,
232  class PointType
233 >
235 (
237  boundBox& bb,
238  label& nPoints
239 )
240 {
241  // Unfortunately nPoints constructs meshPoints() so do compact version
242  // ourselves
243  const PointField& points = p.points();
244 
245  PackedBoolList pointIsUsed(points.size());
246 
247  nPoints = 0;
248  bb = boundBox::invertedBox;
249 
250  forAll(p, faceI)
251  {
252  const Face& f = p[faceI];
253 
254  forAll(f, fp)
255  {
256  label pointI = f[fp];
257  if (pointIsUsed.set(pointI, 1u))
258  {
259  bb.min() = ::Foam::min(bb.min(), points[pointI]);
260  bb.max() = ::Foam::max(bb.max(), points[pointI]);
261  nPoints++;
262  }
263  }
264  }
265 }
266 
267 
268 // ************************************************************************* //
const pointField & points
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:54
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:390
labelList f(nPoints)
const labelListList & edgeFaces() const
Return edge-face addressing.
A bit-packed bool list.
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
static label markZones(const PrimitivePatch< Face, FaceList, PointField, PointType > &, const BoolListType &borderEdge, labelList &faceZone)
Size and fills faceZone with zone of face.
label nPoints() const
Return number of points supporting patch faces.
void setSize(const label)
Reset size of List.
Definition: List.C:318
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define forAll(list, i)
Definition: UList.H:421
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:60
static void calcBounds(const PrimitivePatch< Face, FaceList, PointField, PointType > &p, boundBox &bb, label &nPoints)
errorManip< error > abort(error &err)
Definition: errorManip.H:131
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
A list of faces which address into the list of points.
error FatalError
const labelListList & faceEdges() const
Return face-edge addressing.
static void subsetMap(const PrimitivePatch< Face, FaceList, PointField, PointType > &, const BoolListType &includeFaces, labelList &pointMap, labelList &faceMap)
Determine the mapping for a sub-patch.
const List< Face > & localFaces() const
Return patch faces addressing into local point list.
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:97
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.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
const Field< PointType > & points() const
Return reference to global points.