From d5c0852de164886e52d06949414b52cfe85f1ea1 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 1 Mar 2023 20:52:11 +0100 Subject: [PATCH] ENH: improve diagnostic fields for checkFaMesh -write-vtk ENH: support VTK output of procIDs for point data for some writers TUT: areaWrite for drippingChair --- .../finiteArea/checkFaMesh/faMeshWriteVTK.H | 19 +++++++++----- src/fileFormats/vtk/file/foamVtkFileWriter.C | 18 +++++++++---- src/fileFormats/vtk/file/foamVtkFileWriter.H | 15 ++++++++--- src/fileFormats/vtk/file/foamVtkFileWriterI.H | 14 ++++++++++- src/fileFormats/vtk/write/foamVtkLineWriter.C | 6 ++++- src/fileFormats/vtk/write/foamVtkLineWriter.H | 6 ++--- .../vtk/write/foamVtkSurfaceWriter.C | 6 ++++- .../vtk/write/foamVtkSurfaceWriter.H | 6 ++--- .../writers/vtk/foamVtkCoordSetWriter.H | 5 ++-- .../vtk/patch/foamVtkGenericPatchWriter.H | 6 ++++- .../output/vtk/patch/foamVtkPatchMeshWriter.C | 6 ++++- .../output/vtk/patch/foamVtkPatchMeshWriter.H | 6 ++--- .../kinematicParcelFoam/drippingChair/Allrun | 25 +++++++++++++------ .../drippingChair/Allrun-serial | 15 +++++++---- .../drippingChair/system/areaWrite | 25 +++++++++++++++++++ .../drippingChair/system/controlDict | 5 ++++ .../drippingChair/system/decomposeParDict-6 | 21 ++++++++++++++++ .../drippingChair/system/decomposeParDict-7 | 21 ++++++++++++++++ 18 files changed, 182 insertions(+), 43 deletions(-) create mode 100644 tutorials/lagrangian/kinematicParcelFoam/drippingChair/system/areaWrite create mode 100644 tutorials/lagrangian/kinematicParcelFoam/drippingChair/system/decomposeParDict-6 create mode 100644 tutorials/lagrangian/kinematicParcelFoam/drippingChair/system/decomposeParDict-7 diff --git a/applications/utilities/finiteArea/checkFaMesh/faMeshWriteVTK.H b/applications/utilities/finiteArea/checkFaMesh/faMeshWriteVTK.H index 5a138055d1..04b7bcfa61 100644 --- a/applications/utilities/finiteArea/checkFaMesh/faMeshWriteVTK.H +++ b/applications/utilities/finiteArea/checkFaMesh/faMeshWriteVTK.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2021-2022 OpenCFD Ltd. + Copyright (C) 2021-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -76,9 +76,9 @@ Description writer.beginCellData(4); writer.writeProcIDs(); { - // Use primitive patch order Field fld ( + // Use primitive patch order faMeshTools::flattenEdgeField(aMesh.magLe(), true) ); writer.write("magLe", fld); @@ -93,11 +93,17 @@ Description } { + const Field edgeCentres + ( + // Use primitive patch order + faMeshTools::flattenEdgeField(aMesh.edgeCentres(), true) + ); + // finiteArea - edgeCentres // (no other convenient way to display vectors on the edges) vtk::lineWriter writer ( - aMesh.edgeCentres(), + edgeCentres, edgeList::null(), // vtk::formatType::INLINE_ASCII, fileName @@ -109,19 +115,20 @@ Description writer.writeGeometry(); // PointData - writer.beginPointData(4); + writer.beginPointData(3); + writer.writeProcIDs(); // Unfortunately cannot threshold on points { - // Use primitive patch order Field fld ( + // Use primitive patch order faMeshTools::flattenEdgeField(aMesh.Le(), true) ); writer.write("Le", fld); } { - // Use primitive patch order Field fld ( + // Use primitive patch order faMeshTools::flattenEdgeField(aMesh.edgeAreaNormals(), true) ); writer.write("normal", fld); diff --git a/src/fileFormats/vtk/file/foamVtkFileWriter.C b/src/fileFormats/vtk/file/foamVtkFileWriter.C index 123a69e321..c1bdd88e85 100644 --- a/src/fileFormats/vtk/file/foamVtkFileWriter.C +++ b/src/fileFormats/vtk/file/foamVtkFileWriter.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -76,11 +76,11 @@ Foam::Ostream& Foam::vtk::fileWriter::reportBadState Foam::Ostream& Foam::vtk::fileWriter::reportBadState ( Ostream& os, - outputState expected, + outputState expected1, outputState expected2 ) const { - reportBadState(os, expected) + reportBadState(os, expected1) << " or (" << stateNames[expected2] << ')'; return os; } @@ -554,10 +554,18 @@ bool Foam::vtk::fileWriter::writeProcIDs(const label nValues) { ++nCellData_; } + else if (isState(outputState::POINT_DATA)) + { + ++nPointData_; + } else { - reportBadState(FatalErrorInFunction, outputState::CELL_DATA) - << " for procID field" << nl << endl + reportBadState + ( + FatalErrorInFunction, + outputState::CELL_DATA, + outputState::POINT_DATA + ) << " for procID field" << nl << endl << exit(FatalError); return false; diff --git a/src/fileFormats/vtk/file/foamVtkFileWriter.H b/src/fileFormats/vtk/file/foamVtkFileWriter.H index 98f4793950..abf068a42f 100644 --- a/src/fileFormats/vtk/file/foamVtkFileWriter.H +++ b/src/fileFormats/vtk/file/foamVtkFileWriter.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -201,7 +201,8 @@ protected: const UList& field ); - //- Write nValues of processor ids as CellData (no-op in serial) + //- Write nValues of processor ids as CellData or PointData + //- (no-op in serial) bool writeProcIDs(const label nValues); @@ -305,10 +306,16 @@ public: // \return True if the state changed virtual bool beginPointData(label nFields = 0) = 0; - //- Return the number of CellData written for the Piece thus far. + //- True if output state corresponds to CELL_DATA + inline bool isCellData() const noexcept; + + //- True if output state corresponds to POINT_DATA + inline bool isPointData() const noexcept; + + //- The number of CellData written for the Piece thus far. inline label nCellData() const noexcept; - //- Return the number of PointData written for the Piece thus far. + //- The number of PointData written for the Piece thus far. inline label nPointData() const noexcept; diff --git a/src/fileFormats/vtk/file/foamVtkFileWriterI.H b/src/fileFormats/vtk/file/foamVtkFileWriterI.H index b9cbfd677c..f1fb48f580 100644 --- a/src/fileFormats/vtk/file/foamVtkFileWriterI.H +++ b/src/fileFormats/vtk/file/foamVtkFileWriterI.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -107,4 +107,16 @@ inline Foam::label Foam::vtk::fileWriter::nPointData() const noexcept } +inline bool Foam::vtk::fileWriter::isCellData() const noexcept +{ + return (outputState::CELL_DATA == state_); +} + + +inline bool Foam::vtk::fileWriter::isPointData() const noexcept +{ + return (outputState::POINT_DATA == state_); +} + + // ************************************************************************* // diff --git a/src/fileFormats/vtk/write/foamVtkLineWriter.C b/src/fileFormats/vtk/write/foamVtkLineWriter.C index a5f42b5ad9..3fa9019665 100644 --- a/src/fileFormats/vtk/write/foamVtkLineWriter.C +++ b/src/fileFormats/vtk/write/foamVtkLineWriter.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -131,6 +131,10 @@ void Foam::vtk::lineWriter::piece bool Foam::vtk::lineWriter::writeProcIDs() { + if (this->isPointData()) + { + return vtk::fileWriter::writeProcIDs(nLocalPoints_); + } return vtk::fileWriter::writeProcIDs(nLocalLines_); } diff --git a/src/fileFormats/vtk/write/foamVtkLineWriter.H b/src/fileFormats/vtk/write/foamVtkLineWriter.H index 36245558f2..48d971287a 100644 --- a/src/fileFormats/vtk/write/foamVtkLineWriter.H +++ b/src/fileFormats/vtk/write/foamVtkLineWriter.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -155,8 +155,8 @@ public: void piece(const pointField& points, const edgeList& edges); - //- Write processor ids for each line as CellData - //- (no-op in serial) + //- Write processor ids for each line as CellData or for each point + //- as PointData, depending on isPointData() state. No-op in serial. bool writeProcIDs(); //- Write a uniform field of Cell (Line) or Point values diff --git a/src/fileFormats/vtk/write/foamVtkSurfaceWriter.C b/src/fileFormats/vtk/write/foamVtkSurfaceWriter.C index 7b07cace36..4b42c38809 100644 --- a/src/fileFormats/vtk/write/foamVtkSurfaceWriter.C +++ b/src/fileFormats/vtk/write/foamVtkSurfaceWriter.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -131,6 +131,10 @@ void Foam::vtk::surfaceWriter::piece bool Foam::vtk::surfaceWriter::writeProcIDs() { + if (this->isPointData()) + { + return vtk::fileWriter::writeProcIDs(nLocalPoints_); + } return vtk::fileWriter::writeProcIDs(nLocalPolys_); } diff --git a/src/fileFormats/vtk/write/foamVtkSurfaceWriter.H b/src/fileFormats/vtk/write/foamVtkSurfaceWriter.H index 0a9d2ccdf3..38fcdcf09c 100644 --- a/src/fileFormats/vtk/write/foamVtkSurfaceWriter.H +++ b/src/fileFormats/vtk/write/foamVtkSurfaceWriter.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -155,8 +155,8 @@ public: void piece(const pointField& points, const faceList& faces); - //- Write processor ids for each poly as CellData - //- (no-op in serial) + //- Write processor ids for each poly as CellData or for each point + //- as PointData, depending on isPointData() state. No-op in serial. bool writeProcIDs(); //- Write a uniform field of Cell (Poly) or Point values diff --git a/src/meshTools/coordSet/writers/vtk/foamVtkCoordSetWriter.H b/src/meshTools/coordSet/writers/vtk/foamVtkCoordSetWriter.H index 8963ce6adc..5f965e5727 100644 --- a/src/meshTools/coordSet/writers/vtk/foamVtkCoordSetWriter.H +++ b/src/meshTools/coordSet/writers/vtk/foamVtkCoordSetWriter.H @@ -201,8 +201,9 @@ public: void piece(const UPtrList& points); - //- Write processor ids for each line as CellData - //- (no-op in serial) + //- Write processor ids for each line as CellData or for each point + //- as PointData, depending on isPointData() state. No-op in serial. + // Not implemented. bool writeProcIDs(); diff --git a/src/meshTools/output/vtk/patch/foamVtkGenericPatchWriter.H b/src/meshTools/output/vtk/patch/foamVtkGenericPatchWriter.H index 8dabdc2772..e2db80c63f 100644 --- a/src/meshTools/output/vtk/patch/foamVtkGenericPatchWriter.H +++ b/src/meshTools/output/vtk/patch/foamVtkGenericPatchWriter.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -159,6 +159,10 @@ public: //- Write processor ids for each poly as CellData bool writeProcIDs() { + if (this->isPointData()) + { + return vtk::fileWriter::writeProcIDs(nLocalPoints_); + } return vtk::polyWriter::writeProcIDs(nLocalPolys_); } }; diff --git a/src/meshTools/output/vtk/patch/foamVtkPatchMeshWriter.C b/src/meshTools/output/vtk/patch/foamVtkPatchMeshWriter.C index f12762e7d4..fce8474d65 100644 --- a/src/meshTools/output/vtk/patch/foamVtkPatchMeshWriter.C +++ b/src/meshTools/output/vtk/patch/foamVtkPatchMeshWriter.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -585,6 +585,10 @@ void Foam::vtk::patchMeshWriter::writePatchIDs() bool Foam::vtk::patchMeshWriter::writeProcIDs() { + if (this->isPointData()) + { + return vtk::fileWriter::writeProcIDs(nLocalPoints_); + } return vtk::fileWriter::writeProcIDs(nLocalPolys_); } diff --git a/src/meshTools/output/vtk/patch/foamVtkPatchMeshWriter.H b/src/meshTools/output/vtk/patch/foamVtkPatchMeshWriter.H index 75cae3ffab..de259f740d 100644 --- a/src/meshTools/output/vtk/patch/foamVtkPatchMeshWriter.H +++ b/src/meshTools/output/vtk/patch/foamVtkPatchMeshWriter.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -209,8 +209,8 @@ public: // Must be called within the CELL_DATA state. void writePatchIDs(); - //- Write processor ids as CellData. This is no-op in serial. - // Must be called within the CELL_DATA state. + //- Write processor ids for each line as CellData or for each point + //- as PointData, depending on isPointData() state. No-op in serial. bool writeProcIDs(); //- Write processor neighbour ids as CellData. This is no-op in serial. diff --git a/tutorials/lagrangian/kinematicParcelFoam/drippingChair/Allrun b/tutorials/lagrangian/kinematicParcelFoam/drippingChair/Allrun index d5c14d149d..fb94a6e0b0 100755 --- a/tutorials/lagrangian/kinematicParcelFoam/drippingChair/Allrun +++ b/tutorials/lagrangian/kinematicParcelFoam/drippingChair/Allrun @@ -3,19 +3,30 @@ cd "${0%/*}" || exit # Run from this directory . ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions #------------------------------------------------------------------------------ +unset decompDict +# decompDict=system/decomposeParDict-6 +# decompDict=system/decomposeParDict-7 + runApplication blockMesh runApplication makeFaMesh -runApplication decomposePar +runApplication -decompose-dict="$decompDict" decomposePar -# For the processor partitioning -runParallel -s finiteVolume foamToVTK -name VTK-parallel -time 0 \ - -no-finite-area -no-internal -no-lagrangian -no-fields -with-ids +# For ids and processor partitioning +runParallel -s volume -decompose-dict="$decompDict" \ + foamToVTK -name VTK-parallel -time 0 \ + -no-finite-area -no-internal -no-lagrangian -no-fields -with-ids \ + -patches filmWalls -runParallel $(getApplication) +runParallel -decompose-dict="$decompDict" $(getApplication) -runParallel -s finiteArea foamToVTK -name VTK-parallel \ - -no-boundary -no-internal -no-lagrangian +if false +then + # Not usually needed - uses areaWrite + runParallel -s area -decompose-dict="$decompDict" \ + foamToVTK -name VTK-parallel \ + -no-boundary -no-internal -no-lagrangian -with-ids +fi #------------------------------------------------------------------------------ diff --git a/tutorials/lagrangian/kinematicParcelFoam/drippingChair/Allrun-serial b/tutorials/lagrangian/kinematicParcelFoam/drippingChair/Allrun-serial index 7e8c9929a1..083597c8e8 100755 --- a/tutorials/lagrangian/kinematicParcelFoam/drippingChair/Allrun-serial +++ b/tutorials/lagrangian/kinematicParcelFoam/drippingChair/Allrun-serial @@ -7,13 +7,18 @@ runApplication blockMesh runApplication makeFaMesh -# For the cell ids etc -runApplication -s finiteVolume.serial foamToVTK -name VTK-serial -time 0 \ - -no-finite-area -no-internal -no-lagrangian -no-fields -with-ids +# For ids and processor partitioning +runApplication -s volume.serial foamToVTK -name VTK-serial -time 0 \ + -no-finite-area -no-internal -no-lagrangian -no-fields -with-ids \ + -patches filmWalls runApplication $(getApplication) -runApplication -s finiteArea.serial foamToVTK -name VTK-serial \ - -no-boundary -no-internal -no-lagrangian +if false +then + # Not usually needed - uses areaWrite + runApplication -s area.serial foamToVTK -name VTK-serial \ + -no-boundary -no-internal -no-lagrangian +fi #------------------------------------------------------------------------------ diff --git a/tutorials/lagrangian/kinematicParcelFoam/drippingChair/system/areaWrite b/tutorials/lagrangian/kinematicParcelFoam/drippingChair/system/areaWrite new file mode 100644 index 0000000000..3efb160c88 --- /dev/null +++ b/tutorials/lagrangian/kinematicParcelFoam/drippingChair/system/areaWrite @@ -0,0 +1,25 @@ +// -*- C++ -*- +// Use the areaWrite function object + +areaWrite +{ + type areaWrite; + libs (utilityFunctionObjects); + log true; + + writeControl writeTime; + writeInterval 1; + + // Fields to output (words or regex) + fields (Uf_film hf_film pf_film); + + surfaceFormat ensight; + + formatOptions + { + default { format binary; } + } +} + + +// ************************************************************************* // diff --git a/tutorials/lagrangian/kinematicParcelFoam/drippingChair/system/controlDict b/tutorials/lagrangian/kinematicParcelFoam/drippingChair/system/controlDict index 90570e4629..1127a202e5 100644 --- a/tutorials/lagrangian/kinematicParcelFoam/drippingChair/system/controlDict +++ b/tutorials/lagrangian/kinematicParcelFoam/drippingChair/system/controlDict @@ -52,5 +52,10 @@ regionFaMaxCo 1; maxDeltaT 0.1; +functions +{ + #include "areaWrite" +} + // ************************************************************************* // diff --git a/tutorials/lagrangian/kinematicParcelFoam/drippingChair/system/decomposeParDict-6 b/tutorials/lagrangian/kinematicParcelFoam/drippingChair/system/decomposeParDict-6 new file mode 100644 index 0000000000..34b03d9320 --- /dev/null +++ b/tutorials/lagrangian/kinematicParcelFoam/drippingChair/system/decomposeParDict-6 @@ -0,0 +1,21 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2306 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object decomposeParDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +numberOfSubdomains 6; + +method scotch; + +// ************************************************************************* // diff --git a/tutorials/lagrangian/kinematicParcelFoam/drippingChair/system/decomposeParDict-7 b/tutorials/lagrangian/kinematicParcelFoam/drippingChair/system/decomposeParDict-7 new file mode 100644 index 0000000000..2e873a3493 --- /dev/null +++ b/tutorials/lagrangian/kinematicParcelFoam/drippingChair/system/decomposeParDict-7 @@ -0,0 +1,21 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2306 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object decomposeParDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +numberOfSubdomains 7; + +method scotch; + +// ************************************************************************* //