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

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