BUG: unguarded use of globalIndex in vtk writers (fixes #1110)

- the problem occurred when running the writers in a parallel solver
  or utility but requesting output on the master only.

  Adjusted the logic to avoid globalIndex for these cases.
  Previously the if (parallel_) checks were happening later, after the
  globalIndex had already been created.
This commit is contained in:
Mark Olesen
2018-12-05 21:27:29 +01:00
parent 8d124355dc
commit e3e0e0557f
12 changed files with 119 additions and 127 deletions

View File

@ -123,10 +123,7 @@ void Foam::vtk::internalWriter::writePoints()
}
void Foam::vtk::internalWriter::writeCellsLegacy
(
const globalIndex& pointOffsets
)
void Foam::vtk::internalWriter::writeCellsLegacy(const label pointOffset)
{
const List<uint8_t>& cellTypes = vtuCells_.cellTypes();
const labelList& vertLabels = vtuCells_.vertLabels();
@ -165,7 +162,7 @@ void Foam::vtk::internalWriter::writeCellsLegacy
vtk::vtuSizing::copyVertLabelsLegacy
(
vertLabels,
pointOffsets.localStart()
pointOffset
)
);
}
@ -206,10 +203,7 @@ void Foam::vtk::internalWriter::writeCellsLegacy
}
void Foam::vtk::internalWriter::writeCellsConnectivity
(
const globalIndex& pointOffsets
)
void Foam::vtk::internalWriter::writeCellsConnectivity(const label pointOffset)
{
//
// 'connectivity'
@ -239,7 +233,7 @@ void Foam::vtk::internalWriter::writeCellsConnectivity
vtk::vtuSizing::copyVertLabelsXml
(
vertLabels,
pointOffsets.localStart()
pointOffset
)
);
}
@ -263,12 +257,6 @@ void Foam::vtk::internalWriter::writeCellsConnectivity
const labelList& vertOffsets = vtuCells_.vertOffsets();
label nOffs = vertOffsets.size();
// global connectivity offsets
const globalIndex procOffset
(
vertOffsets.empty() ? 0 : vertOffsets.last()
);
if (parallel_)
{
reduce(nOffs, sumOp<label>());
@ -285,6 +273,12 @@ void Foam::vtk::internalWriter::writeCellsConnectivity
if (parallel_)
{
// processor-local connectivity offsets
const globalIndex procOffset
(
vertOffsets.empty() ? 0 : vertOffsets.last()
);
vtk::writeListParallel(format_.ref(), vertOffsets, procOffset);
}
else
@ -347,10 +341,7 @@ void Foam::vtk::internalWriter::writeCellsConnectivity
}
void Foam::vtk::internalWriter::writeCellsFaces
(
const globalIndex& pointOffsets
)
void Foam::vtk::internalWriter::writeCellsFaces(const label pointOffset)
{
label nFaceLabels = vtuCells_.faceLabels().size();
@ -393,7 +384,7 @@ void Foam::vtk::internalWriter::writeCellsFaces
vtk::vtuSizing::copyFaceLabelsXml
(
faceLabels,
pointOffsets.localStart()
pointOffset
)
);
}
@ -578,12 +569,15 @@ bool Foam::vtk::internalWriter::writeGeometry()
writePoints();
// With addPointCellLabels for the point offsets
const globalIndex globalPointOffset(vtuCells_.nFieldPoints());
// Include addPointCellLabels for the point offsets
const label pointOffset =
(
parallel_ ? globalIndex(vtuCells_.nFieldPoints()).localStart() : 0
);
if (legacy())
{
writeCellsLegacy(globalPointOffset);
writeCellsLegacy(pointOffset);
return true;
}
@ -592,8 +586,8 @@ bool Foam::vtk::internalWriter::writeGeometry()
format().tag(vtk::fileTag::CELLS);
}
writeCellsConnectivity(globalPointOffset);
writeCellsFaces(globalPointOffset);
writeCellsConnectivity(pointOffset);
writeCellsFaces(pointOffset);
if (format_)
{

View File

@ -58,7 +58,6 @@ namespace Foam
{
// Forward declarations
class globalIndex;
class volPointInterpolation;
namespace vtk
@ -96,13 +95,16 @@ class internalWriter
void writePoints();
//- Write cells (connectivity and type), legacy format
void writeCellsLegacy(const globalIndex& pointOffsets);
// \param pointOffset processor-local point offset
void writeCellsLegacy(const label pointOffset);
//- Write cells connectivity
void writeCellsConnectivity(const globalIndex& pointOffsets);
// \param pointOffset processor-local point offset
void writeCellsConnectivity(const label pointOffset);
//- Write cells face streams
void writeCellsFaces(const globalIndex& pointOffsets);
// \param pointOffset processor-local point offset
void writeCellsFaces(const label pointOffset);
//- No copy construct

View File

@ -171,10 +171,7 @@ void Foam::vtk::patchWriter::writePoints()
}
void Foam::vtk::patchWriter::writePolysLegacy
(
const globalIndex& pointOffsets
)
void Foam::vtk::patchWriter::writePolysLegacy(const label pointOffset)
{
const polyBoundaryMesh& patches = mesh_.boundaryMesh();
@ -207,7 +204,7 @@ void Foam::vtk::patchWriter::writePolysLegacy
auto iter = vertLabels.begin();
label off = pointOffsets.localStart();
label off = pointOffset;
for (const label patchId : patchIDs_)
{
@ -245,10 +242,7 @@ void Foam::vtk::patchWriter::writePolysLegacy
}
void Foam::vtk::patchWriter::writePolys
(
const globalIndex& pointOffsets
)
void Foam::vtk::patchWriter::writePolys(const label pointOffset)
{
if (format_)
{
@ -285,7 +279,7 @@ void Foam::vtk::patchWriter::writePolys
auto iter = vertLabels.begin();
label off = pointOffsets.localStart();
label off = pointOffset;
for (const label patchId : patchIDs_)
{
@ -328,9 +322,6 @@ void Foam::vtk::patchWriter::writePolys
labelList vertOffsets(nLocalFaces_);
label nOffs = vertOffsets.size();
// global connectivity offsets
const globalIndex procOffset(nLocalVerts_);
if (parallel_)
{
reduce(nOffs, sumOp<label>());
@ -346,7 +337,12 @@ void Foam::vtk::patchWriter::writePolys
}
label off = procOffset.localStart();
// processor-local connectivity offsets
label off =
(
parallel_ ? globalIndex(nLocalVerts_).localStart() : 0
);
auto iter = vertOffsets.begin();
@ -517,15 +513,18 @@ bool Foam::vtk::patchWriter::writeGeometry()
writePoints();
const globalIndex globalPointOffset(nLocalPoints_);
const label pointOffset =
(
parallel_ ? globalIndex(nLocalPoints_).localStart() : 0
);
if (legacy())
{
writePolysLegacy(globalPointOffset);
writePolysLegacy(pointOffset);
}
else
{
writePolys(globalPointOffset);
writePolys(pointOffset);
}
return true;

View File

@ -55,10 +55,6 @@ SourceFiles
namespace Foam
{
// Forward declarations
class globalIndex;
namespace vtk
{
@ -107,10 +103,12 @@ class patchWriter
void writePoints();
//- Write patch faces, legacy format
void writePolysLegacy(const globalIndex& pointOffsets);
// \param pointOffset processor-local point offset
void writePolysLegacy(const label pointOffset);
//- Write patch faces
void writePolys(const globalIndex& pointOffsets);
// \param pointOffset processor-local point offset
void writePolys(const label pointOffset);
//- No copy construct

View File

@ -24,7 +24,6 @@ License
\*---------------------------------------------------------------------------*/
#include "foamVtkFileWriter.H"
#include "globalIndex.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

View File

@ -148,10 +148,7 @@ void Foam::vtk::indirectPatchWriter::writePoints()
}
void Foam::vtk::indirectPatchWriter::writePolysLegacy
(
const globalIndex& pointOffsets
)
void Foam::vtk::indirectPatchWriter::writePolysLegacy(const label pointOffset)
{
// Connectivity count without additional storage (done internally)
@ -182,7 +179,7 @@ void Foam::vtk::indirectPatchWriter::writePolysLegacy
auto iter = vertLabels.begin();
label off = pointOffsets.localStart();
label off = pointOffset;
{
for (const face& f : pp_.localFaces())
@ -217,10 +214,7 @@ void Foam::vtk::indirectPatchWriter::writePolysLegacy
}
void Foam::vtk::indirectPatchWriter::writePolys
(
const globalIndex& pointOffsets
)
void Foam::vtk::indirectPatchWriter::writePolys(const label pointOffset)
{
if (format_)
{
@ -254,7 +248,7 @@ void Foam::vtk::indirectPatchWriter::writePolys
auto iter = vertLabels.begin();
label off = pointOffsets.localStart();
label off = pointOffset;
{
for (const face& f : pp_.localFaces())
@ -294,9 +288,6 @@ void Foam::vtk::indirectPatchWriter::writePolys
labelList vertOffsets(nLocalFaces_);
label nOffs = vertOffsets.size();
// global connectivity offsets
const globalIndex procOffset(nLocalVerts_);
if (parallel_)
{
reduce(nOffs, sumOp<label>());
@ -311,7 +302,11 @@ void Foam::vtk::indirectPatchWriter::writePolys
}
label off = procOffset.localStart();
// processor-local connectivity offsets
label off =
(
parallel_ ? globalIndex(nLocalVerts_).localStart() : 0
);
auto iter = vertOffsets.begin();
@ -419,15 +414,18 @@ bool Foam::vtk::indirectPatchWriter::writeGeometry()
writePoints();
const globalIndex globalPointOffset(nLocalPoints_);
const label pointOffset =
(
parallel_ ? globalIndex(nLocalPoints_).localStart() : 0
);
if (legacy())
{
writePolysLegacy(globalPointOffset);
writePolysLegacy(pointOffset);
}
else
{
writePolys(globalPointOffset);
writePolys(pointOffset);
}
return true;

View File

@ -54,10 +54,6 @@ SourceFiles
namespace Foam
{
// Forward declarations
class globalIndex;
namespace vtk
{
@ -100,10 +96,12 @@ class indirectPatchWriter
void writePoints();
//- Write patch faces, legacy format
void writePolysLegacy(const globalIndex& pointOffsets);
// \param pointOffset processor-local point offset
void writePolysLegacy(const label pointOffset);
//- Write patch faces
void writePolys(const globalIndex& pointOffsets);
// \param pointOffset processor-local point offset
void writePolys(const label pointOffset);
//- No copy construct

View File

@ -148,10 +148,7 @@ void Foam::vtk::surfaceWriter::writePoints()
}
void Foam::vtk::surfaceWriter::writePolysLegacy
(
const globalIndex& pointOffsets
)
void Foam::vtk::surfaceWriter::writePolysLegacy(const label pointOffset)
{
// Connectivity count without additional storage (done internally)
@ -182,7 +179,7 @@ void Foam::vtk::surfaceWriter::writePolysLegacy
auto iter = vertLabels.begin();
label off = pointOffsets.localStart();
label off = pointOffset;
{
for (const face& f : faces_)
@ -217,10 +214,7 @@ void Foam::vtk::surfaceWriter::writePolysLegacy
}
void Foam::vtk::surfaceWriter::writePolys
(
const globalIndex& pointOffsets
)
void Foam::vtk::surfaceWriter::writePolys(const label pointOffset)
{
if (format_)
{
@ -254,7 +248,7 @@ void Foam::vtk::surfaceWriter::writePolys
auto iter = vertLabels.begin();
label off = pointOffsets.localStart();
label off = pointOffset;
{
for (const face& f : faces_)
@ -294,9 +288,6 @@ void Foam::vtk::surfaceWriter::writePolys
labelList vertOffsets(nLocalFaces_);
label nOffs = vertOffsets.size();
// global connectivity offsets
const globalIndex procOffset(nLocalVerts_);
if (parallel_)
{
reduce(nOffs, sumOp<label>());
@ -311,7 +302,12 @@ void Foam::vtk::surfaceWriter::writePolys
}
label off = procOffset.localStart();
// processor-local connectivity offsets
label off =
(
parallel_ ? globalIndex(nLocalVerts_).localStart() : 0
);
auto iter = vertOffsets.begin();
@ -438,15 +434,18 @@ bool Foam::vtk::surfaceWriter::writeGeometry()
writePoints();
const globalIndex globalPointOffset(nLocalPoints_);
const label pointOffset =
(
parallel_ ? globalIndex(nLocalPoints_).localStart() : 0
);
if (legacy())
{
writePolysLegacy(globalPointOffset);
writePolysLegacy(pointOffset);
}
else
{
writePolys(globalPointOffset);
writePolys(pointOffset);
}
return true;

View File

@ -56,10 +56,6 @@ SourceFiles
namespace Foam
{
// Forward declarations
class globalIndex;
namespace vtk
{
@ -108,10 +104,12 @@ class surfaceWriter
void writePoints();
//- Write patch faces, legacy format
void writePolysLegacy(const globalIndex& pointOffsets);
// \param pointOffset processor-local point offset
void writePolysLegacy(const label pointOffset);
//- Write patch faces
void writePolys(const globalIndex& pointOffsets);
// \param pointOffset processor-local point offset
void writePolys(const label pointOffset);
//- No copy construct

View File

@ -42,8 +42,6 @@ bool Foam::vtk::writeCellSetFaces
{
typedef IndirectList<face> FaceListType;
const globalIndex cellIdOffset(mesh.nCells());
indirectPrimitivePatch pp
(
FaceListType(mesh.faces(), labelList()),
@ -88,22 +86,6 @@ bool Foam::vtk::writeCellSetFaces
// Use these faces
faces.resetAddressing(cellFaces.sortedToc());
// For each face, the corresponding cellID
labelList faceValues(faces.size());
// Cell ID
{
const labelList& faceIds = faces.addressing();
const label off = cellIdOffset.localStart();
forAll(faceValues, facei)
{
faceValues[facei] = cellFaces[faceIds[facei]] + off;
}
}
//-------------------------------------------------------------------------
indirectPatchWriter writer(pp, opts);
@ -115,14 +97,31 @@ bool Foam::vtk::writeCellSetFaces
//-------------------------------------------------------------------------
// CellData - cellID only
{
// CellData - faceID only
writer.beginCellData(1);
{
// For each face, the corresponding cellID
labelList faceValues(faces.size());
const labelList& faceIds = faces.addressing();
// processor-local cellID offset
const label cellIdOffset =
(
writer.parallel() ? globalIndex(mesh.nCells()).localStart() : 0
);
forAll(faceValues, facei)
{
faceValues[facei] = cellFaces[faceIds[facei]] + cellIdOffset;
}
writer.write("faceID", faceValues);
}
// End CellData/PointData is implicit
}
writer.close();

View File

@ -42,8 +42,6 @@ bool Foam::vtk::writeFaceSet
{
typedef IndirectList<face> FaceListType;
const globalIndex faceIdOffset(mesh.nFaces());
indirectPrimitivePatch pp
(
FaceListType(mesh.faces(), labelList()),
@ -69,7 +67,17 @@ bool Foam::vtk::writeFaceSet
writer.beginCellData(1);
labelField faceValues(faces.addressing());
faceValues += faceIdOffset.localStart();
// processor-local faceID offset
const label faceIdOffset =
(
writer.parallel() ? globalIndex(mesh.nFaces()).localStart() : 0
);
if (faceIdOffset)
{
faceValues += faceIdOffset;
}
writer.write("faceID", faceValues);

View File

@ -94,8 +94,6 @@ bool Foam::vtk::writePointSet
//-------------------------------------------------------------------------
const globalIndex pointIdOffset(mesh.nPoints());
labelField pointLabels(set.sortedToc());
label numberOfPoints = pointLabels.size();
@ -206,6 +204,8 @@ bool Foam::vtk::writePointSet
if (parallel)
{
const globalIndex pointIdOffset(mesh.nPoints());
vtk::writeListParallel(format.ref(), pointLabels, pointIdOffset);
}
else