PatchToolsSearch.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | foam-extend: Open Source CFD
4  \\ / O peration | Version: 3.2
5  \\ / A nd | Web: http://www.foam-extend.org
6  \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9  This file is part of foam-extend.
10 
11  foam-extend is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation, either version 3 of the License, or (at your
14  option) any later version.
15 
16  foam-extend is distributed in the hope that it will be useful, but
17  WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with foam-extend. 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 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 // Finds area, starting at faceI, delimited by borderEdge.
34 // Marks all visited faces (from face-edge-face walk) with currentZone.
35 template
36 <
37  class BoolListType,
38  class Face,
39  template<class> class FaceList,
40  class PointField,
41  class PointType
42 >
43 
44 void
46 (
48  const BoolListType& borderEdge,
49  const label faceI,
50  const label currentZone,
52 )
53 {
54  const labelListList& faceEdges = p.faceEdges();
55  const labelListList& edgeFaces = p.edgeFaces();
56 
57  // List of faces whose faceZone has been set.
58  labelList changedFaces(1, faceI);
59 
60  while (true)
61  {
62  // Pick up neighbours of changedFaces
63  dynamicLabelList newChangedFaces(2*changedFaces.size());
64 
65  forAll(changedFaces, i)
66  {
67  label faceI = changedFaces[i];
68 
69  const labelList& fEdges = faceEdges[faceI];
70 
71  forAll(fEdges, fEdgeI)
72  {
73  label edgeI = fEdges[fEdgeI];
74 
75  if (!borderEdge[edgeI])
76  {
77  const labelList& eFaceLst = edgeFaces[edgeI];
78 
79  forAll(eFaceLst, j)
80  {
81  label nbrFaceI = eFaceLst[j];
82 
83  if (faceZone[nbrFaceI] == -1)
84  {
85  faceZone[nbrFaceI] = currentZone;
86  newChangedFaces.append(nbrFaceI);
87  }
88  else if (faceZone[nbrFaceI] != currentZone)
89  {
91  (
92  "PatchTools::markZone"
93  "(const boolList&, const label, const label, labelList&)"
94  )
95  << "Zones " << faceZone[nbrFaceI]
96  << " at face " << nbrFaceI
97  << " connects to zone " << currentZone
98  << " at face " << faceI
99  << abort(FatalError);
100  }
101  }
102  }
103  }
104  }
105 
106  if (newChangedFaces.empty())
107  {
108  break;
109  }
110 
111  // transfer from dynamic to normal list
112  changedFaces.transfer(newChangedFaces);
113  }
114 }
115 
116 
117 // Finds areas delimited by borderEdge (or 'real' edges).
118 // Fills faceZone accordingly
119 template
120 <
121  class BoolListType,
122  class Face,
123  template<class> class FaceList,
124  class PointField,
125  class PointType
126 >
127 
130 (
132  const BoolListType& borderEdge,
134 )
135 {
136  faceZone.setSize(p.size());
137  faceZone = -1;
138 
139  label zoneI = 0;
140  for (label startFaceI = 0; startFaceI < faceZone.size();)
141  {
142  // Find next non-visited face
143  for (; startFaceI < faceZone.size(); ++startFaceI)
144  {
145  if (faceZone[startFaceI] == -1)
146  {
147  faceZone[startFaceI] = zoneI;
148  markZone(p, borderEdge, startFaceI, zoneI, faceZone);
149  zoneI++;
150  break;
151  }
152  }
153  }
154 
155  return zoneI;
156 }
157 
158 
159 
160 // Finds areas delimited by borderEdge (or 'real' edges).
161 // Fills faceZone accordingly
162 template
163 <
164  class BoolListType,
165  class Face,
166  template<class> class FaceList,
167  class PointField,
168  class PointType
169 >
170 
171 void
173 (
175  const BoolListType& includeFaces,
176  labelList& pointMap,
178 )
179 {
180  label faceI = 0;
181  label pointI = 0;
182 
183  const List<Face>& localFaces = p.localFaces();
184 
185  faceMap.setSize(localFaces.size());
186  pointMap.setSize(p.nPoints());
187 
188  boolList pointHad(pointMap.size(), false);
189 
190  forAll(p, oldFaceI)
191  {
192  if (includeFaces[oldFaceI])
193  {
194  // Store new faces compact
195  faceMap[faceI++] = oldFaceI;
196 
197  // Renumber labels for face
198  const Face& f = localFaces[oldFaceI];
199 
200  forAll(f, fp)
201  {
202  const label ptLabel = f[fp];
203  if (!pointHad[ptLabel])
204  {
205  pointHad[ptLabel] = true;
206  pointMap[pointI++] = ptLabel;
207  }
208  }
209  }
210  }
211 
212  // Trim
213  faceMap.setSize(faceI);
214  pointMap.setSize(pointI);
215 }
216 
217 
218 // ************************************************************************* //
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
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::List::transfer
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
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
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
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
Foam::List::append
void append(const T &)
Append an element at the end of the list.
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::FatalError
error FatalError
PatchTools.H
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::List::setSize
void setSize(const label)
Reset size of List.
f
labelList f(nPoints)
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
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.
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88