diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkMesh.C b/applications/utilities/mesh/manipulation/checkMesh/checkMesh.C index 90bdf3a79f..da428feba2 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkMesh.C +++ b/applications/utilities/mesh/manipulation/checkMesh/checkMesh.C @@ -89,6 +89,9 @@ Usage #include "checkMeshQuality.H" #include "writeFields.H" +#include "OFstream.H" +#include "JSONformatter.H" + using namespace Foam; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -151,6 +154,14 @@ int main(int argc, char *argv[]) "Write bad edges (possibly relevant for finite-area) in vtk format" ); + argList::addOption + ( + "writeChecks", + "word", + "Write checks to file in dictionary or JSON format" + ); + + #include "setRootCase.H" #include "createTime.H" #include "getAllRegionOptions.H" @@ -187,6 +198,14 @@ int main(int argc, char *argv[]) "faceZone" }); + #include "writeMeshChecks.H" + + if (args.found("writeChecks")) + { + writeChecksFormat = + writeChecksFormatTypeNames.get(args.get("writeChecks")); + } + const bool writeFaceFields = args.found("writeAllSurfaceFields"); wordHashSet selectedFields; if (args.found("writeFields")) @@ -371,6 +390,8 @@ int main(int argc, char *argv[]) // Write selected fields Foam::writeFields(mesh, selectedFields, writeFaceFields); + + writeMeshChecks(mesh, writeChecksFormat); } } else if (state == polyMesh::POINTS_MOVED) @@ -409,6 +430,8 @@ int main(int argc, char *argv[]) // Write selected fields Foam::writeFields(mesh, selectedFields, writeFaceFields); + + writeMeshChecks(mesh, writeChecksFormat); } } } diff --git a/applications/utilities/mesh/manipulation/checkMesh/writeMeshChecks.H b/applications/utilities/mesh/manipulation/checkMesh/writeMeshChecks.H new file mode 100644 index 0000000000..aaab11816d --- /dev/null +++ b/applications/utilities/mesh/manipulation/checkMesh/writeMeshChecks.H @@ -0,0 +1,64 @@ +enum class writeChecksFormatType +{ + none, + dictionary, + JSON +}; +const Enum writeChecksFormatTypeNames +{ + { writeChecksFormatType::none, "none" }, + { writeChecksFormatType::dictionary, "dictionary" }, + { writeChecksFormatType::JSON, "JSON" }, +}; + +writeChecksFormatType writeChecksFormat(writeChecksFormatType::none); + +auto writeMeshChecks = [](const fvMesh& mesh, const writeChecksFormatType fmt) +{ + if (Pstream::master()) + { + switch (fmt) + { + case writeChecksFormatType::dictionary: + { + OFstream os(mesh.time().globalPath()/"checkMesh.dict"); + + IOdictionary data + ( + IOobject + ( + mesh.time().globalPath()/"checkMesh.dict", + mesh, + IOobject::NO_READ + ) + ); + + data.writeHeader(os); + + mesh.data().meshDict().write(os, false); + + IOobject::writeEndDivider(os); + + Info<< "Writing mesh data to " << data.objectPath() + << nl << endl; + + break; + } + case writeChecksFormatType::JSON: + { + OFstream os(mesh.time().globalPath()/"checkMesh.json"); + + Info<< "Writing mesh data to " << os.name() << nl << endl; + + JSONformatter json(os); + + json.writeDict(mesh.data().meshDict()); + break; + } + default: + { + // Do nothing + } + } + } +};