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

oppositeCellFace.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     Given the cell and a face label, return the opposite face label
00027     and the face oriented in the same sense as the original face.
00028 
00029 \*---------------------------------------------------------------------------*/
00030 
00031 #include "cell.H"
00032 #include "oppositeFace.H"
00033 #include "boolList.H"
00034 
00035 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00036 
00037 
00038 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00039 
00040 Foam::label Foam::cell::opposingFaceLabel
00041 (
00042     const label masterFaceLabel,
00043     const unallocFaceList& meshFaces
00044 ) const
00045 {
00046     // Algorithm:
00047     // Go through all the faces of the cell and find the one which
00048     // does not share a single vertex with the master face.  If there
00049     // are two or more such faces, return the first one and issue a
00050     // warning; if there is no opposite face, return -1;
00051 
00052     const face& masterFace = meshFaces[masterFaceLabel];
00053 
00054     const labelList& curFaceLabels = *this;
00055 
00056     label oppositeFaceLabel = -1;
00057 
00058     forAll (curFaceLabels, faceI)
00059     {
00060         // Compare the face with the master
00061         const face& curFace = meshFaces[curFaceLabels[faceI]];
00062 
00063         // Skip the master face
00064         if
00065         (
00066             curFaceLabels[faceI] != masterFaceLabel
00067          && curFace.size() == masterFace.size()
00068         )
00069         {
00070             bool sharedPoint = false;
00071 
00072             // Compare every vertex of the current face agains the
00073             // vertices of the master face
00074             forAll (curFace, pointI)
00075             {
00076                 const label l = curFace[pointI];
00077 
00078                 forAll (masterFace, masterPointI)
00079                 {
00080                     if (masterFace[masterPointI] == l)
00081                     {
00082                         sharedPoint = true;
00083                         break;
00084                     }
00085                 }
00086 
00087                 if (sharedPoint) break;
00088             }
00089 
00090             // If no points are shared, this is the opposite face
00091             if (!sharedPoint)
00092             {
00093                 if (oppositeFaceLabel == -1)
00094                 {
00095                     // Found opposite face
00096                     oppositeFaceLabel = curFaceLabels[faceI];
00097                 }
00098                 else
00099                 {
00100                     // There has already been an opposite face.
00101                     // Non-prismatic cell
00102                     Info<< "Multiple faces not sharing vertex: " 
00103                         << oppositeFaceLabel << " and "
00104                         << curFaceLabels[faceI] << endl;
00105                     return -1;
00106                 }
00107             }
00108         }
00109     }
00110 
00111     return oppositeFaceLabel;
00112 }
00113 
00114 
00115 Foam::oppositeFace Foam::cell::opposingFace
00116 (
00117     const label masterFaceLabel,
00118     const unallocFaceList& meshFaces
00119 ) const
00120 {
00121     // Get the label of the opposite face
00122     label oppFaceLabel = opposingFaceLabel(masterFaceLabel, meshFaces);
00123 
00124     // If the opposing face is not found, return a failure
00125     if (oppFaceLabel < 0)
00126     {
00127         return oppositeFace(face(0), masterFaceLabel, oppFaceLabel);
00128     }
00129     else
00130     {
00131         // This is a prismatic cell.  Go through all the vertices of the master
00132         // face and find an edge going from the master face vertex to a slave
00133         // face vertex.  If all is OK, there should be only one such
00134         // edge for every master vertex and will provide te
00135         // master-to-slave vertex mapping.  Assemble the opposite face
00136         // in the same manner as the master.
00137 
00138         // Get reference to faces and prepare the return
00139         const face& masterFace = meshFaces[masterFaceLabel];
00140         const face& slaveFace = meshFaces[oppFaceLabel];
00141 
00142         // Get cell edges
00143         const edgeList e = edges(meshFaces);
00144         boolList usedEdges(e.size(), false);
00145 
00146         oppositeFace oppFace
00147         (
00148             face(masterFace.size()),
00149             masterFaceLabel,
00150             oppFaceLabel
00151         );
00152 
00153         forAll (masterFace, pointI)
00154         {
00155             // Go through the list of edges and find the edge from this vertex
00156             // to the slave face
00157             forAll (e, edgeI)
00158             {
00159                 if (!usedEdges[edgeI])
00160                 {
00161                     // Get the other vertex
00162                     label otherVertex =
00163                         e[edgeI].otherVertex(masterFace[pointI]);
00164 
00165                     if (otherVertex != -1)
00166                     {
00167                         // Found an edge coming from this vertex.
00168                         // Check all vertices of the slave to find out
00169                         // if it exists.
00170                         forAll (slaveFace, slavePointI)
00171                         {
00172                             if (slaveFace[slavePointI] == otherVertex)
00173                             {
00174                                 usedEdges[edgeI] = true;
00175                                 oppFace[pointI] = otherVertex;
00176 
00177                                 break;
00178                             }
00179                         }
00180                     }
00181                 }
00182             }
00183         }
00184 
00185         return oppFace;
00186     }
00187 }
00188 
00189 
00190 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd