From 0a78e685eecb9c84888e59f890dfdea422b5c24b Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 5 May 2021 16:08:00 +0200 Subject: [PATCH] ENH: introduce intermediate vtk::polyWriter class - reduces code, simplifies creation of new, specialized polyData writers. - new templated vtk::GenericPatchWriter, which adds support for writing both uindirectPrimitivePatch + indirectPrimitivePatch types. - handle geometric fields separately from regular fields with * vtk:GenericPatchGeoFieldsWriter * vtk:indirectPatchGeoFieldsWriter * vtk:uindirectPatchGeoFieldsWriter --- .../foamToVTK/convertAreaFields.H | 4 +- .../foamToVTK/convertSurfaceFields.H | 6 +- .../dataConversion/foamToVTK/foamToVTK.C | 1 + .../foamToVTK/writeAreaFields.H | 13 +- .../foamToVTK/writeSurfaceFields.H | 57 +++ src/conversion/vtk/adaptor/foamVtkTools.H | 4 +- .../vtk/adaptor/foamVtkVtuAdaptor.H | 4 +- ...C => foamVtkGenericPatchGeoFieldsWriter.C} | 42 +- .../foamVtkGenericPatchGeoFieldsWriter.H | 123 ++++++ .../output/foamVtkIndPatchGeoFieldsWriter.H | 68 ++++ .../vtk/output/foamVtkInternalWriter.H | 4 +- .../output/foamVtkInternalWriterTemplates.C | 20 +- .../vtk/output/foamVtkPatchWriter.H | 6 +- .../vtk/output/foamVtkPatchWriterTemplates.C | 60 ++- .../vtk/output/foamVtkSurfaceFieldWriter.C | 8 +- .../vtk/output/foamVtkSurfaceFieldWriter.H | 4 +- .../vtk/output/foamVtkSurfaceMeshWriter.H | 128 +----- .../output/foamVtkUIndPatchGeoFieldsWriter.H | 68 ++++ .../interfaceTrackingFvMesh/Make/options | 2 + .../interfaceTrackingFvMesh.C | 119 ++---- src/fileFormats/Make/files | 1 + src/fileFormats/vtk/base/foamVtkCore.H | 4 +- src/fileFormats/vtk/base/foamVtkPTraits.H | 4 +- src/fileFormats/vtk/file/foamVtkFileWriter.C | 62 +-- src/fileFormats/vtk/file/foamVtkFileWriter.H | 29 +- src/fileFormats/vtk/file/foamVtkFileWriterI.H | 8 +- .../vtk/file/foamVtkFileWriterTemplates.C | 77 +++- .../vtk/file/foamVtkSeriesWriter.H | 4 +- src/fileFormats/vtk/file/foamVtmWriter.H | 4 +- .../vtk/format/foamVtkAppendBase64Formatter.H | 4 +- .../vtk/format/foamVtkAppendRawFormatter.H | 4 +- .../vtk/format/foamVtkAsciiFormatter.H | 4 +- .../vtk/format/foamVtkBase64Formatter.H | 4 +- .../vtk/format/foamVtkBase64Layer.H | 4 +- src/fileFormats/vtk/format/foamVtkFormatter.H | 4 +- .../vtk/format/foamVtkLegacyAsciiFormatter.H | 4 +- .../vtk/format/foamVtkLegacyRawFormatter.H | 4 +- src/fileFormats/vtk/output/foamVtkOutput.H | 4 +- .../vtk/output/foamVtkOutputOptions.H | 4 +- src/fileFormats/vtk/part/foamVtkMeshMaps.H | 4 +- src/fileFormats/vtk/part/foamVtuCells.H | 4 +- src/fileFormats/vtk/part/foamVtuSizing.H | 4 +- .../vtk/write/foamVtkPolyWriter.C} | 103 ++--- .../vtk/write/foamVtkPolyWriter.H} | 91 +++-- ...mplates.C => foamVtkPolyWriterTemplates.C} | 108 ++---- .../vtk/write/foamVtkSurfaceWriter.C | 366 +----------------- .../vtk/write/foamVtkSurfaceWriter.H | 88 +---- .../conversion/vtk/foamVtkLagrangianWriter.C | 2 +- .../conversion/vtk/foamVtkLagrangianWriter.H | 4 +- .../vtk/foamVtkLagrangianWriterTemplates.C | 84 +--- src/meshTools/Make/files | 14 +- .../output/foamVtkIndPatchWriterTemplates.C | 156 -------- .../mesh}/foamVtkInternalMeshWriter.C | 27 +- .../mesh}/foamVtkInternalMeshWriter.H | 20 +- .../foamVtkInternalMeshWriterTemplates.C | 17 +- .../vtk/patch/foamVtkGenericPatchWriter.C | 53 +++ .../vtk/patch/foamVtkGenericPatchWriter.H | 182 +++++++++ .../output/vtk/patch/foamVtkIndPatchWriter.H | 67 ++++ .../{ => vtk/patch}/foamVtkPatchMeshWriter.C | 70 ++-- .../{ => vtk/patch}/foamVtkPatchMeshWriter.H | 16 +- .../patch}/foamVtkPatchMeshWriterTemplates.C | 0 .../vtk/patch/foamVtkPrimitivePatchWriter.H | 67 ++++ .../output/vtk/patch/foamVtkUIndPatchWriter.H | 67 ++++ .../topoSet}/foamVtkWriteCellSetFaces.C | 0 .../{ => vtk/topoSet}/foamVtkWriteFaceSet.C | 0 .../{ => vtk/topoSet}/foamVtkWritePointSet.C | 0 .../{ => vtk/topoSet}/foamVtkWriteTopoSet.C | 0 .../{ => vtk/topoSet}/foamVtkWriteTopoSet.H | 4 +- 68 files changed, 1281 insertions(+), 1311 deletions(-) create mode 100644 applications/utilities/postProcessing/dataConversion/foamToVTK/writeSurfaceFields.H rename src/conversion/vtk/output/{foamVtkSurfaceMeshWriterTemplates.C => foamVtkGenericPatchGeoFieldsWriter.C} (70%) create mode 100644 src/conversion/vtk/output/foamVtkGenericPatchGeoFieldsWriter.H create mode 100644 src/conversion/vtk/output/foamVtkIndPatchGeoFieldsWriter.H create mode 100644 src/conversion/vtk/output/foamVtkUIndPatchGeoFieldsWriter.H rename src/{meshTools/output/foamVtkIndPatchWriter.C => fileFormats/vtk/write/foamVtkPolyWriter.C} (81%) rename src/{meshTools/output/foamVtkIndPatchWriter.H => fileFormats/vtk/write/foamVtkPolyWriter.H} (74%) rename src/fileFormats/vtk/write/{foamVtkSurfaceWriterTemplates.C => foamVtkPolyWriterTemplates.C} (51%) delete mode 100644 src/meshTools/output/foamVtkIndPatchWriterTemplates.C rename src/meshTools/output/{ => vtk/mesh}/foamVtkInternalMeshWriter.C (96%) rename src/meshTools/output/{ => vtk/mesh}/foamVtkInternalMeshWriter.H (98%) rename src/meshTools/output/{ => vtk/mesh}/foamVtkInternalMeshWriterTemplates.C (87%) create mode 100644 src/meshTools/output/vtk/patch/foamVtkGenericPatchWriter.C create mode 100644 src/meshTools/output/vtk/patch/foamVtkGenericPatchWriter.H create mode 100644 src/meshTools/output/vtk/patch/foamVtkIndPatchWriter.H rename src/meshTools/output/{ => vtk/patch}/foamVtkPatchMeshWriter.C (91%) rename src/meshTools/output/{ => vtk/patch}/foamVtkPatchMeshWriter.H (99%) rename src/meshTools/output/{ => vtk/patch}/foamVtkPatchMeshWriterTemplates.C (100%) create mode 100644 src/meshTools/output/vtk/patch/foamVtkPrimitivePatchWriter.H create mode 100644 src/meshTools/output/vtk/patch/foamVtkUIndPatchWriter.H rename src/meshTools/output/{ => vtk/topoSet}/foamVtkWriteCellSetFaces.C (100%) rename src/meshTools/output/{ => vtk/topoSet}/foamVtkWriteFaceSet.C (100%) rename src/meshTools/output/{ => vtk/topoSet}/foamVtkWritePointSet.C (100%) rename src/meshTools/output/{ => vtk/topoSet}/foamVtkWriteTopoSet.C (100%) rename src/meshTools/output/{ => vtk/topoSet}/foamVtkWriteTopoSet.H (98%) diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertAreaFields.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertAreaFields.H index 86ff61c939..9f4b8fc684 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertAreaFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertAreaFields.H @@ -26,6 +26,8 @@ License Description Code chunk for converting finite-area - included by foamToVTK. + Typedef vtkWriterType_areaMesh is declared in writeAreaFields.H + \*---------------------------------------------------------------------------*/ // @@ -62,7 +64,7 @@ if (doFiniteArea) const auto& pp = faMeshPtr->patch(); - vtk::surfaceMeshWriter writer + vtkWriterType_areaMesh writer ( pp, writeOpts, diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertSurfaceFields.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertSurfaceFields.H index fda629528b..0681e103b3 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/convertSurfaceFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/convertSurfaceFields.H @@ -194,13 +194,13 @@ Description continue; } - indirectPrimitivePatch pp + uindirectPrimitivePatch pp ( - IndirectList(mesh.faces(), fz), + UIndirectList(mesh.faces(), fz), mesh.points() ); - vtk::surfaceMeshWriter writer + vtkWriterType_faceZone writer ( pp, writeOpts, diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C index f31a51d85f..eb498a1eca 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C @@ -160,6 +160,7 @@ Note #include "writeDimFields.H" #include "writeVolFields.H" #include "writePointFields.H" +#include "writeSurfaceFields.H" #include "memInfo.H" diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/writeAreaFields.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/writeAreaFields.H index 2ddb99d44b..959881e65a 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/writeAreaFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/writeAreaFields.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -39,17 +39,20 @@ SourceFiles #define writeAreaFields_H #include "readFields.H" -#include "foamVtkSurfaceMeshWriter.H" +#include "foamVtkIndPatchGeoFieldsWriter.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { +// Writer type for finite-area mesh + fields +typedef vtk::indirectPatchGeoFieldsWriter vtkWriterType_areaMesh; + template bool writeAreaField ( - vtk::surfaceMeshWriter& writer, + vtkWriterType_areaMesh& writer, const tmp& tfield ) { @@ -68,7 +71,7 @@ bool writeAreaField template label writeAreaFields ( - vtk::surfaceMeshWriter& writer, + vtkWriterType_areaMesh& writer, const typename GeoField::Mesh& mesh, const IOobjectList& objects, const bool syncPar @@ -97,7 +100,7 @@ label writeAreaFields label writeAllAreaFields ( - vtk::surfaceMeshWriter& writer, + vtkWriterType_areaMesh& writer, const faMesh& mesh, const IOobjectList& objects, const bool syncPar diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/writeSurfaceFields.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/writeSurfaceFields.H new file mode 100644 index 0000000000..ef67527831 --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/writeSurfaceFields.H @@ -0,0 +1,57 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2021 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 . + +InNamespace + Foam + +Description + Write surface fields from volume mesh + +SourceFiles + writeSurfaceFields.H + +\*---------------------------------------------------------------------------*/ + +#ifndef writeSurfaceFields_H +#define writeSurfaceFields_H + +#include "readFields.H" +#include "foamVtkUIndPatchGeoFieldsWriter.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Writer type for face zones + fields +typedef vtk::uindirectPatchGeoFieldsWriter vtkWriterType_faceZone; + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/conversion/vtk/adaptor/foamVtkTools.H b/src/conversion/vtk/adaptor/foamVtkTools.H index 9f279076e2..6a20fe1c74 100644 --- a/src/conversion/vtk/adaptor/foamVtkTools.H +++ b/src/conversion/vtk/adaptor/foamVtkTools.H @@ -43,8 +43,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef foamVtkTools_H -#define foamVtkTools_H +#ifndef Foam_vtk_vtkTools_H +#define Foam_vtk_vtkTools_H #include "faceList.H" #include "pointField.H" diff --git a/src/conversion/vtk/adaptor/foamVtkVtuAdaptor.H b/src/conversion/vtk/adaptor/foamVtkVtuAdaptor.H index 57a624256c..8af6644317 100644 --- a/src/conversion/vtk/adaptor/foamVtkVtuAdaptor.H +++ b/src/conversion/vtk/adaptor/foamVtkVtuAdaptor.H @@ -43,8 +43,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef foamVtk_vtuAdaptor_H -#define foamVtk_vtuAdaptor_H +#ifndef Foam_vtk_vtuAdaptor_H +#define Foam_vtk_vtuAdaptor_H #include "fvMesh.H" #include "volFieldsFwd.H" diff --git a/src/conversion/vtk/output/foamVtkSurfaceMeshWriterTemplates.C b/src/conversion/vtk/output/foamVtkGenericPatchGeoFieldsWriter.C similarity index 70% rename from src/conversion/vtk/output/foamVtkSurfaceMeshWriterTemplates.C rename to src/conversion/vtk/output/foamVtkGenericPatchGeoFieldsWriter.C index 93f9df41c4..ff8c162b85 100644 --- a/src/conversion/vtk/output/foamVtkSurfaceMeshWriterTemplates.C +++ b/src/conversion/vtk/output/foamVtkGenericPatchGeoFieldsWriter.C @@ -5,8 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2018 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,9 +27,10 @@ License // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +template template Foam::tmp> -Foam::vtk::surfaceMeshWriter::getFaceField +Foam::vtk::GenericPatchGeoFieldsWriter::getFaceField ( const GeometricField& sfld ) const @@ -65,41 +65,33 @@ Foam::vtk::surfaceMeshWriter::getFaceField // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template template -void Foam::vtk::surfaceMeshWriter::write +void Foam::vtk::GenericPatchGeoFieldsWriter::write ( const GeometricField& field ) { - if (notState(outputState::CELL_DATA)) - { - FatalErrorInFunction - << "Bad writer state (" << stateNames[state_] - << ") - should be (" << stateNames[outputState::CELL_DATA] - << ") for field " << field.name() << nl << endl - << exit(FatalError); - } - - this->indirectPatchWriter::write(field.name(), getFaceField(field)()); + this->GenericPatchWriter::writeCellData + ( + field.name(), + getFaceField(field)() + ); } +template template -void Foam::vtk::surfaceMeshWriter::write +void Foam::vtk::GenericPatchGeoFieldsWriter::write ( const GeometricField& field ) { - if (notState(outputState::CELL_DATA)) - { - FatalErrorInFunction - << "Bad writer state (" << stateNames[state_] - << ") - should be (" << stateNames[outputState::CELL_DATA] - << ") for field " << field.name() << nl << endl - << exit(FatalError); - } - - this->indirectPatchWriter::write(field.name(), field.primitiveField()); + this->GenericPatchWriter::writeCellData + ( + field.name(), + field.primitiveField() + ); } diff --git a/src/conversion/vtk/output/foamVtkGenericPatchGeoFieldsWriter.H b/src/conversion/vtk/output/foamVtkGenericPatchGeoFieldsWriter.H new file mode 100644 index 0000000000..0ec42b092c --- /dev/null +++ b/src/conversion/vtk/output/foamVtkGenericPatchGeoFieldsWriter.H @@ -0,0 +1,123 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2021 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 . + +Class + Foam::vtk::GenericPatchGeoFieldsWriter + +Description + A Foam::vtk::GenericPatchWriter with support for geometric fields. + + Caution, currently only works properly for indirect patches. + +SourceFiles + foamVtkGenericPatchGeoFieldsWriter.C + +\*---------------------------------------------------------------------------*/ + +#ifndef Foam_vtk_GenericPatchGeoFieldsWriter_H +#define Foam_vtk_GenericPatchGeoFieldsWriter_H + +#include "areaFields.H" +#include "surfaceFields.H" +#include "foamVtkGenericPatchWriter.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace vtk +{ + +/*---------------------------------------------------------------------------*\ + Class vtk::GenericPatchGeoFieldsWriter Declaration +\*---------------------------------------------------------------------------*/ + +template +class GenericPatchGeoFieldsWriter +: + public vtk::GenericPatchWriter +{ + // Private Member Functions + + //- Get face field (internal face or boundary face) + template + tmp> getFaceField + ( + const GeometricField& sfld + ) const; + + + //- No copy construct + GenericPatchGeoFieldsWriter + ( + const GenericPatchGeoFieldsWriter& + ) = delete; + + //- No copy assignment + void operator=(const GenericPatchGeoFieldsWriter&) = delete; + +public: + + // Constructors + + //- Inherit constructors from GenericPatchWriter + using vtk::GenericPatchWriter::GenericPatchWriter; + + + // Member Functions + + //- Write volume-mesh surface field (CellData) + template + void write + ( + const GeometricField& field + ); + + //- Write area-mesh surface field (CellData) + template + void write + ( + const GeometricField& field + ); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace vtk +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "foamVtkGenericPatchGeoFieldsWriter.C" +#endif + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/conversion/vtk/output/foamVtkIndPatchGeoFieldsWriter.H b/src/conversion/vtk/output/foamVtkIndPatchGeoFieldsWriter.H new file mode 100644 index 0000000000..6f4691d0cf --- /dev/null +++ b/src/conversion/vtk/output/foamVtkIndPatchGeoFieldsWriter.H @@ -0,0 +1,68 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2021 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 . + +Typedef + Foam::vtk::indirectPatchGeoFieldsWriter + +Description + Write indirectPrimitivePatch faces/points + as a vtp file or a legacy vtk file + with support for geometric fields. + +See Also + Foam::vtk::GenericPatchWriter + +\*---------------------------------------------------------------------------*/ + +#ifndef Foam_vtk_IndPatchGeoFieldsWriter_H +#define Foam_vtk_IndPatchGeoFieldsWriter_H + +#include "foamVtkGenericPatchGeoFieldsWriter.H" +#include "indirectPrimitivePatch.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace vtk +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +typedef + GenericPatchGeoFieldsWriter + indirectPatchGeoFieldsWriter; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace vtk +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/conversion/vtk/output/foamVtkInternalWriter.H b/src/conversion/vtk/output/foamVtkInternalWriter.H index f172e60af3..5e29d2be47 100644 --- a/src/conversion/vtk/output/foamVtkInternalWriter.H +++ b/src/conversion/vtk/output/foamVtkInternalWriter.H @@ -48,8 +48,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef foamVtkInternalWriter_H -#define foamVtkInternalWriter_H +#ifndef Foam_vtk_internalWriter_H +#define Foam_vtk_internalWriter_H #include "foamVtkInternalMeshWriter.H" #include "volFields.H" diff --git a/src/conversion/vtk/output/foamVtkInternalWriterTemplates.C b/src/conversion/vtk/output/foamVtkInternalWriterTemplates.C index 4bd5d721da..a740e1a9c3 100644 --- a/src/conversion/vtk/output/foamVtkInternalWriterTemplates.C +++ b/src/conversion/vtk/output/foamVtkInternalWriterTemplates.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -44,10 +44,8 @@ void Foam::vtk::internalWriter::write } else { - FatalErrorInFunction - << "Bad writer state (" << stateNames[state_] - << ") - should be (" << stateNames[outputState::POINT_DATA] - << ") for field " << field.name() << nl << endl + reportBadState(FatalErrorInFunction, outputState::POINT_DATA) + << " for field " << field.name() << nl << endl << exit(FatalError); } @@ -135,10 +133,8 @@ void Foam::vtk::internalWriter::write } else { - FatalErrorInFunction - << "Bad writer state (" << stateNames[state_] - << ") - should be (" << stateNames[outputState::POINT_DATA] - << ") for field " << vfield.name() << nl << endl + reportBadState(FatalErrorInFunction, outputState::POINT_DATA) + << " for field " << vfield.name() << nl << endl << exit(FatalError); } @@ -204,10 +200,8 @@ void Foam::vtk::internalWriter::write } else { - FatalErrorInFunction - << "Bad writer state (" << stateNames[state_] - << ") - should be (" << stateNames[outputState::POINT_DATA] - << ") for field " << vfield.name() << nl << endl + reportBadState(FatalErrorInFunction, outputState::POINT_DATA) + << " for field " << vfield.name() << nl << endl << exit(FatalError); } diff --git a/src/conversion/vtk/output/foamVtkPatchWriter.H b/src/conversion/vtk/output/foamVtkPatchWriter.H index 1fa025e7bf..b6e5297706 100644 --- a/src/conversion/vtk/output/foamVtkPatchWriter.H +++ b/src/conversion/vtk/output/foamVtkPatchWriter.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -47,8 +47,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef foamVtkPatchWriter_H -#define foamVtkPatchWriter_H +#ifndef Foam_vtk_patchWriter_H +#define Foam_vtk_patchWriter_H #include "foamVtkPatchMeshWriter.H" #include "volFields.H" diff --git a/src/conversion/vtk/output/foamVtkPatchWriterTemplates.C b/src/conversion/vtk/output/foamVtkPatchWriterTemplates.C index 0e6cb9cebf..905290b49a 100644 --- a/src/conversion/vtk/output/foamVtkPatchWriterTemplates.C +++ b/src/conversion/vtk/output/foamVtkPatchWriterTemplates.C @@ -42,10 +42,8 @@ void Foam::vtk::patchWriter::write } else { - FatalErrorInFunction - << "Bad writer state (" << stateNames[state_] - << ") - should be (" << stateNames[outputState::POINT_DATA] - << ") for field " << field.name() << nl << endl + reportBadState(FatalErrorInFunction, outputState::POINT_DATA) + << " for field " << field.name() << nl << endl << exit(FatalError); } @@ -106,13 +104,13 @@ void Foam::vtk::patchWriter::write Field recv; // Receive each patch field and write - for (const int slave : Pstream::subProcs()) + for (const int subproci : Pstream::subProcs()) { - IPstream fromSlave(Pstream::commsTypes::blocking, slave); + IPstream fromProc(Pstream::commsTypes::blocking, subproci); for (label i=0; i < nPatches; ++i) { - fromSlave >> recv; + fromProc >> recv; vtk::writeList(format(), recv); } @@ -120,8 +118,8 @@ void Foam::vtk::patchWriter::write } else { - // Send each patch field to master - OPstream toMaster + // Send each patch field + OPstream toProc ( Pstream::commsTypes::blocking, Pstream::masterNo() @@ -135,11 +133,11 @@ void Foam::vtk::patchWriter::write const auto* vpp = isA>(pfld); if (vpp) { - toMaster << *vpp; + toProc << *vpp; } else { - toMaster << pfld.patchInternalField(); + toProc << pfld.patchInternalField(); } } } @@ -166,10 +164,8 @@ void Foam::vtk::patchWriter::write } else { - FatalErrorInFunction - << "Bad writer state (" << stateNames[state_] - << ") - should be (" << stateNames[outputState::CELL_DATA] - << ") for field " << field.name() << nl << endl + reportBadState(FatalErrorInFunction, outputState::CELL_DATA) + << " for field " << field.name() << nl << endl << exit(FatalError); } @@ -227,13 +223,13 @@ void Foam::vtk::patchWriter::write Field recv; // Receive each patch field and write - for (const int slave : Pstream::subProcs()) + for (const int subproci : Pstream::subProcs()) { - IPstream fromSlave(Pstream::commsTypes::blocking, slave); + IPstream fromProc(Pstream::commsTypes::blocking, subproci); for (label i=0; i < nPatches; ++i) { - fromSlave >> recv; + fromProc >> recv; vtk::writeList(format(), recv); } @@ -241,8 +237,8 @@ void Foam::vtk::patchWriter::write } else { - // Send each patch field to master - OPstream toMaster + // Send each patch field + OPstream toProc ( Pstream::commsTypes::blocking, Pstream::masterNo() @@ -254,11 +250,11 @@ void Foam::vtk::patchWriter::write if (useNearCellValue_) { - toMaster << pfld.patchInternalField()(); + toProc << pfld.patchInternalField()(); } else { - toMaster << static_cast&>(pfld); + toProc << static_cast&>(pfld); } } } @@ -286,10 +282,8 @@ void Foam::vtk::patchWriter::write } else { - FatalErrorInFunction - << "Bad writer state (" << stateNames[state_] - << ") - should be (" << stateNames[outputState::POINT_DATA] - << ") for field " << field.name() << nl << endl + reportBadState(FatalErrorInFunction, outputState::POINT_DATA) + << " for field " << field.name() << nl << endl << exit(FatalError); } @@ -356,13 +350,13 @@ void Foam::vtk::patchWriter::write Field recv; // Receive each patch field and write - for (const int slave : Pstream::subProcs()) + for (const int subproci : Pstream::subProcs()) { - IPstream fromSlave(Pstream::commsTypes::blocking, slave); + IPstream fromProc(Pstream::commsTypes::blocking, subproci); for (label i=0; i < nPatches; ++i) { - fromSlave >> recv; + fromProc >> recv; vtk::writeList(format(), recv); } @@ -370,8 +364,8 @@ void Foam::vtk::patchWriter::write } else { - // Send each patch field to master - OPstream toMaster + // Send each patch field + OPstream toProc ( Pstream::commsTypes::blocking, Pstream::masterNo() @@ -389,13 +383,13 @@ void Foam::vtk::patchWriter::write pfld.patchInternalField()() ); - toMaster << tfield(); + toProc << tfield(); } else { auto tfield = pInter.faceToPointInterpolate(pfld); - toMaster << tfield(); + toProc << tfield(); } } } diff --git a/src/conversion/vtk/output/foamVtkSurfaceFieldWriter.C b/src/conversion/vtk/output/foamVtkSurfaceFieldWriter.C index 8a9b3d256f..3cdd62314c 100644 --- a/src/conversion/vtk/output/foamVtkSurfaceFieldWriter.C +++ b/src/conversion/vtk/output/foamVtkSurfaceFieldWriter.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2018 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -231,10 +231,8 @@ void Foam::vtk::surfaceFieldWriter::write(const surfaceVectorField& field) } else { - FatalErrorInFunction - << "Bad writer state (" << stateNames[state_] - << ") - should be (" << stateNames[outputState::POINT_DATA] - << ") for field " << field.name() << nl << endl + reportBadState(FatalErrorInFunction, outputState::POINT_DATA) + << " for field " << field.name() << nl << endl << exit(FatalError); } diff --git a/src/conversion/vtk/output/foamVtkSurfaceFieldWriter.H b/src/conversion/vtk/output/foamVtkSurfaceFieldWriter.H index 77c1d9ac15..1dc5ca1c6d 100644 --- a/src/conversion/vtk/output/foamVtkSurfaceFieldWriter.H +++ b/src/conversion/vtk/output/foamVtkSurfaceFieldWriter.H @@ -51,8 +51,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef foamVtkSurfaceFieldWriter_H -#define foamVtkSurfaceFieldWriter_H +#ifndef Foam_vtk_surfaceFieldWriter_H +#define Foam_vtk_surfaceFieldWriter_H #include "foamVtkFileWriter.H" #include "fvMesh.H" diff --git a/src/conversion/vtk/output/foamVtkSurfaceMeshWriter.H b/src/conversion/vtk/output/foamVtkSurfaceMeshWriter.H index e49b3f339e..4acb3a19ab 100644 --- a/src/conversion/vtk/output/foamVtkSurfaceMeshWriter.H +++ b/src/conversion/vtk/output/foamVtkSurfaceMeshWriter.H @@ -5,8 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017 OpenCFD Ltd. + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -24,34 +23,24 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . -Class +Typedef Foam::vtk::surfaceMeshWriter Description - Write faces (eg face-zones or face-sets) with fields. + Alias for Foam::vtk::indirectPatchGeoFieldsWriter. - The file output states are managed by the Foam::vtk::fileWriter class. - FieldData (eg, TimeValue) must appear before any geometry pieces. + Write vtp file (or legacy vtk) with support for geometric fields. -Note - Parallel output is combined into a single Piece without point merging, - which is similar to using multi-piece data sets, but allows more - convenient creation as a streaming process. - In the future, the duplicate points at processor connections - may be addressed using ghost points. - -SourceFiles - foamVtkSurfaceMeshWriterTemplates.C +See Also + Foam::vtk::GenericPatchWriter \*---------------------------------------------------------------------------*/ -#ifndef foamVtkSurfaceMeshWriter_H -#define foamVtkSurfaceMeshWriter_H +#ifndef Foam_vtk_surfaceMeshWriter_H +#define Foam_vtk_surfaceMeshWriter_H -#include -#include "areaFields.H" -#include "surfaceFields.H" -#include "foamVtkIndPatchWriter.H" +#include "foamVtkGenericPatchGeoFieldsWriter.H" +#include "indirectPrimitivePatch.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -60,106 +49,17 @@ namespace Foam namespace vtk { -/*---------------------------------------------------------------------------*\ - Class vtk::surfaceMeshWriter Declaration -\*---------------------------------------------------------------------------*/ - -class surfaceMeshWriter -: - public vtk::indirectPatchWriter -{ - // Private Member Functions - - //- Get face field (internal face or boundary face) - template - tmp> getFaceField - ( - const GeometricField& sfld - ) const; - - - //- No copy construct - surfaceMeshWriter(const surfaceMeshWriter&) = delete; - - //- No copy assignment - void operator=(const surfaceMeshWriter&) = delete; - - -public: - - // Constructors - - //- Construct from patch (default format INLINE_BASE64) - surfaceMeshWriter - ( - const indirectPrimitivePatch& pp, - const vtk::outputOptions opts = vtk::formatType::INLINE_BASE64 - ) - : - vtk::indirectPatchWriter(pp, opts) - {} - - //- Construct from patch (default format INLINE_BASE64), - //- and open the file for writing. - // The file name is with/without an extension. - surfaceMeshWriter - ( - const indirectPrimitivePatch& pp, - const fileName& file, - bool parallel = Pstream::parRun() - ) - : - vtk::indirectPatchWriter(pp, file, parallel) - {} - - //- Construct from patch and open the file for writing. - // The file name is with/without an extension. - surfaceMeshWriter - ( - const indirectPrimitivePatch& pp, - const vtk::outputOptions opts, - const fileName& file, - bool parallel = Pstream::parRun() - ) - : - vtk::indirectPatchWriter(pp, opts, file, parallel) - {} - - - //- Destructor - virtual ~surfaceMeshWriter() = default; - - - // Member Functions - - //- Write surface field (CellData) - template - void write - ( - const GeometricField& field - ); - - //- Write surface field (CellData) - template - void write - ( - const GeometricField& field - ); -}; +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +typedef + GenericPatchGeoFieldsWriter + surfaceMeshWriter; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace vtk } // End namespace Foam -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#ifdef NoRepository - #include "foamVtkSurfaceMeshWriterTemplates.C" -#endif - - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif diff --git a/src/conversion/vtk/output/foamVtkUIndPatchGeoFieldsWriter.H b/src/conversion/vtk/output/foamVtkUIndPatchGeoFieldsWriter.H new file mode 100644 index 0000000000..30b5b5f63e --- /dev/null +++ b/src/conversion/vtk/output/foamVtkUIndPatchGeoFieldsWriter.H @@ -0,0 +1,68 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2021 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 . + +Typedef + Foam::vtk::uindirectPatchGeoFieldsWriter + +Description + Write uindirectPrimitivePatch faces/points + as a vtp file or a legacy vtk file + with support for geometric fields. + +See Also + Foam::vtk::GenericPatchWriter + +\*---------------------------------------------------------------------------*/ + +#ifndef Foam_vtk_UIndPatchGeoFieldsWriter_H +#define Foam_vtk_UIndPatchGeoFieldsWriter_H + +#include "foamVtkGenericPatchGeoFieldsWriter.H" +#include "uindirectPrimitivePatch.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace vtk +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +typedef + GenericPatchGeoFieldsWriter + uindirectPatchGeoFieldsWriter; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace vtk +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/dynamicFaMesh/interfaceTrackingFvMesh/Make/options b/src/dynamicFaMesh/interfaceTrackingFvMesh/Make/options index e3cea0e094..610b959b8b 100644 --- a/src/dynamicFaMesh/interfaceTrackingFvMesh/Make/options +++ b/src/dynamicFaMesh/interfaceTrackingFvMesh/Make/options @@ -5,6 +5,7 @@ EXE_INC = \ -I$(LIB_SRC)/transportModels/incompressible/singlePhaseTransportModel \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/finiteArea/lnInclude \ + -I$(LIB_SRC)/fileFormats/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/dynamicFvMesh/lnInclude \ -I$(LIB_SRC)/dynamicMesh/lnInclude \ @@ -17,6 +18,7 @@ LIB_LIBS = \ -lincompressibleTransportModels \ -lfiniteVolume \ -lfiniteArea \ + -lfileFormats \ -lmeshTools \ -ldynamicFvMesh \ -lfvMotionSolvers \ diff --git a/src/dynamicFaMesh/interfaceTrackingFvMesh/interfaceTrackingFvMesh.C b/src/dynamicFaMesh/interfaceTrackingFvMesh/interfaceTrackingFvMesh.C index 5eff990577..bf90e5220a 100644 --- a/src/dynamicFaMesh/interfaceTrackingFvMesh/interfaceTrackingFvMesh.C +++ b/src/dynamicFaMesh/interfaceTrackingFvMesh/interfaceTrackingFvMesh.C @@ -48,6 +48,7 @@ License #include "turbulentTransportModel.H" #include "demandDrivenData.H" #include "unitConversion.H" +#include "foamVtkIndPatchWriter.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -2269,112 +2270,46 @@ bool Foam::interfaceTrackingFvMesh::update() void Foam::interfaceTrackingFvMesh::writeVTK() const { - // Write patch and points into VTK - OFstream mps(mesh().time().timePath()/"freeSurface.vtk"); - - const vectorField& points = aMesh().patch().points(); - const IndirectList& faces = aMesh().patch(); - - mps << "# vtk DataFile Version 2.0" << nl - << mesh().time().timePath()/"freeSurface.vtk" << nl - << "ASCII" << nl - << "DATASET POLYDATA" << nl - << "POINTS " << points.size() << " float" << nl; - - // Write points - List mlpBuffer(3*points.size()); - - label counter = 0; - forAll(points, i) - { - mlpBuffer[counter++] = float(points[i].x()); - mlpBuffer[counter++] = float(points[i].y()); - mlpBuffer[counter++] = float(points[i].z()); - } - - forAll(mlpBuffer, i) - { - mps << mlpBuffer[i] << ' '; - - if (i > 0 && (i % 10) == 0) - { - mps << nl; - } - } - - // Write faces - label nFaceVerts = 0; - - forAll(faces, faceI) - { - nFaceVerts += faces[faceI].size() + 1; - } - labelList mlfBuffer(nFaceVerts); - - counter = 0; - forAll(faces, faceI) - { - const face& f = faces[faceI]; - - mlfBuffer[counter++] = f.size(); - - forAll(f, fpI) - { - mlfBuffer[counter++] = f[fpI]; - } - } - mps << nl; - - mps << "POLYGONS " << faces.size() << ' ' << nFaceVerts << endl; - - forAll(mlfBuffer, i) - { - mps << mlfBuffer[i] << ' '; - - if (i > 0 && (i % 10) == 0) - { - mps << nl; - } - } - mps << nl; - - // aMesh().patch().writeVTK - // ( - // mesh().time().timePath()/"freeSurface", - // aMesh().patch(), - // aMesh().patch().points() - // ); + vtk::indirectPatchWriter writer + ( + aMesh().patch(), + vtk::formatType::LEGACY_ASCII, + mesh().time().timePath()/"freeSurface", + false // serial only + ); + writer.writeGeometry(); } void Foam::interfaceTrackingFvMesh::writeVTKControlPoints() { // Write control points into VTK - fileName name(mesh().time().timePath()/"freeSurfaceControlPoints.vtk"); - OFstream mps(name); + OFstream os + ( + mesh().time().timePath()/"freeSurfaceControlPoints.vtk" + ); - Info<< "Writing free surface control point to " << name << endl; + Info<< "Writing free surface control points to " << os.name() << nl; - mps << "# vtk DataFile Version 2.0" << nl - << name << nl + os << "# vtk DataFile Version 2.0" << nl + << "freeSurfaceControlPoints" << nl << "ASCII" << nl - << "DATASET POLYDATA" << nl - << "POINTS " << controlPoints().size() << " float" << nl; + << "DATASET POLYDATA" << nl; - forAll(controlPoints(), pointI) + const label nPoints = controlPoints().size(); + + os << "POINTS " << nPoints << " float" << nl; + for (const point& p : controlPoints()) { - mps << controlPoints()[pointI].x() << ' ' - << controlPoints()[pointI].y() << ' ' - << controlPoints()[pointI].z() << nl; + os << float(p.x()) << ' ' + << float(p.y()) << ' ' + << float(p.z()) << nl; } - // Write vertices - mps << "VERTICES " << controlPoints().size() << ' ' - << controlPoints().size()*2 << nl; - - forAll(controlPoints(), pointI) + os << "VERTICES " << nPoints << ' ' << 2*nPoints << nl; + for (label id = 0; id < nPoints; ++id) { - mps << 1 << ' ' << pointI << nl; + os << 1 << ' ' << id << nl; } } diff --git a/src/fileFormats/Make/files b/src/fileFormats/Make/files index 928615cb5b..2686cefc43 100644 --- a/src/fileFormats/Make/files +++ b/src/fileFormats/Make/files @@ -59,6 +59,7 @@ vtk/part/foamVtuCells.C vtk/part/foamVtuSizing.C vtk/read/vtkUnstructuredReader.C +vtk/write/foamVtkPolyWriter.C vtk/write/foamVtkSurfaceWriter.C coordSet/coordSet.C diff --git a/src/fileFormats/vtk/base/foamVtkCore.H b/src/fileFormats/vtk/base/foamVtkCore.H index a51ff4dd73..2524964a0a 100644 --- a/src/fileFormats/vtk/base/foamVtkCore.H +++ b/src/fileFormats/vtk/base/foamVtkCore.H @@ -34,8 +34,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef foamVtkCore_H -#define foamVtkCore_H +#ifndef Foam_vtk_core_H +#define Foam_vtk_core_H #include #include "Enum.H" diff --git a/src/fileFormats/vtk/base/foamVtkPTraits.H b/src/fileFormats/vtk/base/foamVtkPTraits.H index 0953a3cf8a..0a96729dae 100644 --- a/src/fileFormats/vtk/base/foamVtkPTraits.H +++ b/src/fileFormats/vtk/base/foamVtkPTraits.H @@ -31,8 +31,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef foamVtkPTraits_H -#define foamVtkPTraits_H +#ifndef Foam_vtk_vtkPTraits_H +#define Foam_vtk_vtkPTraits_H #include #include diff --git a/src/fileFormats/vtk/file/foamVtkFileWriter.C b/src/fileFormats/vtk/file/foamVtkFileWriter.C index 622a7a1275..1aac7e0109 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 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -48,6 +48,31 @@ Foam::vtk::fileWriter::stateNames // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // +Foam::Ostream& Foam::vtk::fileWriter::reportBadState +( + Ostream& os, + outputState expected +) const +{ + os << "Bad writer state (" << stateNames[state_] + << ") - should be (" << stateNames[expected] << ')'; + return os; +} + + +Foam::Ostream& Foam::vtk::fileWriter::reportBadState +( + Ostream& os, + outputState expected, + outputState expected2 +) const +{ + reportBadState(os, expected) + << " or (" << stateNames[expected2] << ')'; + return os; +} + + bool Foam::vtk::fileWriter::enter_Piece() { // Finish other output @@ -59,9 +84,7 @@ bool Foam::vtk::fileWriter::enter_Piece() } if (notState(outputState::DECLARED)) { - FatalErrorInFunction - << "Bad writer state (" << stateNames[state_] - << ") - should be (" << stateNames[outputState::DECLARED] << ')' + reportBadState(FatalErrorInFunction, outputState::DECLARED) << exit(FatalError); } state_ = outputState::PIECE; @@ -103,9 +126,7 @@ bool Foam::vtk::fileWriter::enter_CellData(label nEntries, label nFields) if (notState(outputState::PIECE)) { - FatalErrorInFunction - << "Bad writer state (" << stateNames[state_] - << ") - should be (" << stateNames[outputState::PIECE] << ')' + reportBadState(FatalErrorInFunction, outputState::PIECE) << exit(FatalError); } @@ -142,9 +163,7 @@ bool Foam::vtk::fileWriter::enter_PointData(label nEntries, label nFields) if (notState(outputState::PIECE)) { - FatalErrorInFunction - << "Bad writer state (" << stateNames[state_] - << ") - should be (" << stateNames[outputState::PIECE] << ')' + reportBadState(FatalErrorInFunction, outputState::PIECE) << exit(FatalError); } @@ -193,11 +212,8 @@ bool Foam::vtk::fileWriter::exit_File() return true; } - WarningInFunction - << "Bad writer state (" << stateNames[state_] - << ") - should be (" << stateNames[outputState::CLOSED] - << ") or (" << stateNames[outputState::OPENED] - << ") for contentType (" << vtk::fileTagNames[contentType_] + reportBadState(WarningInFunction, outputState::CLOSED, outputState::OPENED) + << " for contentType (" << vtk::fileTagNames[contentType_] << ')' << nl << endl; return false; @@ -241,9 +257,7 @@ bool Foam::vtk::fileWriter::open(const fileName& file, bool parallel) { if (notState(outputState::CLOSED)) { - FatalErrorInFunction - << "Bad writer state (" << stateNames[state_] - << ") - should be (" << stateNames[outputState::CLOSED] << ')' + reportBadState(FatalErrorInFunction, outputState::CLOSED) << exit(FatalError); } @@ -323,9 +337,7 @@ bool Foam::vtk::fileWriter::beginFile(std::string title) } if (notState(outputState::OPENED)) { - FatalErrorInFunction - << "Bad writer state (" << stateNames[state_] - << ") - should be (" << stateNames[outputState::OPENED] << ')' + reportBadState(FatalErrorInFunction, outputState::OPENED) << exit(FatalError); } state_ = outputState::DECLARED; @@ -366,9 +378,7 @@ bool Foam::vtk::fileWriter::beginFieldData(label nFields) } if (notState(outputState::DECLARED)) { - FatalErrorInFunction - << "Bad writer state (" << stateNames[state_] - << ") - should be (" << stateNames[outputState::DECLARED] << ')' + reportBadState(FatalErrorInFunction, outputState::DECLARED) << exit(FatalError); } state_ = outputState::FIELD_DATA; @@ -452,9 +462,7 @@ void Foam::vtk::fileWriter::writeTimeValue(scalar timeValue) } if (notState(outputState::FIELD_DATA)) { - FatalErrorInFunction - << "Bad writer state (" << stateNames[state_] - << ") - should be (" << stateNames[outputState::FIELD_DATA] << ')' + reportBadState(FatalErrorInFunction, outputState::FIELD_DATA) << exit(FatalError); } diff --git a/src/fileFormats/vtk/file/foamVtkFileWriter.H b/src/fileFormats/vtk/file/foamVtkFileWriter.H index 59e7285051..f5cd071590 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-2019 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -45,8 +45,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef foamVtkFileWriter_H -#define foamVtkFileWriter_H +#ifndef Foam_vtk_fileWriter_H +#define Foam_vtk_fileWriter_H #include #include "Enum.H" @@ -116,6 +116,12 @@ protected: // Protected Member Functions + //- Generate message reporting bad writer state + Ostream& reportBadState(Ostream&, outputState expected) const; + + //- Generate message reporting bad writer state + Ostream& reportBadState(Ostream&, outputState, outputState) const; + //- The backend ostream in use inline std::ofstream& os(); @@ -138,6 +144,14 @@ protected: const label nValues ); + //- Write basic (primitive) field content + // No context checking (eg, file-open, CellData, PointData, etc) + template + void writeBasicField + ( + const word& fieldName, + const UList& field + ); //- Trigger change state to Piece. Resets nCellData_, nPointData_. bool enter_Piece(); @@ -200,13 +214,13 @@ public: inline bool legacy() const; //- Parallel output requested? - inline bool parallel() const; + inline bool parallel() const noexcept; //- The output state in printable format inline const word& state() const; //- The current output file name - inline const fileName& output() const; + inline const fileName& output() const noexcept; //- Open file for writing (creates parent directory). @@ -257,10 +271,10 @@ public: virtual bool beginPointData(label nFields = 0) = 0; //- Return the number of CellData written for the Piece thus far. - inline label nCellData() const; + inline label nCellData() const noexcept; //- Return the number of PointData written for the Piece thus far. - inline label nPointData() const; + inline label nPointData() const noexcept; //- Explicitly end FieldData output and switch to DECLARED state @@ -281,7 +295,6 @@ public: // (OPENED | DECLARED) states, in which case it invokes // beginFieldData(1) internally. void writeTimeValue(scalar timeValue); - }; diff --git a/src/fileFormats/vtk/file/foamVtkFileWriterI.H b/src/fileFormats/vtk/file/foamVtkFileWriterI.H index 1662a05dfa..62c7d86600 100644 --- a/src/fileFormats/vtk/file/foamVtkFileWriterI.H +++ b/src/fileFormats/vtk/file/foamVtkFileWriterI.H @@ -77,7 +77,7 @@ inline bool Foam::vtk::fileWriter::legacy() const } -inline bool Foam::vtk::fileWriter::parallel() const +inline bool Foam::vtk::fileWriter::parallel() const noexcept { return parallel_; } @@ -89,19 +89,19 @@ inline const Foam::word& Foam::vtk::fileWriter::state() const } -inline const Foam::fileName& Foam::vtk::fileWriter::output() const +inline const Foam::fileName& Foam::vtk::fileWriter::output() const noexcept { return outputFile_; } -inline Foam::label Foam::vtk::fileWriter::nCellData() const +inline Foam::label Foam::vtk::fileWriter::nCellData() const noexcept { return nCellData_; } -inline Foam::label Foam::vtk::fileWriter::nPointData() const +inline Foam::label Foam::vtk::fileWriter::nPointData() const noexcept { return nPointData_; } diff --git a/src/fileFormats/vtk/file/foamVtkFileWriterTemplates.C b/src/fileFormats/vtk/file/foamVtkFileWriterTemplates.C index bc3912874a..dda7cc9df1 100644 --- a/src/fileFormats/vtk/file/foamVtkFileWriterTemplates.C +++ b/src/fileFormats/vtk/file/foamVtkFileWriterTemplates.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -94,4 +94,79 @@ void Foam::vtk::fileWriter::writeUniform } +template +void Foam::vtk::fileWriter::writeBasicField +( + const word& fieldName, + const UList& field +) +{ + static_assert + ( + ( + std::is_same::cmptType>::value + || std::is_floating_point::cmptType>::value + ), + "Label and Floating-point vector space only" + ); + + const direction nCmpt(pTraits::nComponents); + + label nValues = field.size(); + + if (parallel_) + { + reduce(nValues, sumOp