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

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