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

tetMatcher.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 "tetMatcher.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::tetMatcher::vertPerCell = 4;
00035 const Foam::label Foam::tetMatcher::facePerCell = 4;
00036 const Foam::label Foam::tetMatcher::maxVertPerFace = 3;
00037 
00038 
00039 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00040 
00041 // Construct null
00042 Foam::tetMatcher::tetMatcher()
00043 :
00044     cellMatcher
00045     (
00046         vertPerCell,
00047         facePerCell,
00048         maxVertPerFace,
00049         "tet"
00050     )
00051 {}
00052 
00053 
00054 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00055 
00056 Foam::tetMatcher::~tetMatcher()
00057 {}
00058 
00059 
00060 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00061 
00062 
00063 bool Foam::tetMatcher::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     // Tet for sure now
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 bottom face (face 3)
00103     //
00104 
00105     label face3I = 0;
00106     const face& face3 = localFaces_[face3I];
00107     label face3vert0 = 0;
00108 
00109     //
00110     // Try to follow prespecified path on faces of cell,
00111     // starting at face3vert0
00112     //
00113 
00114     vertLabels_[0] = pointMap_[face3[face3vert0]];
00115     faceLabels_[3] = faceMap_[face3I];
00116 
00117     // Walk face 3 from vertex 0 to 1
00118     label face3vert1 =
00119         nextVert
00120         (
00121             face3vert0,
00122             faceSize_[face3I],
00123             !(owner[faceMap_[face3I]] == cellI)
00124         );
00125     vertLabels_[1] = pointMap_[face3[face3vert1]];
00126 
00127     // Walk face 3 from vertex 1 to 2
00128     label face3vert2 =
00129         nextVert
00130         (
00131             face3vert1,
00132             faceSize_[face3I],
00133             !(owner[faceMap_[face3I]] == cellI)
00134         );
00135     vertLabels_[2] = pointMap_[face3[face3vert2]];
00136 
00137     // Jump edge from face3 to face2
00138     label face2I =
00139         otherFace
00140         (
00141             numVert,
00142             face3[face3vert0],
00143             face3[face3vert1],
00144             face3I
00145         );
00146     faceLabels_[2] = faceMap_[face2I];
00147 
00148     // Jump edge from face3 to face0
00149     label face0I =
00150         otherFace
00151         (
00152             numVert,
00153             face3[face3vert1],
00154             face3[face3vert2],
00155             face3I
00156         );
00157     faceLabels_[0] = faceMap_[face0I];
00158 
00159     // Jump edge from face3 to face1
00160     label face1I =
00161         otherFace
00162         (
00163             numVert,
00164             face3[face3vert2],
00165             face3[face3vert0],
00166             face3I
00167         );
00168     faceLabels_[1] = faceMap_[face1I];
00169     const face& face1 = localFaces_[face1I];
00170 
00171     // Get index of vert0 in face 1
00172     label face1vert0 = pointFaceIndex_[face3[face3vert0]][face1I];
00173 
00174     // Walk face 1 from vertex 0 to 3
00175     label face1vert3 =
00176         nextVert
00177         (
00178             face1vert0,
00179             faceSize_[face1I],
00180             (owner[faceMap_[face1I]] == cellI)
00181         );
00182     vertLabels_[3] = pointMap_[face1[face1vert3]];
00183 
00184     return true;
00185 }
00186 
00187 
00188 Foam::label Foam::tetMatcher::faceHashValue() const
00189 {
00190     return 4*3;
00191 }
00192 
00193 
00194 bool Foam::tetMatcher::faceSizeMatch
00195 (
00196     const faceList& faces,
00197     const labelList& myFaces
00198 ) const
00199 {
00200     if (myFaces.size() != 4)
00201     {
00202         return false;
00203     }
00204 
00205     forAll(myFaces, myFaceI)
00206     {
00207         label size = faces[myFaces[myFaceI]].size();
00208 
00209         if (size != 3)
00210         {
00211             return false;
00212         }
00213     }
00214     return true;
00215 }
00216 
00217 
00218 bool Foam::tetMatcher::isA(const primitiveMesh& mesh, const label cellI)
00219 {
00220     return matchShape
00221     (
00222         true,
00223         mesh.faces(),
00224         mesh.faceOwner(),
00225         cellI,
00226         mesh.cells()[cellI]
00227     );
00228 }
00229 
00230 
00231 bool Foam::tetMatcher::isA(const faceList& faces)
00232 {
00233     // Do as if mesh with one cell only
00234     return matchShape
00235     (
00236         true,
00237         faces,                      // all faces in mesh
00238         labelList(faces.size(), 0), // cell 0 is owner of all faces
00239         0,                          // cell label
00240         makeIdentity(faces.size())  // faces of cell 0
00241     );
00242 }
00243 
00244 
00245 bool Foam::tetMatcher::matches
00246 (
00247     const primitiveMesh& mesh,
00248     const label cellI,
00249     cellShape& shape
00250 )
00251 {
00252     if
00253     (
00254         matchShape
00255         (
00256             false,
00257             mesh.faces(),
00258             mesh.faceOwner(),
00259             cellI,
00260             mesh.cells()[cellI]
00261         )
00262     )
00263     {
00264         shape = cellShape(model(), vertLabels());
00265 
00266         return true;
00267     }
00268     else
00269     {
00270         return false;
00271     }
00272 }
00273 
00274 
00275 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines