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

PrimitivePatchCheck.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 Description
00026     Checks topology of the patch.
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "PrimitivePatch.H"
00031 #include "Map.H"
00032 #include "ListOps.H"
00033 
00034 
00035 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00036 
00037 template
00038 <
00039     class Face,
00040     template<class> class FaceList,
00041     class PointField,
00042     class PointType
00043 >
00044 
00045 void
00046 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00047 visitPointRegion
00048 (
00049     const label pointI,
00050     const labelList& pFaces,
00051     const label startFaceI,
00052     const label startEdgeI,
00053     boolList& pFacesHad
00054 ) const
00055 {
00056     label index = findIndex(pFaces, startFaceI);
00057 
00058     if (!pFacesHad[index])
00059     {
00060         // Mark face as been visited.
00061         pFacesHad[index] = true;
00062 
00063         // Step to next edge on face which is still using pointI
00064         const labelList& fEdges = faceEdges()[startFaceI];
00065 
00066         label nextEdgeI = -1;
00067 
00068         forAll(fEdges, i)
00069         {
00070             label edgeI = fEdges[i];
00071 
00072             const edge& e = edges()[edgeI];
00073 
00074             if (edgeI != startEdgeI && (e[0] == pointI || e[1] == pointI))
00075             {
00076                 nextEdgeI = edgeI;
00077 
00078                 break;
00079             }
00080         }
00081 
00082         if (nextEdgeI == -1)
00083         {
00084             FatalErrorIn
00085             (
00086                 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00087                 "visitPointRegion"
00088             )   << "Problem: cannot find edge out of " << fEdges
00089                 << "on face " << startFaceI << " that uses point " << pointI
00090                 << " and is not edge " << startEdgeI << abort(FatalError);
00091         }
00092 
00093         // Walk to next face(s) across edge.
00094         const labelList& eFaces = edgeFaces()[nextEdgeI];
00095 
00096         forAll(eFaces, i)
00097         {
00098             if (eFaces[i] != startFaceI)
00099             {
00100                 visitPointRegion
00101                 (
00102                     pointI,
00103                     pFaces,
00104                     eFaces[i],
00105                     nextEdgeI,
00106                     pFacesHad
00107                 );
00108             }
00109         }
00110     }
00111 }
00112 
00113 
00114 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00115 
00116 template
00117 <
00118     class Face,
00119     template<class> class FaceList,
00120     class PointField,
00121     class PointType
00122 >
00123 
00124 typename Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::surfaceTopo
00125 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00126 surfaceType() const
00127 {
00128     if (debug)
00129     {
00130         Info<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00131                "surfaceType() : "
00132                "calculating patch topology"
00133             << endl;
00134     }
00135 
00136     const labelListList& edgeFcs = edgeFaces();
00137 
00138     surfaceTopo pType = MANIFOLD;
00139 
00140     forAll(edgeFcs, edgeI)
00141     {
00142         label nNbrs = edgeFcs[edgeI].size();
00143 
00144         if (nNbrs < 1 || nNbrs > 2)
00145         {
00146             pType = ILLEGAL;
00147 
00148             // Can exit now. Surface is illegal.
00149             return pType;
00150         }
00151         else if (nNbrs == 1)
00152         {
00153             // Surface might be open or illegal so keep looping.
00154             pType = OPEN;
00155         }
00156     }
00157 
00158     if (debug)
00159     {
00160         Info<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00161                "surfaceType() : "
00162                "finished calculating patch topology"
00163             << endl;
00164     }
00165 
00166     return pType;
00167 }
00168 
00169 
00170 template
00171 <
00172     class Face,
00173     template<class> class FaceList,
00174     class PointField,
00175     class PointType
00176 >
00177 
00178 bool
00179 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00180 checkTopology
00181 (
00182     const bool report,
00183     labelHashSet* setPtr
00184 ) const
00185 {
00186     if (debug)
00187     {
00188         Info<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00189                "checkTopology(const bool, labelHashSet&) : "
00190                "checking patch topology"
00191             << endl;
00192     }
00193 
00194     // Check edgeFaces
00195 
00196     const labelListList& edgeFcs = edgeFaces();
00197 
00198     surfaceTopo surfaceType = MANIFOLD;
00199 
00200     forAll(edgeFcs, edgeI)
00201     {
00202         label nNbrs = edgeFcs[edgeI].size();
00203 
00204         if (nNbrs < 1 || nNbrs > 2)
00205         {
00206             surfaceType = ILLEGAL;
00207 
00208             if (report)
00209             {
00210                 Info<< "Edge " << edgeI << " with vertices:" << edges()[edgeI]
00211                     << " has " << nNbrs << " face neighbours"
00212                     << endl;
00213             }
00214 
00215             if (setPtr)
00216             {
00217                 const edge& e = edges()[edgeI];
00218 
00219                 setPtr->insert(meshPoints()[e.start()]);
00220                 setPtr->insert(meshPoints()[e.end()]);
00221             }
00222         }
00223         else if (nNbrs == 1)
00224         {
00225             surfaceType = OPEN;
00226         }
00227     }
00228 
00229     if (debug)
00230     {
00231         Info<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00232                "checkTopology(const bool, labelHashSet&) : "
00233                "finished checking patch topology"
00234             << endl;
00235     }
00236 
00237     return surfaceType == ILLEGAL;
00238 }
00239 
00240 
00241 template
00242 <
00243     class Face,
00244     template<class> class FaceList,
00245     class PointField,
00246     class PointType
00247 >
00248 
00249 bool
00250 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00251 checkPointManifold
00252 (
00253     const bool report,
00254     labelHashSet* setPtr
00255 ) const
00256 {
00257     const labelListList& pf = pointFaces();
00258     const labelListList& pe = pointEdges();
00259     const labelListList& ef = edgeFaces();
00260     const labelList& mp = meshPoints();
00261 
00262     bool foundError = false;
00263 
00264     forAll(pf, pointI)
00265     {
00266         const labelList& pFaces = pf[pointI];
00267 
00268         // Visited faces (as indices into pFaces)
00269         boolList pFacesHad(pFaces.size(), false);
00270 
00271         // Starting edge
00272         const labelList& pEdges = pe[pointI];
00273         label startEdgeI = pEdges[0];
00274 
00275         const labelList& eFaces = ef[startEdgeI];
00276 
00277         forAll(eFaces, i)
00278         {
00279             // Visit all faces using pointI, starting from eFaces[i] and
00280             // startEdgeI. Mark off all faces visited in pFacesHad.
00281             this->visitPointRegion
00282             (
00283                 pointI,
00284                 pFaces,
00285                 eFaces[i],  // starting face for walk
00286                 startEdgeI, // starting edge for walk
00287                 pFacesHad
00288             );
00289         }
00290 
00291         // After this all faces using pointI should have been visited and
00292         // marked off in pFacesHad.
00293 
00294         label unset = findIndex(pFacesHad, false);
00295 
00296         if (unset != -1)
00297         {
00298             foundError = true;
00299 
00300             label meshPointI = mp[pointI];
00301 
00302             if (setPtr)
00303             {
00304                 setPtr->insert(meshPointI);
00305             }
00306 
00307             if (report)
00308             {
00309                 Info<< "Point " << meshPointI
00310                     << " uses faces which are not connected through an edge"
00311                     << nl
00312                     << "This means that the surface formed by this patched"
00313                     << " is multiply connected at this point" << nl
00314                     << "Connected (patch) faces:" << nl;
00315 
00316                 forAll(pFacesHad, i)
00317                 {
00318                     if (pFacesHad[i])
00319                     {
00320                         Info<< "    " << pFaces[i] << endl;
00321                     }
00322                 }
00323 
00324                 Info<< nl << "Unconnected (patch) faces:" << nl;
00325                 forAll(pFacesHad, i)
00326                 {
00327                     if (!pFacesHad[i])
00328                     {
00329                         Info<< "    " << pFaces[i] << endl;
00330                     }
00331                 }
00332             }
00333         }
00334     }
00335 
00336     return foundError;
00337 }
00338 
00339 
00340 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd