diff --git a/src/fileFormats/ensight/output/ensightOutput.H b/src/fileFormats/ensight/output/ensightOutput.H index fefe06a535..eeb34f3aca 100644 --- a/src/fileFormats/ensight/output/ensightOutput.H +++ b/src/fileFormats/ensight/output/ensightOutput.H @@ -50,6 +50,7 @@ SourceFiles #include "ListOps.H" #include "ListListOps.H" #include "IndirectList.H" +#include "DynamicList.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -260,17 +261,27 @@ labelList getPolysNFaces(const polyMesh& mesh, const labelUList& addr); labelList getPolysNPointsPerFace(const polyMesh& mesh, const labelUList& addr); -//- Copy specified field component into a scalarField -// works for various lists types +//- Copy specified field component into a scalar buffer +//- works for various lists types. Must be adequately sized before calling template class FieldContainer, class Type> void copyComponent ( - scalarField& res, + List& cmptBuffer, const FieldContainer& input, const direction cmpt ); +//- Write field content (component-wise) +template class FieldContainer, class Type> +void writeFieldContent +( + ensightFile& os, + const FieldContainer& fld, + bool parallel //!< Collective write? +); + + //- Write coordinates (component-wise) for the given part template class FieldContainer> bool writeCoordinates diff --git a/src/fileFormats/ensight/output/ensightOutputTemplates.C b/src/fileFormats/ensight/output/ensightOutputTemplates.C index 3c408d6fc2..0dd52790c8 100644 --- a/src/fileFormats/ensight/output/ensightOutputTemplates.C +++ b/src/fileFormats/ensight/output/ensightOutputTemplates.C @@ -27,20 +27,27 @@ License #include "ensightOutput.H" #include "ensightPTraits.H" +#include "globalIndex.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // template class FieldContainer, class Type> void Foam::ensightOutput::Detail::copyComponent ( - scalarField& res, + List& cmptBuffer, const FieldContainer& input, const direction cmpt ) { - res.resize(input.size()); + if (cmptBuffer.size() < input.size()) + { + FatalErrorInFunction + << "Component buffer too small: " + << cmptBuffer.size() << " < " << input.size() << nl + << exit(FatalError); + } - auto iter = res.begin(); + auto iter = cmptBuffer.begin(); for (const Type& val : input) { @@ -50,6 +57,80 @@ void Foam::ensightOutput::Detail::copyComponent } +template class FieldContainer, class Type> +void Foam::ensightOutput::Detail::writeFieldContent +( + ensightFile& os, + const FieldContainer& fld, + bool parallel +) +{ + // already checked prior to calling, but extra safety + parallel = parallel && Pstream::parRun(); + + // Size information (offsets are irrelevant) + globalIndex procAddr; + if (parallel) + { + procAddr.reset(UPstream::listGatherValues