OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

PatchToolsSearch.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     Searching and marking zones of the patch.
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "PatchTools.H"
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 // Finds area, starting at faceI, delimited by borderEdge.
00035 // Marks all visited faces (from face-edge-face walk) with currentZone.
00036 template
00037 <
00038     class BoolListType,
00039     class Face,
00040     template<class> class FaceList,
00041     class PointField,
00042     class PointType
00043 >
00044 
00045 void
00046 Foam::PatchTools::markZone
00047 (
00048     const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
00049     const BoolListType& borderEdge,
00050     const label faceI,
00051     const label currentZone,
00052     labelList&  faceZone
00053 )
00054 {
00055     const labelListList& faceEdges = p.faceEdges();
00056     const labelListList& edgeFaces = p.edgeFaces();
00057 
00058     // List of faces whose faceZone has been set.
00059     labelList changedFaces(1, faceI);
00060 
00061     while (true)
00062     {
00063         // Pick up neighbours of changedFaces
00064         DynamicList<label> newChangedFaces(2*changedFaces.size());
00065 
00066         forAll(changedFaces, i)
00067         {
00068             label faceI = changedFaces[i];
00069 
00070             const labelList& fEdges = faceEdges[faceI];
00071 
00072             forAll(fEdges, fEdgeI)
00073             {
00074                 label edgeI = fEdges[fEdgeI];
00075 
00076                 if (!borderEdge[edgeI])
00077                 {
00078                     const labelList& eFaceLst = edgeFaces[edgeI];
00079 
00080                     forAll(eFaceLst, j)
00081                     {
00082                         label nbrFaceI = eFaceLst[j];
00083 
00084                         if (faceZone[nbrFaceI] == -1)
00085                         {
00086                             faceZone[nbrFaceI] = currentZone;
00087                             newChangedFaces.append(nbrFaceI);
00088                         }
00089                         else if (faceZone[nbrFaceI] != currentZone)
00090                         {
00091                             FatalErrorIn
00092                             (
00093                                 "PatchTools::markZone"
00094                                 "(const boolList&, const label, const label, labelList&)"
00095                             )
00096                                 << "Zones " << faceZone[nbrFaceI]
00097                                 << " at face " << nbrFaceI
00098                                 << " connects to zone " << currentZone
00099                                 << " at face " << faceI
00100                                 << abort(FatalError);
00101                         }
00102                     }
00103                 }
00104             }
00105         }
00106 
00107         if (newChangedFaces.empty())
00108         {
00109             break;
00110         }
00111 
00112         // transfer from dynamic to normal list
00113         changedFaces.transfer(newChangedFaces);
00114     }
00115 }
00116 
00117 
00118 // Finds areas delimited by borderEdge (or 'real' edges).
00119 // Fills faceZone accordingly
00120 template
00121 <
00122     class BoolListType,
00123     class Face,
00124     template<class> class FaceList,
00125     class PointField,
00126     class PointType
00127 >
00128 
00129 Foam::label
00130 Foam::PatchTools::markZones
00131 (
00132     const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
00133     const BoolListType& borderEdge,
00134     labelList& faceZone
00135 )
00136 {
00137     faceZone.setSize(p.size());
00138     faceZone = -1;
00139 
00140     label zoneI = 0;
00141     for (label startFaceI = 0; startFaceI < faceZone.size();)
00142     {
00143         // Find next non-visited face
00144         for (; startFaceI < faceZone.size(); ++startFaceI)
00145         {
00146             if (faceZone[startFaceI] == -1)
00147             {
00148                 faceZone[startFaceI] = zoneI;
00149                 markZone(p, borderEdge, startFaceI, zoneI, faceZone);
00150                 zoneI++;
00151                 break;
00152             }
00153         }
00154     }
00155 
00156     return zoneI;
00157 }
00158 
00159 
00160 
00161 // Finds areas delimited by borderEdge (or 'real' edges).
00162 // Fills faceZone accordingly
00163 template
00164 <
00165     class BoolListType,
00166     class Face,
00167     template<class> class FaceList,
00168     class PointField,
00169     class PointType
00170 >
00171 
00172 void
00173 Foam::PatchTools::subsetMap
00174 (
00175     const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
00176     const BoolListType& includeFaces,
00177     labelList& pointMap,
00178     labelList& faceMap
00179 )
00180 {
00181     label faceI  = 0;
00182     label pointI = 0;
00183 
00184     const List<Face>& localFaces = p.localFaces();
00185 
00186     faceMap.setSize(localFaces.size());
00187     pointMap.setSize(p.nPoints());
00188 
00189     boolList pointHad(pointMap.size(), false);
00190 
00191     forAll(p, oldFaceI)
00192     {
00193         if (includeFaces[oldFaceI])
00194         {
00195             // Store new faces compact
00196             faceMap[faceI++] = oldFaceI;
00197 
00198             // Renumber labels for face
00199             const Face& f = localFaces[oldFaceI];
00200 
00201             forAll(f, fp)
00202             {
00203                 const label ptLabel = f[fp];
00204                 if (!pointHad[ptLabel])
00205                 {
00206                     pointHad[ptLabel]  = true;
00207                     pointMap[pointI++] = ptLabel;
00208                 }
00209             }
00210         }
00211     }
00212 
00213     // Trim
00214     faceMap.setSize(faceI);
00215     pointMap.setSize(pointI);
00216 }
00217 
00218 
00219 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd