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

wedgeMatcher.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 "wedgeMatcher.H"
00027 #include <OpenFOAM/primitiveMesh.H>
00028 
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 const Foam::label Foam::wedgeMatcher::vertPerCell = 7;
00033 const Foam::label Foam::wedgeMatcher::facePerCell = 6;
00034 const Foam::label Foam::wedgeMatcher::maxVertPerFace = 4;
00035 
00036 
00037 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00038 
00039 // Construct null
00040 Foam::wedgeMatcher::wedgeMatcher()
00041 :
00042     cellMatcher
00043     (
00044         vertPerCell,
00045         facePerCell,
00046         maxVertPerFace,
00047         "wedge"
00048     )
00049 {}
00050 
00051 
00052 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00053 
00054 Foam::wedgeMatcher::~wedgeMatcher()
00055 {}
00056 
00057 
00058 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00059 
00060 bool Foam::wedgeMatcher::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     // Calculate localFaces_ and mapping pointMap_, faceMap_
00075     label numVert = calcLocalFaces(faces, myFaces);
00076 
00077     if (numVert != vertPerCell)
00078     {
00079         return false;
00080     }
00081 
00082     // Set up 'edge' to face mapping.
00083     calcEdgeAddressing(numVert);
00084 
00085     // Set up point on face to index-in-face mapping
00086     calcPointFaceIndex();
00087 
00088     // Storage for maps -vertex to mesh and -face to mesh
00089     vertLabels_.setSize(vertPerCell);
00090     faceLabels_.setSize(facePerCell);
00091 
00092     //
00093     // Try first triangular face. Rotate in all directions.
00094     // Walk path to other triangular face.
00095     //
00096 
00097     label face0I = -1;
00098     forAll(faceSize_, faceI)
00099     {
00100         if (faceSize_[faceI] == 3)
00101         {
00102             face0I = faceI;
00103             break;
00104         }
00105     }
00106 
00107     const face& face0 = localFaces_[face0I];
00108 
00109     // Try all rotations of this face
00110     for(label face0vert0 = 0; face0vert0 < faceSize_[face0I]; face0vert0++)
00111     {
00112         //
00113         // Try to follow prespecified path on faces of cell,
00114         // starting at face0vert0
00115         //
00116 
00117         vertLabels_[0] = pointMap_[face0[face0vert0]];
00118         faceLabels_[0] = faceMap_[face0I];
00119         //Info<< endl << "Wedge vertex 0: vertex " <<  face0[face0vert0]
00120         //    << " at position " << face0vert0 << " in face " << face0
00121         //    << endl;
00122 
00123         // Walk face 0 from vertex 0 to 1
00124         label face0vert1 =
00125             nextVert
00126             (
00127                 face0vert0,
00128                 faceSize_[face0I],
00129                 !(owner[faceMap_[face0I]] == cellI)
00130             );
00131         vertLabels_[1] = pointMap_[face0[face0vert1]];
00132         //Info<< "Wedge vertex 1: vertex " <<  face0[face0vert1]
00133         //    << " at position " << face0vert1 << " in face " << face0
00134         //    << endl;
00135 
00136         // Jump edge from face0 to face4
00137         label face4I =
00138             otherFace
00139             (
00140                 numVert,
00141                 face0[face0vert0],
00142                 face0[face0vert1],
00143                 face0I
00144             );
00145         const face& face4 = localFaces_[face4I];
00146         //Info<< "Stepped to wedge face 4 " << face4
00147         //    << " across edge " << face0[face0vert0] << " "
00148         //    << face0[face0vert1]
00149         //    << endl;
00150 
00151         if (faceSize_[face4I] != 4)
00152         {
00153             //Info<< "Cannot be Wedge Face 4 since size="
00154             //    << faceSize_[face4I] << endl;
00155             continue;
00156         }
00157 
00158         // Is wedge for sure now
00159         if (checkOnly)
00160         {
00161             return true;
00162         }
00163 
00164         faceLabels_[4] = faceMap_[face4I];
00165 
00166         // Get index of vertex 0 in face4
00167         label face4vert0 = pointFaceIndex_[face0[face0vert0]][face4I];
00168 
00169         //Info<< "Wedge vertex 0 also: vertex " <<  face4[face4vert0]
00170         //    << " at position " << face4vert0 << " in face " << face4
00171         //    << endl;
00172 
00173         // Walk face 4 from vertex 4 to 3
00174         label face4vert3 =
00175             nextVert
00176             (
00177                 face4vert0,
00178                 faceSize_[face4I],
00179                 !(owner[faceMap_[face4I]] == cellI)
00180             );
00181         vertLabels_[3] = pointMap_[face4[face4vert3]];
00182         //Info<< "Wedge vertex 3: vertex " <<  face4[face4vert3]
00183         //    << " at position " << face4vert3 << " in face " << face4
00184         //    << endl;
00185 
00186 
00187         // Jump edge from face4 to face2
00188         label face2I =
00189             otherFace
00190             (
00191                 numVert,
00192                 face4[face4vert0],
00193                 face4[face4vert3],
00194                 face4I
00195             );
00196         const face& face2 = localFaces_[face2I];
00197         //Info<< "Stepped to wedge face 2 " << face2
00198         //    << " across edge " << face4[face4vert0] << " "
00199         //    << face4[face4vert3]
00200         //    << endl;
00201 
00202         if (faceSize_[face2I] != 3)
00203         {
00204             //Info<< "Cannot be Wedge Face 2 since size="
00205             //    << faceSize_[face2I] << endl;
00206             continue;
00207         }
00208         faceLabels_[2] = faceMap_[face2I];
00209 
00210         // Is wedge for sure now
00211         //Info<< "** WEDGE **" << endl;
00212 
00213 
00214         //
00215         // Walk to other faces and vertices and assign mapping.
00216         //
00217 
00218         // Vertex 6
00219         label face2vert3 = pointFaceIndex_[face4[face4vert3]][face2I];
00220 
00221         // Walk face 2 from vertex 3 to 6
00222         label face2vert6 =
00223             nextVert
00224             (
00225                 face2vert3,
00226                 faceSize_[face2I],
00227                 (owner[faceMap_[face2I]] == cellI)
00228             );
00229         vertLabels_[6] = pointMap_[face2[face2vert6]];
00230 
00231         // Jump edge from face2 to face1
00232         label face1I =
00233             otherFace
00234             (
00235                 numVert,
00236                 face2[face2vert3],
00237                 face2[face2vert6],
00238                 face2I
00239             );
00240         faceLabels_[1] = faceMap_[face1I];
00241         const face& face1 = localFaces_[face1I];
00242         //Info<< "Stepped to wedge face 1 " << face1
00243         //    << " across edge " << face2[face2vert3] << " "
00244         //    << face2[face2vert6]
00245         //    << endl;
00246 
00247         label face1vert6 = pointFaceIndex_[face2[face2vert6]][face1I];
00248 
00249         // Walk face 1 from vertex 6 to 5
00250         label face1vert5 =
00251             nextVert
00252             (
00253                 face1vert6,
00254                 faceSize_[face1I],
00255                 !(owner[faceMap_[face1I]] == cellI)
00256             );
00257         vertLabels_[5] = pointMap_[face1[face1vert5]];
00258 
00259         // Walk face 1 from vertex 5 to 4
00260         label face1vert4 =
00261             nextVert
00262             (
00263                 face1vert5,
00264                 faceSize_[face1I],
00265                 !(owner[faceMap_[face1I]] == cellI)
00266             );
00267         vertLabels_[4] = pointMap_[face1[face1vert4]];
00268 
00269         // Walk face 0 from vertex 1 to 2
00270         label face0vert2 =
00271             nextVert
00272             (
00273                 face0vert1,
00274                 faceSize_[face0I],
00275                 !(owner[faceMap_[face0I]] == cellI)
00276             );
00277         vertLabels_[2] = pointMap_[face0[face0vert2]];
00278         //Info<< "Wedge vertex 2: vertex " <<  face0[face0vert2]
00279         //    << " at position " << face0vert2 << " in face " << face0
00280         //    << endl;
00281 
00282         // Jump edge from face0 to face3
00283         label face3I =
00284             otherFace
00285             (
00286                 numVert,
00287                 face0[face0vert1],
00288                 face0[face0vert2],
00289                 face0I
00290             );
00291         faceLabels_[3] = faceMap_[face3I];
00292         //const face& face3 = localFaces_[face3I];
00293         //Info<< "Stepped to wedge face 3 " << face3
00294         //    << " across edge " << face0[face0vert1] << " "
00295         //    << face0[face0vert2]
00296         //    << endl;
00297 
00298 
00299         // Jump edge from face0 to face5
00300         label face5I =
00301             otherFace
00302             (
00303                 numVert,
00304                 face0[face0vert2],
00305                 face0[face0vert0],
00306                 face0I
00307             );
00308         faceLabels_[5] = faceMap_[face5I];
00309         //const face& face5 = localFaces_[face5I];
00310         //Info<< "Stepped to wedge face 5 " << face5
00311         //    << " across edge " << face0[face0vert2] << " "
00312         //    << face0[face0vert0]
00313         //    << endl;
00314 
00315         return true;
00316     }
00317 
00318     // Tried all triangular faces, in all rotations but no match found
00319     return false;
00320 }
00321 
00322 
00323 Foam::label Foam::wedgeMatcher::faceHashValue() const
00324 {
00325     return 2*3 + 4*4;
00326 }
00327 
00328 
00329 bool Foam::wedgeMatcher::faceSizeMatch
00330 (
00331     const faceList& faces,
00332     const labelList& myFaces
00333 ) const
00334 {
00335     if (myFaces.size() != 6)
00336     {
00337         return false;
00338     }
00339 
00340     label nTris = 0;
00341     label nQuads = 0;
00342     
00343     forAll(myFaces, myFaceI)
00344     {
00345         label size = faces[myFaces[myFaceI]].size();
00346 
00347         if (size == 3)
00348         {
00349             nTris++;
00350         }
00351         else if (size == 4)
00352         {
00353             nQuads++;
00354         }
00355         else
00356         {
00357             return false;
00358         }
00359     }
00360     if ((nTris == 2) && (nQuads == 4))
00361     {
00362         return true;
00363     }
00364     else
00365     {
00366         return false;
00367     }
00368 }
00369 
00370 
00371 bool Foam::wedgeMatcher::isA(const primitiveMesh& mesh, const label cellI)
00372 {
00373     return matchShape
00374     (
00375         true,
00376         mesh.faces(),
00377         mesh.faceOwner(),
00378         cellI,
00379         mesh.cells()[cellI]
00380     );
00381 }
00382 
00383 
00384 bool Foam::wedgeMatcher::isA(const faceList& faces)
00385 {
00386     // Do as if mesh with one cell only
00387     return matchShape
00388     (
00389         true,
00390         faces,                      // all faces in mesh
00391         labelList(faces.size(), 0), // cell 0 is owner of all faces
00392         0,                          // cell label
00393         makeIdentity(faces.size())  // faces of cell 0
00394     );
00395 }
00396 
00397 
00398 bool Foam::wedgeMatcher::matches
00399 (
00400     const primitiveMesh& mesh,
00401     const label cellI,
00402     cellShape& shape
00403 )
00404 {
00405     if
00406     (
00407         matchShape
00408         (
00409             false,
00410             mesh.faces(),
00411             mesh.faceOwner(),
00412             cellI,
00413             mesh.cells()[cellI]
00414         )
00415     )
00416     {
00417         shape = cellShape(model(), vertLabels());
00418 
00419         return true;
00420     }
00421     else
00422     {
00423         return false;
00424     }
00425 }
00426 
00427 
00428 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines