From cb416fb3ec92f87e2d6ce6fa6898bfcda0147b33 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 1 Feb 2024 12:41:37 +0100 Subject: [PATCH] ENH: add ensight writeBox method (eg, for simple 'placeholder' geometry) - related to issue #3095. Some type of geometry is required when loading "measured" ensight data. ENH: emit a fallback geometry-box for foamToEnsight - eg, with "foamToEnsight -no-internal -no-boundary" and lagrangian --- src/fileFormats/ensight/mesh/ensightMesh.C | 15 ++++++- src/fileFormats/ensight/mesh/ensightMesh.H | 14 ++++--- .../ensight/part/cells/ensightCells.H | 13 +++++- .../ensight/part/cells/ensightCellsIO.C | 42 ++++++++++++++++++- src/finiteArea/output/ensight/ensightFaMesh.H | 4 +- 5 files changed, 78 insertions(+), 10 deletions(-) diff --git a/src/fileFormats/ensight/mesh/ensightMesh.C b/src/fileFormats/ensight/mesh/ensightMesh.C index 8681c14abb..d57478fa2d 100644 --- a/src/fileFormats/ensight/mesh/ensightMesh.C +++ b/src/fileFormats/ensight/mesh/ensightMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -449,6 +449,19 @@ void Foam::ensightMesh::write { faceZoneParts_[id].write(os, mesh_, parallel); } + + // No geometry parts written? + // - with lagrangian-only output the VTK EnsightReader still + // needs a volume geometry, and ensight usually does too + if + ( + cellZoneParts_.empty() + && boundaryParts_.empty() + && faceZoneParts_.empty() + ) + { + ensightCells::writeBox(os, mesh_.bounds()); + } } diff --git a/src/fileFormats/ensight/mesh/ensightMesh.H b/src/fileFormats/ensight/mesh/ensightMesh.H index fb61d716eb..a0cc1cbf54 100644 --- a/src/fileFormats/ensight/mesh/ensightMesh.H +++ b/src/fileFormats/ensight/mesh/ensightMesh.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -216,18 +216,22 @@ public: // Output - //- Write geometry to file. Normally in parallel + //- Write geometry to file (normally in parallel). + // If all geometry is disabled, it will simply writes the mesh + // bounding box (to ensure that the geometry file is non-empty) void write ( ensightGeoFile& os, - bool parallel = Pstream::parRun() + bool parallel = UPstream::parRun() ) const; - //- Write geometry to file. Normally in parallel + //- Write geometry to file (normally in parallel). + // If all geometry is disabled, it will simply writes the mesh + // bounding box (to ensure that the geometry file is non-empty) inline void write ( autoPtr& os, - bool parallel = Pstream::parRun() + bool parallel = UPstream::parRun() ) const; }; diff --git a/src/fileFormats/ensight/part/cells/ensightCells.H b/src/fileFormats/ensight/part/cells/ensightCells.H index ac64cd0d81..5b2197a206 100644 --- a/src/fileFormats/ensight/part/cells/ensightCells.H +++ b/src/fileFormats/ensight/part/cells/ensightCells.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -46,6 +46,7 @@ namespace Foam // Forward Declarations class bitSet; +class boundBox; class polyMesh; template class InfoProxy; @@ -279,6 +280,16 @@ public: const polyMesh& mesh, bool parallel ) const; + + //- Write bounding box geometry. + //- All parameters are only relevant on master + static void writeBox + ( + ensightGeoFile& os, + const boundBox& bb, + const label partIndex = 0, + const word& partName = "geometry-box" + ); }; diff --git a/src/fileFormats/ensight/part/cells/ensightCellsIO.C b/src/fileFormats/ensight/part/cells/ensightCellsIO.C index f45f70a417..2223861df6 100644 --- a/src/fileFormats/ensight/part/cells/ensightCellsIO.C +++ b/src/fileFormats/ensight/part/cells/ensightCellsIO.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,7 +28,9 @@ License #include "ensightCells.H" #include "ensightOutput.H" #include "InfoProxy.H" +#include "boundBox.H" #include "polyMesh.H" +#include "cellModel.H" #include "globalIndex.H" #include "globalMeshData.H" #include "manifoldCellsMeshObject.H" @@ -330,6 +332,44 @@ void Foam::ensightCells::write } +void Foam::ensightCells::writeBox +( + ensightGeoFile& os, + const boundBox& bb, + const label partIndex, + const word& partName +) +{ + pointField points; + cellShapeList shapes; + + if (UPstream::master()) + { + points = bb.hexCorners(); + shapes.emplace_back(cellModel::HEX, identity(8)); + } + + ensightOutput::Detail::writeCoordinates + ( + os, + partIndex, + partName, + 8, // nPoints (global) + points, + false // serial only! (parallel=false) + ); + + if (UPstream::master()) + { + os.writeKeyword(ensightCells::key(ensightCells::elemType::HEXA8)); + os.write(shapes.size()); // one cell (global) + os.newline(); + + ensightOutput::writeCellShapes(os, shapes); + } +} + + // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // template<> diff --git a/src/finiteArea/output/ensight/ensightFaMesh.H b/src/finiteArea/output/ensight/ensightFaMesh.H index 394b4d5463..ce3deb7534 100644 --- a/src/finiteArea/output/ensight/ensightFaMesh.H +++ b/src/finiteArea/output/ensight/ensightFaMesh.H @@ -148,14 +148,14 @@ public: void write ( ensightGeoFile& os, - bool parallel = Pstream::parRun() + bool parallel = UPstream::parRun() ) const; //- Write geometry to file. Normally in parallel inline void write ( autoPtr& os, - bool parallel = Pstream::parRun() + bool parallel = UPstream::parRun() ) const; };