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<class BoolListType, class FaceList, class PointField>
40 (
42  const BoolListType& borderEdge,
43  const label facei,
44  const label currentZone,
46 )
47 {
48  const labelListList& faceEdges = p.faceEdges();
49  const labelListList& edgeFaces = p.edgeFaces();
50 
51  // List of faces whose faceZone has been set.
52  labelList changedFaces(1, facei);
53 
54  while (true)
55  {
56  // Pick up neighbours of changedFaces
57  DynamicList<label> newChangedFaces(2*changedFaces.size());
58 
59  forAll(changedFaces, i)
60  {
61  label facei = changedFaces[i];
62 
63  const labelList& fEdges = faceEdges[facei];
64 
65  forAll(fEdges, fEdgeI)
66  {
67  label edgeI = fEdges[fEdgeI];
68 
69  if (!borderEdge[edgeI])
70  {
71  const labelList& eFaceLst = edgeFaces[edgeI];
72 
73  forAll(eFaceLst, j)
74  {
75  label nbrFacei = eFaceLst[j];
76 
77  if (faceZone[nbrFacei] == -1)
78  {
79  faceZone[nbrFacei] = currentZone;
80  newChangedFaces.append(nbrFacei);
81  }
82  else if (faceZone[nbrFacei] != currentZone)
83  {
85  << "Zones " << faceZone[nbrFacei]
86  << " at face " << nbrFacei
87  << " connects to zone " << currentZone
88  << " at face " << facei
89  << abort(FatalError);
90  }
91  }
92  }
93  }
94  }
95 
96  if (newChangedFaces.empty())
97  {
98  break;
99  }
100 
101  // transfer from dynamic to normal list
102  changedFaces.transfer(newChangedFaces);
103  }
104 }
105 
106 
107 template<class BoolListType, class FaceList, class PointField>
108 Foam::label
110 (
112  const BoolListType& borderEdge,
114 )
115 {
116  faceZone.setSize(p.size());
117  faceZone = -1;
118 
119  label zoneI = 0;
120  for (label startFacei = 0; startFacei < faceZone.size();)
121  {
122  // Find next non-visited face
123  for (; startFacei < faceZone.size(); ++startFacei)
124  {
125  if (faceZone[startFacei] == -1)
126  {
127  faceZone[startFacei] = zoneI;
128  markZone(p, borderEdge, startFacei, zoneI, faceZone);
129  zoneI++;
130  break;
131  }
132  }
133  }
134 
135  return zoneI;
136 }
137 
138 
139 template<class BoolListType, class FaceList, class PointField>
140 void
142 (
144  const BoolListType& includeFaces,
145  labelList& pointMap,
147 )
148 {
149  const auto& localFaces = p.localFaces();
150 
151  faceMap.resize(localFaces.size());
152  pointMap.clear();
153 
154  bitSet pointUsed(p.nPoints());
155 
156  label facei = 0;
157 
158  forAll(localFaces, oldFacei)
159  {
160  if (includeFaces[oldFacei])
161  {
162  // Compact storage for new faces
163  faceMap[facei++] = oldFacei;
164 
165  // Local points used by face
166  pointUsed.set(localFaces[oldFacei]);
167  }
168  }
169 
170  // The newToOld mappings
171  faceMap.resize(facei);
172  pointMap = pointUsed.sortedToc();
173 }
174 
175 
176 template<class FaceList, class PointField>
178 (
180  boundBox& bb,
181  label& nPoints
182 )
183 {
184  // Unfortunately nPoints constructs meshPoints() so do compact version
185  // ourselves
186  const PointField& points = p.points();
187 
188  bitSet pointUsed(points.size());
189 
190  nPoints = 0;
191  bb = boundBox::invertedBox;
192 
193  for (const auto& f : p)
194  {
195  for (const label pointi : f)
196  {
197  if (pointUsed.set(pointi))
198  {
199  bb.add(points[pointi]);
200  ++nPoints;
201  }
202  }
203  }
204 }
205 
206 
207 // ************************************************************************* //
Foam::PatchTools::markZone
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.
Definition: PatchToolsSearch.C:40
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: blockMeshMergeTopological.C:94
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
PatchTools.H
Foam::DynamicList< label >
Foam::PatchTools::calcBounds
static void calcBounds(const PrimitivePatch< FaceList, PointField > &p, boundBox &bb, label &nPoints)
Definition: PatchToolsSearch.C:178
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:296
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
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:459
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
boundBox.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
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::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Foam::PatchTools::markZones
static label markZones(const PrimitivePatch< FaceList, PointField > &, const BoolListType &borderEdge, labelList &faceZone)
Size and fills faceZone with zone of face.
Foam::PatchTools::subsetMap
static void subsetMap(const PrimitivePatch< FaceList, PointField > &p, const BoolListType &includeFaces, labelList &pointMap, labelList &faceMap)
Determine the mapping for a sub-patch.
Definition: PatchToolsSearch.C:142
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:85
Foam::boundBox::add
void add(const boundBox &bb)
Extend to include the second box.
Definition: boundBoxI.H:191