This commit has several changes.

1. Additional ASSERT calls to validate arguments in: DataSetBuilderRegular
2. Fix some untested compile errors in DataSetBuilderRectilinear
3. Added a new unit test, cont/testing/UnitTestDataSetBuilderRectilinear.cxx
4. Provided additional tests for UnitTestDataSetBuilderRegular.cxx.
The new tests in (4) were also included in (3), and provide a much more robust way of validating datasets created. It has nested for loops to do an all-all test on various ways to specify the X,Y, and Z coordinates.  It computes the bounds on the coordinate system and make sure they are correct.
Note: The GetBounds() call for Rectilinear is not working, and is an item for future discussion. It is disabled for now.
This commit is contained in:
dpugmire 2015-12-30 12:34:04 -05:00
parent 482341562f
commit fe1ab945a2
5 changed files with 259 additions and 41 deletions

@ -63,7 +63,7 @@ public:
const vtkm::cont::ArrayHandle<T> &yvals,
std::string coordNm="coords", std::string cellNm="cells")
{
VTKM_ASSERT_CONT(xvals.size()>1 && yvals.size()>1);
VTKM_ASSERT_CONT(xvals.GetNumberOfValues()>1 && yvals.GetNumberOfValues()>1);
vtkm::cont::ArrayHandle<T> zvals;
DFA::Copy(vtkm::cont::make_ArrayHandle(std::vector<T>(1,0)), zvals);
@ -98,8 +98,10 @@ public:
const vtkm::cont::ArrayHandle<T> &zvals,
std::string coordNm="coords", std::string cellNm="cells")
{
VTKM_ASSERT_CONT(xvals.size()>1 && yvals.size()>1 && zvals.size()>1);
return BuildDataSet(2, xvals,yvals,zvals, coordNm, cellNm);
VTKM_ASSERT_CONT(xvals.GetNumberOfValues()>1 &&
yvals.GetNumberOfValues()>1 &&
zvals.GetNumberOfValues()>1);
return BuildDataSet(3, xvals,yvals,zvals, coordNm, cellNm);
}
private:
@ -114,9 +116,9 @@ private:
((dim==2 && nz==1)||(dim==3 && nz>=1)));
vtkm::cont::ArrayHandle<T> Xc, Yc, Zc;
DFA::Copy(vtkm::cont::make_ArrayHandle(nx,xvals), Xc);
DFA::Copy(vtkm::cont::make_ArrayHandle(ny,yvals), Yc);
DFA::Copy(vtkm::cont::make_ArrayHandle(nz,zvals), Zc);
DFA::Copy(vtkm::cont::make_ArrayHandle(xvals,nx), Xc);
DFA::Copy(vtkm::cont::make_ArrayHandle(yvals,ny), Yc);
DFA::Copy(vtkm::cont::make_ArrayHandle(zvals,nz), Zc);
return BuildDataSet(dim, Xc,Yc,Zc, coordNm, cellNm);
}

