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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Description
28  Searching and marking zones of the patch.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "PatchTools.H"
33 #include "bitSet.H"
34 #include "boundBox.H"
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 template
39 <
40  class BoolListType,
41  class Face,
42  template<class> class FaceList,
43  class PointField,
44  class PointType
45 >
47 (
49  const BoolListType& borderEdge,
50  const label facei,
51  const label currentZone,
53 )
54 {
55  const labelListList& faceEdges = p.faceEdges();
56  const labelListList& edgeFaces = p.edgeFaces();
57 
58  // List of faces whose faceZone has been set.
59  labelList changedFaces(1, facei);
60 
61  while (true)
62  {
63  // Pick up neighbours of changedFaces
64  DynamicList<label> newChangedFaces(2*changedFaces.size());
65 
66  forAll(changedFaces, i)
67  {
68  label facei = changedFaces[i];
69 
70  const labelList& fEdges = faceEdges[facei];
71 
72  forAll(fEdges, fEdgeI)
73  {
74  label edgeI = fEdges[fEdgeI];
75 
76  if (!borderEdge[edgeI])
77  {
78  const labelList& eFaceLst = edgeFaces[edgeI];
79 
80  forAll(eFaceLst, j)
81  {
82  label nbrFacei = eFaceLst[j];
83 
84  if (faceZone[nbrFacei] == -1)
85  {
86  faceZone[nbrFacei] = currentZone;
87  newChangedFaces.append(nbrFacei);
88  }
89  else if (faceZone[nbrFacei] != currentZone)
90  {
92  << "Zones " << faceZone[nbrFacei]
93  << " at face " << nbrFacei
94  << " connects to zone " << currentZone
95  << " at face " << facei
96  << abort(FatalError);
97  }
98  }
99  }
100  }
101  }
102 
103  if (newChangedFaces.empty())
104  {
105  break;
106  }
107 
108  // transfer from dynamic to normal list
109  changedFaces.transfer(newChangedFaces);
110  }
111 }
112 
113 
114 template
115 <
116  class BoolListType,
117  class Face,
118  template<class> class FaceList,
119  class PointField,
120  class PointType
121 >
122 
125 (
127  const BoolListType& borderEdge,
129 )
130 {
131  faceZone.setSize(p.size());
132  faceZone = -1;
133 
134  label zoneI = 0;
135  for (label startFacei = 0; startFacei < faceZone.size();)
136  {
137  // Find next non-visited face
138  for (; startFacei < faceZone.size(); ++startFacei)
139  {
140  if (faceZone[startFacei] == -1)
141  {
142  faceZone[startFacei] = zoneI;
143  markZone(p, borderEdge, startFacei, zoneI, faceZone);
144  zoneI++;
145  break;
146  }
147  }
148  }
149 
150  return zoneI;
151 }
152 
153 
154 template
155 <
156  class BoolListType,
157  class Face,
158  template<class> class FaceList,
159  class PointField,
160  class PointType
161 >
162 
163 void
165 (
167  const BoolListType& includeFaces,
168  labelList& pointMap,
170 )
171 {
172  const List<Face>& localFaces = p.localFaces();
173 
174  faceMap.resize(localFaces.size());
175  pointMap.clear();
176 
177  bitSet pointUsed(p.nPoints());
178 
179  label facei = 0;
180 
181  forAll(localFaces, oldFacei)
182  {
183  if (includeFaces[oldFacei])
184  {
185  // Compact storage for new faces
186  faceMap[facei++] = oldFacei;
187 
188  // Local points used by face
189  pointUsed.set(localFaces[oldFacei]);
190  }
191  }
192 
193  // The newToOld mappings
194  faceMap.resize(facei);
195  pointMap = pointUsed.sortedToc();
196 }
197 
198 
199 template
200 <
201  class Face,
202  template<class> class FaceList,
203  class PointField,
204  class PointType
205 >
207 (
209  boundBox& bb,
210  label& nPoints
211 )
212 {
213  // Unfortunately nPoints constructs meshPoints() so do compact version
214  // ourselves
215  const PointField& points = p.points();
216 
217  bitSet pointUsed(points.size());
218 
219  nPoints = 0;
220  bb = boundBox::invertedBox;
221 
222  for (const Face& f : p)
223  {
224  for (const label pointi : f)
225  {
226  if (pointUsed.set(pointi))
227  {
228  bb.add(points[pointi]);
229  ++nPoints;
230  }
231  }
232  }
233 }
234 
235 
236 // ************************************************************************* //
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeFast.C:94
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
Foam::PatchTools::calcBounds
static void calcBounds(const PrimitivePatch< Face, FaceList, PointField, PointType > &p, boundBox &bb, label &nPoints)
Definition: PatchToolsSearch.C:207
PatchTools.H
Foam::DynamicList< label >
Foam::List::append
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:182
bitSet.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::PatchTools::subsetMap
static void subsetMap(const PrimitivePatch< Face, FaceList, PointField, PointType > &p, const BoolListType &includeFaces, labelList &pointMap, labelList &faceMap)
Determine the mapping for a sub-patch.
Definition: PatchToolsSearch.C:165
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:62
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:65
Foam::List::transfer
void transfer(List< T > &list)
Definition: List.C:436
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:47
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
boundBox.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
f
labelList f(nPoints)
Foam::List< label >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::List::clear
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:115
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 min/max extrema points.
Definition: boundBox.H:63
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:90
Foam::boundBox::add
void add(const boundBox &bb)
Extend to include the second box.
Definition: boundBoxI.H:191