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

walkPatch.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 "walkPatch.H"
00030 #include "ListOps.H"
00031 
00032 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00033 
00034 defineTypeNameAndDebug(Foam::walkPatch, 0);
00035 
00036 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00037 
00038 // Get other face using v0, v1 (in localFaces numbering). Or -1.
00039 Foam::label Foam::walkPatch::getNeighbour
00040 (
00041     const label faceI,
00042     const label fp,
00043     const label v0,
00044     const label v1
00045 ) const
00046 {
00047     const labelList& fEdges = pp_.faceEdges()[faceI];
00048 
00049     const edgeList& edges = pp_.edges();
00050 
00051 
00052     label nbrEdgeI = -1;
00053 
00054     // Shortcut: maybe faceEdges are sorted(?) in which case fEdges[fp] is
00055     // edge between v0 and v1.
00056     const edge& e = edges[fEdges[fp]];
00057 
00058     if ((e[0] == v0 && e[1] == v1) || (e[0] == v1 && e[1] == v0))
00059     {
00060         // Correct edge.
00061         nbrEdgeI = fEdges[fp];
00062     }
00063     else
00064     {
00065         // Loop over all faceEdges.
00066         forAll(fEdges, i)
00067         {
00068             label edgeI = fEdges[i];
00069 
00070             const edge& e = edges[edgeI];
00071 
00072             if
00073             (
00074                 (e[0] == v0 && e[1] == v1)
00075              || (e[0] == v1 && e[1] == v0)
00076             )
00077             {
00078                 // Found edge on face which uses v0, v1.
00079                 nbrEdgeI = edgeI;
00080 
00081                 break;
00082             }
00083         }
00084     }
00085 
00086 
00087     if (nbrEdgeI == -1)
00088     {
00089         FatalErrorIn("getNeighbour")
00090             << "Did not find edge on face " << faceI << " that uses vertices"
00091             << v0 << " and " << v1 << abort(FatalError);
00092     }
00093 
00094 
00095     // Get neighbouring face.
00096 
00097     const labelList& eFaces = pp_.edgeFaces()[nbrEdgeI];
00098 
00099     if (eFaces.size() == 1)
00100     {
00101         return -1;
00102     }
00103     else if (eFaces.size() == 2)
00104     {
00105         label nbrFaceI = eFaces[0];
00106 
00107         if (nbrFaceI == faceI)
00108         {
00109             nbrFaceI = eFaces[1];
00110         }
00111 
00112         return nbrFaceI;
00113     }
00114     else
00115     {
00116         FatalErrorIn("getNeighbour")
00117             << "Illegal surface on patch. Face " << faceI
00118             << " at vertices " << v0 << ',' << v1
00119             << " has fewer than 1 or more than 2 neighbours"
00120             << abort(FatalError);
00121         return -1;
00122     }
00123 }
00124 
00125 
00126 // Gets labels of changed faces and enterVertices on faces.
00127 // Returns labels of faces changed and enterVertices on them.
00128 void Foam::walkPatch::faceToFace
00129 (
00130     const labelList& changedFaces,
00131     const labelList& enterVerts,
00132 
00133     labelList& nbrFaces,
00134     labelList& nbrEnterVerts
00135 )
00136 {
00137     nbrFaces.setSize(pp_.size());
00138     nbrEnterVerts.setSize(pp_.size());
00139     label changedI = 0;
00140 
00141     forAll(changedFaces, i)
00142     {
00143         label faceI = changedFaces[i];
00144         label enterVertI = enterVerts[i];
00145 
00146         if (!visited_[faceI])
00147         {
00148             // Do this face
00149             visited_[faceI] = true;
00150             visitOrder_.append(faceI);
00151 
00152             const face& f = pp_.localFaces()[faceI];
00153 
00154             label fp = findIndex(f, enterVertI);
00155 
00156             indexInFace_.append(fp);
00157 
00158             // Visit neighbouring faces in order, starting at fp.
00159             for (label i = 0; i < f.size(); i++)
00160             {
00161                 label fp1 = reverse_ ? f.rcIndex(fp) : f.fcIndex(fp);
00162                 label nbr = getNeighbour(faceI, fp, f[fp], f[fp1]);
00163 
00164                 if
00165                 (
00166                     nbr != -1
00167                  && !visited_[nbr]
00168                  && faceZone_[nbr] == faceZone_[faceI]
00169                 )
00170                 {
00171                     nbrFaces[changedI] = nbr;
00172                     nbrEnterVerts[changedI] = f[fp];
00173                     changedI++;
00174                 }
00175 
00176                 fp = fp1;
00177             }
00178         }
00179     }
00180 
00181     nbrFaces.setSize(changedI);
00182     nbrEnterVerts.setSize(changedI);
00183 }
00184 
00185 
00186 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00187 
00188 // Construct from components
00189 Foam::walkPatch::walkPatch
00190 (
00191     const primitivePatch& pp,
00192     const labelList& faceZone,
00193     const bool reverse,
00194     const label faceI,
00195     const label enterVertI,
00196     boolList& visited
00197 )
00198 :
00199     pp_(pp),
00200     faceZone_(faceZone),
00201     reverse_(reverse),
00202     visited_(visited),
00203     visitOrder_(pp.size()),
00204     indexInFace_(pp.size())
00205 {
00206     // List of faces that have been visited in the current iteration.
00207     labelList changedFaces(1, faceI);
00208     // Corresponding list of entry vertices
00209     labelList enterVerts(1, enterVertI);
00210 
00211     while (true)
00212     {
00213         labelList nbrFaces;
00214         labelList nbrEnterVerts;
00215 
00216         faceToFace
00217         (
00218             changedFaces,
00219             enterVerts,
00220 
00221             nbrFaces,
00222             nbrEnterVerts
00223         );
00224 
00225 
00226         if (nbrFaces.empty())
00227         {
00228             break;
00229         }
00230 
00231         changedFaces = nbrFaces;
00232         enterVerts = nbrEnterVerts;
00233     }
00234 
00235     visitOrder_.shrink();
00236     indexInFace_.shrink();
00237 }
00238 
00239 
00240 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd