From b7fb6116c3abb3d770f9a0517aad5daa4479b4c4 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 29 Jan 2019 15:18:17 +0100 Subject: [PATCH] ENH: restructuring of ensight output files - changed ensightOutput from a class solely comprising static methods to a namespace and added in sub-namespaces Detail and Serial. This makes it easier to "mix-in" functions at different levels. Refactored and combined some serial/parallel code where possible. The general ensightOutput namespace has now shifted to be in the fileFormats lib, while leaving volField outputs in the conversion lib and cloud outputs in the lagrangian-intermediate lib. The ensightCloud namespace is now simply folded into the new ensightOutput namespace. These changes clean up some code, reduce fragmentation and duplication and removes the previous libconversion dependency for sampling. - use int for ensight nTypes constexpr Note: issue #1176 is unaffected except for the change in file name: ensightOutputTemplates.C -> ensightOutputVolFieldTemplates.C --- .../foamToEnsight/convertLagrangian.H | 6 +- .../foamToEnsight/foamToEnsight.C | 2 +- .../foamToEnsight/writeVolFields.H | 4 +- .../foamToEnsightParts/convertLagrangian.H | 6 +- .../foamToEnsightParts/foamToEnsightParts.C | 2 +- .../foamToEnsightParts/writeVolFields.H | 5 +- src/conversion/ensight/output/ensightOutput.H | 164 --------- .../ensight/output/ensightOutputVolField.H | 148 ++++++++ ...tes.C => ensightOutputVolFieldTemplates.C} | 310 +++++++---------- .../ensight/output/ensightSerialOutput.H | 146 -------- .../output/ensightSerialOutputTemplates.C | 174 ---------- .../ensight/output/ensightOutput.H | 146 ++++++++ .../ensight/output/ensightOutputTemplates.C | 323 ++++++++++++++++++ src/fileFormats/ensight/part/ensightCells.H | 2 +- src/fileFormats/ensight/part/ensightFaces.H | 2 +- .../ensight/part/ensightPartCells.C | 6 +- .../ensight/part/ensightPartFaces.C | 8 +- .../ensightWrite/ensightWriteTemplates.C | 8 +- .../conversion/ensight/ensightOutputCloud.C | 8 +- .../conversion/ensight/ensightOutputCloud.H | 19 +- .../ensight/ensightOutputCloudTemplates.C | 6 +- src/sampling/Make/options | 2 - .../ensight/ensightSurfaceWriterImpl.C | 61 +++- 23 files changed, 820 insertions(+), 738 deletions(-) delete mode 100644 src/conversion/ensight/output/ensightOutput.H create mode 100644 src/conversion/ensight/output/ensightOutputVolField.H rename src/conversion/ensight/output/{ensightOutputTemplates.C => ensightOutputVolFieldTemplates.C} (62%) delete mode 100644 src/conversion/ensight/output/ensightSerialOutput.H delete mode 100644 src/conversion/ensight/output/ensightSerialOutputTemplates.C create mode 100644 src/fileFormats/ensight/output/ensightOutput.H create mode 100644 src/fileFormats/ensight/output/ensightOutputTemplates.C diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/convertLagrangian.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/convertLagrangian.H index 46989a4e64..7f94597067 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/convertLagrangian.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/convertLagrangian.H @@ -56,7 +56,7 @@ if (doLagrangian) { autoPtr os = ensCase.newCloud(cloudName); - ensightCloud::writePositions + ensightOutput::writeCloudPositions ( mesh, cloudName, @@ -104,7 +104,7 @@ if (doLagrangian) autoPtr os = ensCase.newCloudData(cloudName, fieldName); - wrote = ensightCloud::writeCloudField + wrote = ensightOutput::writeCloudField ( fieldObject, fieldExists, os ); @@ -114,7 +114,7 @@ if (doLagrangian) autoPtr os = ensCase.newCloudData(cloudName, fieldName); - wrote = ensightCloud::writeCloudField + wrote = ensightOutput::writeCloudField ( fieldObject, fieldExists, os ); diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C index 68815b8bfe..e90b846240 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C @@ -99,8 +99,8 @@ Note #include "ensightCase.H" #include "ensightGeoFile.H" #include "ensightMesh.H" -#include "ensightOutput.H" #include "ensightOutputCloud.H" +#include "ensightOutputVolField.H" #include "fvMeshSubsetProxy.H" // local files diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/writeVolFields.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/writeVolFields.H index 98f388d9ec..f72c74db59 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/writeVolFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/writeVolFields.H @@ -62,11 +62,11 @@ bool writeVolField autoPtr os = ensCase.newData(field.name()); - bool wrote = ensightOutput::writeField + bool wrote = ensightOutput::writeVolField ( field, ensMesh, - os, + os.ref(), nodeValues ); diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/convertLagrangian.H b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/convertLagrangian.H index 827500474b..ce1f9b4d64 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/convertLagrangian.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/convertLagrangian.H @@ -55,7 +55,7 @@ if (doLagrangian) { autoPtr os = ensCase.newCloud(cloudName); - ensightCloud::writePositions + ensightOutput::writeCloudPositions ( mesh, cloudName, @@ -103,7 +103,7 @@ if (doLagrangian) autoPtr os = ensCase.newCloudData(cloudName, fieldName); - wrote = ensightCloud::writeCloudField + wrote = ensightOutput::writeCloudField ( fieldObject, fieldExists, os ); @@ -113,7 +113,7 @@ if (doLagrangian) autoPtr os = ensCase.newCloudData(cloudName, fieldName); - wrote = ensightCloud::writeCloudField + wrote = ensightOutput::writeCloudField ( fieldObject, fieldExists, os ); diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C index 4aa572c436..c3460ea729 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C @@ -94,8 +94,8 @@ Note #include "ensightCase.H" #include "ensightGeoFile.H" #include "ensightParts.H" -#include "ensightSerialOutput.H" #include "ensightOutputCloud.H" +#include "ensightOutputVolField.H" #include "fvMeshSubsetProxy.H" // local files diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/writeVolFields.H b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/writeVolFields.H index 303f97ad53..017ef31bf0 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/writeVolFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/writeVolFields.H @@ -61,11 +61,12 @@ bool writeVolField autoPtr os = ensCase.newData(field.name()); - bool wrote = ensightSerialOutput::writeField + // Currently serial only + bool wrote = ensightOutput::Serial::writeVolField ( field, ensParts, - os + os.ref() ); tfield.clear(); diff --git a/src/conversion/ensight/output/ensightOutput.H b/src/conversion/ensight/output/ensightOutput.H deleted file mode 100644 index 2649fd5b76..0000000000 --- a/src/conversion/ensight/output/ensightOutput.H +++ /dev/null @@ -1,164 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 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::ensightOutput - -Description - A collection of functions for writing ensight file content in parallel. - -SourceFiles - ensightOutput.C - ensightOutputTemplates.C - -\*---------------------------------------------------------------------------*/ - -#ifndef ensightOutput_H -#define ensightOutput_H - -#include "ensightFile.H" -#include "ensightMesh.H" -#include "autoPtr.H" -#include "volFields.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - - -namespace Foam -{ - -/*---------------------------------------------------------------------------*\ - Class ensightOutput Declaration -\*---------------------------------------------------------------------------*/ - -class ensightOutput -{ - // Private Methods - - //- Write field content (component-wise) for the given ensight element type - template class FieldContainer, class Type> - static void writeFieldContent - ( - const char* key, - const FieldContainer& fld, - ensightFile& os - ); - - //- Write a field of faces values as an indirect list, - // using the face ids from ensightFaces - template - static bool writeFaceField - ( - const Field& fld, - const ensightFaces&, - ensightFile& os - ); - - //- Write a field of faces values as a sublist, - // using the sublist sizes ensightFaces - template - static bool writeFaceSubField - ( - const Field& fld, - const ensightFaces&, - ensightFile& os - ); - - //- Write a field of cell values as an indirect list, - // using the cell ids from ensightCells - template - static bool writeCellField - ( - const Field& fld, - const ensightCells&, - ensightFile& os - ); - - - //- Write volume field component-wise - template - static bool writeField - ( - const GeometricField& vf, - const ensightMesh& ensMesh, - ensightFile& os - ); - - //- Write point field component-wise - template - static bool ensightPointField - ( - const GeometricField& pf, - const ensightMesh& ensMesh, - ensightFile& os - ); - - //- No null constructor - ensightOutput() = delete; - - -public: - - // Public Methods - - //- Write volume field component-wise - template - static bool writeField - ( - const GeometricField&, - const ensightMesh& ensMesh, - ensightFile& os, - const bool nodeValues - ); - - - //- Write volume field component-wise - template - static inline bool writeField - ( - const GeometricField& vf, - const ensightMesh& ensMesh, - autoPtr& output, - const bool nodeValues = false - ) - { - return writeField(vf, ensMesh, output.ref(), nodeValues); - } - -}; - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#ifdef NoRepository - #include "ensightOutputTemplates.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/src/conversion/ensight/output/ensightOutputVolField.H b/src/conversion/ensight/output/ensightOutputVolField.H new file mode 100644 index 0000000000..fd3bf9506a --- /dev/null +++ b/src/conversion/ensight/output/ensightOutputVolField.H @@ -0,0 +1,148 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +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::ensightOutput + +Description + A collection of functions for writing volField content in ensight format. + +\*---------------------------------------------------------------------------*/ + +#ifndef ensightOutputVolField_H +#define ensightOutputVolField_H + +#include "ensightOutput.H" +#include "ensightPart.H" +#include "ensightParts.H" +#include "ensightPartFaces.H" +#include "ensightPartCells.H" +#include "volFields.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declarations +class ensightMesh; + +namespace ensightOutput +{ + +/*---------------------------------------------------------------------------*\ + Namespace ensightOutput::Detail +\*---------------------------------------------------------------------------*/ + +namespace Detail +{ + +//- Write volume field component-wise +template +bool writeVolField +( + const GeometricField& vf, + const ensightMesh& ensMesh, + ensightFile& os +); + +//- Write point field component-wise +template +bool writePointField +( + const GeometricField& pf, + const ensightMesh& ensMesh, + ensightFile& os +); + +} // End namespace Detail + + +/*---------------------------------------------------------------------------*\ + Namespace ensightOutput +\*---------------------------------------------------------------------------*/ + +//- Write volume field component-wise +template +bool writeVolField +( + const GeometricField&, + const ensightMesh& ensMesh, + ensightFile& os, + const bool nodeValues = false +); + + +/*---------------------------------------------------------------------------*\ + Namespace ensightOutput::Serial +\*---------------------------------------------------------------------------*/ + +namespace Serial +{ + +//- Write volume field component-wise for specified faces +template +bool writeVolField +( + const GeometricField& vf, + const ensightPartFaces& part, + ensightFile& os +); + + +//- Write volume field component-wise for specified cells +template +bool writeVolField +( + const GeometricField& vf, + const ensightPartCells& part, + ensightFile& os +); + + +//- Write volume field component-wise +template +bool writeVolField +( + const GeometricField& vf, + const ensightParts& list, + ensightFile& os +); + +} // End namespace Serial + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace ensightOutput +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "ensightOutputVolFieldTemplates.C" +#endif + +#endif + +// ************************************************************************* // diff --git a/src/conversion/ensight/output/ensightOutputTemplates.C b/src/conversion/ensight/output/ensightOutputVolFieldTemplates.C similarity index 62% rename from src/conversion/ensight/output/ensightOutputTemplates.C rename to src/conversion/ensight/output/ensightOutputVolFieldTemplates.C index 5176845e6f..4a22d74d8a 100644 --- a/src/conversion/ensight/output/ensightOutputTemplates.C +++ b/src/conversion/ensight/output/ensightOutputVolFieldTemplates.C @@ -23,191 +23,29 @@ License \*---------------------------------------------------------------------------*/ -#include "ensightFile.H" -#include "ensightOutput.H" -#include "ensightPTraits.H" +#include "ensightOutputVolField.H" +#include "ensightMesh.H" #include "fvMesh.H" -#include "volFields.H" -#include "IOField.H" -#include "OFstream.H" -#include "IOmanip.H" -#include "Time.H" -#include "volPointInterpolation.H" #include "globalIndex.H" -#include "uindirectPrimitivePatch.H" +#include "volPointInterpolation.H" #include "interpolation.H" #include "linear.H" #include "processorFvPatch.H" +#include "uindirectPrimitivePatch.H" -// * * * * * * * * * * Static Private Member Functions * * * * * * * * * * * // - -template class FieldContainer, class Type> -void Foam::ensightOutput::writeFieldContent -( - const char* key, - const FieldContainer& fld, - ensightFile& os -) -{ - if (returnReduce(fld.size(), sumOp