mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-19 18:45:43 +00:00
Finish and clean-up unit test of HierarchicalHyperSweeper
This commit is contained in:
parent
b3582b9b48
commit
c584364122
@ -50,7 +50,8 @@
|
|||||||
// Oliver Ruebel (LBNL)
|
// Oliver Ruebel (LBNL)
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#define DEBUG_PRINT
|
// #define DEBUG_PRINT
|
||||||
|
// #define PRINT_RESULT
|
||||||
|
|
||||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||||
#include <vtkm/cont/testing/Testing.h>
|
#include <vtkm/cont/testing/Testing.h>
|
||||||
@ -77,6 +78,9 @@ void TestContourTreeMeshCombine(const std::string& mesh1_filename,
|
|||||||
const std::string& mesh2_filename,
|
const std::string& mesh2_filename,
|
||||||
const std::string& combined_filename)
|
const std::string& combined_filename)
|
||||||
{
|
{
|
||||||
|
std::cout << "Testing combining meshes " << mesh1_filename << " " << mesh2_filename
|
||||||
|
<< " with expected result " << combined_filename << std::endl;
|
||||||
|
|
||||||
vtkm::worklet::contourtree_augmented::ContourTreeMesh<FieldType> contourTreeMesh1;
|
vtkm::worklet::contourtree_augmented::ContourTreeMesh<FieldType> contourTreeMesh1;
|
||||||
contourTreeMesh1.Load(mesh1_filename.c_str());
|
contourTreeMesh1.Load(mesh1_filename.c_str());
|
||||||
vtkm::worklet::contourtree_augmented::ContourTreeMesh<FieldType> contourTreeMesh2;
|
vtkm::worklet::contourtree_augmented::ContourTreeMesh<FieldType> contourTreeMesh2;
|
||||||
@ -99,33 +103,13 @@ void TestContourTreeMeshCombine(const std::string& mesh1_filename,
|
|||||||
VTKM_TEST_ASSERT(contourTreeMesh2.MaxNeighbors == combinedContourTreeMesh.MaxNeighbors);
|
VTKM_TEST_ASSERT(contourTreeMesh2.MaxNeighbors == combinedContourTreeMesh.MaxNeighbors);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
template <typename PortalType, typename T>
|
|
||||||
static inline VTKM_CONT bool test_equal_portal_stl_vector(const PortalType1& portal,
|
|
||||||
const T[] array,
|
|
||||||
{
|
|
||||||
if (portal.GetNumberOfValues() != size)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (vtkm::Id index = 0; index < portal.GetNumberOfValues(); index++)
|
|
||||||
{
|
|
||||||
if (!test_equal(portal.Get(index), array[index]))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void TestHierarchicalHyperSweeper()
|
void TestHierarchicalHyperSweeper()
|
||||||
{
|
{
|
||||||
|
std::cout << "Testing HierarchicalHyperSweeper" << std::endl;
|
||||||
using vtkm::cont::testing::Testing;
|
using vtkm::cont::testing::Testing;
|
||||||
using ContourTreeDataFieldType = vtkm::FloatDefault;
|
using ContourTreeDataFieldType = vtkm::FloatDefault;
|
||||||
|
|
||||||
|
// Test input
|
||||||
const int numBlocks = 4;
|
const int numBlocks = 4;
|
||||||
const char* filenames[numBlocks] = { "misc/8x9test_HierarchicalAugmentedTree_Block0.dat",
|
const char* filenames[numBlocks] = { "misc/8x9test_HierarchicalAugmentedTree_Block0.dat",
|
||||||
"misc/8x9test_HierarchicalAugmentedTree_Block1.dat",
|
"misc/8x9test_HierarchicalAugmentedTree_Block1.dat",
|
||||||
@ -135,17 +119,30 @@ void TestHierarchicalHyperSweeper()
|
|||||||
vtkm::Id3 blocksPerDim{ 2, 2, 1 };
|
vtkm::Id3 blocksPerDim{ 2, 2, 1 };
|
||||||
vtkm::Id3 sizes[numBlocks] = { { 5, 4, 1 }, { 5, 5, 1 }, { 5, 4, 1 }, { 5, 5, 1 } };
|
vtkm::Id3 sizes[numBlocks] = { { 5, 4, 1 }, { 5, 5, 1 }, { 5, 4, 1 }, { 5, 5, 1 } };
|
||||||
vtkm::Id3 origins[numBlocks] = { { 0, 0, 0 }, { 0, 3, 0 }, { 4, 0, 0 }, { 4, 3, 0 } };
|
vtkm::Id3 origins[numBlocks] = { { 0, 0, 0 }, { 0, 3, 0 }, { 4, 0, 0 }, { 4, 3, 0 } };
|
||||||
|
vtkm::Id3 blockIndices[numBlocks] = { { 0, 0, 0 }, { 0, 1, 0 }, { 1, 0, 0 }, { 1, 1, 0 } };
|
||||||
|
|
||||||
auto blockIndicesAH = vtkm::cont::make_ArrayHandle(
|
// Expected output
|
||||||
{ vtkm::Id3{ 0, 0, 0 }, vtkm::Id3{ 0, 1, 0 }, vtkm::Id3{ 1, 0, 0 }, vtkm::Id3{ 1, 1, 0 } });
|
vtkm::cont::ArrayHandle<vtkm::Id> expectedIntrinsicVolume[numBlocks] = {
|
||||||
auto originsAH = vtkm::cont::make_ArrayHandle(
|
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 6, 9, 8, 24, 20, 1, 1 }),
|
||||||
{ vtkm::Id3{ 0, 0, 0 }, vtkm::Id3{ 0, 3, 0 }, vtkm::Id3{ 4, 0, 0 }, vtkm::Id3{ 4, 3, 0 } });
|
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 6, 9, 8, 24, 20, 1, 1 }),
|
||||||
auto sizesAH = vtkm::cont::make_ArrayHandle(
|
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 6, 9, 8, 24, 20, 1 }),
|
||||||
{ vtkm::Id3{ 5, 4, 1 }, vtkm::Id3{ 5, 5, 1 }, vtkm::Id3{ 5, 4, 1 }, vtkm::Id3{ 5, 5, 1 } });
|
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 6, 9, 8, 24, 20, 1, 2 })
|
||||||
|
};
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> expectedDependentVolume[numBlocks] = {
|
||||||
|
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 6, 9, 18, 24, 46, 72, 1 }),
|
||||||
|
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 6, 9, 18, 24, 46, 72, 1 }),
|
||||||
|
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 6, 9, 18, 24, 46, 72 }),
|
||||||
|
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 6, 9, 18, 24, 46, 72, 2 })
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create spatial decomposition
|
||||||
vtkm::worklet::contourtree_distributed::SpatialDecomposition spatialDecomp(
|
vtkm::worklet::contourtree_distributed::SpatialDecomposition spatialDecomp(
|
||||||
blocksPerDim, globalSize, blockIndicesAH, originsAH, sizesAH);
|
blocksPerDim,
|
||||||
|
globalSize,
|
||||||
|
vtkm::cont::make_ArrayHandle(blockIndices, numBlocks, vtkm::CopyFlag::Off),
|
||||||
|
vtkm::cont::make_ArrayHandle(origins, numBlocks, vtkm::CopyFlag::Off),
|
||||||
|
vtkm::cont::make_ArrayHandle(sizes, numBlocks, vtkm::CopyFlag::Off));
|
||||||
|
|
||||||
// Load trees
|
// Load trees
|
||||||
vtkm::worklet::contourtree_distributed::HierarchicalContourTree<vtkm::FloatDefault>
|
vtkm::worklet::contourtree_distributed::HierarchicalContourTree<vtkm::FloatDefault>
|
||||||
@ -153,7 +150,9 @@ void TestHierarchicalHyperSweeper()
|
|||||||
for (vtkm::Id blockNo = 0; blockNo < numBlocks; ++blockNo)
|
for (vtkm::Id blockNo = 0; blockNo < numBlocks; ++blockNo)
|
||||||
{
|
{
|
||||||
hct[blockNo].Load(Testing::DataPath(filenames[blockNo]).c_str());
|
hct[blockNo].Load(Testing::DataPath(filenames[blockNo]).c_str());
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
std::cout << hct[blockNo].DebugPrint("AfterLoad", __FILE__, __LINE__);
|
std::cout << hct[blockNo].DebugPrint("AfterLoad", __FILE__, __LINE__);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and add DIY blocks
|
// Create and add DIY blocks
|
||||||
@ -225,18 +224,23 @@ void TestHierarchicalHyperSweeper()
|
|||||||
master.foreach (
|
master.foreach (
|
||||||
[](vtkm::worklet::contourtree_distributed::HyperSweepBlock<ContourTreeDataFieldType>* b,
|
[](vtkm::worklet::contourtree_distributed::HyperSweepBlock<ContourTreeDataFieldType>* b,
|
||||||
const vtkmdiy::Master::ProxyWithLink&) {
|
const vtkmdiy::Master::ProxyWithLink&) {
|
||||||
// Create HyperSweeper
|
#ifdef DEBUG_PRINT
|
||||||
std::cout << "Block " << b->GlobalBlockId << std::endl;
|
std::cout << "Block " << b->GlobalBlockId << std::endl;
|
||||||
std::cout << b->HierarchicalContourTree.DebugPrint(
|
std::cout << b->HierarchicalContourTree.DebugPrint(
|
||||||
"Before initializing HyperSweeper", __FILE__, __LINE__);
|
"Before initializing HyperSweeper", __FILE__, __LINE__);
|
||||||
|
#endif
|
||||||
|
// Create HyperSweeper
|
||||||
vtkm::worklet::contourtree_distributed::HierarchicalHyperSweeper<vtkm::Id,
|
vtkm::worklet::contourtree_distributed::HierarchicalHyperSweeper<vtkm::Id,
|
||||||
ContourTreeDataFieldType>
|
ContourTreeDataFieldType>
|
||||||
hyperSweeper(
|
hyperSweeper(
|
||||||
b->GlobalBlockId, b->HierarchicalContourTree, b->IntrinsicVolume, b->DependentVolume);
|
b->GlobalBlockId, b->HierarchicalContourTree, b->IntrinsicVolume, b->DependentVolume);
|
||||||
|
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
std::cout << "Block " << b->GlobalBlockId << std::endl;
|
std::cout << "Block " << b->GlobalBlockId << std::endl;
|
||||||
std::cout << b->HierarchicalContourTree.DebugPrint(
|
std::cout << b->HierarchicalContourTree.DebugPrint(
|
||||||
"After initializing HyperSweeper", __FILE__, __LINE__);
|
"After initializing HyperSweeper", __FILE__, __LINE__);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Create mesh and initialize vertex counts
|
// Create mesh and initialize vertex counts
|
||||||
vtkm::worklet::contourtree_augmented::mesh_dem::IdRelabeler idRelabeler{ b->Origin,
|
vtkm::worklet::contourtree_augmented::mesh_dem::IdRelabeler idRelabeler{ b->Origin,
|
||||||
b->Size,
|
b->Size,
|
||||||
@ -258,17 +262,23 @@ void TestHierarchicalHyperSweeper()
|
|||||||
b->HierarchicalContourTree, mesh, idRelabeler, b->IntrinsicVolume);
|
b->HierarchicalContourTree, mesh, idRelabeler, b->IntrinsicVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
std::cout << "Block " << b->GlobalBlockId << std::endl;
|
std::cout << "Block " << b->GlobalBlockId << std::endl;
|
||||||
std::cout << b->HierarchicalContourTree.DebugPrint(
|
std::cout << b->HierarchicalContourTree.DebugPrint(
|
||||||
"After initializing intrinsic vertex count", __FILE__, __LINE__);
|
"After initializing intrinsic vertex count", __FILE__, __LINE__);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Initialize dependentVolume by copy from intrinsicVolume
|
// Initialize dependentVolume by copy from intrinsicVolume
|
||||||
vtkm::cont::Algorithm::Copy(b->IntrinsicVolume, b->DependentVolume);
|
vtkm::cont::Algorithm::Copy(b->IntrinsicVolume, b->DependentVolume);
|
||||||
|
|
||||||
// Perform the local hypersweep
|
// Perform the local hypersweep
|
||||||
hyperSweeper.LocalHyperSweep();
|
hyperSweeper.LocalHyperSweep();
|
||||||
|
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
std::cout << "Block " << b->GlobalBlockId << std::endl;
|
std::cout << "Block " << b->GlobalBlockId << std::endl;
|
||||||
std::cout << b->HierarchicalContourTree.DebugPrint(
|
std::cout << b->HierarchicalContourTree.DebugPrint(
|
||||||
"After local hypersweep", __FILE__, __LINE__);
|
"After local hypersweep", __FILE__, __LINE__);
|
||||||
|
#endif
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reduce
|
// Reduce
|
||||||
@ -284,6 +294,7 @@ void TestHierarchicalHyperSweeper()
|
|||||||
vtkm::worklet::contourtree_distributed::CobmineHyperSweepBlockFunctor<
|
vtkm::worklet::contourtree_distributed::CobmineHyperSweepBlockFunctor<
|
||||||
ContourTreeDataFieldType>{});
|
ContourTreeDataFieldType>{});
|
||||||
|
|
||||||
|
#ifdef PRINT_RESULT
|
||||||
// Print
|
// Print
|
||||||
vtkm::Id totalVolume = globalSize[0] * globalSize[1] * globalSize[2];
|
vtkm::Id totalVolume = globalSize[0] * globalSize[1] * globalSize[2];
|
||||||
master.foreach (
|
master.foreach (
|
||||||
@ -309,6 +320,28 @@ void TestHierarchicalHyperSweeper()
|
|||||||
b->IntrinsicVolume,
|
b->IntrinsicVolume,
|
||||||
b->DependentVolume);
|
b->DependentVolume);
|
||||||
});
|
});
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Compare to expected results
|
||||||
|
master.foreach (
|
||||||
|
[&expectedIntrinsicVolume, &expectedDependentVolume](
|
||||||
|
vtkm::worklet::contourtree_distributed::HyperSweepBlock<ContourTreeDataFieldType>* b,
|
||||||
|
const vtkmdiy::Master::ProxyWithLink&) {
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
|
vtkm::worklet::contourtree_augmented::PrintIndices(
|
||||||
|
"Intrinsic Volume", b->IntrinsicVolume, -1, std::cout);
|
||||||
|
vtkm::worklet::contourtree_augmented::PrintIndices(
|
||||||
|
"Expected Intrinsic Volume", expectedIntrinsicVolume[b->GlobalBlockId], -1, std::cout);
|
||||||
|
vtkm::worklet::contourtree_augmented::PrintIndices(
|
||||||
|
"Dependent Volume", b->DependentVolume, -1, std::cout);
|
||||||
|
vtkm::worklet::contourtree_augmented::PrintIndices(
|
||||||
|
"Expected Dependent Volume", expectedDependentVolume[b->GlobalBlockId], -1, std::cout);
|
||||||
|
#endif
|
||||||
|
VTKM_TEST_ASSERT(test_equal_portals(expectedIntrinsicVolume[b->GlobalBlockId].ReadPortal(),
|
||||||
|
b->IntrinsicVolume.ReadPortal()));
|
||||||
|
VTKM_TEST_ASSERT(test_equal_portals(expectedDependentVolume[b->GlobalBlockId].ReadPortal(),
|
||||||
|
b->DependentVolume.ReadPortal()));
|
||||||
|
});
|
||||||
|
|
||||||
// Clean-up
|
// Clean-up
|
||||||
for (auto b : localHyperSweeperBlocks)
|
for (auto b : localHyperSweeperBlocks)
|
||||||
|
Loading…
Reference in New Issue
Block a user