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-2019 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<class BoolListType, class FaceList, class PointField>
37 (
39  const BoolListType& borderEdge,
40  const label facei,
41  const label currentZone,
42  labelList& faceZone
43 )
44 {
45  const labelListList& faceEdges = p.faceEdges();
46  const labelListList& edgeFaces = p.edgeFaces();
47 
48  // List of faces whose faceZone has been set.
49  labelList changedFaces(1, facei);
50 
51  while (true)
52  {
53  // Pick up neighbours of changedFaces
54  DynamicList<label> newChangedFaces(2*changedFaces.size());
55 
56  forAll(changedFaces, i)
57  {
58  label facei = changedFaces[i];
59 
60  const labelList& fEdges = faceEdges[facei];
61 
62  forAll(fEdges, fEdgeI)
63  {
64  label edgeI = fEdges[fEdgeI];
65 
66  if (!borderEdge[edgeI])
67  {
68  const labelList& eFaceLst = edgeFaces[edgeI];
69 
70  forAll(eFaceLst, j)
71  {
72  label nbrFacei = eFaceLst[j];
73 
74  if (faceZone[nbrFacei] == -1)
75  {
76  faceZone[nbrFacei] = currentZone;
77  newChangedFaces.append(nbrFacei);
78  }
79  else if (faceZone[nbrFacei] != currentZone)
80  {
82  << "Zones " << faceZone[nbrFacei]
83  << " at face " << nbrFacei
84  << " connects to zone " << currentZone
85  << " at face " << facei
86  << abort(FatalError);
87  }
88  }
89  }
90  }
91  }
92 
93  if (newChangedFaces.empty())
94  {
95  break;
96  }
97 
98  // transfer from dynamic to normal list
99  changedFaces.transfer(newChangedFaces);
100  }
101 }
102 
103 
104 template<class BoolListType, class FaceList, class PointField>
106 (
108  const BoolListType& borderEdge,
109  labelList& faceZone
110 )
111 {
112  faceZone.setSize(p.size());
113  faceZone = -1;
114 
115  label zoneI = 0;
116  for (label startFacei = 0; startFacei < faceZone.size();)
117  {
118  // Find next non-visited face
119  for (; startFacei < faceZone.size(); ++startFacei)
120  {
121  if (faceZone[startFacei] == -1)
122  {
123  faceZone[startFacei] = zoneI;
124  markZone(p, borderEdge, startFacei, zoneI, faceZone);
125  zoneI++;
126  break;
127  }
128  }
129  }
130 
131  return zoneI;
132 }
133 
134 
135 template<class BoolListType, class FaceList, class PointField>
137 (
139  const BoolListType& includeFaces,
140  labelList& pointMap,
141  labelList& faceMap
142 )
143 {
144  typedef typename PrimitivePatch<FaceList, PointField>::FaceType FaceType;
145 
146  label facei = 0;
147  label pointi = 0;
148 
149  const List<FaceType>& localFaces = p.localFaces();
150 
151  faceMap.setSize(localFaces.size());
152  pointMap.setSize(p.nPoints());
153 
154  boolList pointHad(pointMap.size(), false);
155 
156  forAll(p, oldFacei)
157  {
158  if (includeFaces[oldFacei])
159  {
160  // Store new faces compact
161  faceMap[facei++] = oldFacei;
162 
163  // Renumber labels for face
164  const FaceType& f = localFaces[oldFacei];
165 
166  forAll(f, fp)
167  {
168  const label ptLabel = f[fp];
169  if (!pointHad[ptLabel])
170  {
171  pointHad[ptLabel] = true;
172  pointMap[pointi++] = ptLabel;
173  }
174  }
175  }
176  }
177 
178  // Trim
179  faceMap.setSize(facei);
180  pointMap.setSize(pointi);
181 }
182 
183 
184 template<class FaceList, class PointField>
186 (
188  boundBox& bb,
189  label& nPoints
190 )
191 {
192  typedef typename PrimitivePatch<FaceList, PointField>::FaceType FaceType;
193 
194  // Unfortunately nPoints constructs meshPoints() so do compact version
195  // ourselves
196  const PointField& points = p.points();
197 
198  PackedBoolList pointIsUsed(points.size());
199 
200  nPoints = 0;
201  bb = boundBox::invertedBox;
202 
203  forAll(p, facei)
204  {
205  const FaceType& f = p[facei];
206 
207  forAll(f, fp)
208  {
209  label pointi = f[fp];
210  if (pointIsUsed.set(pointi, 1u))
211  {
212  bb.min() = ::Foam::min(bb.min(), points[pointi]);
213  bb.max() = ::Foam::max(bb.max(), points[pointi]);
214  nPoints++;
215  }
216  }
217  }
218 }
219 
220 
221 // ************************************************************************* //
label nPoints() const
Return number of points supporting patch faces.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:323
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.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:58
static label markZones(const PrimitivePatch< FaceList, PointField > &, const BoolListType &borderEdge, labelList &faceZone)
Size and fills faceZone with zone of face.
A list of faces which address into the list of points.
static void calcBounds(const PrimitivePatch< FaceList, PointField > &p, boundBox &bb, label &nPoints)
const pointField & points
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:178
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
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.
std::remove_reference< FaceList >::type::value_type FaceType
const List< FaceType > & localFaces() const
Return patch faces addressing into local point list.
static void subsetMap(const PrimitivePatch< FaceList, PointField > &p, const BoolListType &includeFaces, labelList &pointMap, labelList &faceMap)
Determine the mapping for a sub-patch.
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