initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / primitiveMesh / PatchTools / PatchToolsSearch.C
blob0f271008a931ccf5505c06d1d8f26378c3ecc5d1
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
26     Searching and marking zones of the patch.
28 \*---------------------------------------------------------------------------*/
30 #include "PatchTools.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 // Finds area, starting at faceI, delimited by borderEdge.
35 // Marks all visited faces (from face-edge-face walk) with currentZone.
36 template
38     class BoolListType,
39     class Face,
40     template<class> class FaceList,
41     class PointField,
42     class PointType
45 void
46 Foam::PatchTools::markZone
48     const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
49     const BoolListType& borderEdge,
50     const label faceI,
51     const label currentZone,
52     labelList&  faceZone
55     const labelListList& faceEdges = p.faceEdges();
56     const labelListList& edgeFaces = p.edgeFaces();
58     // List of faces whose faceZone has been set.
59     labelList changedFaces(1, faceI);
61     while (true)
62     {
63         // Pick up neighbours of changedFaces
64         DynamicList<label> newChangedFaces(2*changedFaces.size());
66         forAll(changedFaces, i)
67         {
68             label faceI = changedFaces[i];
70             const labelList& fEdges = faceEdges[faceI];
72             forAll(fEdges, fEdgeI)
73             {
74                 label edgeI = fEdges[fEdgeI];
76                 if (!borderEdge[edgeI])
77                 {
78                     const labelList& eFaceLst = edgeFaces[edgeI];
80                     forAll(eFaceLst, j)
81                     {
82                         label nbrFaceI = eFaceLst[j];
84                         if (faceZone[nbrFaceI] == -1)
85                         {
86                             faceZone[nbrFaceI] = currentZone;
87                             newChangedFaces.append(nbrFaceI);
88                         }
89                         else if (faceZone[nbrFaceI] != currentZone)
90                         {
91                             FatalErrorIn
92                             (
93                                 "PatchTools::markZone"
94                                 "(const boolList&, const label, const label, labelList&)"
95                             )
96                                 << "Zones " << faceZone[nbrFaceI]
97                                 << " at face " << nbrFaceI
98                                 << " connects to zone " << currentZone
99                                 << " at face " << faceI
100                                 << abort(FatalError);
101                         }
102                     }
103                 }
104             }
105         }
107         if (newChangedFaces.empty())
108         {
109             break;
110         }
112         // transfer from dynamic to normal list
113         changedFaces.transfer(newChangedFaces);
114     }
118 // Finds areas delimited by borderEdge (or 'real' edges).
119 // Fills faceZone accordingly
120 template
122     class BoolListType,
123     class Face,
124     template<class> class FaceList,
125     class PointField,
126     class PointType
129 Foam::label
130 Foam::PatchTools::markZones
132     const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
133     const BoolListType& borderEdge,
134     labelList& faceZone
137     faceZone.setSize(p.size());
138     faceZone = -1;
140     label zoneI = 0;
141     for (label startFaceI = 0; startFaceI < faceZone.size();)
142     {
143         // Find next non-visited face
144         for (; startFaceI < faceZone.size(); ++startFaceI)
145         {
146             if (faceZone[startFaceI] == -1)
147             {
148                 faceZone[startFaceI] = zoneI;
149                 markZone(p, borderEdge, startFaceI, zoneI, faceZone);
150                 zoneI++;
151                 break;
152             }
153         }
154     }
156     return zoneI;
161 // Finds areas delimited by borderEdge (or 'real' edges).
162 // Fills faceZone accordingly
163 template
165     class BoolListType,
166     class Face,
167     template<class> class FaceList,
168     class PointField,
169     class PointType
172 void
173 Foam::PatchTools::subsetMap
175     const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
176     const BoolListType& includeFaces,
177     labelList& pointMap,
178     labelList& faceMap
181     label faceI  = 0;
182     label pointI = 0;
184     const List<Face>& localFaces = p.localFaces();
186     faceMap.setSize(localFaces.size());
187     pointMap.setSize(p.nPoints());
189     boolList pointHad(pointMap.size(), false);
191     forAll(p, oldFaceI)
192     {
193         if (includeFaces[oldFaceI])
194         {
195             // Store new faces compact
196             faceMap[faceI++] = oldFaceI;
198             // Renumber labels for face
199             const Face& f = localFaces[oldFaceI];
201             forAll(f, fp)
202             {
203                 const label ptLabel = f[fp];
204                 if (!pointHad[ptLabel])
205                 {
206                     pointHad[ptLabel]  = true;
207                     pointMap[pointI++] = ptLabel;
208                 }
209             }
210         }
211     }
213     // Trim
214     faceMap.setSize(faceI);
215     pointMap.setSize(pointI);
219 // ************************************************************************* //