Skip to content
Snippets Groups Projects
checkGeometry.C 8.17 KiB
Newer Older
  • Learn to ignore specific revisions
  • #include "checkGeometry.H"
    #include "polyMesh.H"
    #include "globalMeshData.H"
    #include "cellSet.H"
    #include "faceSet.H"
    #include "pointSet.H"
    
    #include "EdgeMap.H"
    
    
    Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry)
    {
        label noFailedChecks = 0;
    
        Info<< "\nChecking geometry..." << endl;
    
        // Get a small relative length from the bounding box
        const boundBox& globalBb = mesh.bounds();
    
        Info<< "    Overall domain bounding box "
            << globalBb.min() << " " << globalBb.max() << endl;
    
    
        // Min length
    
        scalar minDistSqr = magSqr(1e-6 * globalBb.span());
    
        // Non-empty directions
    
    mattijs's avatar
    mattijs committed
        const Vector<label> validDirs = (mesh.geometricD() + Vector<label>::one)/2;
        Info<< "    Mesh (non-empty, non-wedge) directions " << validDirs << endl;
    
    mattijs's avatar
    mattijs committed
        const Vector<label> solDirs = (mesh.solutionD() + Vector<label>::one)/2;
        Info<< "    Mesh (non-empty) directions " << solDirs << endl;
    
    mattijs's avatar
    mattijs committed
        if (mesh.nGeometricD() < 3)
    
        {
            pointSet nonAlignedPoints(mesh, "nonAlignedEdges", mesh.nPoints()/100);
    
            if (mesh.checkEdgeAlignment(true, validDirs, &nonAlignedPoints))
            {
                noFailedChecks++;
    
    mattijs's avatar
    mattijs committed
                label nNonAligned = returnReduce
                (
                    nonAlignedPoints.size(),
                    sumOp<label>()
                );
    
    mattijs's avatar
    mattijs committed
                if (nNonAligned > 0)
    
    mattijs's avatar
    mattijs committed
                    Info<< "  <<Writing " << nNonAligned
    
                        << " points on non-aligned edges to set "
                        << nonAlignedPoints.name() << endl;
    
                    nonAlignedPoints.instance() = mesh.pointsInstance();
    
                    nonAlignedPoints.write();
                }
            }
        }
    
    
        if (mesh.checkClosedBoundary(true)) noFailedChecks++;
    
        {
            cellSet cells(mesh, "nonClosedCells", mesh.nCells()/100+1);
            cellSet aspectCells(mesh, "highAspectRatioCells", mesh.nCells()/100+1);
            if (mesh.checkClosedCells(true, &cells, &aspectCells))
            {
                noFailedChecks++;
    
    
    mattijs's avatar
    mattijs committed
                label nNonClosed = returnReduce(cells.size(), sumOp<label>());
    
                if (nNonClosed > 0)
    
    mattijs's avatar
    mattijs committed
                    Info<< "  <<Writing " << nNonClosed
    
                        << " non closed cells to set " << cells.name() << endl;
    
                    cells.instance() = mesh.pointsInstance();
    
    mattijs's avatar
    mattijs committed
    
            label nHighAspect = returnReduce(aspectCells.size(), sumOp<label>());
    
            if (nHighAspect > 0)
    
    mattijs's avatar
    mattijs committed
                Info<< "  <<Writing " << nHighAspect
    
                    << " cells with high aspect ratio to set "
                    << aspectCells.name() << endl;
    
                aspectCells.instance() = mesh.pointsInstance();
    
                aspectCells.write();
            }
        }
    
        {
            faceSet faces(mesh, "zeroAreaFaces", mesh.nFaces()/100 + 1);
            if (mesh.checkFaceAreas(true, &faces))
            {
                noFailedChecks++;
    
    
    mattijs's avatar
    mattijs committed
                label nFaces = returnReduce(faces.size(), sumOp<label>());
    
                if (nFaces > 0)
    
    mattijs's avatar
    mattijs committed
                    Info<< "  <<Writing " << nFaces
    
                        << " zero area faces to set " << faces.name() << endl;
    
                    faces.instance() = mesh.pointsInstance();
    
                    faces.write();
                }
            }
        }
    
        {
            cellSet cells(mesh, "zeroVolumeCells", mesh.nCells()/100 + 1);
            if (mesh.checkCellVolumes(true, &cells))
            {
                noFailedChecks++;
    
    
    mattijs's avatar
    mattijs committed
                label nCells = returnReduce(cells.size(), sumOp<label>());
    
                if (nCells > 0)
    
    mattijs's avatar
    mattijs committed
                    Info<< "  <<Writing " << nCells
    
                        << " zero volume cells to set " << cells.name() << endl;
    
                    cells.instance() = mesh.pointsInstance();
    
                    cells.write();
                }
            }
        }
    
        {
            faceSet faces(mesh, "nonOrthoFaces", mesh.nFaces()/100 + 1);
            if (mesh.checkFaceOrthogonality(true, &faces))
            {
                noFailedChecks++;
            }
    
    
    mattijs's avatar
    mattijs committed
            label nFaces = returnReduce(faces.size(), sumOp<label>());
    
            if (nFaces > 0)
    
    mattijs's avatar
    mattijs committed
                Info<< "  <<Writing " << nFaces
    
                    << " non-orthogonal faces to set " << faces.name() << endl;
    
                faces.instance() = mesh.pointsInstance();
    
                faces.write();
            }
        }
    
    
        {
            faceSet faces(mesh, "wrongOrientedFaces", mesh.nFaces()/100 + 1);
            if (mesh.checkFacePyramids(true, -SMALL, &faces))
            {
                noFailedChecks++;
    
    
    mattijs's avatar
    mattijs committed
                label nFaces = returnReduce(faces.size(), sumOp<label>());
    
                if (nFaces > 0)
    
    mattijs's avatar
    mattijs committed
                    Info<< "  <<Writing " << nFaces
    
                        << " faces with incorrect orientation to set "
                        << faces.name() << endl;
    
                    faces.instance() = mesh.pointsInstance();
    
                    faces.write();
                }
            }
        }
    
        {
            faceSet faces(mesh, "skewFaces", mesh.nFaces()/100 + 1);
            if (mesh.checkFaceSkewness(true, &faces))
            {
                noFailedChecks++;
    
    
    mattijs's avatar
    mattijs committed
                label nFaces = returnReduce(faces.size(), sumOp<label>());
    
                if (nFaces > 0)
    
    mattijs's avatar
    mattijs committed
                    Info<< "  <<Writing " << nFaces
    
                        << " skew faces to set " << faces.name() << endl;
    
                    faces.instance() = mesh.pointsInstance();
    
                    faces.write();
                }
            }
        }
    
        if (allGeometry)
        {
            // Note use of nPoints since don't want edge construction.
            pointSet points(mesh, "shortEdges", mesh.nPoints()/1000 + 1);
            if (mesh.checkEdgeLength(true, minDistSqr, &points))
            {
                //noFailedChecks++;
    
    
    mattijs's avatar
    mattijs committed
                label nPoints = returnReduce(points.size(), sumOp<label>());
    
                if (nPoints > 0)
    
    mattijs's avatar
    mattijs committed
                    Info<< "  <<Writing " << nPoints
    
                        << " points on short edges to set " << points.name()
                        << endl;
    
                    points.instance() = mesh.pointsInstance();
    
    mattijs's avatar
    mattijs committed
            label nEdgeClose = returnReduce(points.size(), sumOp<label>());
    
    
            if (mesh.checkPointNearness(false, minDistSqr, &points))
            {
                //noFailedChecks++;
    
    
    mattijs's avatar
    mattijs committed
                label nPoints = returnReduce(points.size(), sumOp<label>());
    
                if (nPoints > nEdgeClose)
    
                {
                    pointSet nearPoints(mesh, "nearPoints", points);
    
    mattijs's avatar
    mattijs committed
                    Info<< "  <<Writing " << nPoints
    
                        << " near (closer than " << Foam::sqrt(minDistSqr)
                        << " apart) points to set " << nearPoints.name() << endl;
    
                    nearPoints.instance() = mesh.pointsInstance();
    
                    nearPoints.write();
                }
            }
        }
    
        if (allGeometry)
        {
            faceSet faces(mesh, "concaveFaces", mesh.nFaces()/100 + 1);
            if (mesh.checkFaceAngles(true, 10, &faces))
            {
                //noFailedChecks++;
    
    
    mattijs's avatar
    mattijs committed
                label nFaces = returnReduce(faces.size(), sumOp<label>());
    
                if (nFaces > 0)
    
    mattijs's avatar
    mattijs committed
                    Info<< "  <<Writing " << nFaces
    
                        << " faces with concave angles to set " << faces.name()
                        << endl;
    
                    faces.instance() = mesh.pointsInstance();
    
                    faces.write();
                }
            }
        }
    
        if (allGeometry)
        {
            faceSet faces(mesh, "warpedFaces", mesh.nFaces()/100 + 1);
            if (mesh.checkFaceFlatness(true, 0.8, &faces))
            {
                //noFailedChecks++;
    
    
    mattijs's avatar
    mattijs committed
                label nFaces = returnReduce(faces.size(), sumOp<label>());
    
                if (nFaces > 0)
    
    mattijs's avatar
    mattijs committed
                    Info<< "  <<Writing " << nFaces
    
                        << " warped faces to set " << faces.name() << endl;
    
                    faces.instance() = mesh.pointsInstance();
    
                    faces.write();
                }
            }
        }
    
        if (allGeometry)
        {
            cellSet cells(mesh, "underdeterminedCells", mesh.nCells()/100);
            if (mesh.checkCellDeterminant(true, &cells))
            {
                noFailedChecks++;
    
    
    mattijs's avatar
    mattijs committed
                label nCells = returnReduce(cells.size(), sumOp<label>());
    
                Info<< "  <<Writing " << nCells
    
                    << " under-determined cells to set " << cells.name() << endl;
    
                cells.instance() = mesh.pointsInstance();