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

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