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

tetMatcher.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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "tetMatcher.H"
00028 #include "cellMatcher.H"
00029 #include "primitiveMesh.H"
00030 #include "primitiveMesh.H"
00031 #include "cellModeller.H"
00032 
00033 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00034 
00035 const Foam::label Foam::tetMatcher::vertPerCell = 4;
00036 const Foam::label Foam::tetMatcher::facePerCell = 4;
00037 const Foam::label Foam::tetMatcher::maxVertPerFace = 3;
00038 
00039 
00040 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00041 
00042 // Construct null
00043 Foam::tetMatcher::tetMatcher()
00044 :
00045     cellMatcher
00046     (
00047         vertPerCell,
00048         facePerCell,
00049         maxVertPerFace,
00050         "tet"
00051     )
00052 {}
00053 
00054 
00055 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00056 
00057 Foam::tetMatcher::~tetMatcher()
00058 {}
00059 
00060 
00061 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00062 
00063 
00064 bool Foam::tetMatcher::matchShape
00065 (
00066     const bool checkOnly,
00067     const faceList& faces,
00068     const labelList& owner,
00069     const label cellI,
00070     const labelList& myFaces
00071 )
00072 {
00073     if (!faceSizeMatch(faces, myFaces))
00074     {
00075         return false;
00076     }
00077 
00078     // Tet for sure now
00079     if (checkOnly)
00080     {
00081         return true;
00082     }
00083 
00084     // Calculate localFaces_ and mapping pointMap_, faceMap_
00085     label numVert = calcLocalFaces(faces, myFaces);
00086 
00087     if (numVert != vertPerCell)
00088     {
00089         return false;
00090     }
00091 
00092     // Set up 'edge' to face mapping.
00093     calcEdgeAddressing(numVert);
00094 
00095     // Set up point on face to index-in-face mapping
00096     calcPointFaceIndex();
00097 
00098     // Storage for maps -vertex to mesh and -face to mesh
00099     vertLabels_.setSize(vertPerCell);
00100     faceLabels_.setSize(facePerCell);
00101 
00102     //
00103     // Try bottom face (face 3)
00104     //
00105 
00106     label face3I = 0;
00107     const face& face3 = localFaces_[face3I];
00108     label face3vert0 = 0;
00109 
00110     //
00111     // Try to follow prespecified path on faces of cell,
00112     // starting at face3vert0
00113     //
00114 
00115     vertLabels_[0] = pointMap_[face3[face3vert0]];
00116     faceLabels_[3] = faceMap_[face3I];
00117 
00118     // Walk face 3 from vertex 0 to 1
00119     label face3vert1 =
00120         nextVert
00121         (
00122             face3vert0,
00123             faceSize_[face3I],
00124             !(owner[faceMap_[face3I]] == cellI)
00125         );
00126     vertLabels_[1] = pointMap_[face3[face3vert1]];
00127 
00128     // Walk face 3 from vertex 1 to 2
00129     label face3vert2 =
00130         nextVert
00131         (
00132             face3vert1,
00133             faceSize_[face3I],
00134             !(owner[faceMap_[face3I]] == cellI)
00135         );
00136     vertLabels_[2] = pointMap_[face3[face3vert2]];
00137 
00138     // Jump edge from face3 to face2
00139     label face2I =
00140         otherFace
00141         (
00142             numVert,
00143             face3[face3vert0],
00144             face3[face3vert1],
00145             face3I
00146         );
00147     faceLabels_[2] = faceMap_[face2I];
00148 
00149     // Jump edge from face3 to face0
00150     label face0I =
00151         otherFace
00152         (
00153             numVert,
00154             face3[face3vert1],
00155             face3[face3vert2],
00156             face3I
00157         );
00158     faceLabels_[0] = faceMap_[face0I];
00159 
00160     // Jump edge from face3 to face1
00161     label face1I =
00162         otherFace
00163         (
00164             numVert,
00165             face3[face3vert2],
00166             face3[face3vert0],
00167             face3I
00168         );
00169     faceLabels_[1] = faceMap_[face1I];
00170     const face& face1 = localFaces_[face1I];
00171 
00172     // Get index of vert0 in face 1
00173     label face1vert0 = pointFaceIndex_[face3[face3vert0]][face1I];
00174 
00175     // Walk face 1 from vertex 0 to 3
00176     label face1vert3 =
00177         nextVert
00178         (
00179             face1vert0,
00180             faceSize_[face1I],
00181             (owner[faceMap_[face1I]] == cellI)
00182         );
00183     vertLabels_[3] = pointMap_[face1[face1vert3]];
00184 
00185     return true;
00186 }
00187 
00188 
00189 Foam::label Foam::tetMatcher::faceHashValue() const
00190 {
00191     return 4*3;
00192 }
00193 
00194 
00195 bool Foam::tetMatcher::faceSizeMatch
00196 (
00197     const faceList& faces,
00198     const labelList& myFaces
00199 ) const
00200 {
00201     if (myFaces.size() != 4)
00202     {
00203         return false;
00204     }
00205 
00206     forAll(myFaces, myFaceI)
00207     {
00208         label size = faces[myFaces[myFaceI]].size();
00209 
00210         if (size != 3)
00211         {
00212             return false;
00213         }
00214     }
00215     return true;
00216 }
00217 
00218 
00219 bool Foam::tetMatcher::isA(const primitiveMesh& mesh, const label cellI)
00220 {
00221     return matchShape
00222     (
00223         true,
00224         mesh.faces(),
00225         mesh.faceOwner(),
00226         cellI,
00227         mesh.cells()[cellI]
00228     );
00229 }
00230 
00231 
00232 bool Foam::tetMatcher::isA(const faceList& faces)
00233 {
00234     // Do as if mesh with one cell only
00235     return matchShape
00236     (
00237         true,
00238         faces,                      // all faces in mesh
00239         labelList(faces.size(), 0), // cell 0 is owner of all faces
00240         0,                          // cell label
00241         makeIdentity(faces.size())  // faces of cell 0
00242     );
00243 }
00244 
00245 
00246 bool Foam::tetMatcher::matches
00247 (
00248     const primitiveMesh& mesh,
00249     const label cellI,
00250     cellShape& shape
00251 )
00252 {
00253     if
00254     (
00255         matchShape
00256         (
00257             false,
00258             mesh.faces(),
00259             mesh.faceOwner(),
00260             cellI,
00261             mesh.cells()[cellI]
00262         )
00263     )
00264     {
00265         shape = cellShape(model(), vertLabels());
00266 
00267         return true;
00268     }
00269     else
00270     {
00271         return false;
00272     }
00273 }
00274 
00275 
00276 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd