From dfc9a8923a07b6f75b4d05d2e69c9245a2a0f3d4 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 13 May 2024 18:57:38 +0200 Subject: [PATCH] ENH: read support for EnSight single-file transient (#3154) - the ensightReadFile init() now automatically sets up binary/ascii (for geometry files) and checks for the transient "BEGIN TIME STEP" marker. If found, will also populate the file offsets for each of the timesteps. If no corresponding footer is found (which would be very inefficient), it simply pretends that there is only a single time step instead of performing a costly file scan. - parsing of the ensight case file now also supports the use of filename numbers: as an alternative to filename start number: filename increment: - improved parsing robustness of "time values:" entry. Can now also have contents on the same line as the introducer. ENH: base-level adjustments for writing transient single-file - beginGeometry() is now separated out from file creation. - in append mode, ensightFile and ensightGeoFile will attempt to parse existing time-step information. --- applications/test/ensightFile/Make/files | 3 - applications/test/ensightFile/Make/options | 8 - applications/test/ensightFile1/Make/files | 3 + applications/test/ensightFile1/Make/options | 5 + .../test/ensightFile1/Test-ensightFile1.cxx | 137 ++++ applications/test/ensightFileName/Make/files | 3 + .../test/ensightFileName/Make/options | 5 + .../Test-ensightFileName.cxx} | 4 +- .../ensightToFoam/ensightMeshReader.C | 399 +++++----- .../foamToEnsight/foamToEnsight.C | 6 +- src/fileFormats/ensight/file/ensightCase.C | 69 +- src/fileFormats/ensight/file/ensightCase.H | 28 +- src/fileFormats/ensight/file/ensightCaseI.H | 4 +- .../ensight/file/ensightCaseTemplates.C | 31 +- src/fileFormats/ensight/file/ensightFile.C | 331 +++++++-- src/fileFormats/ensight/file/ensightFile.H | 140 +++- src/fileFormats/ensight/file/ensightGeoFile.C | 119 ++- src/fileFormats/ensight/file/ensightGeoFile.H | 84 ++- src/fileFormats/ensight/mesh/ensightMesh.C | 5 + src/fileFormats/ensight/mesh/ensightMesh.H | 5 +- .../ensight/name/ensightFileName.H | 7 +- .../ensight/name/ensightFileNameI.H | 14 +- src/fileFormats/ensight/name/ensightVarName.H | 7 +- .../ensight/name/ensightVarNameI.H | 15 +- .../ensight/part/cells/ensightCells.H | 2 + .../ensight/part/faces/ensightFaces.C | 2 +- .../ensight/part/faces/ensightFaces.H | 1 + .../ensight/part/part/ensightPart.C | 4 +- .../ensight/part/part/ensightPart.H | 4 +- .../part/surface/ensightOutputSurface.H | 16 +- .../ensight/read/ensightReadFile.C | 485 ++++++++++--- .../ensight/read/ensightReadFile.H | 121 +++- src/finiteArea/output/ensight/ensightFaMesh.C | 7 +- src/finiteArea/output/ensight/ensightFaMesh.H | 9 +- .../ensightCloud/ensightCloudWriteObject.cxx | 5 + .../utilities/ensightWrite/ensightWrite.C | 2 +- .../ensight/ensightCoordSetWriterCollated.C | 16 +- .../ensight/ensightCoordSetWriterUncollated.C | 12 +- .../readers/ensight/ensightSurfaceReader.C | 685 +++++++++++++----- .../readers/ensight/ensightSurfaceReader.H | 76 +- .../ensight/ensightSurfaceReaderTemplates.C | 52 +- .../ensight/ensightSurfaceWriterCollated.C | 19 +- .../ensight/ensightSurfaceWriterUncollated.C | 60 +- 43 files changed, 2135 insertions(+), 875 deletions(-) delete mode 100644 applications/test/ensightFile/Make/files delete mode 100644 applications/test/ensightFile/Make/options create mode 100644 applications/test/ensightFile1/Make/files create mode 100644 applications/test/ensightFile1/Make/options create mode 100644 applications/test/ensightFile1/Test-ensightFile1.cxx create mode 100644 applications/test/ensightFileName/Make/files create mode 100644 applications/test/ensightFileName/Make/options rename applications/test/{ensightFile/Test-ensightFile.C => ensightFileName/Test-ensightFileName.cxx} (96%) diff --git a/applications/test/ensightFile/Make/files b/applications/test/ensightFile/Make/files deleted file mode 100644 index 856556c316..0000000000 --- a/applications/test/ensightFile/Make/files +++ /dev/null @@ -1,3 +0,0 @@ -Test-ensightFile.C - -EXE = $(FOAM_USER_APPBIN)/Test-ensightFile diff --git a/applications/test/ensightFile/Make/options b/applications/test/ensightFile/Make/options deleted file mode 100644 index 6684cce1e7..0000000000 --- a/applications/test/ensightFile/Make/options +++ /dev/null @@ -1,8 +0,0 @@ -EXE_INC = \ - -I$(LIB_SRC)/fileFormats/lnInclude \ - -I$(LIB_SRC)/meshTools/lnInclude \ - -I$(LIB_SRC)/conversion/lnInclude - -EXE_LIBS = \ - -lmeshTools \ - -lconversion diff --git a/applications/test/ensightFile1/Make/files b/applications/test/ensightFile1/Make/files new file mode 100644 index 0000000000..aa5fb56152 --- /dev/null +++ b/applications/test/ensightFile1/Make/files @@ -0,0 +1,3 @@ +Test-ensightFile1.cxx + +EXE = $(FOAM_USER_APPBIN)/Test-ensightFile1 diff --git a/applications/test/ensightFile1/Make/options b/applications/test/ensightFile1/Make/options new file mode 100644 index 0000000000..7ce182425d --- /dev/null +++ b/applications/test/ensightFile1/Make/options @@ -0,0 +1,5 @@ +EXE_INC = \ + -I$(LIB_SRC)/fileFormats/lnInclude + +EXE_LIBS = \ + -lfileFormats diff --git a/applications/test/ensightFile1/Test-ensightFile1.cxx b/applications/test/ensightFile1/Test-ensightFile1.cxx new file mode 100644 index 0000000000..9be1b4f3ab --- /dev/null +++ b/applications/test/ensightFile1/Test-ensightFile1.cxx @@ -0,0 +1,137 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2024 OpenCFD Ltd. +------------------------------------------------------------------------------- +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 . + +Application + Test-ensightFile + +Description + check cleanup of ensight file and variable names + +\*---------------------------------------------------------------------------*/ + +#include "argList.H" +#include "ensightFile.H" +#include "ensightGeoFile.H" +#include "Switch.H" +#include "IOstreams.H" + +using namespace Foam; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Main program: + +int main(int argc, char *argv[]) +{ + argList::noBanner(); + argList::noParallel(); + argList::addBoolOption("ascii", "open as ascii instead of binary"); + argList::addBoolOption("binary", "(default)"); + argList::addBoolOption("clear", "force clear of time-steps"); + argList::addBoolOption("no-end", "skip use of endTimeStep"); + argList::addBoolOption("append", "open in append mode"); + argList::addOption("geom", "geometry file"); + argList::addOption("field", "field file"); + + #include "setRootCase.H" + + const bool with_ascii = args.found("ascii") && !args.found("binary"); + // const bool with_binary = args.found("binary"); + const bool with_append = args.found("append"); + const bool with_clear = args.found("clear"); + const bool without_end = args.found("no-end"); + + const IOstreamOption::streamFormat fmt = + ( + with_ascii + ? IOstreamOption::ASCII + : IOstreamOption::BINARY + ); + + const IOstreamOption::appendType append = + ( + with_append + ? IOstreamOption::APPEND_ATE + : IOstreamOption::NO_APPEND + ); + + + fileName file; + if (args.readIfPresent("geom", file)) + { + Info<< "Open " << file << " as geometry " + << " format:" << (with_ascii ? "ASCII" : "BINARY") + << " append:" << Switch::name(with_append) << nl; + + ensightGeoFile ensFile(append, file, fmt); + + if (append) + { + ensFile.beginTimeStep(); + + // At the moment need to pair begin/end time-step calls + if (!without_end) + { + ensFile.endTimeStep(); + } + } + + if (with_clear) + { + ensFile.clearTimeSteps(); + } + } + + if (args.readIfPresent("field", file)) + { + Info<< "Open " << file << " as field" + << " format:" << (with_ascii ? "ASCII" : "BINARY") + << " append:" << Switch::name(with_append) << nl; + + ensightFile ensFile(append, file, fmt); + + if (append) + { + ensFile.beginTimeStep(); + + // At the moment need to pair begin/end time-step calls + if (!without_end) + { + ensFile.endTimeStep(); + } + } + + if (with_clear) + { + ensFile.clearTimeSteps(); + } + } + + + Info<< "\nEnd\n" << endl; + return 0; +} + + +// ************************************************************************* // diff --git a/applications/test/ensightFileName/Make/files b/applications/test/ensightFileName/Make/files new file mode 100644 index 0000000000..f2b4af2f48 --- /dev/null +++ b/applications/test/ensightFileName/Make/files @@ -0,0 +1,3 @@ +Test-ensightFileName.cxx + +EXE = $(FOAM_USER_APPBIN)/Test-ensightFileName diff --git a/applications/test/ensightFileName/Make/options b/applications/test/ensightFileName/Make/options new file mode 100644 index 0000000000..7ce182425d --- /dev/null +++ b/applications/test/ensightFileName/Make/options @@ -0,0 +1,5 @@ +EXE_INC = \ + -I$(LIB_SRC)/fileFormats/lnInclude + +EXE_LIBS = \ + -lfileFormats diff --git a/applications/test/ensightFile/Test-ensightFile.C b/applications/test/ensightFileName/Test-ensightFileName.cxx similarity index 96% rename from applications/test/ensightFile/Test-ensightFile.C rename to applications/test/ensightFileName/Test-ensightFileName.cxx index 927bb84545..57bcc306a6 100644 --- a/applications/test/ensightFile/Test-ensightFile.C +++ b/applications/test/ensightFileName/Test-ensightFileName.cxx @@ -24,10 +24,10 @@ License along with OpenFOAM. If not, see . Application - Test-ensightFile + Test-ensightFileName Description - check cleanup of ensight file and variable names + Check cleanup of ensight file and variable names \*---------------------------------------------------------------------------*/ diff --git a/applications/utilities/mesh/conversion/ensightToFoam/ensightMeshReader.C b/applications/utilities/mesh/conversion/ensightToFoam/ensightMeshReader.C index 91be645d68..85de497991 100644 --- a/applications/utilities/mesh/conversion/ensightToFoam/ensightMeshReader.C +++ b/applications/utilities/mesh/conversion/ensightToFoam/ensightMeshReader.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2022-2023 OpenCFD Ltd. + Copyright (C) 2022-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -93,29 +93,34 @@ void Foam::fileFormats::ensightMeshReader::readIDs ( ensightReadFile& is, const bool doRead, - const label nShapes, + const label elemCount, labelList& foamToElem, Map