@ -72,6 +72,7 @@ private:
std::string coordNm, std::string cellNm)
{
VTKM_ASSERT_CONT(nx>1 && ny>1 && ((dim==2 && nz==1)||(dim==3 && nz>=1)));
VTKM_ASSERT_CONT(spacingX>0 && spacingY>0 && spacingZ>0);
vtkm::cont::DataSet dataSet;
vtkm::cont::ArrayHandleUniformPointCoordinates

@ -45,6 +45,7 @@ set(unit_tests
UnitTestArrayPortalToIterators.cxx
UnitTestContTesting.cxx
UnitTestComputeBoundsSerial.cxx
UnitTestDataSetBuilderRectilinear.cxx
UnitTestDataSetBuilderRegular.cxx
UnitTestDataSetRegular.cxx
UnitTestDataSetRectilinear.cxx

@ -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 2015 Sandia Corporation.
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015 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/DataSetBuilderRectilinear.h>
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/cont/Assert.h>
#include <vtkm/cont/testing/Testing.h>
#include <vector>
namespace DataSetBuilderRectilinearNamespace {
typedef vtkm::cont::DeviceAdapterAlgorithm<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> DFA;
typedef VTKM_DEFAULT_DEVICE_ADAPTER_TAG DeviceAdapter;
void ValidateDataSet(const vtkm::cont::DataSet &ds,
int dim,
vtkm::Id numPoints, vtkm::Id numCells,
vtkm::Float64 *bounds)
{
//Verify basics..
VTKM_TEST_ASSERT(ds.GetNumberOfCellSets() == 1,
"Wrong number of cell sets.");
VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 0,
"Wrong number of fields.");
VTKM_TEST_ASSERT(ds.GetNumberOfCoordinateSystems() == 1,
"Wrong number of coordinate systems.");
VTKM_TEST_ASSERT(ds.GetCoordinateSystem().GetData().GetNumberOfValues() == numPoints,
"Wrong number of coordinates.");
VTKM_TEST_ASSERT(ds.GetCellSet().GetCellSet().GetNumberOfCells() == numCells,
"Wrong number of cells.");
//Make sure the bounds are correct.
//This is not working at present...
/*
vtkm::Float64 res[6];
ds.GetCoordinateSystem().GetBounds(res, DeviceAdapter());
VTKM_TEST_ASSERT(bounds[0]==res[0] && bounds[1]==res[1] &&
bounds[2]==res[2] && bounds[3]==res[3] &&
bounds[4]==res[4] && bounds[5]==res[5],
"Bounds of coordinates do not match");
*/
if (dim == 2)
{
typedef vtkm::cont::CellSetStructured<2> CellSetType;
CellSetType cellSet = ds.GetCellSet(0).CastTo<CellSetType>();
vtkm::IdComponent shape = cellSet.GetCellShape();
VTKM_TEST_ASSERT(shape == vtkm::CELL_SHAPE_QUAD, "Wrong element type");
}
else if (dim == 3)
{
typedef vtkm::cont::CellSetStructured<3> CellSetType;
CellSetType cellSet = ds.GetCellSet(0).CastTo<CellSetType>();
vtkm::IdComponent shape = cellSet.GetCellShape();
VTKM_TEST_ASSERT(shape == vtkm::CELL_SHAPE_HEXAHEDRON, "Wrong element type");
}
}
template <typename T>
void FillArray(std::vector<T> &arr, vtkm::Id sz, int fillMethod)
{
arr.resize(sz);
for (vtkm::Id i = 0; i < sz; i++)
{
T xi;
switch (fillMethod)
{
case 0: xi = (T)i; break;
case 1: xi = (T)i / (vtkm::Float32)sz; break;
case 2: xi = (T)(i*2); break;
case 3: xi = (T)i*0.1f; break;
case 4: xi = (T)(i*i); break;
}
arr[i] = xi;
}
}
void
TestDataSetBuilderRectilinear()
{
vtkm::cont::DataSetBuilderRectilinear dsb;
vtkm::cont::DataSet ds;
vtkm::Id nx = 15, ny = 15, nz = 15;
int nm = 5;
std::vector<vtkm::Float32> xvals, yvals, zvals;
for (vtkm::Id i = 2; i < nx; i++)
for (vtkm::Id j = 2; j < ny; j++)
for (int mx = 0; mx < nm; mx++)
for (int my = 0; my < nm; my++)
{
//Do the 2D cases.
vtkm::Id np = i*j, nc = (i-1)*(j-1);
FillArray(xvals, i, mx);
FillArray(yvals, j, my);
vtkm::Float64 bounds[6] = {xvals[0],xvals[i-1],
yvals[0],yvals[j-1],
0.0, 0.0};
//Test std::vector
ds = dsb.Create(xvals, yvals);
ValidateDataSet(ds, 2, np, nc, bounds);
//Test vtkm::Float *
ds = dsb.Create(i,j, &xvals[0],&yvals[0]);
ValidateDataSet(ds, 2, np, nc, bounds);
//Test ArrayHandle
ds = dsb.Create(vtkm::cont::make_ArrayHandle(xvals),
vtkm::cont::make_ArrayHandle(yvals));
ValidateDataSet(ds, 2, np, nc, bounds);
//Do the 3D cases.
for (vtkm::Id k = 2; k < nz; k++)
for (int mz = 0; mz < nm; mz++)
{
np = i*j*k;
nc = (i-1)*(j-1)*(k-1);
FillArray(zvals, k, mz);
//Test std::vector
ds = dsb.Create(xvals, yvals, zvals);
ValidateDataSet(ds, 3, np, nc, bounds);
//Test vtkm::Float *
ds = dsb.Create(i,j,k, &xvals[0],&yvals[0], &zvals[0]);
ValidateDataSet(ds, 3, np, nc, bounds);
//Test ArrayHandle
ds = dsb.Create(vtkm::cont::make_ArrayHandle(xvals),
vtkm::cont::make_ArrayHandle(yvals),
vtkm::cont::make_ArrayHandle(zvals));
ValidateDataSet(ds, 3, np, nc, bounds);
}
}
}
} // namespace DataSetBuilderRectilinearNamespace
int UnitTestDataSetBuilderRectilinear(int, char *[])
{
using namespace DataSetBuilderRectilinearNamespace;
return vtkm::cont::testing::Testing::Run(TestDataSetBuilderRectilinear);
}

@ -33,39 +33,66 @@
namespace DataSetBuilderRegularNamespace {
typedef vtkm::cont::DeviceAdapterAlgorithm<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> DFA;
typedef VTKM_DEFAULT_DEVICE_ADAPTER_TAG DeviceAdapter;
void ValidateDataSet(const vtkm::cont::DataSet &ds,
int dim,
int numPoints, int numCells)
int dim,
vtkm::Id numPoints, vtkm::Id numCells,
vtkm::Float64 *bounds)
{
//Verify basics..
VTKM_TEST_ASSERT(ds.GetNumberOfCellSets() == 1,
"Wrong number of cell sets.");
"Wrong number of cell sets.");
VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 0,
"Wrong number of fields.");
"Wrong number of fields.");
VTKM_TEST_ASSERT(ds.GetNumberOfCoordinateSystems() == 1,
"Wrong number of coordinate systems.");
"Wrong number of coordinate systems.");
VTKM_TEST_ASSERT(ds.GetCoordinateSystem().GetData().GetNumberOfValues() == numPoints,
"Wrong number of coordinates.");
"Wrong number of coordinates.");
VTKM_TEST_ASSERT(ds.GetCellSet().GetCellSet().GetNumberOfCells() == numCells,
"Wrong number of cells.");
"Wrong number of cells.");
//Make sure bounds are correct.
vtkm::Float64 res[6];
ds.GetCoordinateSystem().GetBounds(res, DeviceAdapter());
VTKM_TEST_ASSERT(bounds[0]==res[0] && bounds[1]==res[1] &&
bounds[2]==res[2] && bounds[3]==res[3] &&
bounds[4]==res[4] && bounds[5]==res[5],
"Bounds of coordinates do not match");
if (dim == 2)
{
typedef vtkm::cont::CellSetStructured<2> CellSetType;
CellSetType cellSet = ds.GetCellSet(0).CastTo<CellSetType>();
vtkm::IdComponent shape = cellSet.GetCellShape();
VTKM_TEST_ASSERT(shape == vtkm::CELL_SHAPE_QUAD, "Wrong element type");
typedef vtkm::cont::CellSetStructured<2> CellSetType;
CellSetType cellSet = ds.GetCellSet(0).CastTo<CellSetType>();
vtkm::IdComponent shape = cellSet.GetCellShape();
VTKM_TEST_ASSERT(shape == vtkm::CELL_SHAPE_QUAD, "Wrong element type");
}
else if (dim == 3)
{
typedef vtkm::cont::CellSetStructured<3> CellSetType;
CellSetType cellSet = ds.GetCellSet(0).CastTo<CellSetType>();
vtkm::IdComponent shape = cellSet.GetCellShape();
VTKM_TEST_ASSERT(shape == vtkm::CELL_SHAPE_HEXAHEDRON, "Wrong element type");
typedef vtkm::cont::CellSetStructured<3> CellSetType;
CellSetType cellSet = ds.GetCellSet(0).CastTo<CellSetType>();
vtkm::IdComponent shape = cellSet.GetCellShape();
VTKM_TEST_ASSERT(shape == vtkm::CELL_SHAPE_HEXAHEDRON, "Wrong element type");
}
}
template <typename T>
void FillMethod(int method, vtkm::Id n, T &o, T &s,
vtkm::Float64 &b0, vtkm::Float64 &b1)
{
switch (method)
{
case 0 : o = 0; s = 1; break;
case 1 : o = 0; s = static_cast<T>(1.0/n); break;
case 2 : o = 0; s = 2; break;
case 3 : o = static_cast<T>(-(n-1)); s = 1; break;
case 4 : o = static_cast<T>(2.780941); s = static_cast<T>(182.381901); break;
}
b0 = static_cast<vtkm::Float64>(o);
b1 = static_cast<vtkm::Float64>(o + (n-1)*s);
}
void
TestDataSetBuilderRegular()
@ -73,29 +100,46 @@ TestDataSetBuilderRegular()
vtkm::cont::DataSetBuilderRegular dsb;
vtkm::cont::DataSet ds;
int nx = 20, ny = 20, nz = 20;
//2D cases.
for (int i = 2; i < nx; i++)
for (int j = 2; j < ny; j++)
{
vtkm::Id2 dims(i,j);
ds = dsb.Create(dims);
ValidateDataSet(ds, 2, i*j, (i-1)*(j-1));
}
vtkm::Id nx = 12, ny = 12, nz = 12;
int nm = 5;
vtkm::Float64 bounds[6];
//3D cases.
for (int i = 2; i < nx; i++)
for (int j = 2; j < ny; j++)
for (int k = 2; k < nz; k++)
{
vtkm::Id3 dims(i,j,k);
ds = dsb.Create(dims);
ValidateDataSet(ds, 3, i*j*k, (i-1)*(j-1)*(k-1));
}
for (vtkm::Id i = 2; i < nx; i++)
for (vtkm::Id j = 2; j < ny; j++)
for (int mi = 0; mi < nm; mi++)
for (int mj = 0; mj < nm; mj++)
{
//2D cases
vtkm::Id np = i*j, nc = (i-1)*(j-1);
vtkm::Id2 dims2(i,j);
vtkm::Float32 oi, oj, si, sj;
FillMethod(mi, dims2[0], oi, si, bounds[0],bounds[1]);
FillMethod(mj, dims2[1], oj, sj, bounds[2],bounds[3]);
bounds[4] = bounds[5] = 0;
vtkm::Vec<vtkm::Float32,2> o2(oi,oj), sp2(si,sj);
ds = dsb.Create(dims2, o2, sp2);
ValidateDataSet(ds, 2, np, nc, bounds);
//3D cases
for (vtkm::Id k = 2; k < nz; k++)
for (int mk = 0; mk < nm; mk++)
{
np = i*j*k;
nc = (i-1)*(j-1)*(k-1);
vtkm::Id3 dims3(i,j,k);
vtkm::Float32 ok, sk;
FillMethod(mk, dims3[2], ok, sk, bounds[4],bounds[5]);
vtkm::Vec<vtkm::Float32,3> o3(oi,oj,ok), sp3(si,sj,sk);
ds = dsb.Create(dims3, o3, sp3);
ValidateDataSet(ds, 3, np, nc, bounds);
}
}
}
} // namespace ArrayHandleCartesianProductNamespace
} // namespace DataSetBuilderRegularNamespace
int UnitTestDataSetBuilderRegular(int, char *[])
{