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

checkGeometry.C

Go to the documentation of this file.
00001 #include "checkGeometry.H"
00002 #include "polyMesh.H"
00003 #include "globalMeshData.H"
00004 #include "cellSet.H"
00005 #include "faceSet.H"
00006 #include "pointSet.H"
00007 #include "EdgeMap.H"
00008 
00009 Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry)
00010 {
00011     label noFailedChecks = 0;
00012 
00013     Info<< "\nChecking geometry..." << endl;
00014 
00015     // Get a small relative length from the bounding box
00016     const boundBox& globalBb = mesh.bounds();
00017 
00018     Info<< "    Overall domain bounding box "
00019         << globalBb.min() << " " << globalBb.max() << endl;
00020 
00021 
00022     // Min length
00023     scalar minDistSqr = magSqr(1e-6 * globalBb.span());
00024 
00025     // Non-empty directions
00026     const Vector<label> validDirs = (mesh.geometricD() + Vector<label>::one)/2;
00027     Info<< "    Mesh (non-empty, non-wedge) directions " << validDirs << endl;
00028 
00029     const Vector<label> solDirs = (mesh.solutionD() + Vector<label>::one)/2;
00030     Info<< "    Mesh (non-empty) directions " << solDirs << endl;
00031 
00032     if (mesh.nGeometricD() < 3)
00033     {
00034         pointSet nonAlignedPoints(mesh, "nonAlignedEdges", mesh.nPoints()/100);
00035 
00036         if (mesh.checkEdgeAlignment(true, validDirs, &nonAlignedPoints))
00037         {
00038             noFailedChecks++;
00039             label nNonAligned = returnReduce
00040             (
00041                 nonAlignedPoints.size(),
00042                 sumOp<label>()
00043             );
00044 
00045             if (nNonAligned > 0)
00046             {
00047                 Info<< "  <<Writing " << nNonAligned
00048                     << " points on non-aligned edges to set "
00049                     << nonAlignedPoints.name() << endl;
00050                 nonAlignedPoints.write();
00051             }
00052         }
00053     }
00054 
00055     if (mesh.checkClosedBoundary(true)) noFailedChecks++;
00056 
00057     {
00058         cellSet cells(mesh, "nonClosedCells", mesh.nCells()/100+1);
00059         cellSet aspectCells(mesh, "highAspectRatioCells", mesh.nCells()/100+1);
00060         if (mesh.checkClosedCells(true, &cells, &aspectCells))
00061         {
00062             noFailedChecks++;
00063 
00064             label nNonClosed = returnReduce(cells.size(), sumOp<label>());
00065 
00066             if (nNonClosed > 0)
00067             {
00068                 Info<< "  <<Writing " << nNonClosed
00069                     << " non closed cells to set " << cells.name() << endl;
00070                 cells.write();
00071             }
00072         }
00073 
00074         label nHighAspect = returnReduce(aspectCells.size(), sumOp<label>());
00075 
00076         if (nHighAspect > 0)
00077         {
00078             Info<< "  <<Writing " << nHighAspect
00079                 << " cells with high aspect ratio to set "
00080                 << aspectCells.name() << endl;
00081             aspectCells.write();
00082         }
00083     }
00084 
00085     {
00086         faceSet faces(mesh, "zeroAreaFaces", mesh.nFaces()/100 + 1);
00087         if (mesh.checkFaceAreas(true, &faces))
00088         {
00089             noFailedChecks++;
00090 
00091             label nFaces = returnReduce(faces.size(), sumOp<label>());
00092 
00093             if (nFaces > 0)
00094             {
00095                 Info<< "  <<Writing " << nFaces
00096                     << " zero area faces to set " << faces.name() << endl;
00097                 faces.write();
00098             }
00099         }
00100     }
00101 
00102     {
00103         cellSet cells(mesh, "zeroVolumeCells", mesh.nCells()/100 + 1);
00104         if (mesh.checkCellVolumes(true, &cells))
00105         {
00106             noFailedChecks++;
00107 
00108             label nCells = returnReduce(cells.size(), sumOp<label>());
00109 
00110             if (nCells > 0)
00111             {
00112                 Info<< "  <<Writing " << nCells
00113                     << " zero volume cells to set " << cells.name() << endl;
00114                 cells.write();
00115             }
00116         }
00117     }
00118 
00119     {
00120         faceSet faces(mesh, "nonOrthoFaces", mesh.nFaces()/100 + 1);
00121         if (mesh.checkFaceOrthogonality(true, &faces))
00122         {
00123             noFailedChecks++;
00124         }
00125 
00126         label nFaces = returnReduce(faces.size(), sumOp<label>());
00127 
00128         if (nFaces > 0)
00129         {
00130             Info<< "  <<Writing " << nFaces
00131                 << " non-orthogonal faces to set " << faces.name() << endl;
00132             faces.write();
00133         }
00134     }
00135 
00136 
00137     {
00138         faceSet faces(mesh, "wrongOrientedFaces", mesh.nFaces()/100 + 1);
00139         if (mesh.checkFacePyramids(true, -SMALL, &faces))
00140         {
00141             noFailedChecks++;
00142 
00143             label nFaces = returnReduce(faces.size(), sumOp<label>());
00144 
00145             if (nFaces > 0)
00146             {
00147                 Info<< "  <<Writing " << nFaces
00148                     << " faces with incorrect orientation to set "
00149                     << faces.name() << endl;
00150                 faces.write();
00151             }
00152         }
00153     }
00154 
00155     {
00156         faceSet faces(mesh, "skewFaces", mesh.nFaces()/100 + 1);
00157         if (mesh.checkFaceSkewness(true, &faces))
00158         {
00159             noFailedChecks++;
00160 
00161             label nFaces = returnReduce(faces.size(), sumOp<label>());
00162 
00163             if (nFaces > 0)
00164             {
00165                 Info<< "  <<Writing " << nFaces
00166                     << " skew faces to set " << faces.name() << endl;
00167                 faces.write();
00168             }
00169         }
00170     }
00171 
00172     if (allGeometry)
00173     {
00174         // Note use of nPoints since don't want edge construction.
00175         pointSet points(mesh, "shortEdges", mesh.nPoints()/1000 + 1);
00176         if (mesh.checkEdgeLength(true, minDistSqr, &points))
00177         {
00178             //noFailedChecks++;
00179 
00180             label nPoints = returnReduce(points.size(), sumOp<label>());
00181 
00182             if (nPoints > 0)
00183             {
00184                 Info<< "  <<Writing " << nPoints
00185                     << " points on short edges to set " << points.name()
00186                     << endl;
00187                 points.write();
00188             }
00189         }
00190 
00191         label nEdgeClose = returnReduce(points.size(), sumOp<label>());
00192 
00193         if (mesh.checkPointNearness(false, minDistSqr, &points))
00194         {
00195             //noFailedChecks++;
00196 
00197             label nPoints = returnReduce(points.size(), sumOp<label>());
00198 
00199             if (nPoints > nEdgeClose)
00200             {
00201                 pointSet nearPoints(mesh, "nearPoints", points);
00202                 Info<< "  <<Writing " << nPoints
00203                     << " near (closer than " << Foam::sqrt(minDistSqr)
00204                     << " apart) points to set " << nearPoints.name() << endl;
00205                 nearPoints.write();
00206             }
00207         }
00208     }
00209 
00210     if (allGeometry)
00211     {
00212         faceSet faces(mesh, "concaveFaces", mesh.nFaces()/100 + 1);
00213         if (mesh.checkFaceAngles(true, 10, &faces))
00214         {
00215             //noFailedChecks++;
00216 
00217             label nFaces = returnReduce(faces.size(), sumOp<label>());
00218 
00219             if (nFaces > 0)
00220             {
00221                 Info<< "  <<Writing " << nFaces
00222                     << " faces with concave angles to set " << faces.name()
00223                     << endl;
00224                 faces.write();
00225             }
00226         }
00227     }
00228 
00229     if (allGeometry)
00230     {
00231         faceSet faces(mesh, "warpedFaces", mesh.nFaces()/100 + 1);
00232         if (mesh.checkFaceFlatness(true, 0.8, &faces))
00233         {
00234             //noFailedChecks++;
00235 
00236             label nFaces = returnReduce(faces.size(), sumOp<label>());
00237 
00238             if (nFaces > 0)
00239             {
00240                 Info<< "  <<Writing " << nFaces
00241                     << " warped faces to set " << faces.name() << endl;
00242                 faces.write();
00243             }
00244         }
00245     }
00246 
00247     if (allGeometry)
00248     {
00249         cellSet cells(mesh, "underdeterminedCells", mesh.nCells()/100);
00250         if (mesh.checkCellDeterminant(true, &cells))
00251         {
00252             noFailedChecks++;
00253 
00254             label nCells = returnReduce(cells.size(), sumOp<label>());
00255 
00256             Info<< "  <<Writing " << nCells
00257                 << " under-determined cells to set " << cells.name() << endl;
00258             cells.write();
00259         }
00260     }
00261 
00262 
00263     return noFailedChecks;
00264 }
Copyright © 2000-2009 OpenCFD Ltd