Forward compatibility: flex
[foam-extend-3.2.git] / src / foam / meshes / primitiveMesh / PatchTools / PatchToolsSearch.C
blob4541eb1c3e5911bf53d20eb80fd54b9bf23d989a
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.
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.
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.
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/>.
24 Description
25     Searching and marking zones of the patch.
27 \*---------------------------------------------------------------------------*/
29 #include "PatchTools.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 // Finds area, starting at faceI, delimited by borderEdge.
34 // Marks all visited faces (from face-edge-face walk) with currentZone.
35 template
37     class BoolListType,
38     class Face,
39     template<class> class FaceList,
40     class PointField,
41     class PointType
44 void
45 Foam::PatchTools::markZone
47     const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
48     const BoolListType& borderEdge,
49     const label faceI,
50     const label currentZone,
51     labelList&  faceZone
54     const labelListList& faceEdges = p.faceEdges();
55     const labelListList& edgeFaces = p.edgeFaces();
57     // List of faces whose faceZone has been set.
58     labelList changedFaces(1, faceI);
60     while (true)
61     {
62         // Pick up neighbours of changedFaces
63         dynamicLabelList newChangedFaces(2*changedFaces.size());
65         forAll(changedFaces, i)
66         {
67             label faceI = changedFaces[i];
69             const labelList& fEdges = faceEdges[faceI];
71             forAll(fEdges, fEdgeI)
72             {
73                 label edgeI = fEdges[fEdgeI];
75                 if (!borderEdge[edgeI])
76                 {
77                     const labelList& eFaceLst = edgeFaces[edgeI];
79                     forAll(eFaceLst, j)
80                     {
81                         label nbrFaceI = eFaceLst[j];
83                         if (faceZone[nbrFaceI] == -1)
84                         {
85                             faceZone[nbrFaceI] = currentZone;
86                             newChangedFaces.append(nbrFaceI);
87                         }
88                         else if (faceZone[nbrFaceI] != currentZone)
89                         {
90                             FatalErrorIn
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         }
106         if (newChangedFaces.empty())
107         {
108             break;
109         }
111         // transfer from dynamic to normal list
112         changedFaces.transfer(newChangedFaces);
113     }
117 // Finds areas delimited by borderEdge (or 'real' edges).
118 // Fills faceZone accordingly
119 template
121     class BoolListType,
122     class Face,
123     template<class> class FaceList,
124     class PointField,
125     class PointType
128 Foam::label
129 Foam::PatchTools::markZones
131     const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
132     const BoolListType& borderEdge,
133     labelList& faceZone
136     faceZone.setSize(p.size());
137     faceZone = -1;
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     }
155     return zoneI;
160 // Finds areas delimited by borderEdge (or 'real' edges).
161 // Fills faceZone accordingly
162 template
164     class BoolListType,
165     class Face,
166     template<class> class FaceList,
167     class PointField,
168     class PointType
171 void
172 Foam::PatchTools::subsetMap
174     const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
175     const BoolListType& includeFaces,
176     labelList& pointMap,
177     labelList& faceMap
180     label faceI  = 0;
181     label pointI = 0;
183     const List<Face>& localFaces = p.localFaces();
185     faceMap.setSize(localFaces.size());
186     pointMap.setSize(p.nPoints());
188     boolList pointHad(pointMap.size(), false);
190     forAll(p, oldFaceI)
191     {
192         if (includeFaces[oldFaceI])
193         {
194             // Store new faces compact
195             faceMap[faceI++] = oldFaceI;
197             // Renumber labels for face
198             const Face& f = localFaces[oldFaceI];
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     }
212     // Trim
213     faceMap.setSize(faceI);
214     pointMap.setSize(pointI);
218 // ************************************************************************* //