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

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