mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Consolidate UnitTestDataSet*
Previously, each device adapter implementation had their own version of these tests by including a common header. Simplify this by making a single test in UnitTests_vtkm_cont_testing for each, which can now be compiled for and tested on a device.
This commit is contained in:
parent
f48789f57c
commit
b2b075f047
@ -9,8 +9,6 @@
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestCudaDataSetExplicit.cu
|
||||
UnitTestCudaDataSetSingleType.cu
|
||||
UnitTestCudaDeviceAdapter.cu
|
||||
UnitTestCudaImplicitFunction.cu
|
||||
UnitTestCudaIterators.cu
|
||||
|
@ -1,22 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/cuda/DeviceAdapterCuda.h>
|
||||
#include <vtkm/cont/cuda/internal/testing/Testing.h>
|
||||
#include <vtkm/cont/testing/TestingDataSetExplicit.h>
|
||||
|
||||
int UnitTestCudaDataSetExplicit(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{});
|
||||
int result =
|
||||
vtkm::cont::testing::TestingDataSetExplicit<vtkm::cont::DeviceAdapterTagCuda>::Run(argc, argv);
|
||||
return vtkm::cont::cuda::internal::Testing::CheckCudaBeforeExit(result);
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/cuda/DeviceAdapterCuda.h>
|
||||
|
||||
#include <vtkm/cont/cuda/internal/testing/Testing.h>
|
||||
#include <vtkm/cont/testing/TestingDataSetSingleType.h>
|
||||
|
||||
int UnitTestCudaDataSetSingleType(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{});
|
||||
int result = vtkm::cont::testing::TestingDataSetSingleType<vtkm::cont::DeviceAdapterTagCuda>::Run(
|
||||
argc, argv);
|
||||
return vtkm::cont::cuda::internal::Testing::CheckCudaBeforeExit(result);
|
||||
}
|
@ -9,8 +9,6 @@
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestKokkosDataSetExplicit.cxx
|
||||
UnitTestKokkosDataSetSingleType.cxx
|
||||
UnitTestKokkosDeviceAdapter.cxx
|
||||
UnitTestKokkosImplicitFunction.cxx
|
||||
UnitTestKokkosPointLocatorSparseGrid.cxx
|
||||
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/kokkos/DeviceAdapterKokkos.h>
|
||||
#include <vtkm/cont/testing/TestingDataSetExplicit.h>
|
||||
|
||||
int UnitTestKokkosDataSetExplicit(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagKokkos{});
|
||||
return vtkm::cont::testing::TestingDataSetExplicit<vtkm::cont::DeviceAdapterTagKokkos>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/kokkos/DeviceAdapterKokkos.h>
|
||||
#include <vtkm/cont/testing/TestingDataSetSingleType.h>
|
||||
|
||||
int UnitTestKokkosDataSetSingleType(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagKokkos{});
|
||||
return vtkm::cont::testing::TestingDataSetSingleType<vtkm::cont::DeviceAdapterTagKokkos>::Run(
|
||||
argc, argv);
|
||||
}
|
@ -9,8 +9,6 @@
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestOpenMPDataSetExplicit.cxx
|
||||
UnitTestOpenMPDataSetSingleType.cxx
|
||||
UnitTestOpenMPDeviceAdapter.cxx
|
||||
UnitTestOpenMPImplicitFunction.cxx
|
||||
UnitTestOpenMPPointLocatorSparseGrid.cxx
|
||||
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#include <vtkm/cont/openmp/DeviceAdapterOpenMP.h>
|
||||
#include <vtkm/cont/testing/TestingDataSetExplicit.h>
|
||||
|
||||
int UnitTestOpenMPDataSetExplicit(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{});
|
||||
return vtkm::cont::testing::TestingDataSetExplicit<vtkm::cont::DeviceAdapterTagOpenMP>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#include <vtkm/cont/openmp/DeviceAdapterOpenMP.h>
|
||||
#include <vtkm/cont/testing/TestingDataSetSingleType.h>
|
||||
|
||||
int UnitTestOpenMPDataSetSingleType(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{});
|
||||
return vtkm::cont::testing::TestingDataSetSingleType<vtkm::cont::DeviceAdapterTagOpenMP>::Run(
|
||||
argc, argv);
|
||||
}
|
@ -9,8 +9,6 @@
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestSerialDataSetExplicit.cxx
|
||||
UnitTestSerialDataSetSingleType.cxx
|
||||
UnitTestSerialDeviceAdapter.cxx
|
||||
UnitTestSerialImplicitFunction.cxx
|
||||
UnitTestSerialPointLocatorSparseGrid.cxx
|
||||
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/serial/DeviceAdapterSerial.h>
|
||||
#include <vtkm/cont/testing/TestingDataSetExplicit.h>
|
||||
|
||||
int UnitTestSerialDataSetExplicit(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{});
|
||||
return vtkm::cont::testing::TestingDataSetExplicit<vtkm::cont::DeviceAdapterTagSerial>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/serial/DeviceAdapterSerial.h>
|
||||
#include <vtkm/cont/testing/TestingDataSetSingleType.h>
|
||||
|
||||
int UnitTestSerialDataSetSingleType(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{});
|
||||
return vtkm::cont::testing::TestingDataSetSingleType<vtkm::cont::DeviceAdapterTagSerial>::Run(
|
||||
argc, argv);
|
||||
}
|
@ -9,8 +9,6 @@
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestTBBDataSetExplicit.cxx
|
||||
UnitTestTBBDataSetSingleType.cxx
|
||||
UnitTestTBBDeviceAdapter.cxx
|
||||
UnitTestTBBImplicitFunction.cxx
|
||||
UnitTestTBBPointLocatorSparseGrid.cxx
|
||||
|
@ -1,21 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/tbb/DeviceAdapterTBB.h>
|
||||
|
||||
#include <vtkm/cont/testing/TestingDataSetExplicit.h>
|
||||
|
||||
int UnitTestTBBDataSetExplicit(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{});
|
||||
return vtkm::cont::testing::TestingDataSetExplicit<vtkm::cont::DeviceAdapterTagTBB>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/tbb/DeviceAdapterTBB.h>
|
||||
|
||||
#include <vtkm/cont/testing/TestingDataSetSingleType.h>
|
||||
|
||||
int UnitTestTBBDataSetSingleType(int argc, char* argv[])
|
||||
{
|
||||
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{});
|
||||
return vtkm::cont::testing::TestingDataSetSingleType<vtkm::cont::DeviceAdapterTagTBB>::Run(argc,
|
||||
argv);
|
||||
}
|
@ -13,8 +13,6 @@ set(headers
|
||||
MakeTestDataSet.h
|
||||
Testing.h
|
||||
TestingDeviceAdapter.h
|
||||
TestingDataSetExplicit.h
|
||||
TestingDataSetSingleType.h
|
||||
TestingImplicitFunction.h
|
||||
TestingPointLocatorSparseGrid.h
|
||||
TestingRuntimeDeviceConfiguration.h
|
||||
@ -44,6 +42,7 @@ set(unit_tests
|
||||
UnitTestDataSetBuilderRectilinear.cxx
|
||||
UnitTestDataSetBuilderUniform.cxx
|
||||
UnitTestDataSetConvertToExpected.cxx
|
||||
UnitTestDataSetExplicit.cxx
|
||||
UnitTestDataSetRectilinear.cxx
|
||||
UnitTestDataSetUniform.cxx
|
||||
UnitTestDeviceAdapterAlgorithmGeneral.cxx
|
||||
@ -106,6 +105,7 @@ set(unit_tests_device
|
||||
UnitTestCellSetPermutation.cxx
|
||||
UnitTestColorTable.cxx
|
||||
UnitTestDataSetPermutation.cxx
|
||||
UnitTestDataSetSingleType.cxx
|
||||
UnitTestDeviceAdapterAlgorithmDependency.cxx
|
||||
UnitTestParticleArrayCopy.cxx
|
||||
)
|
||||
|
@ -1,165 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#ifndef vtk_m_cont_testing_TestingDataSetExplicit_h
|
||||
#define vtk_m_cont_testing_TestingDataSetExplicit_h
|
||||
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
namespace testing
|
||||
{
|
||||
|
||||
/// This class has a single static member, Run, that tests DataSetExplicit
|
||||
/// with the given DeviceAdapter
|
||||
///
|
||||
template <class DeviceAdapterTag>
|
||||
class TestingDataSetExplicit
|
||||
{
|
||||
private:
|
||||
template <typename T, typename Storage>
|
||||
static bool TestArrayHandle(const vtkm::cont::ArrayHandle<T, Storage>& ah,
|
||||
const T* expected,
|
||||
vtkm::Id size)
|
||||
{
|
||||
if (size != ah.GetNumberOfValues())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ahPortal = ah.ReadPortal();
|
||||
for (vtkm::Id i = 0; i < size; ++i)
|
||||
{
|
||||
if (ahPortal.Get(i) != expected[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void TestDataSet_Explicit()
|
||||
{
|
||||
vtkm::cont::testing::MakeTestDataSet tds;
|
||||
vtkm::cont::DataSet ds = tds.Make3DExplicitDataSet0();
|
||||
|
||||
VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Incorrect number of fields");
|
||||
|
||||
// test various field-getting methods and associations
|
||||
const vtkm::cont::Field& f1 = ds.GetField("pointvar");
|
||||
VTKM_TEST_ASSERT(f1.GetAssociation() == vtkm::cont::Field::Association::Points,
|
||||
"Association of 'pointvar' was not Association::Points");
|
||||
try
|
||||
{
|
||||
ds.GetCellField("cellvar");
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
VTKM_TEST_FAIL("Failed to get field 'cellvar' with Association::Cells.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ds.GetPointField("cellvar");
|
||||
VTKM_TEST_FAIL("Failed to get expected error for association mismatch.");
|
||||
}
|
||||
catch (vtkm::cont::ErrorBadValue& error)
|
||||
{
|
||||
std::cout << "Caught expected error for association mismatch: " << std::endl
|
||||
<< " " << error.GetMessage() << std::endl;
|
||||
}
|
||||
|
||||
VTKM_TEST_ASSERT(ds.GetNumberOfCoordinateSystems() == 1,
|
||||
"Incorrect number of coordinate systems");
|
||||
|
||||
// test cell-to-point connectivity
|
||||
vtkm::cont::CellSetExplicit<> cellset;
|
||||
ds.GetCellSet().AsCellSet(cellset);
|
||||
|
||||
vtkm::Id connectivitySize = 7;
|
||||
vtkm::Id numPoints = 5;
|
||||
|
||||
vtkm::UInt8 correctShapes[] = { 1, 1, 1, 1, 1 };
|
||||
vtkm::IdComponent correctNumIndices[] = { 1, 2, 2, 1, 1 };
|
||||
vtkm::Id correctConnectivity[] = { 0, 0, 1, 0, 1, 1, 1 };
|
||||
|
||||
vtkm::cont::ArrayHandleConstant<vtkm::UInt8> shapes =
|
||||
cellset.GetShapesArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
|
||||
auto numIndices =
|
||||
cellset.GetNumIndicesArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> conn =
|
||||
cellset.GetConnectivityArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
|
||||
|
||||
VTKM_TEST_ASSERT(TestArrayHandle(shapes, correctShapes, numPoints), "Got incorrect shapes");
|
||||
VTKM_TEST_ASSERT(TestArrayHandle(numIndices, correctNumIndices, numPoints),
|
||||
"Got incorrect numIndices");
|
||||
|
||||
// Some device adapters have unstable sorts, which may cause the order of
|
||||
// the indices for each point to be different but still correct. Iterate
|
||||
// over all the points and check the connectivity for each one.
|
||||
VTKM_TEST_ASSERT(conn.GetNumberOfValues() == connectivitySize,
|
||||
"Connectivity array wrong size.");
|
||||
vtkm::Id connectivityIndex = 0;
|
||||
auto connPortal = conn.ReadPortal();
|
||||
for (vtkm::Id pointIndex = 0; pointIndex < numPoints; pointIndex++)
|
||||
{
|
||||
vtkm::IdComponent numIncidentCells = correctNumIndices[pointIndex];
|
||||
std::set<vtkm::Id> correctIncidentCells;
|
||||
for (vtkm::IdComponent cellIndex = 0; cellIndex < numIncidentCells; cellIndex++)
|
||||
{
|
||||
correctIncidentCells.insert(correctConnectivity[connectivityIndex + cellIndex]);
|
||||
}
|
||||
for (vtkm::IdComponent cellIndex = 0; cellIndex < numIncidentCells; cellIndex++)
|
||||
{
|
||||
vtkm::Id expectedCell = connPortal.Get(connectivityIndex + cellIndex);
|
||||
std::set<vtkm::Id>::iterator foundCell = correctIncidentCells.find(expectedCell);
|
||||
VTKM_TEST_ASSERT(foundCell != correctIncidentCells.end(),
|
||||
"An incident cell in the connectivity list is wrong or repeated.");
|
||||
correctIncidentCells.erase(foundCell);
|
||||
}
|
||||
connectivityIndex += numIncidentCells;
|
||||
}
|
||||
|
||||
//verify that GetIndices works properly
|
||||
vtkm::Id expectedPointIds[4] = { 2, 1, 3, 4 };
|
||||
vtkm::Id4 retrievedPointIds;
|
||||
cellset.GetIndices(1, retrievedPointIds);
|
||||
for (vtkm::IdComponent i = 0; i < 4; i++)
|
||||
{
|
||||
VTKM_TEST_ASSERT(retrievedPointIds[i] == expectedPointIds[i],
|
||||
"Incorrect point ID for quad cell");
|
||||
}
|
||||
}
|
||||
|
||||
struct TestAll
|
||||
{
|
||||
VTKM_CONT void operator()() const { TestingDataSetExplicit::TestDataSet_Explicit(); }
|
||||
};
|
||||
|
||||
public:
|
||||
static VTKM_CONT int Run(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestAll(), argc, argv);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::testing
|
||||
|
||||
#endif // vtk_m_cont_testing_TestingDataSetExplicit_h
|
@ -1,153 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#ifndef vtk_m_cont_testing_TestingDataSetSingleType_h
|
||||
#define vtk_m_cont_testing_TestingDataSetSingleType_h
|
||||
|
||||
#include <vtkm/cont/CellSetSingleType.h>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/DataSetBuilderExplicit.h>
|
||||
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <vtkm/filter/field_conversion/worklet/CellAverage.h>
|
||||
#include <vtkm/worklet/DispatcherMapTopology.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
namespace testing
|
||||
{
|
||||
|
||||
/// This class has a single static member, Run, that tests DataSetSingleType
|
||||
/// with the given DeviceAdapter
|
||||
///
|
||||
template <class DeviceAdapterTag>
|
||||
class TestingDataSetSingleType
|
||||
{
|
||||
private:
|
||||
template <typename T, typename Storage>
|
||||
static bool TestArrayHandle(const vtkm::cont::ArrayHandle<T, Storage>& ah,
|
||||
const T* expected,
|
||||
vtkm::Id size)
|
||||
{
|
||||
if (size != ah.GetNumberOfValues())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto portal = ah.ReadPortal();
|
||||
for (vtkm::Id i = 0; i < size; ++i)
|
||||
{
|
||||
if (portal.Get(i) != expected[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline vtkm::cont::DataSet make_SingleTypeDataSet()
|
||||
{
|
||||
using CoordType = vtkm::Vec3f_32;
|
||||
std::vector<CoordType> coordinates;
|
||||
coordinates.push_back(CoordType(0, 0, 0));
|
||||
coordinates.push_back(CoordType(1, 0, 0));
|
||||
coordinates.push_back(CoordType(1, 1, 0));
|
||||
coordinates.push_back(CoordType(2, 1, 0));
|
||||
coordinates.push_back(CoordType(2, 2, 0));
|
||||
|
||||
std::vector<vtkm::Id> conn;
|
||||
// First Cell
|
||||
conn.push_back(0);
|
||||
conn.push_back(1);
|
||||
conn.push_back(2);
|
||||
// Second Cell
|
||||
conn.push_back(1);
|
||||
conn.push_back(2);
|
||||
conn.push_back(3);
|
||||
// Third Cell
|
||||
conn.push_back(2);
|
||||
conn.push_back(3);
|
||||
conn.push_back(4);
|
||||
|
||||
vtkm::cont::DataSet ds;
|
||||
vtkm::cont::DataSetBuilderExplicit builder;
|
||||
ds = builder.Create(coordinates, vtkm::CellShapeTagTriangle(), 3, conn);
|
||||
|
||||
//Set point scalar
|
||||
const int nVerts = 5;
|
||||
vtkm::Float32 vars[nVerts] = { 10.1f, 20.1f, 30.2f, 40.2f, 50.3f };
|
||||
|
||||
ds.AddPointField("pointvar", vars, nVerts);
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
static void TestDataSet_SingleType()
|
||||
{
|
||||
vtkm::cont::DataSet dataSet = make_SingleTypeDataSet();
|
||||
|
||||
//verify that we can get a CellSetSingleType from a dataset
|
||||
vtkm::cont::CellSetSingleType<> cellset;
|
||||
dataSet.GetCellSet().AsCellSet(cellset);
|
||||
|
||||
//verify that the point to cell connectivity types are correct
|
||||
vtkm::cont::ArrayHandleConstant<vtkm::UInt8> shapesPointToCell =
|
||||
cellset.GetShapesArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint());
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> connPointToCell =
|
||||
cellset.GetConnectivityArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint());
|
||||
|
||||
VTKM_TEST_ASSERT(shapesPointToCell.GetNumberOfValues() == 3, "Wrong number of shapes");
|
||||
VTKM_TEST_ASSERT(connPointToCell.GetNumberOfValues() == 9, "Wrong connectivity length");
|
||||
|
||||
//verify that the cell to point connectivity types are correct
|
||||
//note the handle storage types differ compared to point to cell
|
||||
vtkm::cont::ArrayHandleConstant<vtkm::UInt8> shapesCellToPoint =
|
||||
cellset.GetShapesArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> connCellToPoint =
|
||||
cellset.GetConnectivityArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
|
||||
|
||||
VTKM_TEST_ASSERT(shapesCellToPoint.GetNumberOfValues() == 5, "Wrong number of shapes");
|
||||
VTKM_TEST_ASSERT(connCellToPoint.GetNumberOfValues() == 9, "Wrong connectivity length");
|
||||
|
||||
//run a basic for-each topology algorithm on this
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> result;
|
||||
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellAverage> dispatcher;
|
||||
dispatcher.SetDevice(DeviceAdapterTag());
|
||||
dispatcher.Invoke(cellset, dataSet.GetField("pointvar"), result);
|
||||
|
||||
vtkm::Float32 expected[3] = { 20.1333f, 30.1667f, 40.2333f };
|
||||
auto portal = result.ReadPortal();
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
VTKM_TEST_ASSERT(test_equal(portal.Get(i), expected[i]),
|
||||
"Wrong result for CellAverage worklet on explicit single type cellset data");
|
||||
}
|
||||
}
|
||||
|
||||
struct TestAll
|
||||
{
|
||||
VTKM_CONT void operator()() const { TestingDataSetSingleType::TestDataSet_SingleType(); }
|
||||
};
|
||||
|
||||
public:
|
||||
static VTKM_CONT int Run(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestAll(), argc, argv);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::testing
|
||||
|
||||
#endif // vtk_m_cont_testing_TestingDataSetSingleType_h
|
144
vtkm/cont/testing/UnitTestDataSetExplicit.cxx
Normal file
144
vtkm/cont/testing/UnitTestDataSetExplicit.cxx
Normal file
@ -0,0 +1,144 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
template <typename T, typename Storage>
|
||||
bool TestArrayHandle(const vtkm::cont::ArrayHandle<T, Storage>& ah,
|
||||
const T* expected,
|
||||
vtkm::Id size)
|
||||
{
|
||||
if (size != ah.GetNumberOfValues())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ahPortal = ah.ReadPortal();
|
||||
for (vtkm::Id i = 0; i < size; ++i)
|
||||
{
|
||||
if (ahPortal.Get(i) != expected[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TestDataSet_Explicit()
|
||||
{
|
||||
vtkm::cont::testing::MakeTestDataSet tds;
|
||||
vtkm::cont::DataSet ds = tds.Make3DExplicitDataSet0();
|
||||
|
||||
VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Incorrect number of fields");
|
||||
|
||||
// test various field-getting methods and associations
|
||||
const vtkm::cont::Field& f1 = ds.GetField("pointvar");
|
||||
VTKM_TEST_ASSERT(f1.GetAssociation() == vtkm::cont::Field::Association::Points,
|
||||
"Association of 'pointvar' was not Association::Points");
|
||||
try
|
||||
{
|
||||
ds.GetCellField("cellvar");
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
VTKM_TEST_FAIL("Failed to get field 'cellvar' with Association::Cells.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ds.GetPointField("cellvar");
|
||||
VTKM_TEST_FAIL("Failed to get expected error for association mismatch.");
|
||||
}
|
||||
catch (vtkm::cont::ErrorBadValue& error)
|
||||
{
|
||||
std::cout << "Caught expected error for association mismatch: " << std::endl
|
||||
<< " " << error.GetMessage() << std::endl;
|
||||
}
|
||||
|
||||
VTKM_TEST_ASSERT(ds.GetNumberOfCoordinateSystems() == 1,
|
||||
"Incorrect number of coordinate systems");
|
||||
|
||||
// test cell-to-point connectivity
|
||||
vtkm::cont::CellSetExplicit<> cellset;
|
||||
ds.GetCellSet().AsCellSet(cellset);
|
||||
|
||||
vtkm::Id connectivitySize = 7;
|
||||
vtkm::Id numPoints = 5;
|
||||
|
||||
vtkm::UInt8 correctShapes[] = { 1, 1, 1, 1, 1 };
|
||||
vtkm::IdComponent correctNumIndices[] = { 1, 2, 2, 1, 1 };
|
||||
vtkm::Id correctConnectivity[] = { 0, 0, 1, 0, 1, 1, 1 };
|
||||
|
||||
vtkm::cont::ArrayHandleConstant<vtkm::UInt8> shapes =
|
||||
cellset.GetShapesArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
|
||||
auto numIndices =
|
||||
cellset.GetNumIndicesArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> conn =
|
||||
cellset.GetConnectivityArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
|
||||
|
||||
VTKM_TEST_ASSERT(TestArrayHandle(shapes, correctShapes, numPoints), "Got incorrect shapes");
|
||||
VTKM_TEST_ASSERT(TestArrayHandle(numIndices, correctNumIndices, numPoints),
|
||||
"Got incorrect numIndices");
|
||||
|
||||
// Some device adapters have unstable sorts, which may cause the order of
|
||||
// the indices for each point to be different but still correct. Iterate
|
||||
// over all the points and check the connectivity for each one.
|
||||
VTKM_TEST_ASSERT(conn.GetNumberOfValues() == connectivitySize, "Connectivity array wrong size.");
|
||||
vtkm::Id connectivityIndex = 0;
|
||||
auto connPortal = conn.ReadPortal();
|
||||
for (vtkm::Id pointIndex = 0; pointIndex < numPoints; pointIndex++)
|
||||
{
|
||||
vtkm::IdComponent numIncidentCells = correctNumIndices[pointIndex];
|
||||
std::set<vtkm::Id> correctIncidentCells;
|
||||
for (vtkm::IdComponent cellIndex = 0; cellIndex < numIncidentCells; cellIndex++)
|
||||
{
|
||||
correctIncidentCells.insert(correctConnectivity[connectivityIndex + cellIndex]);
|
||||
}
|
||||
for (vtkm::IdComponent cellIndex = 0; cellIndex < numIncidentCells; cellIndex++)
|
||||
{
|
||||
vtkm::Id expectedCell = connPortal.Get(connectivityIndex + cellIndex);
|
||||
std::set<vtkm::Id>::iterator foundCell = correctIncidentCells.find(expectedCell);
|
||||
VTKM_TEST_ASSERT(foundCell != correctIncidentCells.end(),
|
||||
"An incident cell in the connectivity list is wrong or repeated.");
|
||||
correctIncidentCells.erase(foundCell);
|
||||
}
|
||||
connectivityIndex += numIncidentCells;
|
||||
}
|
||||
|
||||
//verify that GetIndices works properly
|
||||
vtkm::Id expectedPointIds[4] = { 2, 1, 3, 4 };
|
||||
vtkm::Id4 retrievedPointIds;
|
||||
cellset.GetIndices(1, retrievedPointIds);
|
||||
for (vtkm::IdComponent i = 0; i < 4; i++)
|
||||
{
|
||||
VTKM_TEST_ASSERT(retrievedPointIds[i] == expectedPointIds[i],
|
||||
"Incorrect point ID for quad cell");
|
||||
}
|
||||
}
|
||||
|
||||
void TestAll()
|
||||
{
|
||||
TestDataSet_Explicit();
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestDataSetExplicit(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestAll, argc, argv);
|
||||
}
|
160
vtkm/cont/testing/UnitTestDataSetSingleType.cxx
Normal file
160
vtkm/cont/testing/UnitTestDataSetSingleType.cxx
Normal file
@ -0,0 +1,160 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/ArrayCopy.h>
|
||||
#include <vtkm/cont/CellSetSingleType.h>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/DataSetBuilderExplicit.h>
|
||||
#include <vtkm/cont/Invoker.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <vtkm/filter/field_conversion/worklet/CellAverage.h>
|
||||
#include <vtkm/worklet/DispatcherMapTopology.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
//simple functor that returns the average point value as a cell field
|
||||
class CellAverage : public vtkm::worklet::WorkletVisitCellsWithPoints
|
||||
{
|
||||
public:
|
||||
using ControlSignature = void(CellSetIn cellset, FieldInPoint inPoints, FieldOutCell outCells);
|
||||
using ExecutionSignature = void(PointCount, _2, _3);
|
||||
using InputDomain = _1;
|
||||
|
||||
template <typename PointValueVecType, typename OutType>
|
||||
VTKM_EXEC void operator()(const vtkm::IdComponent& numPoints,
|
||||
const PointValueVecType& pointValues,
|
||||
OutType& average) const
|
||||
{
|
||||
average = OutType(pointValues[0]);
|
||||
for (vtkm::IdComponent pointIndex = 1; pointIndex < numPoints; ++pointIndex)
|
||||
{
|
||||
average = average + pointValues[pointIndex];
|
||||
}
|
||||
|
||||
average = static_cast<OutType>(average * (1.0 / numPoints));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Storage>
|
||||
bool TestArrayHandle(const vtkm::cont::ArrayHandle<T, Storage>& ah,
|
||||
const T* expected,
|
||||
vtkm::Id size)
|
||||
{
|
||||
if (size != ah.GetNumberOfValues())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto portal = ah.ReadPortal();
|
||||
for (vtkm::Id i = 0; i < size; ++i)
|
||||
{
|
||||
if (portal.Get(i) != expected[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline vtkm::cont::DataSet make_SingleTypeDataSet()
|
||||
{
|
||||
using CoordType = vtkm::Vec3f_32;
|
||||
std::vector<CoordType> coordinates;
|
||||
coordinates.push_back(CoordType(0, 0, 0));
|
||||
coordinates.push_back(CoordType(1, 0, 0));
|
||||
coordinates.push_back(CoordType(1, 1, 0));
|
||||
coordinates.push_back(CoordType(2, 1, 0));
|
||||
coordinates.push_back(CoordType(2, 2, 0));
|
||||
|
||||
std::vector<vtkm::Id> conn;
|
||||
// First Cell
|
||||
conn.push_back(0);
|
||||
conn.push_back(1);
|
||||
conn.push_back(2);
|
||||
// Second Cell
|
||||
conn.push_back(1);
|
||||
conn.push_back(2);
|
||||
conn.push_back(3);
|
||||
// Third Cell
|
||||
conn.push_back(2);
|
||||
conn.push_back(3);
|
||||
conn.push_back(4);
|
||||
|
||||
vtkm::cont::DataSet ds;
|
||||
vtkm::cont::DataSetBuilderExplicit builder;
|
||||
ds = builder.Create(coordinates, vtkm::CellShapeTagTriangle(), 3, conn);
|
||||
|
||||
//Set point scalar
|
||||
const int nVerts = 5;
|
||||
vtkm::Float32 vars[nVerts] = { 10.1f, 20.1f, 30.2f, 40.2f, 50.3f };
|
||||
|
||||
ds.AddPointField("pointvar", vars, nVerts);
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
void TestDataSet_SingleType()
|
||||
{
|
||||
vtkm::cont::Invoker invoke;
|
||||
|
||||
vtkm::cont::DataSet dataSet = make_SingleTypeDataSet();
|
||||
|
||||
//verify that we can get a CellSetSingleType from a dataset
|
||||
vtkm::cont::CellSetSingleType<> cellset;
|
||||
dataSet.GetCellSet().AsCellSet(cellset);
|
||||
|
||||
//verify that the point to cell connectivity types are correct
|
||||
vtkm::cont::ArrayHandleConstant<vtkm::UInt8> shapesPointToCell =
|
||||
cellset.GetShapesArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint());
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> connPointToCell =
|
||||
cellset.GetConnectivityArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint());
|
||||
|
||||
VTKM_TEST_ASSERT(shapesPointToCell.GetNumberOfValues() == 3, "Wrong number of shapes");
|
||||
VTKM_TEST_ASSERT(connPointToCell.GetNumberOfValues() == 9, "Wrong connectivity length");
|
||||
|
||||
//verify that the cell to point connectivity types are correct
|
||||
//note the handle storage types differ compared to point to cell
|
||||
vtkm::cont::ArrayHandleConstant<vtkm::UInt8> shapesCellToPoint =
|
||||
cellset.GetShapesArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> connCellToPoint =
|
||||
cellset.GetConnectivityArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
|
||||
|
||||
VTKM_TEST_ASSERT(shapesCellToPoint.GetNumberOfValues() == 5, "Wrong number of shapes");
|
||||
VTKM_TEST_ASSERT(connCellToPoint.GetNumberOfValues() == 9, "Wrong connectivity length");
|
||||
|
||||
//run a basic for-each topology algorithm on this
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> input;
|
||||
vtkm::cont::ArrayCopyShallowIfPossible(dataSet.GetField("pointvar").GetData(), input);
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> result;
|
||||
invoke(CellAverage{}, cellset, input, result);
|
||||
|
||||
vtkm::Float32 expected[3] = { 20.1333f, 30.1667f, 40.2333f };
|
||||
auto portal = result.ReadPortal();
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
VTKM_TEST_ASSERT(test_equal(portal.Get(i), expected[i]),
|
||||
"Wrong result for CellAverage worklet on explicit single type cellset data");
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_CONT void Run()
|
||||
{
|
||||
TestDataSet_SingleType();
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestDataSetSingleType(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(Run, argc, argv);
|
||||
}
|
Loading…
Reference in New Issue
Block a user