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

ENH: support VTK output of point ids

- can be useful for diagnosing mesh internals and the locations of
  decomposed cells.
parent 9cb6338c
......@@ -313,7 +313,13 @@ Description
internalWriter->beginPointData
(
nVolFields + nDimFields + nPointFields
+ (withPointIds ? 1 : 0)
);
if (withPointIds)
{
internalWriter->writePointIDs();
}
}
forAll(patchWriters, writeri)
......
......@@ -91,6 +91,9 @@ Usage
- \par -no-point-data
Suppress conversion of pointFields. No interpolated PointData.
- \par -with-point-ids
Additional pointID field for internal mesh
- \par -poly-decomp
Decompose polyhedral cells into tets/pyramids
......@@ -379,6 +382,12 @@ int main(int argc, char *argv[])
);
argList::addOptionCompat("no-point-data", {"noPointValues", 1806});
argList::addBoolOption
(
"with-point-ids",
"Additional pointID field for internal mesh"
);
argList::addBoolOption
(
"one-boundary", // allPatches
......@@ -495,6 +504,19 @@ int main(int argc, char *argv[])
<< nl;
}
const bool withPointIds = args.found("with-point-ids");
if (withPointIds)
{
Info<< "Write point ids requested";
if (noPointValues)
{
Info<< ", but ignored due to the '-no-point-data' option";
}
Info<< nl;
}
wordRes includePatches, excludePatches;
if (doBoundary)
{
......
......@@ -730,4 +730,75 @@ bool Foam::vtk::internalWriter::writeProcIDs()
}
void Foam::vtk::internalWriter::writePointIDs()
{
if (isState(outputState::POINT_DATA))
{
++nPointData_;
}
else
{
FatalErrorInFunction
<< "Bad writer state (" << stateNames[state_]
<< ") - should be (" << stateNames[outputState::POINT_DATA]
<< ") for pointID field" << nl << endl
<< exit(FatalError);
}
if (format_)
{
if (legacy())
{
vtk::legacy::intField<1>(format(), "pointID", numberOfPoints_);
}
else
{
const uint64_t payLoad = vtk::sizeofData<label>(numberOfPoints_);
format().beginDataArray<label>("pointID");
format().writeSize(payLoad);
}
}
// Point offset for regular mesh points (without decomposed)
const label pointOffset =
(
parallel_ ? globalIndex(vtuCells_.nPoints()).localStart() : 0
);
// Cell offset for *regular* mesh cells (without decomposed)
const label cellOffset =
(
parallel_ ? globalIndex(vtuCells_.nCells()).localStart() : 0
);
labelList pointIds = identity(vtuCells_.nFieldPoints(), pointOffset);
// The pointID for added points is the cellID, tag as a negative number
label pointi = vtuCells_.nPoints();
for (const label celli : vtuCells_.addPointCellLabels())
{
pointIds[pointi] = (-1 - celli - cellOffset);
++pointi;
}
if (parallel_)
{
vtk::writeListParallel(format_.ref(), pointIds);
}
else
{
vtk::writeList(format(), pointIds);
}
if (format_)
{
format().flush();
format().endDataArray();
}
}
// ************************************************************************* //
......@@ -207,6 +207,10 @@ public:
// Must be called within the CELL_DATA state.
bool writeProcIDs();
//- Write point ids as PointData.
// Must be called within the POINT_DATA state.
void writePointIDs();
// Write
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment