Commit 4380349f authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

ENH: add vtk::writeIdentity() and optional repeat value for vtk::write()

- An identity is often useful when generating connectivity and offset
  information.

- The optional repeat value for vtk::write() allows it to also be used
  as a fill method.
parent 10a03ceb
......@@ -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();
......
......@@ -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);
}
}
}
......
......@@ -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_)
......
......@@ -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,
......
......@@ -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
......
......@@ -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
......
......@@ -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));
}
}
}
......
......@@ -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();
}
......
......@@ -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();
}
......
......@@ -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();
......
......@@ -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();
......
......@@ -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();
......
......@@ -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