From e2336fefd3be87c61b9f77eaaddaf9484de2b6e2 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Sun, 12 Jun 2016 20:51:07 +0100 Subject: [PATCH] checkMesh: Added writing of faceSets and cellSets containing errors In parallel the sets are reconstructed. e.g. mpirun -np 6 checkMesh -parallel -allGeometry -allTopology -writeSets vtk will create a postProcessing/ folder with the vtk files of the (reconstructed) faceSets and cellSets. Also improved analysis of disconnected regions now also checks for point connectivity with is useful for detecting if AMI regions have duplicate points. Patch contributed by Mattijs Janssens --- .../mesh/manipulation/checkMesh/Make/files | 2 +- .../mesh/manipulation/checkMesh/Make/options | 4 + .../manipulation/checkMesh/checkGeometry.C | 69 +++- .../manipulation/checkMesh/checkGeometry.H | 8 +- .../mesh/manipulation/checkMesh/checkMesh.C | 46 ++- .../manipulation/checkMesh/checkMeshQuality.C | 10 +- .../manipulation/checkMesh/checkMeshQuality.H | 9 +- .../mesh/manipulation/checkMesh/checkTools.C | 374 ++++++++++++++++++ .../mesh/manipulation/checkMesh/checkTools.H | 33 ++ .../manipulation/checkMesh/checkTopology.C | 96 ++++- .../manipulation/checkMesh/checkTopology.H | 11 +- .../primitiveMesh/PatchTools/PatchTools.H | 29 ++ .../PatchTools/PatchToolsGatherAndMerge.C | 105 ++++- 13 files changed, 775 insertions(+), 21 deletions(-) create mode 100644 applications/utilities/mesh/manipulation/checkMesh/checkTools.C create mode 100644 applications/utilities/mesh/manipulation/checkMesh/checkTools.H diff --git a/applications/utilities/mesh/manipulation/checkMesh/Make/files b/applications/utilities/mesh/manipulation/checkMesh/Make/files index 1a3130a23c..21febe2789 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/Make/files +++ b/applications/utilities/mesh/manipulation/checkMesh/Make/files @@ -1,4 +1,4 @@ -printMeshStats.C +checkTools.C checkTopology.C checkGeometry.C checkMeshQuality.C diff --git a/applications/utilities/mesh/manipulation/checkMesh/Make/options b/applications/utilities/mesh/manipulation/checkMesh/Make/options index 2ff5dbabfe..4700e225a5 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/Make/options +++ b/applications/utilities/mesh/manipulation/checkMesh/Make/options @@ -1,8 +1,12 @@ EXE_INC = \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/sampling/lnInclude \ + -I$(LIB_SRC)/surfMesh/lnInclude \ -I$(LIB_SRC)/dynamicMesh/lnInclude EXE_LIBS = \ -lmeshTools \ + -lsampling \ + -lsurfMesh \ -ldynamicMesh diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.C b/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.C index 655b43a1b2..6646456d54 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.C +++ b/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.C @@ -7,6 +7,8 @@ #include "wedgePolyPatch.H" #include "unitConversion.H" #include "polyMeshTetDecomposition.H" +#include "surfaceWriter.H" +#include "checkTools.H" // Find wedge with opposite orientation. Note: does not actually check that @@ -472,7 +474,12 @@ bool Foam::checkCoupledPoints } -Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry) +Foam::label Foam::checkGeometry +( + const polyMesh& mesh, + const bool allGeometry, + const autoPtr& writer +) { label noFailedChecks = 0; @@ -558,6 +565,10 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry) << " non closed cells to set " << cells.name() << endl; cells.instance() = mesh.pointsInstance(); cells.write(); + if (writer.valid()) + { + mergeAndWrite(writer(), cells); + } } } @@ -570,6 +581,10 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry) << aspectCells.name() << endl; aspectCells.instance() = mesh.pointsInstance(); aspectCells.write(); + if (writer.valid()) + { + mergeAndWrite(writer(), aspectCells); + } } } @@ -587,6 +602,10 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry) << " zero area faces to set " << faces.name() << endl; faces.instance() = mesh.pointsInstance(); faces.write(); + if (writer.valid()) + { + mergeAndWrite(writer(), faces); + } } } } @@ -605,6 +624,10 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry) << " zero volume cells to set " << cells.name() << endl; cells.instance() = mesh.pointsInstance(); cells.write(); + if (writer.valid()) + { + mergeAndWrite(writer(), cells); + } } } } @@ -624,6 +647,10 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry) << " non-orthogonal faces to set " << faces.name() << endl; faces.instance() = mesh.pointsInstance(); faces.write(); + if (writer.valid()) + { + mergeAndWrite(writer(), faces); + } } } @@ -642,6 +669,10 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry) << faces.name() << endl; faces.instance() = mesh.pointsInstance(); faces.write(); + if (writer.valid()) + { + mergeAndWrite(writer(), faces); + } } } } @@ -660,6 +691,10 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry) << " skew faces to set " << faces.name() << endl; faces.instance() = mesh.pointsInstance(); faces.write(); + if (writer.valid()) + { + mergeAndWrite(writer(), faces); + } } } } @@ -680,6 +715,10 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry) << faces.name() << endl; faces.instance() = mesh.pointsInstance(); faces.write(); + if (writer.valid()) + { + mergeAndWrite(writer(), faces); + } } } } @@ -709,6 +748,10 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry) << "decomposition tets to set " << faces.name() << endl; faces.instance() = mesh.pointsInstance(); faces.write(); + if (writer.valid()) + { + mergeAndWrite(writer(), faces); + } } } } @@ -769,6 +812,10 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry) << endl; faces.instance() = mesh.pointsInstance(); faces.write(); + if (writer.valid()) + { + mergeAndWrite(writer(), faces); + } } } } @@ -788,6 +835,10 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry) << " warped faces to set " << faces.name() << endl; faces.instance() = mesh.pointsInstance(); faces.write(); + if (writer.valid()) + { + mergeAndWrite(writer(), faces); + } } } } @@ -805,6 +856,10 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry) << " under-determined cells to set " << cells.name() << endl; cells.instance() = mesh.pointsInstance(); cells.write(); + if (writer.valid()) + { + mergeAndWrite(writer(), cells); + } } } @@ -821,6 +876,10 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry) << " concave cells to set " << cells.name() << endl; cells.instance() = mesh.pointsInstance(); cells.write(); + if (writer.valid()) + { + mergeAndWrite(writer(), cells); + } } } @@ -838,6 +897,10 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry) << faces.name() << endl; faces.instance() = mesh.pointsInstance(); faces.write(); + if (writer.valid()) + { + mergeAndWrite(writer(), faces); + } } } @@ -855,6 +918,10 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh, const bool allGeometry) << faces.name() << endl; faces.instance() = mesh.pointsInstance(); faces.write(); + if (writer.valid()) + { + mergeAndWrite(writer(), faces); + } } } diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.H b/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.H index edc1f44826..9658512eb1 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.H +++ b/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.H @@ -6,6 +6,7 @@ namespace Foam { class polyMesh; class wedgePolyPatch; + class surfaceWriter; label findOppositeWedge(const polyMesh&, const wedgePolyPatch&); @@ -21,5 +22,10 @@ namespace Foam //- Check 0th vertex on coupled faces bool checkCoupledPoints(const polyMesh&, const bool report, labelHashSet*); - label checkGeometry(const polyMesh& mesh, const bool allGeometry); + label checkGeometry + ( + const polyMesh& mesh, + const bool allGeometry, + const autoPtr& + ); } diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkMesh.C b/applications/utilities/mesh/manipulation/checkMesh/checkMesh.C index 93f4b27288..07b831e1fd 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkMesh.C +++ b/applications/utilities/mesh/manipulation/checkMesh/checkMesh.C @@ -42,16 +42,20 @@ Usage \param -region \ \n Specify an alternative mesh region. + \param -writeSets \ \n + Reconstruct all cellSets and faceSets geometry and write to postProcessing/ + directory according to surfaceFormat (e.g. vtk or ensight) + \*---------------------------------------------------------------------------*/ #include "argList.H" #include "timeSelector.H" #include "Time.H" - #include "polyMesh.H" #include "globalMeshData.H" +#include "vtkSurfaceWriter.H" -#include "printMeshStats.H" +#include "checkTools.H" #include "checkTopology.H" #include "checkGeometry.H" #include "checkMeshQuality.H" @@ -84,6 +88,12 @@ int main(int argc, char *argv[]) "meshQuality", "read user-defined mesh quality criterions from system/meshQualityDict" ); + argList::addOption + ( + "writeSets", + "" + "reconstruct and write all faceSets and cellSets in selected format" + ); #include "setRootCase.H" #include "createTime.H" @@ -95,6 +105,9 @@ int main(int argc, char *argv[]) const bool allTopology = args.optionFound("allTopology"); const bool meshQuality = args.optionFound("meshQuality"); + word surfaceFormat; + const bool writeSets = args.optionReadIfPresent("writeSets", surfaceFormat); + if (noTopology) { Info<< "Disabling all topology checks." << nl << endl; @@ -112,6 +125,12 @@ int main(int argc, char *argv[]) { Info<< "Enabling user-defined geometry checks." << nl << endl; } + if (writeSets) + { + Info<< "Reconstructing and writing " << surfaceFormat + << " representation" + << " of all faceSets and cellSets." << nl << endl; + } autoPtr qualDict; @@ -134,6 +153,13 @@ int main(int argc, char *argv[]) } + autoPtr writer; + if (writeSets) + { + writer = surfaceWriter::New(surfaceFormat); + } + + forAll(timeDirs, timeI) { runTime.setTime(timeDirs[timeI], timeI); @@ -158,14 +184,20 @@ int main(int argc, char *argv[]) if (!noTopology) { - nFailedChecks += checkTopology(mesh, allTopology, allGeometry); + nFailedChecks += checkTopology + ( + mesh, + allTopology, + allGeometry, + writer + ); } - nFailedChecks += checkGeometry(mesh, allGeometry); + nFailedChecks += checkGeometry(mesh, allGeometry, writer); if (meshQuality) { - nFailedChecks += checkMeshQuality(mesh, qualDict()); + nFailedChecks += checkMeshQuality(mesh, qualDict(), writer); } @@ -186,11 +218,11 @@ int main(int argc, char *argv[]) { Info<< "Time = " << runTime.timeName() << nl << endl; - label nFailedChecks = checkGeometry(mesh, allGeometry); + label nFailedChecks = checkGeometry(mesh, allGeometry, writer); if (meshQuality) { - nFailedChecks += checkMeshQuality(mesh, qualDict()); + nFailedChecks += checkMeshQuality(mesh, qualDict(), writer); } diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkMeshQuality.C b/applications/utilities/mesh/manipulation/checkMesh/checkMeshQuality.C index b00f02f8ef..a6a01c7336 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkMeshQuality.C +++ b/applications/utilities/mesh/manipulation/checkMesh/checkMeshQuality.C @@ -3,12 +3,14 @@ #include "cellSet.H" #include "faceSet.H" #include "motionSmoother.H" - +#include "surfaceWriter.H" +#include "checkTools.H" Foam::label Foam::checkMeshQuality ( const polyMesh& mesh, - const dictionary& dict + const dictionary& dict, + const autoPtr& writer ) { label noFailedChecks = 0; @@ -27,6 +29,10 @@ Foam::label Foam::checkMeshQuality << " faces in error to set " << faces.name() << endl; faces.instance() = mesh.pointsInstance(); faces.write(); + if (writer.valid()) + { + mergeAndWrite(writer(), faces); + } } } diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkMeshQuality.H b/applications/utilities/mesh/manipulation/checkMesh/checkMeshQuality.H index 1e5b3489c9..52507986bf 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkMeshQuality.H +++ b/applications/utilities/mesh/manipulation/checkMesh/checkMeshQuality.H @@ -2,5 +2,12 @@ namespace Foam { - label checkMeshQuality(const polyMesh& mesh, const dictionary&); + class surfaceWriter; + + label checkMeshQuality + ( + const polyMesh&, + const dictionary&, + const autoPtr& + ); } diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkTools.C b/applications/utilities/mesh/manipulation/checkMesh/checkTools.C new file mode 100644 index 0000000000..e68ff5d7eb --- /dev/null +++ b/applications/utilities/mesh/manipulation/checkMesh/checkTools.C @@ -0,0 +1,374 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015-2016 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 . + +\*---------------------------------------------------------------------------*/ + +#include "checkTools.H" +#include "polyMesh.H" +#include "globalMeshData.H" +#include "hexMatcher.H" +#include "wedgeMatcher.H" +#include "prismMatcher.H" +#include "pyrMatcher.H" +#include "tetWedgeMatcher.H" +#include "tetMatcher.H" +#include "IOmanip.H" +#include "faceSet.H" +#include "cellSet.H" +#include "Time.H" +#include "surfaceWriter.H" +#include "syncTools.H" +#include "globalIndex.H" +#include "PatchTools.H" + + +void Foam::printMeshStats(const polyMesh& mesh, const bool allTopology) +{ + Info<< "Mesh stats" << nl + << " points: " + << returnReduce(mesh.points().size(), sumOp