diff --git a/vtkm/cont/DataSetBuilderRectilinear.h b/vtkm/cont/DataSetBuilderRectilinear.h index 922141cd6..e3ed65de1 100644 --- a/vtkm/cont/DataSetBuilderRectilinear.h +++ b/vtkm/cont/DataSetBuilderRectilinear.h @@ -56,6 +56,19 @@ public: std::vector zvals(1,0); return Create(2, xvals, yvals, zvals, coordNm, cellNm); } + template + VTKM_CONT_EXPORT + vtkm::cont::DataSet + Create(const vtkm::cont::ArrayHandle &xvals, + const vtkm::cont::ArrayHandle &yvals, + std::string coordNm="coords", std::string cellNm="cells") + { + VTKM_ASSERT_CONT(xvals.size()>1 && yvals.size()>1); + + vtkm::cont::ArrayHandle zvals; + DFA::Copy(vtkm::cont::make_ArrayHandle(std::vector(1,0)), zvals); + return BuildDataSet(2, xvals,yvals,zvals, coordNm, cellNm); + } //3D grids. template @@ -77,6 +90,17 @@ public: { return Create(3, xvals, yvals, zvals, coordNm, cellNm); } + template + VTKM_CONT_EXPORT + vtkm::cont::DataSet + Create(const vtkm::cont::ArrayHandle &xvals, + const vtkm::cont::ArrayHandle &yvals, + const vtkm::cont::ArrayHandle &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: template @@ -89,11 +113,12 @@ private: VTKM_ASSERT_CONT(nx>1 && ny>1 && ((dim==2 && nz==1)||(dim==3 && nz>=1))); - vtkm::cont::ArrayHandle X = vtkm::cont::make_ArrayHandle(nx,xvals); - vtkm::cont::ArrayHandle Y = vtkm::cont::make_ArrayHandle(ny,yvals); - vtkm::cont::ArrayHandle Z = vtkm::cont::make_ArrayHandle(nz,zvals); + vtkm::cont::ArrayHandle 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); - return BuildDataSet(dim, X,Y,Z, coordNm, cellNm); + return BuildDataSet(dim, Xc,Yc,Zc, coordNm, cellNm); } template @@ -108,11 +133,12 @@ private: VTKM_ASSERT_CONT(xvals.size()>1 && yvals.size()>1 && ((dim==2 && zvals.size()==1)||(dim==3 && zvals.size()>=1))); - vtkm::cont::ArrayHandle X = vtkm::cont::make_ArrayHandle(xvals); - vtkm::cont::ArrayHandle Y = vtkm::cont::make_ArrayHandle(yvals); - vtkm::cont::ArrayHandle Z = vtkm::cont::make_ArrayHandle(zvals); + vtkm::cont::ArrayHandle Xc, Yc, Zc; + DFA::Copy(vtkm::cont::make_ArrayHandle(xvals), Xc); + 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 diff --git a/vtkm/cont/testing/CMakeLists.txt b/vtkm/cont/testing/CMakeLists.txt index 0f812f892..d066cd766 100644 --- a/vtkm/cont/testing/CMakeLists.txt +++ b/vtkm/cont/testing/CMakeLists.txt @@ -45,6 +45,7 @@ set(unit_tests UnitTestArrayPortalToIterators.cxx UnitTestContTesting.cxx UnitTestComputeBoundsSerial.cxx + UnitTestDataSetBuilderRegular.cxx UnitTestDataSetRegular.cxx UnitTestDataSetRectilinear.cxx UnitTestDataSetExplicit.cxx diff --git a/vtkm/cont/testing/UnitTestDataSetBuilderRegular.cxx b/vtkm/cont/testing/UnitTestDataSetBuilderRegular.cxx new file mode 100644 index 000000000..cb3405ea0 --- /dev/null +++ b/vtkm/cont/testing/UnitTestDataSetBuilderRegular.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 +#include +#include +#include +#include + +#include + +#include + +namespace DataSetBuilderRegularNamespace { + +typedef vtkm::cont::DeviceAdapterAlgorithm 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(); + 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(); + 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); +}