Compare commits

...

8 Commits

Author SHA1 Message Date
Gunther Weber
7353e53730 Merge branch 'add-compute-global-point-size' into 'master'
WIP: Add ComputeGlobalPointDimensions

See merge request vtk/vtk-m!2935
2024-07-09 17:16:19 -04:00
Kenneth Moreland
31b9c44fc3 Merge branch 'release-2.2' 2024-07-09 07:11:22 -04:00
Kenneth Moreland
3440dfa9f9 Merge topic 'undeprecate-extract-include-boundary'
012853a73 Un-deprecate extract boundary in ExtractStructured filter

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Vicente Bolea <vicente.bolea@kitware.com>
Merge-request: !3244
2024-07-09 07:11:22 -04:00
Kenneth Moreland
67b0fea23a Merge topic 'undeprecate-extract-include-boundary' into release-2.2
012853a73 Un-deprecate extract boundary in ExtractStructured filter

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Vicente Bolea <vicente.bolea@kitware.com>
Merge-request: !3244
2024-07-09 07:11:22 -04:00
Kenneth Moreland
012853a73b Un-deprecate extract boundary in ExtractStructured filter
This method was deprecated because it was not well explained in the
documentation nor was it used in VTK-m or Ascent. However, it is used in
VTK, and VTK has a bit more documentation on what this feature is
supposed to do. Thus this feature has been un-deprecated so that it will
continue to stick around. Also, additional documentation is provided to
describe the feature, and the testing has been expanded a bit.
2024-07-08 17:51:13 -04:00
Gunther H. Weber
fae6ef8c93 Add code to shift logical extents 2024-05-08 17:44:34 -07:00
Gunther H. Weber
8b87ae192f Updates based on review 2024-05-08 17:44:34 -07:00
Gunther H. Weber
99900576c5 Add ComputeGlobalPointSize 2024-05-08 17:44:34 -07:00
5 changed files with 181 additions and 37 deletions

@ -155,6 +155,110 @@ private:
std::vector<std::string> mCLOptions;
};
void ComputeGlobalPointDimensions(vtkm::cont::PartitionedDataSet& pds)
{
// Compute GlobalPointDimensions as maximum of GlobalPointIndexStart + PointDimensions
// for each dimension across all blocks
// Compute GlobalPointDimensions for all data sets on this MPI rank
std::vector<vtkm::Id> globalPointDimensionsThisRank;
using ds_const_iterator = vtkm::cont::PartitionedDataSet::const_iterator;
for (ds_const_iterator ds_it = pds.cbegin(); ds_it != pds.cend(); ++ds_it)
{
ds_it->GetCellSet().CastAndCallForTypes<vtkm::cont::CellSetListStructured>(
[&globalPointDimensionsThisRank](const auto& css) {
globalPointDimensionsThisRank.resize(css.Dimension, -1);
for (vtkm::IdComponent d = 0; d < css.Dimension; ++d)
{
globalPointDimensionsThisRank[d] =
std::max(globalPointDimensionsThisRank[d],
css.GetGlobalPointIndexStart()[d] + css.GetPointDimensions()[d]);
}
});
}
// Perform global reduction to find GlobalPointDimensions across all ranks
std::vector<vtkm::Id> globalPointDimensions;
auto comm = vtkm::cont::EnvironmentTracker::GetCommunicator();
vtkmdiy::mpi::all_reduce(
comm, globalPointDimensionsThisRank, globalPointDimensions, vtkmdiy::mpi::maximum<vtkm::Id>{});
// Set this information in all cell sets
using ds_iterator = vtkm::cont::PartitionedDataSet::iterator;
for (ds_iterator ds_it = pds.begin(); ds_it != pds.end(); ++ds_it)
{
// This does not work, i.e., it does not really change the cell set for the DataSet
ds_it->GetCellSet().CastAndCallForTypes<vtkm::cont::CellSetListStructured>(
[&globalPointDimensions, &ds_it](auto& css) {
typename std::remove_reference_t<decltype(css)>::SchedulingRangeType gpd;
for (vtkm::IdComponent d = 0; d < css.Dimension; ++d)
{
gpd[d] = globalPointDimensions[d];
}
css.SetGlobalPointDimensions(gpd);
// Why is the following necessary? Shouldn't it be sufficient to update the
// CellSet through the reference?
ds_it->SetCellSet(css);
});
}
// Debug
pds.PrintSummary(std::cout);
}
void ShiftLogicalOriginToZero(vtkm::cont::PartitionedDataSet& pds)
{
// Shift the logical origin (minimum of LocalPointIndexStart) to zero
// along each dimension
// Compute minimum global point index start for all data sets on this MPI rank
std::vector<vtkm::Id> minimumGlobalPointIndexStartThisRank;
using ds_const_iterator = vtkm::cont::PartitionedDataSet::const_iterator;
for (ds_const_iterator ds_it = pds.cbegin(); ds_it != pds.cend(); ++ds_it)
{
ds_it->GetCellSet().CastAndCallForTypes<vtkm::cont::CellSetListStructured>(
[&minimumGlobalPointIndexStartThisRank](const auto& css) {
minimumGlobalPointIndexStartThisRank.resize(css.Dimension,
std::numeric_limits<vtkm::Id>::max());
for (vtkm::IdComponent d = 0; d < css.Dimension; ++d)
{
minimumGlobalPointIndexStartThisRank[d] =
std::min(minimumGlobalPointIndexStartThisRank[d], css.GetGlobalPointIndexStart()[d]);
}
});
}
// Perform global reduction to find GlobalPointDimensions across all ranks
std::vector<vtkm::Id> minimumGlobalPointIndexStart;
auto comm = vtkm::cont::EnvironmentTracker::GetCommunicator();
vtkmdiy::mpi::all_reduce(comm,
minimumGlobalPointIndexStartThisRank,
minimumGlobalPointIndexStart,
vtkmdiy::mpi::minimum<vtkm::Id>{});
// Shift all cell sets so that minimum global point index start
// along each dimension is zero
using ds_iterator = vtkm::cont::PartitionedDataSet::iterator;
for (ds_iterator ds_it = pds.begin(); ds_it != pds.end(); ++ds_it)
{
// This does not work, i.e., it does not really change the cell set for the DataSet
ds_it->GetCellSet().CastAndCallForTypes<vtkm::cont::CellSetListStructured>(
[&minimumGlobalPointIndexStart, &ds_it](auto& css) {
auto pointIndexStart = css.GetGlobalPointIndexStart();
typename std::remove_reference_t<decltype(css)>::SchedulingRangeType shiftedPointIndexStart;
for (vtkm::IdComponent d = 0; d < css.Dimension; ++d)
{
shiftedPointIndexStart[d] = pointIndexStart[d] - minimumGlobalPointIndexStart[d];
}
css.SetGlobalPointIndexStart(shiftedPointIndexStart);
// Why is the following necessary? Shouldn't it be sufficient to update the
// CellSet through the reference?
ds_it->SetCellSet(css);
});
}
// Debug
//pds.PrintSummary(std::cout);
}
// Compute and render an isosurface for a uniform grid example
int main(int argc, char* argv[])
@ -652,6 +756,8 @@ int main(int argc, char* argv[])
filter.SetActiveField("values");
// Execute the contour tree analysis
ShiftLogicalOriginToZero(useDataSet);
ComputeGlobalPointDimensions(useDataSet);
auto result = filter.Execute(useDataSet);
currTime = totalTime.GetElapsedTime();

@ -346,7 +346,8 @@ bool read3DHDF5File(const int& mpi_rank,
ds = dsb.Create(v_dims, v_origin, v_spacing);
vtkm::cont::CellSetStructured<3> cs;
cs.SetPointDimensions(v_dims);
cs.SetGlobalPointDimensions(globalSize);
// NOTE: Comment out for test purposes
//cs.SetGlobalPointDimensions(globalSize);
cs.SetGlobalPointIndexStart(vtkm::Id3{ v_origin[0], v_origin[1], v_origin[2] });
ds.SetCellSet(cs);
@ -587,7 +588,8 @@ bool readPreSplitFiles(const int& rank,
ds = dsb.Create(v_dims, v_origin, v_spacing);
vtkm::cont::CellSetStructured<2> cs;
cs.SetPointDimensions(v_dims);
cs.SetGlobalPointDimensions(vtkm::Id2{ globalSize[0], globalSize[1] });
// NOTE: Comment out for test purposes
//cs.SetGlobalPointDimensions(vtkm::Id2{ globalSize[0], globalSize[1] });
cs.SetGlobalPointIndexStart(vtkm::Id2{ offset[0], offset[1] });
ds.SetCellSet(cs);
}
@ -604,7 +606,8 @@ bool readPreSplitFiles(const int& rank,
ds = dsb.Create(v_dims, v_origin, v_spacing);
vtkm::cont::CellSetStructured<3> cs;
cs.SetPointDimensions(v_dims);
cs.SetGlobalPointDimensions(globalSize);
// NOTE: Comment out for test purposes
//cs.SetGlobalPointDimensions(globalSize);
cs.SetGlobalPointIndexStart(vtkm::Id3{ offset[0], offset[1], offset[2] });
ds.SetCellSet(cs);
}
@ -815,7 +818,8 @@ bool readSingleBlockFile(const int& rank,
ds = dsb.Create(vdims, origin, spacing);
vtkm::cont::CellSetStructured<2> cs;
cs.SetPointDimensions(vdims);
cs.SetGlobalPointDimensions(vtkm::Id2{ globalSize[0], globalSize[1] });
// NOTE: Comment out for test purposes
//cs.SetGlobalPointDimensions(vtkm::Id2{ globalSize[0], globalSize[1] });
cs.SetGlobalPointIndexStart(vtkm::Id2{ 0, (blockStart / blockSliceSize) });
ds.SetCellSet(cs);
localBlockIndicesPortal.Set(localBlockIndex, vtkm::Id3(0, blockIndex, 0));
@ -832,7 +836,8 @@ bool readSingleBlockFile(const int& rank,
ds = dsb.Create(vdims, origin, spacing);
vtkm::cont::CellSetStructured<3> cs;
cs.SetPointDimensions(vdims);
cs.SetGlobalPointDimensions(globalSize);
// NOTE: Comment out for test purposes
//cs.SetGlobalPointDimensions(globalSize);
cs.SetGlobalPointIndexStart(vtkm::Id3(0, 0, blockStart / blockSliceSize));
ds.SetCellSet(cs);
localBlockIndicesPortal.Set(localBlockIndex, vtkm::Id3(0, 0, blockIndex));

@ -233,33 +233,56 @@ vtkm::cont::DataSet MakeTestDataSet::Make3DUniformDataSet1()
constexpr vtkm::Id nVerts = 125;
constexpr vtkm::Id nCells = 64;
constexpr vtkm::Float32 pointvar[nVerts] = {
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // 0-4, 0, 0
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // 0-4, 1, 0
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // 0-4, 2, 0
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // 0-4, 3, 0
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // 0-4, 4, 0
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 99.0f, 90.0f, 85.0f, 0.0f, 0.0f, 95.0f, 80.0f,
95.0f, 0.0f, 0.0f, 85.0f, 90.0f, 99.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // 0-4, 0, 1
0.0f, 99.0f, 90.0f, 85.0f, 0.0f, // 0-4, 1, 1
0.0f, 95.0f, 80.0f, 95.0f, 0.0f, // 0-4, 2, 1
0.0f, 85.0f, 90.0f, 99.0f, 0.0f, // 0-4, 3, 1
0.0f, 0.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f, 0.0f, 0.0f, 0.0f, // 0-4, 3, 4
0.0f, 0.0f, 0.0f, 0.0f, 0.0f // 0-4, 4, 4
};
constexpr vtkm::Float32 cellvar[nCells] = {
0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f,
8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f,
0.0f, 1.0f, 2.0f, 3.0f, // 0-3, 0, 0
4.0f, 5.0f, 6.0f, 7.0f, // 0-3, 1, 0
8.0f, 9.0f, 10.0f, 11.0f, // 0-3, 2, 0
12.0f, 13.0f, 14.0f, 15.0f, // 0-3, 3, 0
16.0f, 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f,
24.0f, 25.0f, 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, 31.0f,
16.0f, 17.0f, 18.0f, 19.0f, // 0-3, 0, 1
20.0f, 21.0f, 22.0f, 23.0f, // 0-3, 1, 1
24.0f, 25.0f, 26.0f, 27.0f, // 0-3, 2, 1
28.0f, 29.0f, 30.0f, 31.0f, // 0-3, 3, 1
32.0f, 33.0f, 34.0f, 35.0f, 36.0f, 37.0f, 38.0f, 39.0f,
40.0f, 41.0f, 42.0f, 43.0f, 44.0f, 45.0f, 46.0f, 47.0f,
32.0f, 33.0f, 34.0f, 35.0f, // 0-3, 0, 2
36.0f, 37.0f, 38.0f, 39.0f, // 0-3, 1, 2
40.0f, 41.0f, 42.0f, 43.0f, // 0-3, 2, 2
44.0f, 45.0f, 46.0f, 47.0f, // 0-3, 3, 2
48.0f, 49.0f, 50.0f, 51.0f, 52.0f, 53.0f, 54.0f, 55.0f,
56.0f, 57.0f, 58.0f, 59.0f, 60.0f, 61.0f, 62.0f, 63.0f
48.0f, 49.0f, 50.0f, 51.0f, // 0-3, 0, 3
52.0f, 53.0f, 54.0f, 55.0f, // 0-3, 1, 3
56.0f, 57.0f, 58.0f, 59.0f, // 0-3, 2, 3
60.0f, 61.0f, 62.0f, 63.0f // 0-3, 3, 3
};
dataSet.AddPointField("pointvar", pointvar, nVerts);

@ -85,17 +85,23 @@ public:
VTKM_CONT
void SetSampleRate(vtkm::Id3 sampleRate) { this->SampleRate = sampleRate; }
// Get if we should include the outer boundary on a subsample
// (NOTE: This method is deprecated because it is not clear from either
// the documentation or the source code what the intention of this feature
// is. If your are using this method somewhere and think it should remain,
// please open a merge request to "de-deprecate" it and add a test and
// documentation of the expected behavior.)
VTKM_DEPRECATED(2.2)
/// @brief Specifies if the outer boundary should always be included.
///
/// When a subsample rate is specified, it is possible that some of the
/// boundary samples will not be included in the sampling. If this is the
/// case and `IncludeBoundary` is set to true, then an extra sample is
/// set in the output and the values on the boundary are included. For example,
/// say the input has resolution (5, 5, 1) (and the VOI matches), and the sample
/// rate is set to (3, 3, 1). If `IncludeBoundary` is false, then the output will
/// have the 4 points that correspond to the 3D indices (0, 0, 0), (3, 0, 0),
/// (0, 3, 0), and (3, 3, 0) of the input. This misses the outer boundary at
/// index 4 in the x and y directions. If `IncludeBoundary is set to true, then
/// the output will have the 9 points that correspond to the 3D indices (0, 0, 0),
/// (3, 0, 0), (4, 0, 0), (0, 3, 0), (3, 3, 0), (4, 3, 0), (0, 4, 0), (3, 4, 0),
/// and (4, 4, 0) to capture this outer boundary.
VTKM_CONT
bool GetIncludeBoundary() const { return this->IncludeBoundary; }
// Set if we should include the outer boundary on a subsample
VTKM_DEPRECATED(2.2)
/// @copydoc GetIncludeBoundary
VTKM_CONT
void SetIncludeBoundary(bool value) { this->IncludeBoundary = value; }

@ -341,7 +341,7 @@ public:
static void TestUniform3D7()
{
std::cout << "Testing extract structured uniform" << std::endl;
std::cout << "Testing extract structured uniform, exclude boundary" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
vtkm::filter::entity_extraction::ExtractStructured extract;
@ -351,6 +351,7 @@ public:
vtkm::Id3 sample(3, 3, 2);
extract.SetVOI(range);
extract.SetSampleRate(sample);
extract.SetIncludeBoundary(false); // default
extract.SetFieldsToPass({ "pointvar", "cellvar" });
vtkm::cont::DataSet output = extract.Execute(dataset);
@ -371,16 +372,16 @@ public:
"Data/Geometry mismatch for ExtractStructured filter");
VTKM_TEST_ASSERT(outPointData.ReadPortal().Get(0) == 0.0f, "Wrong point field data");
VTKM_TEST_ASSERT(outPointData.ReadPortal().Get(3) == 99.0f, "Wrong point field data");
VTKM_TEST_ASSERT(outPointData.ReadPortal().Get(4) == 0.0f, "Wrong point field data");
VTKM_TEST_ASSERT(outPointData.ReadPortal().Get(7) == 97.0f, "Wrong point field data");
VTKM_TEST_ASSERT(outCellData.ReadPortal().Get(0) == 16.0f, "Wrong cell field data");
}
VTKM_DEPRECATED_SUPPRESS_BEGIN
// This test repeates TestUniform3D7 but uses deprecated behavior.
static void TestUniform3D8()
{
std::cout << "Testing extract structured uniform" << std::endl;
std::cout << "Testing extract structured uniform, include boundary" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
vtkm::filter::entity_extraction::ExtractStructured extract;
@ -411,12 +412,15 @@ public:
VTKM_TEST_ASSERT(outPointData.ReadPortal().Get(0) == 0.0f, "Wrong point field data");
VTKM_TEST_ASSERT(outPointData.ReadPortal().Get(4) == 99.0f, "Wrong point field data");
VTKM_TEST_ASSERT(outPointData.ReadPortal().Get(5) == 0.0f, "Wrong point field data");
VTKM_TEST_ASSERT(outPointData.ReadPortal().Get(7) == 0.0f, "Wrong point field data");
VTKM_TEST_ASSERT(outPointData.ReadPortal().Get(13) == 97.0f, "Wrong point field data");
VTKM_TEST_ASSERT(outCellData.ReadPortal().Get(0) == 16.0f, "Wrong cell field data");
VTKM_TEST_ASSERT(outCellData.ReadPortal().Get(1) == 19.0f, "Wrong cell field data");
VTKM_TEST_ASSERT(outCellData.ReadPortal().Get(2) == 28.0f, "Wrong cell field data");
VTKM_TEST_ASSERT(outCellData.ReadPortal().Get(3) == 31.0f, "Wrong cell field data");
}
VTKM_DEPRECATED_SUPPRESS_END
static void TestRectilinear2D()
{