Parallel CellToPoint initial code.

This commit is contained in:
Patricia Kroll Fasel - 090207 2015-10-30 13:59:36 -06:00
parent 52467474aa
commit ed0ecf284d
12 changed files with 591 additions and 326 deletions

@ -26,6 +26,12 @@
#include <vtkm/exec/ConnectivityExplicit.h>
#include <vtkm/TopologyElementTag.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/exec/ExecutionWholeArray.h>
#include <vtkm/cont/ArrayHandleCounting.h>
#include <vtkm/cont/ArrayHandleConstant.h>
#include <map>
#include <utility>
@ -177,12 +183,13 @@ public:
return this->PointToCell.Shapes.GetPortalConstControl().Get(cellIndex);
}
template <vtkm::IdComponent ItemTupleLength>
template <typename Device, vtkm::IdComponent ItemTupleLength>
VTKM_CONT_EXPORT
void GetIndices(vtkm::Id index,
void GetIndices(Device,
vtkm::Id index,
vtkm::Vec<vtkm::Id,ItemTupleLength> &ids) const
{
this->PointToCell.BuildIndexOffsets(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
this->PointToCell.BuildIndexOffsets(Device());
vtkm::IdComponent numIndices = this->GetNumberOfPointsInCell(index);
vtkm::Id start =
this->PointToCell.IndexOffsets.GetPortalConstControl().Get(index);
@ -333,7 +340,7 @@ public:
typename ExecutionTypes<Device,FromTopology,ToTopology>::ExecObjectType
PrepareForInput(Device, FromTopology, ToTopology) const
{
this->BuildConnectivity(FromTopology(), ToTopology());
this->BuildConnectivity(Device(), FromTopology(), ToTopology());
const typename
ConnectivityChooser<FromTopology,ToTopology>::ConnectivityType
@ -350,9 +357,9 @@ public:
connectivity.IndexOffsets.PrepareForInput(Device()));
}
template<typename FromTopology, typename ToTopology>
template<typename Device, typename FromTopology, typename ToTopology>
VTKM_CONT_EXPORT
void BuildConnectivity(FromTopology, ToTopology) const
void BuildConnectivity(Device, FromTopology, ToTopology) const
{
typedef CellSetExplicit<ShapeStorageTag,
NumIndicesStorageTag,
@ -360,93 +367,114 @@ public:
OffsetsStorageTag> CSE;
CSE *self = const_cast<CSE*>(this);
self->CreateConnectivity(FromTopology(), ToTopology());
self->CreateConnectivity(Device(), FromTopology(), ToTopology());
self->GetConnectivity(FromTopology(), ToTopology()).
BuildIndexOffsets(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
BuildIndexOffsets(Device());
}
template<typename Device>
VTKM_CONT_EXPORT
void CreateConnectivity(vtkm::TopologyElementTagPoint,
void CreateConnectivity(Device,
vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell)
{
// nothing to do
}
// Worklet to expand the PointToCell numIndices array by repeating cell index
class ExpandIndices : public vtkm::worklet::WorkletMapField
{
public:
typedef void ControlSignature(FieldIn<> cellIndex,
FieldIn<> offset,
FieldIn<> numIndices,
ExecObject cellIndices);
typedef void ExecutionSignature(_1,_2,_3,_4);
typedef _1 InputDomain;
VTKM_CONT_EXPORT
ExpandIndices() {}
VTKM_EXEC_EXPORT
void operator()(const vtkm::Id &cellIndex,
const vtkm::Id &offset,
const vtkm::Id &numIndices,
vtkm::exec::ExecutionWholeArray<vtkm::Id> &cellIndices) const
{
vtkm::Id startIndex = offset;
for (vtkm::Id i = 0; i < numIndices; i++)
{
cellIndices.Set(startIndex++, cellIndex);
}
}
};
template<typename Device>
VTKM_CONT_EXPORT
void CreateConnectivity(vtkm::TopologyElementTagCell,
void CreateConnectivity(Device,
vtkm::TopologyElementTagCell,
vtkm::TopologyElementTagPoint)
{
// PointToCell connectivity array (point indices) will be
// transformed into the CellToPoint numIndices array using reduction
//
// PointToCell numIndices array using expansion will be
// transformed into the CellToPoint connectivity array
if (this->CellToPoint.ElementsValid)
{
return;
}
typedef vtkm::cont::DeviceAdapterAlgorithm<Device> Algorithm;
std::multimap<vtkm::Id,vtkm::Id> cells_of_nodes;
// Sizes of the PointToCell information
int numberOfCells = this->GetNumberOfCells();
int connectivityLength = this->PointToCell.Connectivity.GetNumberOfValues();
vtkm::Id pairCount = 0;
vtkm::Id maxNodeID = 0;
vtkm::Id numCells = this->GetNumberOfCells();
for (vtkm::Id cell = 0, cindex = 0; cell < numCells; ++cell)
{
vtkm::Id npts = this->PointToCell.NumIndices.GetPortalConstControl().Get(cell);
for (int pt=0; pt<npts; ++pt)
{
vtkm::Id index = this->PointToCell.Connectivity.GetPortalConstControl().Get(cindex++);
if (index > maxNodeID)
{
maxNodeID = index;
}
cells_of_nodes.insert(std::pair<vtkm::Id,vtkm::Id>(index,cell));
pairCount++;
}
}
// PointToCell connectivity will be basis of CellToPoint numIndices
vtkm::cont::ArrayHandle<vtkm::Id> pointIndices;
Algorithm::Copy(this->PointToCell.Connectivity, pointIndices);
// PointToCell numIndices will be basis of CellToPoint connectivity
vtkm::cont::ArrayHandle<vtkm::Id> cellIndices;
cellIndices.Allocate(connectivityLength);
vtkm::cont::ArrayHandleCounting<vtkm::Id> index(0, 1, numberOfCells);
vtkm::worklet::DispatcherMapField<ExpandIndices> expandDispatcher;
expandDispatcher.Invoke(index,
this->PointToCell.IndexOffsets,
this->PointToCell.NumIndices,
vtkm::exec::ExecutionWholeArray<vtkm::Id>(cellIndices, connectivityLength));
// SortByKey where key is PointToCell connectivity and value is the expanded cellIndex
Algorithm::SortByKey(pointIndices, cellIndices);
if(this->GetNumberOfPoints() <= 0)
{
this->NumberOfPoints = maxNodeID + 1;
this->NumberOfPoints = pointIndices.GetPortalControl().Get(connectivityLength - 1) + 1;
}
int numberOfPoints = this->GetNumberOfPoints();
vtkm::Id numPoints = this->GetNumberOfPoints();
// CellToPoint numIndices from the now sorted PointToCell connectivity
vtkm::cont::ArrayHandleConstant<vtkm::Id> numArray(1, connectivityLength);
vtkm::cont::ArrayHandle<vtkm::Id> uniquePoints;
vtkm::cont::ArrayHandle<vtkm::Id> numIndices;
vtkm::cont::ArrayHandle<vtkm::Id> shapes;
uniquePoints.Allocate(numberOfPoints);
numIndices.Allocate(numberOfPoints);
shapes.Allocate(numberOfPoints);
this->CellToPoint.Shapes.Allocate(numPoints);
this->CellToPoint.NumIndices.Allocate(numPoints);
this->CellToPoint.Connectivity.Allocate(pairCount);
Algorithm::ReduceByKey(pointIndices, numArray,
uniquePoints, numIndices,
vtkm::internal::Add());
vtkm::Id connIndex = 0;
vtkm::Id pointIndex = 0;
for (std::multimap<vtkm::Id,vtkm::Id>::iterator iter = cells_of_nodes.begin();
iter != cells_of_nodes.end(); iter++)
{
vtkm::Id pointId = iter->first;
while (pointIndex <= pointId)
{
// add empty spots to skip points not referenced by our cells
// also initialize the current one
this->CellToPoint.Shapes.GetPortalControl().Set(pointIndex,CELL_SHAPE_VERTEX);
this->CellToPoint.NumIndices.GetPortalControl().Set(pointIndex,0);
++pointIndex;
}
vtkm::Id cellId = iter->second;
this->CellToPoint.Connectivity.GetPortalControl().Set(connIndex,cellId);
++connIndex;
const vtkm::IdComponent oldCellCount =
this->CellToPoint.NumIndices.GetPortalConstControl().Get(pointIndex-1);
this->CellToPoint.NumIndices.GetPortalControl().Set(pointIndex-1,
oldCellCount+1);
}
while (pointIndex < numPoints)
{
// add empty spots for tail points not referenced by our cells
this->CellToPoint.Shapes.GetPortalControl().Set(pointIndex,CELL_SHAPE_VERTEX);
this->CellToPoint.NumIndices.GetPortalControl().Set(pointIndex,0);
++pointIndex;
}
// Set the CellToPoint information
vtkm::cont::ArrayHandleConstant<vtkm::Id> shapeArray(CELL_SHAPE_VERTEX, numberOfPoints);
Algorithm::Copy(shapeArray, this->CellToPoint.Shapes);
Algorithm::Copy(numIndices, this->CellToPoint.NumIndices);
Algorithm::Copy(cellIndices, this->CellToPoint.Connectivity);
this->CellToPoint.ElementsValid = true;
this->CellToPoint.IndexOffsetsValid = false;

@ -22,6 +22,8 @@ set(unit_tests
UnitTestComputeBoundsCuda.cu
UnitTestCudaArrayHandle.cu
UnitTestCudaArrayHandleFancy.cu
UnitTestCudaDataSetExplicit.cu
UnitTestCudaDataSetSingleType.cu
UnitTestCudaMath.cu
UnitTestDeviceAdapterCuda.cu
)

@ -0,0 +1,34 @@
//============================================================================
// 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_ERROR
#define BOOST_SP_DISABLE_THREADS
#include <vtkm/cont/cuda/DeviceAdapterCuda.h>
#include <vtkm/cont/testing/TestingDataSetExplicit.h>
#include <vtkm/cont/cuda/internal/testing/Testing.h>
int UnitTestCudaDataSetExplicit(int, char *[])
{
int result = vtkm::cont::testing::TestingDataSetExplicit
<vtkm::cont::DeviceAdapterTagCuda>::Run();
return vtkm::cont::cuda::internal::Testing::CheckCudaBeforeExit(result);
}

@ -0,0 +1,34 @@
//============================================================================
// 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_ERROR
#define BOOST_SP_DISABLE_THREADS
#include <vtkm/cont/cuda/DeviceAdapterCuda.h>
#include <vtkm/cont/testing/TestingDataSetSingleType.h>
#include <vtkm/cont/cuda/internal/testing/Testing.h>
int UnitTestCudaDataSetSingleType(int, char *[])
{
int result = vtkm::cont::testing::TestingDataSetSingleType
<vtkm::cont::DeviceAdapterTagCuda>::Run();
return vtkm::cont::cuda::internal::Testing::CheckCudaBeforeExit(result);
}

@ -20,6 +20,8 @@
set(unit_tests
UnitTestComputeBoundsTBB.cxx
UnitTestDataSetExplicitTBB.cxx
UnitTestDataSetSingleTypeTBB.cxx
UnitTestDeviceAdapterTBB.cxx
UnitTestTBBArrayHandle.cxx
UnitTestTBBArrayHandleFancy.cxx

@ -0,0 +1,29 @@
//============================================================================
// 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/cont/tbb/DeviceAdapterTBB.h>
#include <vtkm/cont/testing/TestingDataSetExplicit.h>
int UnitTestDataSetExplicitTBB(int, char *[])
{
return vtkm::cont::testing::TestingDataSetExplicit
<vtkm::cont::DeviceAdapterTagTBB>::Run();
}

@ -0,0 +1,29 @@
//============================================================================
// 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/cont/tbb/DeviceAdapterTBB.h>
#include <vtkm/cont/testing/TestingDataSetSingleType.h>
int UnitTestDataSetSingleTypeTBB(int, char *[])
{
return vtkm::cont::testing::TestingDataSetSingleType
<vtkm::cont::DeviceAdapterTagTBB>::Run();
}

@ -24,6 +24,8 @@ set(headers
TestingArrayHandles.h
TestingComputeBounds.h
TestingDeviceAdapter.h
TestingDataSetExplicit.h
TestingDataSetSingleType.h
TestingFancyArrayHandles.h
)

@ -0,0 +1,170 @@
//============================================================================
// 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_cont_testing_TestingDataSetExplicit_h
#define vtk_m_cont_testing_TestingDataSetExplicit_h
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
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;
}
for (vtkm::Id i = 0; i < size; ++i)
{
if (ah.GetPortalConstControl().Get(i) != expected[i])
{
return false;
}
}
return true;
}
static void TestDataSet_Explicit()
{
vtkm::cont::testing::MakeTestDataSet tds;
vtkm::cont::DataSet ds = tds.Make3DExplicitDataSet1();
VTKM_TEST_ASSERT(ds.GetNumberOfCellSets() == 1,
"Incorrect number of cell sets");
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::ASSOC_POINTS,
"Association of 'pointvar' was not ASSOC_POINTS");
try
{
//const vtkm::cont::Field &f2 =
ds.GetField("cellvar", vtkm::cont::Field::ASSOC_CELL_SET);
}
catch (...)
{
VTKM_TEST_FAIL("Failed to get field 'cellvar' with ASSOC_CELL_SET.");
}
try
{
//const vtkm::cont::Field &f3 =
ds.GetField("cellvar", vtkm::cont::Field::ASSOC_POINTS);
VTKM_TEST_FAIL("Failed to get expected error for association mismatch.");
}
catch (vtkm::cont::ErrorControlBadValue 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(0).CastTo<vtkm::cont::CellSetExplicit<> >();
cellset.BuildConnectivity(DeviceAdapterTag(),
vtkm::TopologyElementTagCell(),
vtkm::TopologyElementTagPoint());
ds.PrintSummary(std::cout);
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::ArrayHandle<vtkm::UInt8> shapes = cellset.GetShapesArray(
vtkm::TopologyElementTagCell(),vtkm::TopologyElementTagPoint());
vtkm::cont::ArrayHandle<vtkm::IdComponent> numIndices = cellset.GetNumIndicesArray(
vtkm::TopologyElementTagCell(),vtkm::TopologyElementTagPoint());
vtkm::cont::ArrayHandle<vtkm::Id> conn = cellset.GetConnectivityArray(
vtkm::TopologyElementTagCell(),vtkm::TopologyElementTagPoint());
VTKM_TEST_ASSERT(TestArrayHandle(shapes,
correctShapes,
numPoints),
"Got incorrect shapes");
VTKM_TEST_ASSERT(TestArrayHandle(numIndices,
correctNumIndices,
numPoints),
"Got incorrect shapes");
VTKM_TEST_ASSERT(TestArrayHandle(conn,
correctConnectivity,
connectivitySize),
"Got incorrect conectivity");
//verify that GetIndices works properly
vtkm::Id expectedPointIds[4] = {2,1,3,4};
vtkm::Vec<vtkm::Id,4> retrievedPointIds;
cellset.GetIndices(DeviceAdapterTag(), 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_EXPORT void operator()() const
{
TestingDataSetExplicit::TestDataSet_Explicit();
}
};
public:
static VTKM_CONT_EXPORT int Run()
{
return vtkm::cont::testing::Testing::Run(TestAll());
}
};
}
}
} // namespace vtkm::cont::testing
#endif // vtk_m_cont_testing_TestingDataSetExplicit_h

@ -0,0 +1,185 @@
//============================================================================
// 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_cont_testing_TestingDataSetSingleType_h
#define vtk_m_cont_testing_TestingDataSetSingleType_h
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/CellSetSingleType.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/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;
}
for (vtkm::Id i = 0; i < size; ++i)
{
if (ah.GetPortalConstControl().Get(i) != expected[i])
{
return false;
}
}
return true;
}
static inline vtkm::cont::DataSet make_SingleTypeDataSet()
{
using vtkm::cont::Field;
vtkm::cont::DataSet dataSet;
const int nVerts = 5;
typedef vtkm::Vec<vtkm::Float32,3> CoordType;
CoordType coordinates[nVerts] = {
CoordType(0, 0, 0),
CoordType(1, 0, 0),
CoordType(1, 1, 0),
CoordType(2, 1, 0),
CoordType(2, 2, 0)
};
//Set coordinate system
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem("coordinates", 1, coordinates, nVerts));
//Set point scalar
vtkm::Float32 vars[nVerts] = {10.1f, 20.1f, 30.2f, 40.2f, 50.3f};
dataSet.AddField(Field("pointvar", 1, vtkm::cont::Field::ASSOC_POINTS, vars, nVerts));
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::CellSetSingleType<> cellSet(vtkm::CellShapeTagTriangle(),
"cells");
cellSet.FillViaCopy(conn);
dataSet.AddCellSet(cellSet);
return dataSet;
}
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(0).CastTo<vtkm::cont::CellSetSingleType<> >();
//verify that we can compute the cell to point connectivity
cellset.BuildConnectivity(DeviceAdapterTag(),
vtkm::TopologyElementTagCell(),
vtkm::TopologyElementTagPoint());
dataSet.PrintSummary(std::cout);
//verify that the point to cell connectivity types are correct
vtkm::cont::ArrayHandleConstant<vtkm::UInt8> shapesPointToCell = cellset.GetShapesArray(
vtkm::TopologyElementTagPoint(),vtkm::TopologyElementTagCell());
vtkm::cont::ArrayHandleConstant<vtkm::IdComponent> numIndicesPointToCell = cellset.GetNumIndicesArray(
vtkm::TopologyElementTagPoint(),vtkm::TopologyElementTagCell());
vtkm::cont::ArrayHandle<vtkm::Id> connPointToCell = cellset.GetConnectivityArray(
vtkm::TopologyElementTagPoint(),vtkm::TopologyElementTagCell());
VTKM_TEST_ASSERT( shapesPointToCell.GetNumberOfValues() == 3, "Wrong number of shapes");
VTKM_TEST_ASSERT( numIndicesPointToCell.GetNumberOfValues() == 3, "Wrong number of indices");
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::ArrayHandle<vtkm::UInt8> shapesCellToPoint = cellset.GetShapesArray(
vtkm::TopologyElementTagCell(),vtkm::TopologyElementTagPoint());
vtkm::cont::ArrayHandle<vtkm::IdComponent> numIndicesCellToPoint = cellset.GetNumIndicesArray(
vtkm::TopologyElementTagCell(),vtkm::TopologyElementTagPoint());
vtkm::cont::ArrayHandle<vtkm::Id> connCellToPoint = cellset.GetConnectivityArray(
vtkm::TopologyElementTagCell(),vtkm::TopologyElementTagPoint());
VTKM_TEST_ASSERT( shapesCellToPoint.GetNumberOfValues() == 5, "Wrong number of shapes");
VTKM_TEST_ASSERT( numIndicesCellToPoint.GetNumberOfValues() == 5, "Wrong number of indices");
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.Invoke(dataSet.GetField("pointvar").GetData(),
cellset,
result);
vtkm::Float32 expected[3] = { 20.1333f, 30.1667f, 40.2333f };
for (int i = 0; i < 3; ++i)
{
VTKM_TEST_ASSERT(test_equal(result.GetPortalConstControl().Get(i),
expected[i]), "Wrong result for CellAverage worklet on explicit single type cellset data");
}
}
struct TestAll
{
VTKM_CONT_EXPORT void operator()() const
{
TestingDataSetSingleType::TestDataSet_SingleType();
}
};
public:
static VTKM_CONT_EXPORT int Run()
{
return vtkm::cont::testing::Testing::Run(TestAll());
}
};
}
}
} // namespace vtkm::cont::testing
#endif // vtk_m_cont_testing_TestingDataSetSingleType_h

