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

PatchToolsCheck.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 "PatchTools.H"
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 template
00032 <
00033     class Face,
00034     template<class> class FaceList,
00035     class PointField,
00036     class PointType
00037 >
00038 
00039 bool
00040 Foam::PatchTools::checkOrientation
00041 (
00042     const PrimitivePatch<Face, FaceList, PointField, PointType>& p,
00043     const bool report,
00044     labelHashSet* setPtr
00045 )
00046 {
00047     bool foundError = false;
00048 
00049     // Check edge normals, face normals, point normals.
00050     forAll(p.faceEdges(), faceI)
00051     {
00052         const labelList& edgeLabels = p.faceEdges()[faceI];
00053         bool valid = true;
00054 
00055         if (edgeLabels.size() < 3)
00056         {
00057             if (report)
00058             {
00059                 Info<< "Face[" << faceI << "] " << p[faceI]
00060                     << " has fewer than 3 edges. Edges: " << edgeLabels
00061                     << endl;
00062             }
00063             valid = false;
00064         }
00065         else
00066         {
00067             forAll(edgeLabels, i)
00068             {
00069                 if (edgeLabels[i] < 0 || edgeLabels[i] >= p.nEdges())
00070                 {
00071                     if (report)
00072                     {
00073                         Info<< "edge number " << edgeLabels[i]
00074                             << " on face " << faceI
00075                             << " out-of-range\n"
00076                             << "This usually means the input surface has "
00077                             << "edges with more than 2 faces connected."
00078                             << endl;
00079                     }
00080                     valid = false;
00081                 }
00082             }
00083         }
00084 
00085         if (!valid)
00086         {
00087             foundError = true;
00088             continue;
00089         }
00090 
00091 
00092         //
00093         //- Compute normal from 3 points, use the first as the origin
00094         // minor warpage should not be a problem
00095         const Face& f = p[faceI];
00096         const point& p0 = p.points()[f[0]];
00097         const point& p1 = p.points()[f[1]];
00098         const point& p2 = p.points()[f[f.size()-1]];
00099 
00100         const vector pointNormal((p1 - p0) ^ (p2 - p0));
00101         if ((pointNormal & p.faceNormals()[faceI]) < 0)
00102         {
00103             foundError = false;
00104 
00105             if (report)
00106             {
00107                 Info
00108                     << "Normal calculated from points inconsistent"
00109                     << " with faceNormal" << nl
00110                     << "face: " << f << nl
00111                     << "points: " << p0 << ' ' << p1 << ' ' << p2 << nl
00112                     << "pointNormal:" << pointNormal << nl
00113                     << "faceNormal:" << p.faceNormals()[faceI] << endl;
00114             }
00115         }
00116     }
00117 
00118 
00119     forAll(p.edges(), edgeI)
00120     {
00121         const edge& e = p.edges()[edgeI];
00122         const labelList& neighbouringFaces = p.edgeFaces()[edgeI];
00123 
00124         if (neighbouringFaces.size() == 2)
00125         {
00126             // we use localFaces() since edges() are LOCAL
00127             // these are both already available
00128             const Face& faceA = p.localFaces()[neighbouringFaces[0]];
00129             const Face& faceB = p.localFaces()[neighbouringFaces[1]];
00130 
00131             // If the faces are correctly oriented, the edges must go in
00132             // different directions on connected faces.
00133             if (faceA.edgeDirection(e) == faceB.edgeDirection(e))
00134             {
00135                 if (report)
00136                 {
00137                     Info<< "face orientation incorrect." << nl
00138                         << "localEdge[" << edgeI << "] " << e
00139                         << " between faces:" << nl
00140                         << "  face[" << neighbouringFaces[0] << "] "
00141                         << p[neighbouringFaces[0]]
00142                         << "   localFace: " << faceA
00143                         << nl
00144                         << "  face[" << neighbouringFaces[1] << "] "
00145                         << p[neighbouringFaces[1]]
00146                         << "   localFace: " << faceB
00147                         << endl;
00148                 }
00149                 if (setPtr)
00150                 {
00151                     setPtr->insert(edgeI);
00152                 }
00153 
00154                 foundError = true;
00155             }
00156         }
00157         else if (neighbouringFaces.size() != 1)
00158         {
00159             if (report)
00160             {
00161                 Info
00162                     << "Wrong number of edge neighbours." << nl
00163                     << "edge[" << edgeI << "] " << e
00164                     << " with points:" << p.localPoints()[e.start()]
00165                     << ' ' << p.localPoints()[e.end()]
00166                     << " has neighbouringFaces:" << neighbouringFaces << endl;
00167             }
00168 
00169             if (setPtr)
00170             {
00171                 setPtr->insert(edgeI);
00172             }
00173 
00174             foundError = true;
00175         }
00176     }
00177 
00178     return foundError;
00179 }
00180 
00181 
00182 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd