FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Description
00025     Searching and marking zones of the patch.
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "PatchTools.H"
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 // Finds area, starting at faceI, delimited by borderEdge.
00034 // Marks all visited faces (from face-edge-face walk) with currentZone.
00035 template
00036 <
00037     class BoolListType,
00038     class Face,
00039     template<class> class FaceList,
00040     class PointField,
00041     class PointType
00042 >
00043 
00044 void
00045 Foam::PatchTools::markZone
00046 (
00047     const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
00048     const BoolListType& borderEdge,
00049     const label faceI,
00050     const label currentZone,
00051     labelList&  faceZone
00052 )
00053 {
00054     const labelListList& faceEdges = p.faceEdges();
00055     const labelListList& edgeFaces = p.edgeFaces();
00056 
00057     // List of faces whose faceZone has been set.
00058     labelList changedFaces(1, faceI);
00059 
00060     while (true)
00061     {
00062         // Pick up neighbours of changedFaces
00063         DynamicList<label> newChangedFaces(2*changedFaces.size());
00064 
00065         forAll(changedFaces, i)
00066         {
00067             label faceI = changedFaces[i];
00068 
00069             const labelList& fEdges = faceEdges[faceI];
00070 
00071             forAll(fEdges, fEdgeI)
00072             {
00073                 label edgeI = fEdges[fEdgeI];
00074 
00075                 if (!borderEdge[edgeI])
00076                 {
00077                     const labelList& eFaceLst = edgeFaces[edgeI];
00078 
00079                     forAll(eFaceLst, j)
00080                     {
00081                         label nbrFaceI = eFaceLst[j];
00082 
00083                         if (faceZone[nbrFaceI] == -1)
00084                         {
00085                             faceZone[nbrFaceI] = currentZone;
00086                             newChangedFaces.append(nbrFaceI);
00087                         }
00088                         else if (faceZone[nbrFaceI] != currentZone)
00089                         {
00090                             FatalErrorIn
00091                             (
00092                                 "PatchTools::markZone"
00093                                 "(const boolList&, const label, const label, labelList&)"
00094                             )
00095                                 << "Zones " << faceZone[nbrFaceI]
00096                                 << " at face " << nbrFaceI
00097                                 << " connects to zone " << currentZone
00098                                 << " at face " << faceI
00099                                 << abort(FatalError);
00100                         }
00101                     }
00102                 }
00103             }
00104         }
00105 
00106         if (newChangedFaces.empty())
00107         {
00108             break;
00109         }
00110 
00111         // transfer from dynamic to normal list
00112         changedFaces.transfer(newChangedFaces);
00113     }
00114 }
00115 
00116 
00117 // Finds areas delimited by borderEdge (or 'real' edges).
00118 // Fills faceZone accordingly
00119 template
00120 <
00121     class BoolListType,
00122     class Face,
00123     template<class> class FaceList,
00124     class PointField,
00125     class PointType
00126 >
00127 
00128 Foam::label
00129 Foam::PatchTools::markZones
00130 (
00131     const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
00132     const BoolListType& borderEdge,
00133     labelList& faceZone
00134 )
00135 {
00136     faceZone.setSize(p.size());
00137     faceZone = -1;
00138 
00139     label zoneI = 0;
00140     for (label startFaceI = 0; startFaceI < faceZone.size();)
00141     {
00142         // Find next non-visited face
00143         for (; startFaceI < faceZone.size(); ++startFaceI)
00144         {
00145             if (faceZone[startFaceI] == -1)
00146             {
00147                 faceZone[startFaceI] = zoneI;
00148                 markZone(p, borderEdge, startFaceI, zoneI, faceZone);
00149                 zoneI++;
00150                 break;
00151             }
00152         }
00153     }
00154 
00155     return zoneI;
00156 }
00157 
00158 
00159 
00160 // Finds areas delimited by borderEdge (or 'real' edges).
00161 // Fills faceZone accordingly
00162 template
00163 <
00164     class BoolListType,
00165     class Face,
00166     template<class> class FaceList,
00167     class PointField,
00168     class PointType
00169 >
00170 
00171 void
00172 Foam::PatchTools::subsetMap
00173 (
00174     const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
00175     const BoolListType& includeFaces,
00176     labelList& pointMap,
00177     labelList& faceMap
00178 )
00179 {
00180     label faceI  = 0;
00181     label pointI = 0;
00182 
00183     const List<Face>& localFaces = p.localFaces();
00184 
00185     faceMap.setSize(localFaces.size());
00186     pointMap.setSize(p.nPoints());
00187 
00188     boolList pointHad(pointMap.size(), false);
00189 
00190     forAll(p, oldFaceI)
00191     {
00192         if (includeFaces[oldFaceI])
00193         {
00194             // Store new faces compact
00195             faceMap[faceI++] = oldFaceI;
00196 
00197             // Renumber labels for face
00198             const Face& f = localFaces[oldFaceI];
00199 
00200             forAll(f, fp)
00201             {
00202                 const label ptLabel = f[fp];
00203                 if (!pointHad[ptLabel])
00204                 {
00205                     pointHad[ptLabel]  = true;
00206                     pointMap[pointI++] = ptLabel;
00207                 }
00208             }
00209         }
00210     }
00211 
00212     // Trim
00213     faceMap.setSize(faceI);
00214     pointMap.setSize(pointI);
00215 }
00216 
00217 
00218 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines