Add some more tests for regular data sets.

This commit is contained in:
Dave Pugmire 2015-05-18 11:04:15 -04:00
parent 97844f6ca2
commit 1941c455f1
3 changed files with 229 additions and 24 deletions

@ -20,7 +20,7 @@
#ifndef vtk_m_RegularStructure_h #ifndef vtk_m_RegularStructure_h
#define vtk_m_RegularStructure_h #define vtk_m_RegularStructure_h
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/Types.h> #include <vtkm/Types.h>
#include <vtkm/CellType.h> #include <vtkm/CellType.h>
@ -65,10 +65,8 @@ public:
if (index < nodeDims[0]-1) if (index < nodeDims[0]-1)
ids[idx++] = index; ids[idx++] = index;
} }
vtkm::Id cellDims[1];
private: vtkm::Id nodeDims[1];
vtkm::Id cellDims[1];
vtkm::Id nodeDims[1];
}; };
//2 D specialization. //2 D specialization.
@ -77,7 +75,7 @@ class RegularStructure<2>
{ {
public: public:
VTKM_EXEC_CONT_EXPORT VTKM_EXEC_CONT_EXPORT
void SetNodeDimension(int node_i, int node_j, int) void SetNodeDimension(int node_i, int node_j, int=0)
{ {
cellDims[0] = node_i-1; cellDims[0] = node_i-1;
nodeDims[0] = node_i; nodeDims[0] = node_i;
@ -121,6 +119,9 @@ public:
ids[idx++] = CalculateCellIndex(i , j ); ids[idx++] = CalculateCellIndex(i , j );
} }
vtkm::Id cellDims[2];
vtkm::Id nodeDims[2];
private: private:
VTKM_EXEC_CONT_EXPORT VTKM_EXEC_CONT_EXPORT
void CalculateLogicalNodeIndices(vtkm::Id index, int &i, int &j) const void CalculateLogicalNodeIndices(vtkm::Id index, int &i, int &j) const
@ -133,9 +134,6 @@ private:
{ {
return j*cellDims[0] + i; return j*cellDims[0] + i;
} }
vtkm::Id cellDims[2];
vtkm::Id nodeDims[2];
}; };
//3 D specialization. //3 D specialization.
@ -184,7 +182,9 @@ public:
VTKM_EXEC_CONT_EXPORT VTKM_EXEC_CONT_EXPORT
void GetCellsOfNode(vtkm::Id index, vtkm::Vec<vtkm::Id,8> &ids) const void GetCellsOfNode(vtkm::Id index, vtkm::Vec<vtkm::Id,8> &ids) const
{ {
ids[0]=ids[1]=ids[2]=ids[3]=ids[4]=ids[5]=ids[6]=ids[7]=0;
ids[0]=ids[1]=ids[2]=ids[3]=ids[4]=ids[5]=ids[6]=ids[7]=-1;
int i, j, k, idx=0; int i, j, k, idx=0;
CalculateLogicalNodeIndices(index, i, j, k); CalculateLogicalNodeIndices(index, i, j, k);
@ -206,6 +206,9 @@ public:
if (i < nodeDims[0]-1 && j < nodeDims[1]-1 && k < nodeDims[2]-1) if (i < nodeDims[0]-1 && j < nodeDims[1]-1 && k < nodeDims[2]-1)
ids[idx++] = CalculateCellIndex(i , j , k); ids[idx++] = CalculateCellIndex(i , j , k);
} }
vtkm::Id cellDims[3];
vtkm::Id nodeDims[3];
private: private:
VTKM_EXEC_CONT_EXPORT VTKM_EXEC_CONT_EXPORT
@ -223,9 +226,6 @@ private:
{ {
return (k * cellDims[1] + j) * cellDims[0] + i; return (k * cellDims[1] + j) * cellDims[0] + i;
} }
vtkm::Id cellDims[3];
vtkm::Id nodeDims[3];
}; };
} // namespace vtkm } // namespace vtkm

@ -25,13 +25,23 @@ public:
return structure.GetNumberOfCells(); return structure.GetNumberOfCells();
} }
vtkm::RegularConnectivity<NODE,CELL,Dimension> vtkm::RegularConnectivity<vtkm::cont::NODE,vtkm::cont::CELL,Dimension>
GetNodeToCellConnectivity() GetNodeToCellConnectivity()
{ {
vtkm::RegularConnectivity<NODE,CELL,Dimension> regConn; vtkm::RegularConnectivity<vtkm::cont::NODE,vtkm::cont::CELL,Dimension> regConn;
regConn.SetNodeDimension(structure.nodeDims.Max[0], regConn.SetNodeDimension(structure.nodeDims[0],
structure.nodeDims.Max[1], structure.nodeDims[1],
structure.nodeDims.Max[2]); structure.nodeDims[2]);
return regConn;
}
vtkm::RegularConnectivity<vtkm::cont::CELL,vtkm::cont::NODE,Dimension>
GetCellToNodeConnectivity()
{
vtkm::RegularConnectivity<vtkm::cont::CELL,vtkm::cont::NODE,Dimension> regConn;
regConn.SetNodeDimension(structure.nodeDims[0],
structure.nodeDims[1],
structure.nodeDims[2]);
return regConn; return regConn;
} }

@ -22,11 +22,186 @@
#include <vtkm/cont/DataSet.h> #include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h> #include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/CellType.h> #include <vtkm/CellType.h>
#include <vtkm/RegularConnectivity.h>
static void TwoDimRegularTest();
static void ThreeDimRegularTest();
void TestDataSet_Regular() void TestDataSet_Regular()
{ {
std::cout << std::endl; std::cout << std::endl;
std::cout << "--TestDataSet_Regular--" << std::endl << std::endl; std::cout << "--TestDataSet_Regular--" << std::endl << std::endl;
TwoDimRegularTest();
ThreeDimRegularTest();
#if 0
ds.x_idx = 0;
ds.y_idx = 1;
ds.z_idx = 2;
const int nVerts = 18;
vtkm::Float32 xVals[nVerts] = {0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2};
vtkm::Float32 yVals[nVerts] = {0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1};
vtkm::Float32 zVals[nVerts] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2};
vtkm::Float32 vars[nVerts] = {10.1, 20.1, 30.1, 40.1, 50.2, 60.2, 70.2, 80.2, 90.3, 100.3, 110.3, 120.3, 130.4, 140.4, 150.4, 160.4, 170.5, 180.5};
ds.AddFieldViaCopy(xVals, nVerts);
ds.AddFieldViaCopy(yVals, nVerts);
ds.AddFieldViaCopy(zVals, nVerts);
//Set node scalar
ds.AddFieldViaCopy(vars, nVerts);
//Set cell scalar
vtkm::Float32 cellvar[4] = {100.1, 100.2, 100.3, 100.4};
ds.AddFieldViaCopy(cellvar, 4);
static const vtkm::IdComponent dim = 3;
vtkm::cont::CellSetStructured<dim> *cs = new vtkm::cont::CellSetStructured<dim>("cells");
ds.AddCellSet(cs);
//Set regular structure
cs->structure.SetNodeDimension(3,2,3);
//Run a worklet to populate a cell centered field.
vtkm::Float32 cellVals[4] = {-1.1, -1.2, -1.3, -1.4};
ds.AddFieldViaCopy(cellVals, 4);
VTKM_TEST_ASSERT(ds.GetNumberOfCellSets() == 1,
"Incorrect number of cell sets");
VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 6,
"Incorrect number of fields");
VTKM_TEST_ASSERT(cs->structure.GetNumberOfNodes() == 18,
"Incorrect number of nodes");
VTKM_TEST_ASSERT(cs->structure.GetNumberOfCells() == 4,
"Incorrect number of cells");
vtkm::Id numCells = cs->structure.GetNumberOfCells();
for (int i = 0; i < numCells; i++)
{
VTKM_TEST_ASSERT(cs->structure.GetNumberOfIndices() == 8,
"Incorrect number of cell indices");
vtkm::CellType shape = cs->structure.GetElementShapeType();
VTKM_TEST_ASSERT(shape == vtkm::VTKM_VOXEL, "Incorrect element type.");
}
//Test regular connectivity.
vtkm::RegularConnectivity<vtkm::cont::NODE,
vtkm::cont::CELL,dim> nodeToCell = cs->GetNodeToCellConnectivity();
vtkm::Vec<vtkm::Id,8> nodeIds;
nodeToCell.GetIndices(5, nodeIds);
for (int i = 0; i < 8; i++)
std::cout<<i<<": nodeIds= "<<nodeIds[i]<<std::endl;
std::cout<<std::endl;
vtkm::RegularConnectivity<vtkm::cont::CELL,
vtkm::cont::NODE,dim> cellToNode = cs->GetCellToNodeConnectivity();
for (int i = 0; i < 4; i++)
{
vtkm::Vec<vtkm::Id,8> cellIds;
cellToNode.GetIndices(i, cellIds);
for (int i = 0; i < 8; i++)
std::cout<<i<<": cellIds= "<<cellIds[i]<<std::endl;
std::cout<<std::endl;
}
//cleanup memory now
delete cs;
#endif
}
static void
TwoDimRegularTest()
{
std::cout<<"2D Regular data set"<<std::endl;
vtkm::cont::DataSet ds_2d;
//2D case.
ds_2d.x_idx = 0;
ds_2d.y_idx = 1;
ds_2d.z_idx = -1;
const int nVerts = 6;
vtkm::Float32 xVals[nVerts] = {0, 1, 2, 0, 1, 2};
vtkm::Float32 yVals[nVerts] = {0, 0, 0, 1, 1, 1};
vtkm::Float32 vars[nVerts] = {10.1, 20.1, 30.1, 40.1, 50.1, 60.1};
ds_2d.AddFieldViaCopy(xVals, nVerts);
ds_2d.AddFieldViaCopy(yVals, nVerts);
//set node scalar.
ds_2d.AddFieldViaCopy(vars, nVerts);
vtkm::Float32 cellvar[1] = {100.1};
ds_2d.AddFieldViaCopy(cellvar, 1);
vtkm::cont::CellSetStructured<2> *cs = new vtkm::cont::CellSetStructured<2>("cells");
//Set regular structure
cs->structure.SetNodeDimension(3,2);
ds_2d.AddCellSet(cs);
VTKM_TEST_ASSERT(ds_2d.GetNumberOfCellSets() == 1,
"Incorrect number of cell sets");
//std::cout<<"Num nodes= "<<cs->structure.GetNumberOfNodes()<<std::endl;
//std::cout<<"Num cells= "<<cs->structure.GetNumberOfCells()<<std::endl;
VTKM_TEST_ASSERT(cs->structure.GetNumberOfNodes() == 6,
"Incorrect number of nodes");
VTKM_TEST_ASSERT(cs->structure.GetNumberOfCells() == 2,
"Incorrect number of cells");
vtkm::Id numCells = cs->structure.GetNumberOfCells();
for (int i = 0; i < numCells; i++)
{
VTKM_TEST_ASSERT(cs->structure.GetNumberOfIndices() == 4,
"Incorrect number of cell indices");
vtkm::CellType shape = cs->structure.GetElementShapeType();
VTKM_TEST_ASSERT(shape == vtkm::VTKM_PIXEL, "Incorrect element type.");
}
vtkm::RegularConnectivity<vtkm::cont::NODE,
vtkm::cont::CELL,2> nodeToCell = cs->GetNodeToCellConnectivity();
vtkm::RegularConnectivity<vtkm::cont::CELL,
vtkm::cont::NODE,2> cellToNode = cs->GetCellToNodeConnectivity();
vtkm::Id cells[2][4] = {{0,1,3,4}, {1,2,4,5}};
vtkm::Vec<vtkm::Id,4> nodeIds;
for (int i = 0; i < 2; i++)
{
nodeToCell.GetIndices(i, nodeIds);
for (int j = 0; j < 4; j++)
{
VTKM_TEST_ASSERT(nodeIds[j] == cells[i][j],
"Incorrect node ID for cell");
}
}
vtkm::Id nodes[6][4] = {{0,-1,-1,-1},
{0,1,-1,-1},
{0,-1,-1,-1},
{0,1,-1,-1},
{2,-1,-1,-1},
{2,3,-1,-1}};
for (int i = 0; i < 6; i++)
{
vtkm::Vec<vtkm::Id,4> cellIds;
cellToNode.GetIndices(i, cellIds);
for (int j = 0; j < 4; j++)
VTKM_TEST_ASSERT(cellIds[j] == nodes[i][j],
"Incorrect cell ID for node");
}
delete cs;
}
static void
ThreeDimRegularTest()
{
std::cout<<"3D Regular data set"<<std::endl;
vtkm::cont::DataSet ds; vtkm::cont::DataSet ds;
ds.x_idx = 0; ds.x_idx = 0;
@ -61,26 +236,46 @@ void TestDataSet_Regular()
vtkm::Float32 cellVals[4] = {-1.1, -1.2, -1.3, -1.4}; vtkm::Float32 cellVals[4] = {-1.1, -1.2, -1.3, -1.4};
ds.AddFieldViaCopy(cellVals, 4); ds.AddFieldViaCopy(cellVals, 4);
VTKM_TEST_ASSERT(test_equal(ds.GetNumberOfCellSets(), 1), VTKM_TEST_ASSERT(ds.GetNumberOfCellSets() == 1,
"Incorrect number of cell sets"); "Incorrect number of cell sets");
VTKM_TEST_ASSERT(test_equal(ds.GetNumberOfFields(), 6), VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 6,
"Incorrect number of fields"); "Incorrect number of fields");
VTKM_TEST_ASSERT(test_equal(cs->structure.GetNumberOfCells(), 4), VTKM_TEST_ASSERT(cs->structure.GetNumberOfNodes() == 18,
"Incorrect number of nodes");
VTKM_TEST_ASSERT(cs->structure.GetNumberOfCells() == 4,
"Incorrect number of cells"); "Incorrect number of cells");
vtkm::Id numCells = cs->structure.GetNumberOfCells(); vtkm::Id numCells = cs->structure.GetNumberOfCells();
vtkm::Vec<vtkm::Id,8> ids;
for (int i = 0; i < numCells; i++) for (int i = 0; i < numCells; i++)
{ {
VTKM_TEST_ASSERT(test_equal(cs->structure.GetNumberOfIndices(), 8), VTKM_TEST_ASSERT(cs->structure.GetNumberOfIndices() == 8,
"Incorrect number of cell indices"); "Incorrect number of cell indices");
vtkm::CellType shape = cs->structure.GetElementShapeType(); vtkm::CellType shape = cs->structure.GetElementShapeType();
VTKM_TEST_ASSERT(shape == vtkm::VTKM_VOXEL, "Incorrect element type."); VTKM_TEST_ASSERT(shape == vtkm::VTKM_VOXEL, "Incorrect element type.");
} }
//cleanup memory now //Test regular connectivity.
vtkm::RegularConnectivity<vtkm::cont::NODE,
vtkm::cont::CELL,dim> nodeToCell = cs->GetNodeToCellConnectivity();
vtkm::Id nodes[8] = {0,1,3,4,6,7,9,10};
vtkm::Vec<vtkm::Id,8> nodeIds;
nodeToCell.GetIndices(0, nodeIds);
for (int i = 0; i < 8; i++)
VTKM_TEST_ASSERT(nodeIds[i] == nodes[i],
"Incorrect node ID for cell");
vtkm::RegularConnectivity<vtkm::cont::CELL,
vtkm::cont::NODE,dim> cellToNode = cs->GetCellToNodeConnectivity();
vtkm::Vec<vtkm::Id,8> cellIds;
vtkm::Id cells[8] = {0,-1,-1,-1,-1,-1,-1,-1};
cellToNode.GetIndices(0, cellIds);
for (int i = 0; i < 8; i++)
VTKM_TEST_ASSERT(cellIds[i] == cells[i],
"Incorrect cell ID for node");
delete cs; delete cs;
} }