Skip to content

Commit

Permalink
checkMesh, functionObjects::checkMesh: Updated and made consistent
Browse files Browse the repository at this point in the history
Now both the checkMesh utility and functionObject operate in the same manner
with the same controls, executing the same checkGeometry and checkTopology
functions from the new meshCheck library.  The controls have been updated and
made more consistent and flexible, in particular by the addition of optional
user specification for the non-orthogonality and skewness error thresholds:

Application
    checkMesh

Description
    Checks validity of a mesh.

Usage
    \b checkMesh [OPTION]

    Options:
      - \par noTopology
        Skip checking the mesh topology

      - \par -allTopology
        Check all (including non finite-volume specific) addressing

      - \par -allGeometry
        Check all (including non finite-volume specific) geometry

      - \par -meshQuality
        Check against user defined (in \a system/meshQualityDict) quality
        settings

      - \par -region \<name\>
        Specify an alternative mesh region.

      - \par -writeSurfaces
        Reconstruct cellSets and faceSets of problem faces and write to
        postProcessing directory.

      - \par -surfaceFormat <format>
        Format used to write the cellSets and faceSets surfaces
        e.g. vtk or ensight.

      - \par -writeSets
        Reconstruct pointSets of problem points nd write to
        postProcessing directory.

      - \par -setFormat <format>
        Format used to write the pointSets
        e.g. vtk or ensight.

      - \par -nonOrthThreshold <threshold value in degrees>
        Threshold in degrees for reporting non-orthogonality errors,
        default: 70"

      - \par -skewThreshold <threshold value>
        Threshold for reporting skewness errors, default: 4.

Class
    Foam::functionObjects::checkMesh

Description
    Executes primitiveMesh::checkMesh(true) every execute time for which the
    mesh changed, i.e. moved or changed topology.

    Useful to check the correctness of changing and morphing meshes.

Usage
    \table
        Property      | Description               | Required     | Default value
        type          | type name: checkMesh      | yes          |
        noTopology    | Skip checking the mesh topology | no     | false
        allTopology   | Check all addressing      | no           | false
        allGeometry   | Check all geometry        | no           | false
        writeSurfaces | Reconstruct and write problem faces | no | false
        surfaceFormat | Format for problem faceSets | no         | vtk
        writeSets     | Reconstruct and write problem points | no | false
        setFormat     | Format used to write the problem pointSets | no | vtk
        nonOrthThreshold | Threshold for non-orthogonality errors | no | 70 deg
        skewThreshold | Threshold for reporting skewness errors | no | 4
    \endtable

    Example of checkMesh specification:
    \verbatim
    checkMesh
    {
        type            checkMesh;
        libs            ("libutilityFunctionObjects.so");

        executeControl  timeStep;
        executeInterval 10;

        allGeometry     true;
        allTopology     true;

        writeSurfaces   true;
        surfaceFormat   vtk;

        writeSets       true;
        setFormat       vtk;
    }
    \endverbatim

    or using the standard configuration file:

    \verbatim
    #includeFunc checkMesh(executeInterval=10, allGeometry=true)
    \endverbatim
  • Loading branch information
Henry Weller committed Oct 24, 2023
1 parent 819c938 commit 4ab9979
Show file tree
Hide file tree
Showing 11 changed files with 278 additions and 90 deletions.
131 changes: 103 additions & 28 deletions applications/utilities/mesh/manipulation/checkMesh/checkMesh.C
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,44 @@ Usage
\b checkMesh [OPTION]
Options:
- \par -allGeometry
Checks all (including non finite-volume specific) geometry
- \par noTopology
Skip checking the mesh topology
- \par -allTopology
Checks all (including non finite-volume specific) addressing
Check all (including non finite-volume specific) addressing
- \par -allGeometry
Check all (including non finite-volume specific) geometry
- \par -meshQuality
Checks against user defined (in \a system/meshQualityDict) quality
Check against user defined (in \a system/meshQualityDict) quality
settings
- \par -region \<name\>
Specify an alternative mesh region.
- \par -writeSets \<surfaceFormat\>
Reconstruct all cellSets and faceSets geometry and write to
postProcessing directory according to surfaceFormat
(e.g. vtk or ensight). Additionally reconstructs all pointSets and
writes as vtk format.
- \par -writeSurfaces
Reconstruct cellSets and faceSets of problem faces and write to
postProcessing directory.
- \par -surfaceFormat <format>
Format used to write the cellSets and faceSets surfaces
e.g. vtk or ensight.
- \par -writeSets
Reconstruct pointSets of problem points nd write to
postProcessing directory.
- \par -setFormat <format>
Format used to write the pointSets
e.g. vtk or ensight.
- \par -nonOrthThreshold <threshold value in degrees>
Threshold in degrees for reporting non-orthogonality errors,
default: 70"
- \par -skewThreshold <threshold value>
Threshold for reporting skewness errors, default: 4.
\*---------------------------------------------------------------------------*/

