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

patchZones.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 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "patchZones.H"
00030 
00031 
00032 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00033 
00034 defineTypeNameAndDebug(Foam::patchZones, 0);
00035 
00036 
00037 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
00038 
00039 // Gets labels of changed faces and propagates them to the edges. Returns
00040 // labels of edges changed.
00041 Foam::labelList Foam::patchZones::faceToEdge
00042 (
00043     const labelList& changedFaces,
00044     labelList& edgeRegion
00045 )
00046 {
00047     labelList changedEdges(pp_.nEdges(), -1);
00048     label changedI = 0;
00049 
00050     forAll(changedFaces, i)
00051     {
00052         label faceI = changedFaces[i];
00053 
00054         const labelList& fEdges = pp_.faceEdges()[faceI];
00055 
00056         forAll(fEdges, fEdgeI)
00057         {
00058             label edgeI = fEdges[fEdgeI];
00059 
00060             if (!borderEdge_[edgeI] && (edgeRegion[edgeI] == -1))
00061             {
00062                 edgeRegion[edgeI] = nZones_;
00063 
00064                 changedEdges[changedI++] = edgeI;
00065             }
00066         }
00067     }
00068 
00069     changedEdges.setSize(changedI);
00070 
00071     return changedEdges;
00072 }
00073 
00074 
00075 // Reverse of faceToEdge: gets edges and returns faces
00076 Foam::labelList Foam::patchZones::edgeToFace(const labelList& changedEdges)
00077 {
00078     labelList changedFaces(pp_.size(), -1);
00079     label changedI = 0;
00080 
00081     forAll(changedEdges, i)
00082     {
00083         label edgeI = changedEdges[i];
00084 
00085         const labelList& eFaces = pp_.edgeFaces()[edgeI];
00086 
00087         forAll(eFaces, eFaceI)
00088         {
00089             label faceI = eFaces[eFaceI];
00090 
00091             if (operator[](faceI) == -1)
00092             {
00093                 operator[](faceI) = nZones_;
00094 
00095                 changedFaces[changedI++] = faceI;
00096             }
00097         }
00098     }
00099 
00100     changedFaces.setSize(changedI);
00101 
00102     return changedFaces;
00103 }
00104 
00105 
00106 // Finds area, starting at faceI, delimited by borderEdge
00107 void Foam::patchZones::markZone(label faceI)
00108 {
00109     // List of faces whose faceZone has been set.
00110     labelList changedFaces(1, faceI);
00111     // List of edges whose faceZone has been set.
00112     labelList changedEdges;
00113 
00114     // Zones on all edges.
00115     labelList edgeZone(pp_.nEdges(), -1);
00116 
00117     while(1)
00118     {
00119         changedEdges = faceToEdge(changedFaces, edgeZone);
00120 
00121         if (debug)
00122         {
00123             Info<< "From changedFaces:" << changedFaces.size()
00124                 << " to changedEdges:" << changedEdges.size()
00125                 << endl;
00126         }
00127 
00128         if (changedEdges.empty())
00129         {
00130             break;
00131         }
00132 
00133         changedFaces = edgeToFace(changedEdges);
00134 
00135         if (debug)
00136         {
00137             Info<< "From changedEdges:" << changedEdges.size()
00138                 << " to changedFaces:" << changedFaces.size()
00139                 << endl;
00140         }
00141 
00142         if (changedEdges.empty())
00143         {
00144             break;
00145         }
00146     }
00147 }
00148 
00149 
00150 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00151 
00152 // Construct from components
00153 Foam::patchZones::patchZones
00154 (
00155     const primitivePatch& pp,
00156     const boolList& borderEdge
00157 )
00158 :
00159     labelList(pp.size(), -1),
00160     pp_(pp),
00161     borderEdge_(borderEdge),
00162     nZones_(0)
00163 {
00164     // Finds areas delimited by borderEdge (or 'real' edges).
00165     // Fills *this with zone number accordingly.
00166 
00167     if (borderEdge.size() != pp_.nEdges())
00168     {
00169         FatalErrorIn
00170         (
00171             "patchZones::patchZones(const primitivePatch&, const boolList&)"
00172         )   << "borderEdge boolList not same size as number of edges" << endl
00173             << "borderEdge:" << borderEdge.size() << endl
00174             << "nEdges    :" << pp_.nEdges()
00175             << abort(FatalError);
00176     }
00177 
00178     label faceI = 0;
00179 
00180     while (true)
00181     {
00182         // Find first non-visited face
00183         for (; faceI < pp_.size(); faceI++)
00184         {
00185             if (operator[](faceI) == -1)
00186             {
00187                 operator[](faceI) = nZones_;
00188 
00189                 markZone(faceI);
00190 
00191                 break;
00192             }
00193         }
00194 
00195         if (faceI == pp_.size())
00196         {
00197             // Finished.
00198             break;
00199         }
00200 
00201         nZones_++;
00202     }
00203 }
00204 
00205 
00206 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd