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

@ -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,15 +97,32 @@ bool Foam::vtk::writeCellSetFaces
//-------------------------------------------------------------------------
// CellData - cellID only
// CellData - faceID only
writer.beginCellData(1);
{
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
}
// End CellData/PointData is implicit
writer.close();
return true;

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