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

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