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

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