diff --git a/src/conversion/vtk/output/foamVtkInternalWriter.C b/src/conversion/vtk/output/foamVtkInternalWriter.C index af675ce176f417f1c9c423b0380c05ac6e46e2f6..0d43a65c50faa13b696fd5928851cb2ce1de2486 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 b47c59cb323ea3e8343990b2012b44cc63dbbffe..890b4fd3aed36ae887f88a7bdefddf6469610f09 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<processorPolyPatch>(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 606d522c4ae0526c51e69b5126b8bb9370a1935e..00a51fbceb30ae38cbd18c8c61c9fa755f93f392 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 5311fd0db1d3bb9dd7a793f1e031194026085730..25eeb5014835782bf1276e3c5c0972ef36145fc4 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 37cc0b55405aa41ec9d2c68d71549bc04de73f8e..832fa0049ab9870952d24d107a46aa2e5bc39cf5 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 an identity list of labels. + // The output does not include the payload size. + 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 writeList - ( - vtk::formatter& fmt, - const UList<uint8_t>& values - ); + void writeList(vtk::formatter& fmt, const UList<uint8_t>& values); //- Write a list of uint8_t values. // The output does not include the payload size. - void writeListParallel - ( - vtk::formatter& fmt, - const UList<uint8_t>& values - ); + void writeListParallel(vtk::formatter& fmt, const UList<uint8_t>& values); - //- Write a value component-wise. + //- Component-wise write of a value (N times) template<class Type> - 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<class Type> - void writeList - ( - vtk::formatter& fmt, - const UList<Type>& values - ); + void writeList(vtk::formatter& fmt, const UList<Type>& values); //- Write a list of values. // The output does not include the payload size. template<class Type, unsigned N> - void writeList - ( - vtk::formatter& fmt, - const FixedList<Type, N>& values - ); + void writeList(vtk::formatter& fmt, const FixedList<Type, N>& 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 40b5275737a809d406c51cba3abf1f59a5ec03a8..735277a0904329ae5f36b3fa9d793d72d46cda9c 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<label>(vtk::formatter& fmt, const label& val) +inline void write<label>(vtk::formatter& fmt, const label& val, const label n) { - fmt.write(val); + for (label i=0; i < n; ++i) + { + fmt.write(val); + } } //- Template specialization for float template<> -inline void write<float>(vtk::formatter& fmt, const float& val) +inline void write<float>(vtk::formatter& fmt, const float& val, const label n) { - fmt.write(val); + for (label i=0; i < n; ++i) + { + fmt.write(val); + } } //- Template specialization for double template<> -inline void write<double>(vtk::formatter& fmt, const double& val) +inline void write<double>(vtk::formatter& fmt, const double& val, const label n) { - fmt.write(val); + for (label i=0; i < n; ++i) + { + fmt.write(val); + } } + +//- Template specialization for symmTensor ordering +// VTK order is (XX, YY, ZZ, XY, YZ, XZ) +template<> +inline void write(vtk::formatter& fmt, const symmTensor& val, const label n) +{ + for (label i=0; i < n; ++i) + { + fmt.write(component(val, symmTensor::XX)); + fmt.write(component(val, symmTensor::YY)); + fmt.write(component(val, symmTensor::ZZ)); + fmt.write(component(val, symmTensor::XY)); + fmt.write(component(val, symmTensor::YZ)); + fmt.write(component(val, symmTensor::XZ)); + } +} + + } // End namespace vtk } // End namespace Foam diff --git a/src/fileFormats/vtk/output/foamVtkOutputTemplates.C b/src/fileFormats/vtk/output/foamVtkOutputTemplates.C index 46781934e875b60bf6f4f6005861a178061898c3..ecbeff2ac9c3ccb5443c8a9515e9e2b07aa98a60 100644 --- a/src/fileFormats/vtk/output/foamVtkOutputTemplates.C +++ b/src/fileFormats/vtk/output/foamVtkOutputTemplates.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 @@ -32,13 +32,18 @@ template<class Type> inline void Foam::vtk::write ( vtk::formatter& fmt, - const Type& val + const Type& val, + const label n ) { const direction nCmpt = pTraits<Type>::nComponents; - for (direction cmpt=0; cmpt < nCmpt; ++cmpt) + + for (label i=0; i < n; ++i) { - fmt.write(component(val, cmpt)); + for (direction cmpt=0; cmpt < nCmpt; ++cmpt) + { + fmt.write(component(val, cmpt)); + } } } diff --git a/src/functionObjects/lagrangian/vtkCloud/vtkCloud.C b/src/functionObjects/lagrangian/vtkCloud/vtkCloud.C index 6fdb41b00bb0a71e9576662c51e8a024f6a965b7..9abd8f09269c1c7a78b242081e0985f486fd9ac0 100644 --- a/src/functionObjects/lagrangian/vtkCloud/vtkCloud.C +++ b/src/functionObjects/lagrangian/vtkCloud/vtkCloud.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -69,10 +69,8 @@ void Foam::functionObjects::vtkCloud::writeVerts format().beginDataArray<label>(vtk::dataArrayAttr::CONNECTIVITY); format().writeSize(payLoad); - for (label i=0; i < nTotParcels; ++i) - { - format().write(i); - } + vtk::writeIdentity(format(), nTotParcels); + format().flush(); format().endDataArray(); } @@ -85,10 +83,8 @@ void Foam::functionObjects::vtkCloud::writeVerts format().beginDataArray<label>(vtk::dataArrayAttr::OFFSETS); format().writeSize(payLoad); - for (label i=0; i < nTotParcels; ++i) - { - format().write(i+1); - } + vtk::writeIdentity(format(), nTotParcels, 1); + format().flush(); format().endDataArray(); } diff --git a/src/lagrangian/intermediate/conversion/vtk/foamVtkLagrangianWriter.C b/src/lagrangian/intermediate/conversion/vtk/foamVtkLagrangianWriter.C index 792e3757bd8c2c05bc57b643714d482fd680dc76..dd2b3b3685f933cfff98ea7a729a4bf340c588a1 100644 --- a/src/lagrangian/intermediate/conversion/vtk/foamVtkLagrangianWriter.C +++ b/src/lagrangian/intermediate/conversion/vtk/foamVtkLagrangianWriter.C @@ -43,9 +43,9 @@ Foam::pointField Foam::vtk::lagrangianWriter::positions() const auto outIter = pts.begin(); - forAllConstIters(parcels, iter) + for (const auto& p : parcels) { - *outIter = iter().position(); + *outIter = p.position(); ++outIter; } @@ -74,10 +74,8 @@ void Foam::vtk::lagrangianWriter::writeVerts() format().beginDataArray<label>(vtk::dataArrayAttr::CONNECTIVITY); format().writeSize(payLoad); - for (label i=0; i < nVerts; ++i) - { - format().write(i); - } + vtk::writeIdentity(format(), nVerts); + format().flush(); format().endDataArray(); } @@ -90,10 +88,8 @@ void Foam::vtk::lagrangianWriter::writeVerts() format().beginDataArray<label>(vtk::dataArrayAttr::OFFSETS); format().writeSize(payLoad); - for (label i=0; i < nVerts; ++i) - { - format().write(i+1); - } + vtk::writeIdentity(format(), nVerts, 1); + format().flush(); format().endDataArray(); } diff --git a/src/lumpedPointMotion/lumpedPointMovementWriter.C b/src/lumpedPointMotion/lumpedPointMovementWriter.C index 3cc17656a68d1e01b4c2a781400b09f357368553..0a3266dfbcc3abe54de4a5beff39c147460d50f3 100644 --- a/src/lumpedPointMotion/lumpedPointMovementWriter.C +++ b/src/lumpedPointMotion/lumpedPointMovementWriter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -100,10 +100,8 @@ void Foam::lumpedPointMovement::writeForcesAndMomentsVTP format().beginDataArray<label>(vtk::dataArrayAttr::CONNECTIVITY); format().writeSize(payLoad); - for (label i=0; i<nPoints; ++i) - { - format().write(i); - } + vtk::writeIdentity(format(), nPoints); + format().flush(); format().endDataArray(); @@ -119,10 +117,8 @@ void Foam::lumpedPointMovement::writeForcesAndMomentsVTP format().beginDataArray<label>(vtk::dataArrayAttr::OFFSETS); format().writeSize(payLoad); - for (label i=0; i<nPoints; ++i) - { - format().write(i+1); - } + vtk::writeIdentity(format(), nPoints, 1); + format().flush(); format().endDataArray(); @@ -284,10 +280,8 @@ void Foam::lumpedPointMovement::writeZonesVTP format().beginDataArray<label>("zoneId"); format().writeSize(payLoad); - forAll(pp, facei) - { - format().write(zoneI); - } + vtk::write(format(), zoneI, pp.size()); + format().flush(); format().endDataArray(); diff --git a/src/lumpedPointMotion/lumpedPointStateWriter.C b/src/lumpedPointMotion/lumpedPointStateWriter.C index 1af7503e150547eb92760d6a2e9112de3c2cc386..30bce4a051b512502185121d9d5647d1e3841db2 100644 --- a/src/lumpedPointMotion/lumpedPointStateWriter.C +++ b/src/lumpedPointMotion/lumpedPointStateWriter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,6 +25,7 @@ License #include "lumpedPointState.H" #include "OFstream.H" +#include "sliceRange.H" #include "axesRotation.H" #include "coordinateSystem.H" #include "foamVtkOutput.H" @@ -106,10 +107,8 @@ void Foam::lumpedPointState::writeVTP format().beginDataArray<label>(vtk::dataArrayAttr::CONNECTIVITY); format().writeSize(payLoad); - forAll(points_, i) - { - format().write(i); - } + vtk::writeIdentity(format(), points_.size()); + format().flush(); format().endDataArray(); @@ -125,10 +124,8 @@ void Foam::lumpedPointState::writeVTP format().beginDataArray<label>(vtk::dataArrayAttr::OFFSETS); format().writeSize(payLoad); - forAll(points_, i) - { - format().write(i+1); - } + vtk::writeIdentity(format(), points_.size(), 1); + format().flush(); format().endDataArray(); @@ -150,10 +147,8 @@ void Foam::lumpedPointState::writeVTP format().beginDataArray<label>(vtk::dataArrayAttr::CONNECTIVITY); format().writeSize(payLoad); - forAll(points_, i) - { - format().write(i); - } + vtk::writeIdentity(format(), points_.size()); + format().flush(); format().endDataArray(); @@ -256,10 +251,8 @@ void Foam::lumpedPointState::writeVTP format().beginDataArray<label>(vtk::dataArrayAttr::CONNECTIVITY); format().writeSize(payLoad); - for (label i=0; i < 4*nPolys; ++i) - { - format().write(i); - } + vtk::writeIdentity(format(), 4*nPolys); + format().flush(); format().endDataArray(); @@ -275,9 +268,8 @@ void Foam::lumpedPointState::writeVTP format().beginDataArray<label>(vtk::dataArrayAttr::OFFSETS); format().writeSize(payLoad); - for (label i=0; i < nPolys; ++i) + for (const label off : sliceRange(4, nPolys, 4)) { - const label off = 4 * (i+1); format().write(off); } format().flush(); @@ -297,10 +289,8 @@ void Foam::lumpedPointState::writeVTP format().beginDataArray<label>("zoneId"); format().writeSize(payLoad); - for (label i=0; i < nPolys; ++i) - { - format().write(i); - } + vtk::writeIdentity(format(), nPolys); + format().flush(); format().endDataArray(); diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C index 00556c8f0c4291ac7ce7270f934f5bd16739b2d7..e74a9a81b2e4a6af625378933c50fafdee3b3c98 100644 --- a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C @@ -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) 2004-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -86,7 +86,7 @@ void Foam::fileFormats::VTKsurfaceFormatCore::writeCellData // Number of faces covered by the zones label nFaces = 0; - for (const auto& z : zones) + for (const surfZone& z : zones) { nFaces += z.size(); } @@ -95,12 +95,9 @@ void Foam::fileFormats::VTKsurfaceFormatCore::writeCellData vtk::legacy::intField<1>(format, "region", nFaces); // 1 component label zoneId = 0; - for (const surfZone& zone : zones) + for (const surfZone& z : zones) { - forAll(zone, i) - { - format.write(zoneId); - } + vtk::write(format, zoneId, z.size()); ++zoneId; } format.flush(); diff --git a/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.C index 5d927c347c8cefa46c574577caf80335db42aad8..893744a0abc3d2f78a20b7921d63597cc953fb34 100644 --- a/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.C @@ -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 @@ -121,7 +121,7 @@ void Foam::fileFormats::VTPsurfaceFormatCore::writeCellData // Number of faces covered by the zones label nFaces = 0; - for (const auto& z : zones) + for (const surfZone& z : zones) { nFaces += z.size(); } @@ -133,12 +133,9 @@ void Foam::fileFormats::VTPsurfaceFormatCore::writeCellData format.writeSize(payLoad); label zoneId = 0; - for (const surfZone& zone : zones) + for (const surfZone& z : zones) { - forAll(zone, i) - { - format.write(zoneId); - } + vtk::write(format, zoneId, z.size()); ++zoneId; }