PatchToolsSearch.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 template
36 <
37  class BoolListType,
38  class Face,
39  template<class> class FaceList,
40  class PointField,
41  class PointType
42 >
44 (
46  const BoolListType& borderEdge,
47  const label facei,
48  const label currentZone,
49  labelList& faceZone
50 )
51 {
52  const labelListList& faceEdges = p.faceEdges();
53  const labelListList& edgeFaces = p.edgeFaces();
54 
55  // List of faces whose faceZone has been set.
56  labelList changedFaces(1, facei);
57 
58  while (true)
59  {
60  // Pick up neighbours of changedFaces
61  DynamicList<label> newChangedFaces(2*changedFaces.size());
62 
63  forAll(changedFaces, i)
64  {
65  label facei = changedFaces[i];
66 
67  const labelList& fEdges = faceEdges[facei];
68 
69  forAll(fEdges, fEdgeI)
70  {
71  label edgeI = fEdges[fEdgeI];
72 
73  if (!borderEdge[edgeI])
74  {
75  const labelList& eFaceLst = edgeFaces[edgeI];
76 
77  forAll(eFaceLst, j)
78  {
79  label nbrFacei = eFaceLst[j];
80 
81  if (faceZone[nbrFacei] == -1)
82  {
83  faceZone[nbrFacei] = currentZone;
84  newChangedFaces.append(nbrFacei);
85  }
86  else if (faceZone[nbrFacei] != currentZone)
87  {
89  << "Zones " << faceZone[nbrFacei]
90  << " at face " << nbrFacei
91  << " connects to zone " << currentZone
92  << " at face " << facei
93  << abort(FatalError);
94  }
95  }
96  }
97  }
98  }
99 
100  if (newChangedFaces.empty())
101  {
102  break;
103  }
104 
105  // transfer from dynamic to normal list
106  changedFaces.transfer(newChangedFaces);
107  }
108 }
109 
110 
111 template
112 <
113  class BoolListType,
114  class Face,
115  template<class> class FaceList,
116  class PointField,
117  class PointType
118 >
119 
122 (
124  const BoolListType& borderEdge,
125  labelList& faceZone
126 )
127 {
128  faceZone.setSize(p.size());
129  faceZone = -1;
130 
131  label zoneI = 0;
132  for (label startFacei = 0; startFacei < faceZone.size();)
133  {
134  // Find next non-visited face
135  for (; startFacei < faceZone.size(); ++startFacei)
136  {
137  if (faceZone[startFacei] == -1)
138  {
139  faceZone[startFacei] = zoneI;
140  markZone(p, borderEdge, startFacei, zoneI, faceZone);
141  zoneI++;
142  break;
143  }
144  }
145  }
146 
147  return zoneI;
148 }
149 
150 
151 template
152 <
153  class BoolListType,
154  class Face,
155  template<class> class FaceList,
156  class PointField,
157  class PointType
158 >
159 
160 void
162 (
164  const BoolListType& includeFaces,
165  labelList& pointMap,
166  labelList& faceMap
167 )
168 {
169  label facei = 0;
170  label pointi = 0;
171 
172  const List<Face>& localFaces = p.localFaces();
173 
174  faceMap.setSize(localFaces.size());
175  pointMap.setSize(p.nPoints());
176 
177  boolList pointHad(pointMap.size(), false);
178 
179  forAll(p, oldFacei)
180  {
181  if (includeFaces[oldFacei])
182  {
183  // Store new faces compact
184  faceMap[facei++] = oldFacei;
185 
186  // Renumber labels for face
187  const Face& f = localFaces[oldFacei];
188 
189  forAll(f, fp)
190  {
191  const label ptLabel = f[fp];
192  if (!pointHad[ptLabel])
193  {
194  pointHad[ptLabel] = true;
195  pointMap[pointi++] = ptLabel;
196  }
197  }
198  }
199  }
200 
201  // Trim
202  faceMap.setSize(facei);
203  pointMap.setSize(pointi);
204 }
205 
206 
207 template
208 <
209  class Face,
210  template<class> class FaceList,
211  class PointField,
212  class PointType
213 >
215 (
217  boundBox& bb,
218  label& nPoints
219 )
220 {
221  // Unfortunately nPoints constructs meshPoints() so do compact version
222  // ourselves
223  const PointField& points = p.points();
224 
225  PackedBoolList pointIsUsed(points.size());
226 
227  nPoints = 0;
228  bb = boundBox::invertedBox;
229 
230  forAll(p, facei)
231  {
232  const Face& f = p[facei];
233 
234  forAll(f, fp)
235  {
236  label pointi = f[fp];
237  if (pointIsUsed.set(pointi, 1u))
238  {
239  bb.min() = ::Foam::min(bb.min(), points[pointi]);
240  bb.max() = ::Foam::max(bb.max(), points[pointi]);
241  nPoints++;
242  }
243  }
244  }
245 }
246 
247 
248 // ************************************************************************* //
label nPoints() const
Return number of points supporting patch faces.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
error FatalError
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:58
const List< Face > & localFaces() const
Return patch faces addressing into local point list.
static void subsetMap(const PrimitivePatch< Face, FaceList, PointField, PointType > &p, const BoolListType &includeFaces, labelList &pointMap, labelList &faceMap)
Determine the mapping for a sub-patch.
A list of faces which address into the list of points.
const pointField & points
static label markZones(const PrimitivePatch< Face, FaceList, PointField, PointType > &, const BoolListType &borderEdge, labelList &faceZone)
Size and fills faceZone with zone of face.
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:184
static void calcBounds(const PrimitivePatch< Face, FaceList, PointField, PointType > &p, boundBox &bb, label &nPoints)
const Field< PointType > & points() const
Return reference to global points.
const labelListList & edgeFaces() const
Return edge-face addressing.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
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.
labelList f(nPoints)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
void setSize(const label)
Reset size of List.
Definition: List.C:281
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:60
A bit-packed bool list.
const labelListList & faceEdges() const
Return face-edge addressing.
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:342