@ -18,128 +18,12 @@
// this software.
//============================================================================
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
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;
}
for (vtkm::Id i = 0; i < size; ++i)
{
if (ah.GetPortalConstControl().Get(i) != expected[i])
{
return false;
}
}
return true;
}
void TestDataSet_Explicit()
{
vtkm::cont::testing::MakeTestDataSet tds;
vtkm::cont::DataSet ds = tds.Make3DExplicitDataSet1();
ds.PrintSummary(std::cout);
VTKM_TEST_ASSERT(ds.GetNumberOfCellSets() == 1,
"Incorrect number of cell sets");
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::ASSOC_POINTS,
"Association of 'pointvar' was not ASSOC_POINTS");
try
{
//const vtkm::cont::Field &f2 =
ds.GetField("cellvar", vtkm::cont::Field::ASSOC_CELL_SET);
}
catch (...)
{
VTKM_TEST_FAIL("Failed to get field 'cellvar' with ASSOC_CELL_SET.");
}
try
{
//const vtkm::cont::Field &f3 =
ds.GetField("cellvar", vtkm::cont::Field::ASSOC_POINTS);
VTKM_TEST_FAIL("Failed to get expected error for association mismatch.");
}
catch (vtkm::cont::ErrorControlBadValue 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(0).CastTo<vtkm::cont::CellSetExplicit<> >();
cellset.BuildConnectivity(vtkm::TopologyElementTagCell(),
vtkm::TopologyElementTagPoint());
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::ArrayHandle<vtkm::UInt8> shapes = cellset.GetShapesArray(
vtkm::TopologyElementTagCell(),vtkm::TopologyElementTagPoint());
vtkm::cont::ArrayHandle<vtkm::IdComponent> numIndices = cellset.GetNumIndicesArray(
vtkm::TopologyElementTagCell(),vtkm::TopologyElementTagPoint());
vtkm::cont::ArrayHandle<vtkm::Id> conn = cellset.GetConnectivityArray(
vtkm::TopologyElementTagCell(),vtkm::TopologyElementTagPoint());
VTKM_TEST_ASSERT(TestArrayHandle(shapes,
correctShapes,
numPoints),
"Got incorrect shapes");
VTKM_TEST_ASSERT(TestArrayHandle(numIndices,
correctNumIndices,
numPoints),
"Got incorrect shapes");
VTKM_TEST_ASSERT(TestArrayHandle(conn,
correctConnectivity,
connectivitySize),
"Got incorrect conectivity");
//verify that GetIndices works properly
vtkm::Id expectedPointIds[4] = {2,1,3,4};
vtkm::Vec<vtkm::Id,4> 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");
}
}
}
#include <vtkm/cont/DeviceAdapterSerial.h>
#include <vtkm/cont/testing/TestingDataSetExplicit.h>
int UnitTestDataSetExplicit(int, char *[])
{
return vtkm::cont::testing::Testing::Run(TestDataSet_Explicit);
return vtkm::cont::testing::TestingDataSetExplicit
<vtkm::cont::DeviceAdapterTagSerial>::Run();
}

