Clarify dimension values for 2d, 1d. fix test

This commit is contained in:
Dave Pugmire 2021-06-09 16:16:34 -04:00
parent 651345b491
commit 3bd15950bd
2 changed files with 54 additions and 34 deletions

@ -35,7 +35,7 @@ public:
vtkm::Id dim = static_cast<vtkm::Id>(xVals.size());
auto coords = vtkm::cont::make_ArrayHandleSOA<vtkm::Vec<T, 3>>({ xVals, yVals, zVals });
return DataSetBuilderCurvilinear::Create(coords, { dim, 1, 1 }, 1, coordsNm);
return DataSetBuilderCurvilinear::Create(coords, { dim, 0, 0 }, 1, coordsNm);
}
template <typename T>
@ -49,7 +49,7 @@ public:
std::vector<T> zVals(xVals.size(), 0);
auto coords = vtkm::cont::make_ArrayHandleSOA<vtkm::Vec<T, 3>>({ xVals, yVals, zVals });
return DataSetBuilderCurvilinear::Create(coords, { dims[0], dims[1], 1 }, 2, coordsNm);
return DataSetBuilderCurvilinear::Create(coords, { dims[0], dims[1], 0 }, 2, coordsNm);
}
template <typename T>
@ -89,7 +89,7 @@ public:
const vtkm::Id2& dims,
const std::string& coordsNm = "coords")
{
return DataSetBuilderCurvilinear::Create(coords, { dims[0], dims[1], 1 }, 2, coordsNm);
return DataSetBuilderCurvilinear::Create(coords, { dims[0], dims[1], 0 }, 2, coordsNm);
}
template <typename CoordsType>
@ -97,7 +97,7 @@ public:
const std::string& coordsNm = "coords")
{
return DataSetBuilderCurvilinear::Create(
coords, { coords.GetNumberOfValues(), 1, 1 }, 1, coordsNm);
coords, { coords.GetNumberOfValues(), 0, 0 }, 1, coordsNm);
}
private:
@ -107,26 +107,32 @@ private:
const vtkm::Id& cellSetDim,
const std::string& coordsNm = "coords")
{
VTKM_ASSERT(dims[0] >= 1 && dims[1] >= 1 && dims[2] >= 1);
VTKM_ASSERT(coords.GetNumberOfValues() == dims[0] * dims[1] * dims[2]);
vtkm::cont::DataSet ds;
ds.AddCoordinateSystem(vtkm::cont::CoordinateSystem(coordsNm, coords));
if (cellSetDim == 3)
{
VTKM_ASSERT(dims[0] >= 1 && dims[1] >= 1 && dims[2] >= 1);
VTKM_ASSERT(coords.GetNumberOfValues() == dims[0] * dims[1] * dims[2]);
vtkm::cont::CellSetStructured<3> cellSet;
cellSet.SetPointDimensions(dims);
ds.SetCellSet(cellSet);
}
else if (cellSetDim == 2)
{
VTKM_ASSERT(dims[0] >= 1 && dims[1] >= 1 && dims[2] == 0);
VTKM_ASSERT(coords.GetNumberOfValues() == dims[0] * dims[1]);
vtkm::cont::CellSetStructured<2> cellSet;
cellSet.SetPointDimensions({ dims[0], dims[1] });
ds.SetCellSet(cellSet);
}
else if (cellSetDim == 1)
{
VTKM_ASSERT(dims[0] >= 1 && dims[1] == 0 && dims[2] == 0);
VTKM_ASSERT(coords.GetNumberOfValues() == dims[0]);
vtkm::cont::CellSetStructured<1> cellSet;
cellSet.SetPointDimensions(dims[0]);
ds.SetCellSet(cellSet);

@ -55,7 +55,10 @@ void ValidateDataSet(const vtkm::cont::DataSet& ds,
//Make sure bounds are correct.
vtkm::Bounds res = ds.GetCoordinateSystem().GetBounds();
VTKM_TEST_ASSERT(test_equal(bounds, res), "Bounds of coordinates do not match");
VTKM_TEST_ASSERT(bounds.Contains(vtkm::Vec3f_64(res.X.Min, res.Y.Min, res.Z.Min)) &&
bounds.Contains(vtkm::Vec3f_64(res.X.Max, res.Y.Max, res.Z.Max)),
test_equal(bounds, res),
"Bounds of coordinates do not match");
if (dim == 1)
{
vtkm::cont::CellSetStructured<1> cellSet;
@ -95,39 +98,50 @@ void CurvilinearTests()
std::uniform_real_distribution<T> randomVal(minReal, maxReal);
std::uniform_int_distribution<vtkm::Id> randomDim(2, 20);
vtkm::Bounds bounds(minReal, maxReal, minReal, maxReal, minReal, maxReal);
for (int i = 0; i < 10; i++)
{
vtkm::Id3 dims(
randomDim(g_RandomGenerator), randomDim(g_RandomGenerator), randomDim(g_RandomGenerator));
vtkm::Id numPoints = dims[0] * dims[1] * dims[2];
vtkm::Id numCells = (dims[0] - 1) * (dims[1] - 1) * (dims[2] - 1);
std::vector<T> x, y, z;
for (vtkm::Id j = 0; j < numPoints; j++)
{
x.push_back(randomVal(g_RandomGenerator));
y.push_back(randomVal(g_RandomGenerator));
z.push_back(randomVal(g_RandomGenerator));
}
vtkm::Bounds bounds(minReal, maxReal, minReal, maxReal, minReal, maxReal);
vtkm::Id numPoints = 1;
vtkm::Id numCells = 1;
//test 3d
for (int ndim = 0; ndim < 3; ndim++)
{
auto ds = vtkm::cont::DataSetBuilderCurvilinear::Create(x, y, z, dims);
AddFields<T>(ds, numPoints, numCells);
ValidateDataSet(ds, 3, numPoints, numCells, bounds);
}
//test 2d
{
auto ds = vtkm::cont::DataSetBuilderCurvilinear::Create(x, y, { dims[0], dims[1] });
AddFields<T>(ds, numPoints, numCells);
ValidateDataSet(ds, 2, numPoints, numCells, bounds);
}
//test 1d
{
auto ds = vtkm::cont::DataSetBuilderCurvilinear::Create(x);
AddFields<T>(ds, numPoints, numCells);
ValidateDataSet(ds, 1, numPoints, numCells, bounds);
numPoints *= dims[ndim];
numCells *= (dims[ndim] - 1);
std::vector<T> x, y, z;
for (vtkm::Id j = 0; j < numPoints; j++)
{
x.push_back(randomVal(g_RandomGenerator));
y.push_back(randomVal(g_RandomGenerator));
z.push_back(randomVal(g_RandomGenerator));
}
//test 3d
if (ndim == 2)
{
auto ds = vtkm::cont::DataSetBuilderCurvilinear::Create(x, y, z, dims);
AddFields<T>(ds, numPoints, numCells);
ValidateDataSet(ds, 3, numPoints, numCells, bounds);
}
//test 2d
else if (ndim == 1)
{
auto ds = vtkm::cont::DataSetBuilderCurvilinear::Create(x, y, { dims[0], dims[1] });
AddFields<T>(ds, numPoints, numCells);
ValidateDataSet(ds, 2, numPoints, numCells, bounds);
}
//test 1d
else if (ndim == 0)
{
auto ds = vtkm::cont::DataSetBuilderCurvilinear::Create(x);
AddFields<T>(ds, numPoints, numCells);
ValidateDataSet(ds, 1, numPoints, numCells, bounds);
}
}
}
}