diff --git a/src/OpenFOAM/meshes/polyMesh/polyMeshCheck/polyMeshCheck.C b/src/OpenFOAM/meshes/polyMesh/polyMeshCheck/polyMeshCheck.C index f64381188f..9a8b055aed 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMeshCheck/polyMeshCheck.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMeshCheck/polyMeshCheck.C @@ -23,11 +23,19 @@ License \*---------------------------------------------------------------------------*/ -#include "polyMesh.H" +#include "polyMeshCheck.H" #include "polyMeshTools.H" #include "unitConversion.H" #include "syncTools.H" +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +Foam::scalar Foam::polyMeshCheck::closedThreshold = 1.0e-6; +Foam::scalar Foam::polyMeshCheck::aspectThreshold = 1000; +Foam::scalar Foam::polyMeshCheck::nonOrthThreshold = 70; // deg +Foam::scalar Foam::polyMeshCheck::skewThreshold = 4; +Foam::scalar Foam::polyMeshCheck::planarCosAngle = 1.0e-6; + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // bool Foam::polyMesh::checkFaceOrthogonality @@ -56,7 +64,7 @@ bool Foam::polyMesh::checkFaceOrthogonality // Severe nonorthogonality threshold const scalar severeNonorthogonalityThreshold = - ::cos(degToRad(primitiveMeshCheck::nonOrthThreshold)); + ::cos(degToRad(polyMeshCheck::nonOrthThreshold)); scalar minDDotS = great; @@ -125,7 +133,7 @@ bool Foam::polyMesh::checkFaceOrthogonality if (severeNonOrth > 0) { Info<< " *Number of severely non-orthogonal (> " - << primitiveMeshCheck::nonOrthThreshold << " degrees) faces: " + << polyMeshCheck::nonOrthThreshold << " degrees) faces: " << severeNonOrth << "." << endl; } } @@ -191,7 +199,7 @@ bool Foam::polyMesh::checkFaceSkewness { // Check if the skewness vector is greater than the PN vector. // This does not cause trouble but is a good indication of a poor mesh. - if (skew[facei] > primitiveMeshCheck::skewThreshold) + if (skew[facei] > polyMeshCheck::skewThreshold) { if (setPtr) { @@ -636,4 +644,99 @@ bool Foam::polyMesh::checkVolRatio } + +bool Foam::polyMeshCheck::checkTopology(const polyMesh& mesh, const bool report) +{ + label noFailedChecks = 0; + + if (mesh.checkPoints(report)) noFailedChecks++; + if (mesh.checkUpperTriangular(report)) noFailedChecks++; + if (mesh.checkCellsZipUp(report)) noFailedChecks++; + if (mesh.checkFaceVertices(report)) noFailedChecks++; + if (mesh.checkFaceFaces(report)) noFailedChecks++; + + if (noFailedChecks == 0) + { + if (report) + { + Info<< " Mesh topology OK." << endl; + } + + return false; + } + else + { + if (report) + { + Info<< " Failed " << noFailedChecks + << " mesh topology checks." << endl; + } + + return true; + } +} + + +bool Foam::polyMeshCheck::checkGeometry(const polyMesh& mesh, const bool report) +{ + label noFailedChecks = 0; + + if (mesh.checkClosedBoundary(report)) noFailedChecks++; + if (mesh.checkClosedCells(report)) noFailedChecks++; + if (mesh.checkFaceAreas(report)) noFailedChecks++; + if (mesh.checkCellVolumes(report)) noFailedChecks++; + if (mesh.checkFaceOrthogonality(report)) noFailedChecks++; + if (mesh.checkFacePyramids(report)) noFailedChecks++; + if (mesh.checkFaceSkewness(report)) noFailedChecks++; + + if (noFailedChecks == 0) + { + if (report) + { + Info<< " Mesh geometry OK." << endl; + } + + return false; + } + else + { + if (report) + { + Info<< " Failed " << noFailedChecks + << " mesh geometry checks." << endl; + } + + return true; + } +} + + +bool Foam::polyMeshCheck::checkMesh(const polyMesh& mesh, const bool report) +{ + const label noFailedChecks = + checkTopology(mesh, report) + + checkGeometry(mesh, report); + + if (noFailedChecks == 0) + { + if (report) + { + Info<< "Mesh OK." << endl; + } + + return false; + } + else + { + if (report) + { + Info<< " Failed " << noFailedChecks + << " mesh checks." << endl; + } + + return true; + } +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/meshes/polyMesh/polyMeshCheck/polyMeshCheck.H b/src/OpenFOAM/meshes/polyMesh/polyMeshCheck/polyMeshCheck.H new file mode 100644 index 0000000000..4774d3ebec --- /dev/null +++ b/src/OpenFOAM/meshes/polyMesh/polyMeshCheck/polyMeshCheck.H @@ -0,0 +1,72 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Namespace + Foam::polyMeshCheck + +Description + + +SourceFiles + polyMeshCheck.C + +\*---------------------------------------------------------------------------*/ + +#ifndef polyMeshCheck_H +#define polyMeshCheck_H + +#include "polyMesh.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Namespace polyMeshCheck Declaration +\*---------------------------------------------------------------------------*/ + +namespace polyMeshCheck +{ + //- Check mesh topology for correctness. + // Returns false for no error. + bool checkTopology(const polyMesh& mesh, const bool report = false); + + //- Check mesh geometry (& implicitly topology) for correctness. + // Returns false for no error. + bool checkGeometry(const polyMesh& mesh, const bool report = false); + + //- Check mesh for correctness. Returns false for no error. + bool checkMesh(const polyMesh& mesh, const bool report = false); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/meshes/polyMesh/polyMeshFromShapeMesh.C b/src/OpenFOAM/meshes/polyMesh/polyMeshFromShapeMesh.C index 4798e11239..f1cfee0d86 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMeshFromShapeMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMeshFromShapeMesh.C @@ -665,14 +665,6 @@ Foam::polyMesh::polyMesh // Calculate the geometry for the patches (transformation tensors etc.) boundary_.calcGeometry(); } - - if (debug) - { - if (checkMesh()) - { - Info<< "Mesh OK" << endl; - } - } } @@ -945,14 +937,6 @@ Foam::polyMesh::polyMesh // Calculate the geometry for the patches (transformation tensors etc.) boundary_.calcGeometry(); } - - if (debug) - { - if (checkMesh()) - { - Info << "Mesh OK" << endl; - } - } } diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H index 0a31fd1853..06b59566cd 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H @@ -250,128 +250,6 @@ protected: void calcEdgeVectors() const; - // Mesh checking - - //- Check if all points on face are shared with another face. - bool checkDuplicateFaces - ( - const label, - const Map