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

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