diff --git a/src/conversion/vtk/output/foamVtkInternalWriter.C b/src/conversion/vtk/output/foamVtkInternalWriter.C index af675ce176..0d43a65c50 100644 --- a/src/conversion/vtk/output/foamVtkInternalWriter.C +++ b/src/conversion/vtk/output/foamVtkInternalWriter.C @@ -711,12 +711,7 @@ bool Foam::vtk::internalWriter::writeProcIDs() // Per-processor ids for (label proci=0; proci < Pstream::nProcs(); ++proci) { - label len = procMaps.localSize(proci); - - while (len--) - { - format().write(proci); - } + vtk::write(format(), proci, procMaps.localSize(proci)); } format().flush(); diff --git a/src/conversion/vtk/output/foamVtkPatchWriter.C b/src/conversion/vtk/output/foamVtkPatchWriter.C index b47c59cb32..890b4fd3ae 100644 --- a/src/conversion/vtk/output/foamVtkPatchWriter.C +++ b/src/conversion/vtk/output/foamVtkPatchWriter.C @@ -587,13 +587,7 @@ void Foam::vtk::patchWriter::writePatchIDs() { for (const label patchId : patchIDs_) { - label count = patches[patchId].size(); - const label val = patchId; - - while (count--) - { - format().write(val); - } + vtk::write(format(), patchId, patches[patchId].size()); } } @@ -615,16 +609,13 @@ void Foam::vtk::patchWriter::writePatchIDs() fromSlave >> recv; - for (label i=0; i < recv.size(); ++i) + // Receive as [size, id] pairs + for (label i=0; i < recv.size(); i += 2) { - label count = recv[i]; - ++i; - const label val = recv[i]; + const label len = recv[i]; + const label val = recv[i+1]; - while (count--) - { - format().write(val); - } + vtk::write(format(), val, len); } } } @@ -722,12 +713,7 @@ bool Foam::vtk::patchWriter::writeProcIDs() // Per-processor ids for (label proci=0; proci < Pstream::nProcs(); ++proci) { - label len = procSizes.localSize(proci); - - while (len--) - { - format().write(proci); - } + vtk::write(format(), proci, procSizes.localSize(proci)); } good = true; @@ -735,14 +721,7 @@ bool Foam::vtk::patchWriter::writeProcIDs() } else { - const label proci = Pstream::myProcNo(); - - label len = nLocalFaces_; - - while (len--) - { - format().write(proci); - } + vtk::write(format(), Pstream::myProcNo(), nLocalFaces_); good = true; } @@ -811,16 +790,11 @@ bool Foam::vtk::patchWriter::writeNeighIDs() { for (const label patchId : patchIDs_) { - label count = patches[patchId].size(); - const auto* pp = isA(patches[patchId]); - const label val = (pp ? pp->neighbProcNo() : -1); + const label val = (pp ? pp->neighbProcNo() : -1); - while (count--) - { - format().write(val); - } + vtk::write(format(), val, patches[patchId].size()); } good = true; @@ -844,16 +818,13 @@ bool Foam::vtk::patchWriter::writeNeighIDs() fromSlave >> recv; - for (label i=0; i < recv.size(); ++i) + // Receive as [size, id] pairs + for (label i=0; i < recv.size(); i += 2) { - label count = recv[i]; - ++i; - const label val = recv[i]; + const label len = recv[i]; + const label val = recv[i+1]; - while (count--) - { - format().write(val); - } + vtk::write(format(), val, len); } } } diff --git a/src/fileFormats/vtk/file/foamVtkFileWriterTemplates.C b/src/fileFormats/vtk/file/foamVtkFileWriterTemplates.C index 606d522c4a..00a51fbceb 100644 --- a/src/fileFormats/vtk/file/foamVtkFileWriterTemplates.C +++ b/src/fileFormats/vtk/file/foamVtkFileWriterTemplates.C @@ -81,10 +81,7 @@ void Foam::vtk::fileWriter::writeUniform if (format_) { - for (label i=0; i < nValues; ++i) - { - vtk::write(format(), val); - } + vtk::write(format(), val, nValues); } if (format_) diff --git a/src/fileFormats/vtk/output/foamVtkOutput.C b/src/fileFormats/vtk/output/foamVtkOutput.C index 5311fd0db1..25eeb50148 100644 --- a/src/fileFormats/vtk/output/foamVtkOutput.C +++ b/src/fileFormats/vtk/output/foamVtkOutput.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -89,6 +89,22 @@ Foam::vtk::newFormatter } +void Foam::vtk::writeIdentity +( + vtk::formatter& fmt, + const label len, + label start +) +{ + // No nComponents for label, so use fmt.write() directly + for (label i=0; i < len; ++i) + { + fmt.write(start); + ++start; + } +} + + void Foam::vtk::writeList ( vtk::formatter& fmt, diff --git a/src/fileFormats/vtk/output/foamVtkOutput.H b/src/fileFormats/vtk/output/foamVtkOutput.H index 37cc0b5540..832fa0049a 100644 --- a/src/fileFormats/vtk/output/foamVtkOutput.H +++ b/src/fileFormats/vtk/output/foamVtkOutput.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -84,48 +84,32 @@ namespace vtk ); - //- Write a list of uint8_t values. + //- Write an identity list of labels. // The output does not include the payload size. - void writeList - ( - vtk::formatter& fmt, - const UList& values - ); + void writeIdentity(vtk::formatter& fmt, const label len, label start=0); //- Write a list of uint8_t values. // The output does not include the payload size. - void writeListParallel - ( - vtk::formatter& fmt, - const UList& values - ); + void writeList(vtk::formatter& fmt, const UList& values); - //- Write a value component-wise. + //- Write a list of uint8_t values. + // The output does not include the payload size. + void writeListParallel(vtk::formatter& fmt, const UList& values); + + //- Component-wise write of a value (N times) template - inline void write - ( - vtk::formatter& fmt, - const Type& val - ); + inline void write(vtk::formatter& fmt, const Type& val, const label n=1); //- Write a list of values. // The output does not include the payload size. template - void writeList - ( - vtk::formatter& fmt, - const UList& values - ); + void writeList(vtk::formatter& fmt, const UList& values); //- Write a list of values. // The output does not include the payload size. template - void writeList - ( - vtk::formatter& fmt, - const FixedList& values - ); + void writeList(vtk::formatter& fmt, const FixedList& values); //- Write a list of values via indirect addressing. @@ -327,22 +311,6 @@ namespace legacy // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -//- Template specialization for symmTensor ordering -template<> -inline void write(vtk::formatter& fmt, const symmTensor& val) -{ - // symmTensor ( XX, XY, XZ, YY, YZ, ZZ ) - // VTK order ( XX, YY, ZZ, XY, YZ, XZ ) -> (0, 3, 5, 1, 4, 2) - - fmt.write(component(val, 0)); // XX - fmt.write(component(val, 3)); // YY - fmt.write(component(val, 5)); // ZZ - fmt.write(component(val, 1)); // XY - fmt.write(component(val, 4)); // YZ - fmt.write(component(val, 2)); // XZ -} - - } // End namespace vtk } // End namespace Foam diff --git a/src/fileFormats/vtk/output/foamVtkOutputI.H b/src/fileFormats/vtk/output/foamVtkOutputI.H index 40b5275737..735277a090 100644 --- a/src/fileFormats/vtk/output/foamVtkOutputI.H +++ b/src/fileFormats/vtk/output/foamVtkOutputI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -32,27 +32,54 @@ namespace vtk //- Template specialization for label template<> -inline void write