Add more robust testing for DataSetBuilderRegular class. Also, add options for creating rectilinear dataset from ArrayHandle.

This commit is contained in:
dpugmire 2015-12-29 12:17:46 -05:00
parent c0d188c2da
commit 482341562f
3 changed files with 139 additions and 8 deletions

@ -56,6 +56,19 @@ public:
std::vector<T> zvals(1,0); std::vector<T> zvals(1,0);
return Create(2, xvals, yvals, zvals, coordNm, cellNm); return Create(2, xvals, yvals, zvals, coordNm, cellNm);
} }
template<typename T>
VTKM_CONT_EXPORT
vtkm::cont::DataSet
Create(const vtkm::cont::ArrayHandle<T> &xvals,
const vtkm::cont::ArrayHandle<T> &yvals,
std::string coordNm="coords", std::string cellNm="cells")
{
VTKM_ASSERT_CONT(xvals.size()>1 && yvals.size()>1);
vtkm::cont::ArrayHandle<T> zvals;
DFA::Copy(vtkm::cont::make_ArrayHandle(std::vector<T>(1,0)), zvals);
return BuildDataSet(2, xvals,yvals,zvals, coordNm, cellNm);
}
//3D grids. //3D grids.
template<typename T> template<typename T>
@ -77,6 +90,17 @@ public:
{ {
return Create(3, xvals, yvals, zvals, coordNm, cellNm); return Create(3, xvals, yvals, zvals, coordNm, cellNm);
} }
template<typename T>
VTKM_CONT_EXPORT
vtkm::cont::DataSet
Create(const vtkm::cont::ArrayHandle<T> &xvals,
const vtkm::cont::ArrayHandle<T> &yvals,
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);
}
private: private:
template<typename T> template<typename T>
@ -89,11 +113,12 @@ private:
VTKM_ASSERT_CONT(nx>1 && ny>1 && VTKM_ASSERT_CONT(nx>1 && ny>1 &&
((dim==2 && nz==1)||(dim==3 && nz>=1))); ((dim==2 && nz==1)||(dim==3 && nz>=1)));
vtkm::cont::ArrayHandle<T> X = vtkm::cont::make_ArrayHandle(nx,xvals); vtkm::cont::ArrayHandle<T> Xc, Yc, Zc;
vtkm::cont::ArrayHandle<T> Y = vtkm::cont::make_ArrayHandle(ny,yvals); DFA::Copy(vtkm::cont::make_ArrayHandle(nx,xvals), Xc);
vtkm::cont::ArrayHandle<T> Z = vtkm::cont::make_ArrayHandle(nz,zvals); DFA::Copy(vtkm::cont::make_ArrayHandle(ny,yvals), Yc);
DFA::Copy(vtkm::cont::make_ArrayHandle(nz,zvals), Zc);
return BuildDataSet(dim, X,Y,Z, coordNm, cellNm); return BuildDataSet(dim, Xc,Yc,Zc, coordNm, cellNm);
} }
template<typename T> template<typename T>
@ -108,11 +133,12 @@ private:
VTKM_ASSERT_CONT(xvals.size()>1 && yvals.size()>1 && VTKM_ASSERT_CONT(xvals.size()>1 && yvals.size()>1 &&
((dim==2 && zvals.size()==1)||(dim==3 && zvals.size()>=1))); ((dim==2 && zvals.size()==1)||(dim==3 && zvals.size()>=1)));
vtkm::cont::ArrayHandle<T> X = vtkm::cont::make_ArrayHandle(xvals); vtkm::cont::ArrayHandle<T> Xc, Yc, Zc;
vtkm::cont::ArrayHandle<T> Y = vtkm::cont::make_ArrayHandle(yvals); DFA::Copy(vtkm::cont::make_ArrayHandle(xvals), Xc);
vtkm::cont::ArrayHandle<T> Z = vtkm::cont::make_ArrayHandle(zvals); DFA::Copy(vtkm::cont::make_ArrayHandle(yvals), Yc);
DFA::Copy(vtkm::cont::make_ArrayHandle(zvals), Zc);
return BuildDataSet(dim, X,Y,Z, coordNm, cellNm); return BuildDataSet(dim, Xc,Yc,Zc, coordNm, cellNm);
} }
template<typename T> template<typename T>

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

@ -0,0 +1,104 @@
//=============================================================================
//
// 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/DataSetBuilderRegular.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 DataSetBuilderRegularNamespace {
typedef vtkm::cont::DeviceAdapterAlgorithm<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> DFA;
void ValidateDataSet(const vtkm::cont::DataSet &ds,
int dim,
int numPoints, int numCells)
{
//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.");
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");
}
}
void
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));
}
//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));
}
}
} // namespace ArrayHandleCartesianProductNamespace
int UnitTestDataSetBuilderRegular(int, char *[])
{
using namespace DataSetBuilderRegularNamespace;
return vtkm::cont::testing::Testing::Run(TestDataSetBuilderRegular);
}