FreeFOAM The Cross-Platform CFD Toolkit
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 | Copyright (C) 1991-2010 OpenCFD Ltd.
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 
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  DynamicList<label> 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 
128 Foam::label
130 (
132  const BoolListType& borderEdge,
133  labelList& faceZone
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,
177  labelList& faceMap
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 // ************************ vim: set sw=4 sts=4 et: ************************ //