Expand All @@ -57,7 +77,7 @@ Usage
#include "Time.H"
#include "polyMesh.H"
#include "globalMeshData.H"
#include "surfaceWriter.H"
#include "vtkSurfaceWriter.H"
#include "vtkSetWriter.H"
#include "IOdictionary.H"

Expand Down Expand Up @@ -92,11 +112,40 @@ int main(int argc, char *argv[])
"meshQuality",
"read user-defined mesh quality criterions from system/meshQualityDict"
);
argList::addBoolOption
(
"writeSurfaces",
"reconstruct and write faceSets and cellSets of the problem faces"
);
argList::addOption
(
"writeSets",
"surfaceFormat",
"reconstruct and write all faceSets and cellSets in selected format"
"surfaceFormat",
"Format for faceSets and cellSets of the problem faces, defaults to vtk"
);
argList::addBoolOption
(
"writeSets",
"reconstruct and write pointSets of the problem points"
);
argList::addOption
(
"setFormat",
"setFormat",
"Format for pointSets of the problem points, defaults to vtk"
);
argList::addOption
(
"nonOrthThreshold",
"nonOrthThreshold",
"Threshold in degrees "
"for reporting non-orthogonality errors, default: 70"
);
argList::addOption
(
"skewThreshold",
"skewThreshold",
"Threshold for reporting non-orthogonality errors, default: 4"
);

#include "setRootCase.H"
Expand All @@ -108,9 +157,20 @@ int main(int argc, char *argv[])
const bool allGeometry = args.optionFound("allGeometry");
const bool allTopology = args.optionFound("allTopology");
const bool meshQuality = args.optionFound("meshQuality");
const bool writeSurfaces = args.optionFound("writeSurfaces");
const bool writeSets = args.optionFound("writeSets");

word surfaceFormat(vtkSurfaceWriter::typeName);
args.optionReadIfPresent("surfaceFormat", surfaceFormat);

word setFormat(vtkSetWriter::typeName);
args.optionReadIfPresent("surfaceFormat", setFormat);

word surfaceFormat;
const bool writeSets = args.optionReadIfPresent("writeSets", surfaceFormat);
scalar nonOrthThreshold = 70;
args.optionReadIfPresent("nonOrthThreshold", nonOrthThreshold);

scalar skewThreshold = 4;
args.optionReadIfPresent("skewThreshold", skewThreshold);

if (noTopology)
{
Expand All @@ -129,11 +189,17 @@ int main(int argc, char *argv[])
{
Info<< "Enabling user-defined geometry checks." << nl << endl;
}
if (writeSurfaces)
{
Info<< "Reconstructing and writing surface representation of the "
<< "faceSets and cellSets of problem faces in "
<< surfaceFormat << " format" << nl << endl;
}
if (writeSets)
{
Info<< "Reconstructing and writing " << surfaceFormat
<< " representation"
<< " of all faceSets and cellSets." << nl << endl;
Info<< "Reconstructing and writing the problem points in "
<< setFormat << " format"
<< nl << endl;
}


Expand All @@ -156,20 +222,23 @@ int main(int argc, char *argv[])
);
}


autoPtr<surfaceWriter> surfWriter;
autoPtr<Foam::setWriter> setWriter;
if (writeSets)
autoPtr<Foam::surfaceWriter> surfaceWriter;
if (writeSurfaces)
{
surfWriter = surfaceWriter::New
surfaceWriter = surfaceWriter::New
(
surfaceFormat,
mesh.time().writeFormat(),
mesh.time().writeCompression()
);
}

autoPtr<Foam::setWriter> setWriter;
if (writeSets)
{
setWriter = Foam::setWriter::New
(
vtkSetWriter::typeName,
setFormat,
mesh.time().writeFormat(),
mesh.time().writeCompression()
);
Expand Down Expand Up @@ -204,7 +273,7 @@ int main(int argc, char *argv[])
(
mesh,
allTopology,
surfWriter,
surfaceWriter,
setWriter
);
}
Expand All @@ -213,13 +282,16 @@ int main(int argc, char *argv[])
(
mesh,
allGeometry,
surfWriter,
nonOrthThreshold,
skewThreshold,
surfaceWriter,
setWriter
);