@ -18,146 +18,12 @@
// this software.
//============================================================================
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/CellSetSingleType.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/worklet/CellAverage.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
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;
}
for (vtkm::Id i = 0; i < size; ++i)
{
if (ah.GetPortalConstControl().Get(i) != expected[i])
{
return false;
}
}
return true;
}
inline vtkm::cont::DataSet make_SingleTypeDataSet()
{
using vtkm::cont::Field;
vtkm::cont::DataSet dataSet;
const int nVerts = 5;
typedef vtkm::Vec<vtkm::Float32,3> CoordType;
CoordType coordinates[nVerts] = {
CoordType(0, 0, 0),
CoordType(1, 0, 0),
CoordType(1, 1, 0),
CoordType(2, 1, 0),
CoordType(2, 2, 0)
};
//Set coordinate system
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem("coordinates", 1, coordinates, nVerts));
//Set point scalar
vtkm::Float32 vars[nVerts] = {10.1f, 20.1f, 30.2f, 40.2f, 50.3f};
dataSet.AddField(Field("pointvar", 1, vtkm::cont::Field::ASSOC_POINTS, vars, nVerts));
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::CellSetSingleType<> cellSet(vtkm::CellShapeTagTriangle(),
"cells");
cellSet.FillViaCopy(conn);
dataSet.AddCellSet(cellSet);
return dataSet;
}
void TestDataSet_Explicit()
{
vtkm::cont::DataSet dataSet = make_SingleTypeDataSet();
dataSet.PrintSummary(std::cout);
//verify that we can get a CellSetSingleType from a dataset
vtkm::cont::CellSetSingleType<> &cellset =
dataSet.GetCellSet(0).CastTo<vtkm::cont::CellSetSingleType<> >();
//verify that we can compute the cell to point connectivity
cellset.BuildConnectivity(vtkm::TopologyElementTagCell(),
vtkm::TopologyElementTagPoint());
//verify that the point to cell connectivity types are correct
vtkm::cont::ArrayHandleConstant<vtkm::UInt8> shapesPointToCell = cellset.GetShapesArray(
vtkm::TopologyElementTagPoint(),vtkm::TopologyElementTagCell());
vtkm::cont::ArrayHandleConstant<vtkm::IdComponent> numIndicesPointToCell = cellset.GetNumIndicesArray(
vtkm::TopologyElementTagPoint(),vtkm::TopologyElementTagCell());
vtkm::cont::ArrayHandle<vtkm::Id> connPointToCell = cellset.GetConnectivityArray(
vtkm::TopologyElementTagPoint(),vtkm::TopologyElementTagCell());
VTKM_TEST_ASSERT( shapesPointToCell.GetNumberOfValues() == 3, "Wrong number of shapes");
VTKM_TEST_ASSERT( numIndicesPointToCell.GetNumberOfValues() == 3, "Wrong number of indices");
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::ArrayHandle<vtkm::UInt8> shapesCellToPoint = cellset.GetShapesArray(
vtkm::TopologyElementTagCell(),vtkm::TopologyElementTagPoint());
vtkm::cont::ArrayHandle<vtkm::IdComponent> numIndicesCellToPoint = cellset.GetNumIndicesArray(
vtkm::TopologyElementTagCell(),vtkm::TopologyElementTagPoint());
vtkm::cont::ArrayHandle<vtkm::Id> connCellToPoint = cellset.GetConnectivityArray(
vtkm::TopologyElementTagCell(),vtkm::TopologyElementTagPoint());
VTKM_TEST_ASSERT( shapesCellToPoint.GetNumberOfValues() == 5, "Wrong number of shapes");
VTKM_TEST_ASSERT( numIndicesCellToPoint.GetNumberOfValues() == 5, "Wrong number of indices");
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.Invoke(dataSet.GetField("pointvar").GetData(),
cellset,
result);
vtkm::Float32 expected[3] = { 20.1333f, 30.1667f, 40.2333f };
for (int i = 0; i < 3; ++i)
{
VTKM_TEST_ASSERT(test_equal(result.GetPortalConstControl().Get(i),
expected[i]), "Wrong result for CellAverage worklet on explicit single type cellset data");
}
}
}
#include <vtkm/cont/DeviceAdapterSerial.h>
#include <vtkm/cont/testing/TestingDataSetSingleType.h>
int UnitTestDataSetSingleType(int, char *[])
{
return vtkm::cont::testing::Testing::Run(TestDataSet_Explicit);
return vtkm::cont::testing::TestingDataSetSingleType
<vtkm::cont::DeviceAdapterTagSerial>::Run();
}