From f078643f8c66cfd4353c9da8da329157a97340f1 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 25 Nov 2021 19:57:35 +0100 Subject: [PATCH] ENH: add blockFaces.vtp output for blockMesh -write-vtk --- .../mesh/generation/blockMesh/blockMesh.C | 1 + .../mesh/generation/blockMesh/blockMeshVTK.H | 79 +++++++++++++++++-- bin/tools/CleanFunctions | 2 +- src/mesh/blockMesh/blockMesh/blockMesh.C | 7 +- 4 files changed, 79 insertions(+), 10 deletions(-) diff --git a/applications/utilities/mesh/generation/blockMesh/blockMesh.C b/applications/utilities/mesh/generation/blockMesh/blockMesh.C index 520f4b2105..dae940888c 100644 --- a/applications/utilities/mesh/generation/blockMesh/blockMesh.C +++ b/applications/utilities/mesh/generation/blockMesh/blockMesh.C @@ -75,6 +75,7 @@ Usage #include "blockMesh.H" #include "foamVtkInternalMeshWriter.H" +#include "foamVtkSurfaceWriter.H" #include "attachPolyTopoChanger.H" #include "polyTopoChange.H" #include "cyclicPolyPatch.H" diff --git a/applications/utilities/mesh/generation/blockMesh/blockMeshVTK.H b/applications/utilities/mesh/generation/blockMesh/blockMeshVTK.H index 55c2554dec..e46205b7bc 100644 --- a/applications/utilities/mesh/generation/blockMesh/blockMeshVTK.H +++ b/applications/utilities/mesh/generation/blockMesh/blockMeshVTK.H @@ -13,22 +13,25 @@ License Description VTK output of blockMesh topology blocks + Always write in ASCII since the mesh is small and we want easily + readable output for inspection. + \*---------------------------------------------------------------------------*/ +// Common + +refPtr topoMeshPtr(blocks.topology(true)); +const polyMesh& topoMesh = topoMeshPtr(); + +// Internal mesh - ie, the blocks { - // Non-legacy and ASCII (mesh is small, want readable output) - const vtk::outputOptions writeOpts = vtk::formatType::INLINE_ASCII; - - refPtr topoMeshPtr(blocks.topology(true)); - const polyMesh& topoMesh = topoMeshPtr(); - - const vtk::vtuCells topoCells(topoMesh, writeOpts); + const vtk::vtuCells topoCells(topoMesh, vtk::formatType::INLINE_ASCII); vtk::internalMeshWriter writer ( topoMesh, topoCells, - writeOpts, + vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology" ); @@ -99,4 +102,64 @@ Description } +// Block boundary faces +{ + const label nIntFaces = topoMesh.nInternalFaces(); + const label nBndFaces = topoMesh.nBoundaryFaces(); + + faceList bndFaces + ( + faceList::subList(topoMesh.faces(), nBndFaces, nIntFaces) + ); + + vtk::surfaceWriter writer + ( + topoMesh.points(), + bndFaces, + vtk::formatType::INLINE_ASCII, + runTime.path()/"blockFaces" + ); + + + labelList blockIds(nBndFaces, -1); + labelList cellFaceIds(nBndFaces, -1); + labelList patchIds(nBndFaces, -1); + + { + const labelList& own = topoMesh.faceOwner(); + const cellList& cells = topoMesh.cells(); + const polyPatchList& patches = topoMesh.boundaryMesh(); + + for (const polyPatch& pp : patches) + { + label bndFacei = pp.start() - nIntFaces; + label meshFacei = pp.start(); + + forAll(pp, bfacei) + { + const label celli = own[meshFacei]; + const label cellFacei = cells[celli].find(meshFacei); + + blockIds[bndFacei] = celli; + cellFaceIds[bndFacei] = cellFacei; + patchIds[bndFacei] = pp.index(); + + ++bndFacei; + ++meshFacei; + } + } + } + + Info<< "Writing block boundary faces in vtk format: " + << args.relativePath(writer.output()).c_str() << endl; + + writer.writeGeometry(); + + writer.beginCellData(); + writer.writeCellData("block", blockIds); + writer.writeCellData("face", cellFaceIds); + writer.writeCellData("patch", patchIds); +} + + // ************************************************************************* // diff --git a/bin/tools/CleanFunctions b/bin/tools/CleanFunctions index 5a3c139725..174d3a488a 100644 --- a/bin/tools/CleanFunctions +++ b/bin/tools/CleanFunctions @@ -123,7 +123,7 @@ cleanCase() rm -rf system/machines # Possible blockMesh output - rm -f blockTopology.vtu blockTopology.obj blockCentres.obj + rm -f blockTopology.vtu blockFaces.vtp blockTopology.obj blockCentres.obj # From mpirunDebug rm -f gdbCommands mpirun.schema diff --git a/src/mesh/blockMesh/blockMesh/blockMesh.C b/src/mesh/blockMesh/blockMesh/blockMesh.C index f9777d83c3..dc7ea58153 100644 --- a/src/mesh/blockMesh/blockMesh/blockMesh.C +++ b/src/mesh/blockMesh/blockMesh/blockMesh.C @@ -271,7 +271,12 @@ Foam::blockMesh::blockMesh { // Command-line options have precedence over dictionary setting - if (!verbose_) + if (verbose_ < 0) + { + // Forced as 'off' + verbose_ = 0; + } + else if (!verbose_) { verbose_ = meshDict_.getOrDefault("verbose", verboseOutput); }