if (meshQuality)
{
nFailedChecks += checkMeshQuality(mesh, qualDict(), surfWriter);
nFailedChecks +=
checkMeshQuality(mesh, qualDict(), surfaceWriter);
}


Expand All @@ -244,13 +316,16 @@ int main(int argc, char *argv[])
(
mesh,
allGeometry,
surfWriter,
nonOrthThreshold,
skewThreshold,
surfaceWriter,
setWriter
);

if (meshQuality)
{
nFailedChecks += checkMeshQuality(mesh, qualDict(), surfWriter);
nFailedChecks +=
checkMeshQuality(mesh, qualDict(), surfaceWriter);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/

#include "attachPolyTopoChanger.H"
#include "meshCheck.H"
#include "polyMesh.H"
#include "polyTopoChange.H"

// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Expand Down Expand Up @@ -119,8 +119,6 @@ void Foam::attachPolyTopoChanger::attach(const bool removeEmptyPatches)
Pout<< "void attachPolyTopoChanger::attach(): "
<< "Finished attaching mesh" << endl;
}

meshCheck::checkMesh(mesh_);
}


Expand Down
6 changes: 4 additions & 2 deletions src/functionObjects/utilities/Make/options
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshCheck/lnInclude
-I$(LIB_SRC)/meshCheck/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude

LIB_LIBS = \
-lfiniteVolume \
-lmeshCheck
-lmeshCheck \
-lsampling
92 changes: 91 additions & 1 deletion src/functionObjects/utilities/checkMesh/checkMesh.C
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ License
#include "checkMesh.H"
#include "fvMesh.H"
#include "meshCheck.H"
#include "vtkSetWriter.H"
#include "vtkSurfaceWriter.H"
#include "addToRunTimeSelectionTable.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
Expand Down Expand Up @@ -63,11 +65,99 @@ Foam::functionObjects::checkMesh::~checkMesh()

// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

bool Foam::functionObjects::checkMesh::read(const dictionary& dict)
{
noTopology_ = dict.lookupOrDefault("noTopology", false);
allGeometry_ = dict.lookupOrDefault("allGeometry", false);
allTopology_ = dict.lookupOrDefault("allTopology", false);

writeSurfaces_ = dict.lookupOrDefault("writeSurfaces", false);
if (writeSurfaces_)
{
surfaceFormat_ = dict.lookupOrDefault<word>
(
"surfaceFormat",
vtkSurfaceWriter::typeName
);
}

writeSets_ = dict.lookupOrDefault("writeSets", false);
if (writeSets_)
{
setFormat_ = dict.lookupOrDefault<word>
(
"setFormat",
vtkSetWriter::typeName
);
}

nonOrthThreshold_ = dict.lookupOrDefault("nonOrthThreshold", 70.0);
skewThreshold_ = dict.lookupOrDefault("skewThreshold", 4.0);

return functionObject::read(dict);
}


bool Foam::functionObjects::checkMesh::execute()
{
if (mesh_.changing())
{
return meshCheck::checkMesh(mesh_, true);
autoPtr<surfaceWriter> surfWriter;
if (writeSurfaces_)
{
surfWriter = surfaceWriter::New
(
surfaceFormat_,
mesh_.time().writeFormat(),
mesh_.time().writeCompression()
);
}

autoPtr<setWriter> setWriter;
if (writeSets_)
{
setWriter = setWriter::New
(
setFormat_,
mesh_.time().writeFormat(),
mesh_.time().writeCompression()
);
}

label nFailedChecks = 0;

if (!noTopology_)
{
nFailedChecks += meshCheck::checkTopology
(
mesh_,
allTopology_,
surfWriter,
setWriter
);
}

nFailedChecks += meshCheck::checkGeometry
(
mesh_,
allGeometry_,
nonOrthThreshold_,
skewThreshold_,
surfWriter,
setWriter
);

if (nFailedChecks == 0)
{
Info<< "\n Mesh OK.\n" << endl;
}
else
{
Info<< "\n Failed " << nFailedChecks << " mesh checks.\n"
<< endl;
}

return nFailedChecks == 0;
}
else
{
Expand Down
Loading

0 comments on commit 4ab9979

Please sign in to comment.