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

tetWedgeMatcher.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 "tetWedgeMatcher.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::tetWedgeMatcher::vertPerCell = 5;
00036 const Foam::label Foam::tetWedgeMatcher::facePerCell = 4;
00037 const Foam::label Foam::tetWedgeMatcher::maxVertPerFace = 4;
00038 
00039 
00040 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00041 
00042 // Construct null
00043 Foam::tetWedgeMatcher::tetWedgeMatcher()
00044 :
00045     cellMatcher
00046     (
00047         vertPerCell,
00048         facePerCell,
00049         maxVertPerFace,
00050        "tetWedge"
00051     )
00052 {}
00053 
00054 
00055 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00056 
00057 Foam::tetWedgeMatcher::~tetWedgeMatcher()
00058 {}
00059 
00060 
00061 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00062 
00063 bool Foam::tetWedgeMatcher::matchShape
00064 (
00065     const bool checkOnly,
00066     const faceList& faces,
00067     const labelList& owner,
00068     const label cellI,
00069     const labelList& myFaces
00070 )
00071 {
00072     if (!faceSizeMatch(faces, myFaces))
00073     {
00074         return false;
00075     }
00076 
00077     // Is tetWedge for sure now. No other shape has two tri, two quad
00078     if (checkOnly)
00079     {
00080         return true;
00081     }
00082 
00083     // Calculate localFaces_ and mapping pointMap_, faceMap_
00084     label numVert = calcLocalFaces(faces, myFaces);
00085 
00086     if (numVert != vertPerCell)
00087     {
00088         return false;
00089     }
00090 
00091     // Set up 'edge' to face mapping.
00092     calcEdgeAddressing(numVert);
00093 
00094     // Set up point on face to index-in-face mapping
00095     calcPointFaceIndex();
00096 
00097     // Storage for maps -vertex to mesh and -face to mesh
00098     vertLabels_.setSize(vertPerCell);
00099     faceLabels_.setSize(facePerCell);
00100 
00101     //
00102     // Try first triangular face. Rotate in all directions.
00103     // Walk path to other triangular face.
00104     //
00105 
00106     label face0I = -1;
00107     forAll(faceSize_, faceI)
00108     {
00109         if (faceSize_[faceI] == 3)
00110         {
00111             face0I = faceI;
00112             break;
00113         }
00114     }
00115 
00116     const face& face0 = localFaces_[face0I];
00117 
00118     // Try all rotations of this face
00119     for(label face0vert0 = 0; face0vert0 < faceSize_[face0I]; face0vert0++)
00120     {
00121         //
00122         // Try to follow prespecified path on faces of cell,
00123         // starting at face0vert0
00124         //
00125 
00126         vertLabels_[0] = pointMap_[face0[face0vert0]];
00127         faceLabels_[0] = faceMap_[face0I];
00128 
00129         // Walk face 0 from vertex 0 to 1
00130         label face0vert1 =
00131             nextVert
00132             (
00133                 face0vert0,
00134                 faceSize_[face0I],
00135                 !(owner[faceMap_[face0I]] == cellI)
00136             );
00137         vertLabels_[1] = pointMap_[face0[face0vert1]];
00138 
00139         // Jump edge from face0 to face1 (the other triangular face)
00140         label face1I =
00141             otherFace
00142             (
00143                 numVert,
00144                 face0[face0vert0],
00145                 face0[face0vert1],
00146                 face0I
00147             );
00148 
00149         if (faceSize_[face1I] != 3)
00150         {
00151             continue;
00152         }
00153         faceLabels_[1] = faceMap_[face1I];
00154 
00155 
00156         // Now correctly oriented tet-wedge for sure.
00157 
00158         // Walk face 0 from vertex 1 to 2
00159         label face0vert2 =
00160             nextVert
00161             (
00162                 face0vert1,
00163                 faceSize_[face0I],
00164                 !(owner[faceMap_[face0I]] == cellI)
00165             );
00166         vertLabels_[2] = pointMap_[face0[face0vert2]];
00167 
00168         // Jump edge from face0 to face3
00169         label face3I =
00170             otherFace
00171             (
00172                 numVert,
00173                 face0[face0vert1],
00174                 face0[face0vert2],
00175                 face0I
00176             );
00177         faceLabels_[3] = faceMap_[face3I];
00178 
00179         // Jump edge from face0 to face2
00180         label face2I =
00181             otherFace
00182             (
00183                 numVert,
00184                 face0[face0vert2],
00185                 face0[face0vert0],
00186                 face0I
00187             );
00188         faceLabels_[2] = faceMap_[face2I];
00189 
00190         // Get index of vertex 2 in face3
00191         label face3vert2 = pointFaceIndex_[face0[face0vert2]][face3I];
00192 
00193         // Walk face 3 from vertex 2 to 4
00194         label face3vert4 =
00195             nextVert
00196             (
00197                 face3vert2,
00198                 faceSize_[face3I],
00199                 (owner[faceMap_[face3I]] == cellI)
00200             );
00201 
00202         const face& face3 = localFaces_[face3I];
00203 
00204         vertLabels_[4] = pointMap_[face3[face3vert4]];
00205 
00206         // Walk face 3 from vertex 4 to 3
00207         label face3vert3 =
00208             nextVert
00209             (
00210                 face3vert4,
00211                 faceSize_[face3I],
00212                 (owner[faceMap_[face3I]] == cellI)
00213             );
00214         vertLabels_[3] = pointMap_[face3[face3vert3]];
00215 
00216         return true;
00217     }
00218 
00219     // Tried all triangular faces, in all rotations but no match found
00220     return false;
00221 }
00222 
00223 
00224 Foam::label Foam::tetWedgeMatcher::faceHashValue() const
00225 {
00226     return 2*3 + 2*4;
00227 }
00228 
00229 
00230 bool Foam::tetWedgeMatcher::faceSizeMatch
00231 (
00232     const faceList& faces,
00233     const labelList& myFaces
00234 ) const
00235 {
00236     if (myFaces.size() != 4)
00237     {
00238         return false;
00239     }
00240 
00241     label nTris = 0;
00242     label nQuads = 0;
00243     
00244     forAll(myFaces, myFaceI)
00245     {
00246         label size = faces[myFaces[myFaceI]].size();
00247 
00248         if (size == 3)
00249         {
00250             nTris++;
00251         }
00252         else if (size == 4)
00253         {
00254             nQuads++;
00255         }
00256         else
00257         {
00258             return false;
00259         }
00260     }
00261     if ((nTris == 2) && (nQuads == 2))
00262     {
00263         return true;
00264     }
00265     else
00266     {
00267         return false;
00268     }
00269 }
00270 
00271 
00272 bool Foam::tetWedgeMatcher::isA(const primitiveMesh& mesh, const label cellI)
00273 {
00274     return matchShape
00275     (
00276         true,
00277         mesh.faces(),
00278         mesh.faceOwner(),
00279         cellI,
00280         mesh.cells()[cellI]
00281     );
00282 }
00283 
00284 
00285 bool Foam::tetWedgeMatcher::isA(const faceList& faces)
00286 {
00287     // Do as if mesh with one cell only
00288     return matchShape
00289     (
00290         true,
00291         faces,                      // all faces in mesh
00292         labelList(faces.size(), 0), // cell 0 is owner of all faces
00293         0,                          // cell label
00294         makeIdentity(faces.size())  // faces of cell 0
00295     );
00296 }
00297 
00298 
00299 bool Foam::tetWedgeMatcher::matches
00300 (
00301     const primitiveMesh& mesh,
00302     const label cellI,
00303     cellShape& shape
00304 )
00305 {
00306     if
00307     (
00308         matchShape
00309         (
00310             false,
00311             mesh.faces(),
00312             mesh.faceOwner(),
00313             cellI,
00314             mesh.cells()[cellI]
00315         )
00316     )
00317     {
00318         shape = cellShape(model(), vertLabels());
00319 
00320         return true;
00321     }
00322     else
00323     {
00324         return false;
00325     }
00326 }
00327 
00328 
00329 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd