mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-19 18:45:43 +00:00
f9750e83f7
I ran into a few minor issues with the constructors to the Field class. The big change I made was that I removed the Field constructors that take an example type and create an empty field of that type. The problem was that the example type was easily confused with some other type that was supposed to describe an array. This lead to some odd behavior in the compiler and resulted in errors in unexpected places. The use case for this constructor is dubious. There were several tests in the code that would create an empty field, add it to a data set, then get it back out to pass to the worklet. The code is much simpler if you just make an ArrayHandle of the right type and use that in the worklet invoke directly. It is also faster to compile with smaller code because the type is known statically (whereas it is lost the other way). The other change was to declare references to ArrayHandle and DynamicArrayHandle as const. There is nothing in the behavior that invalidates the const, and it accepts arrays constructed in the parameter.
116 lines
3.6 KiB
C++
116 lines
3.6 KiB
C++
//============================================================================
|
|
// 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 2014 Sandia Corporation.
|
|
// Copyright 2014 UT-Battelle, LLC.
|
|
// Copyright 2014 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/worklet/CellAverage.h>
|
|
#include <vtkm/worklet/DispatcherMapTopology.h>
|
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
|
|
|
VTKM_THIRDPARTY_PRE_INCLUDE
|
|
#include <boost/shared_ptr.hpp>
|
|
VTKM_THIRDPARTY_POST_INCLUDE
|
|
|
|
namespace {
|
|
|
|
void TestCellAverageUniform3D()
|
|
{
|
|
std::cout << "Testing CellAverage Worklet on 3D strucutred data" << std::endl;
|
|
|
|
vtkm::cont::testing::MakeTestDataSet testDataSet;
|
|
vtkm::cont::DataSet dataSet = testDataSet.Make3DUniformDataSet0();
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Float32> result;
|
|
|
|
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellAverage> dispatcher;
|
|
dispatcher.Invoke(dataSet.GetField("pointvar").GetData(),
|
|
dataSet.GetCellSet(),
|
|
result);
|
|
|
|
vtkm::Float32 expected[4] = { 60.1875f, 70.2125f, 120.3375f, 130.3625f };
|
|
for (int i = 0; i < 4; ++i)
|
|
{
|
|
VTKM_TEST_ASSERT(
|
|
test_equal(result.GetPortalConstControl().Get(i), expected[i]),
|
|
"Wrong result for CellAverage worklet on 3D uniform data");
|
|
}
|
|
}
|
|
|
|
void TestCellAverageUniform2D()
|
|
{
|
|
std::cout << "Testing CellAverage Worklet on 2D strucutred data" << std::endl;
|
|
|
|
vtkm::cont::testing::MakeTestDataSet testDataSet;
|
|
vtkm::cont::DataSet dataSet = testDataSet.Make2DUniformDataSet0();
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Float32> result;
|
|
|
|
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellAverage> dispatcher;
|
|
dispatcher.Invoke(dataSet.GetField("pointvar").GetData(),
|
|
dataSet.GetCellSet(),
|
|
result);
|
|
|
|
vtkm::Float32 expected[2] = { 30.1f, 40.1f };
|
|
for (int i = 0; i < 2; ++i)
|
|
{
|
|
VTKM_TEST_ASSERT(
|
|
test_equal(result.GetPortalConstControl().Get(i), expected[i]),
|
|
"Wrong result for CellAverage worklet on 2D uniform data");
|
|
}
|
|
}
|
|
|
|
void TestCellAverageExplicit()
|
|
{
|
|
std::cout << "Testing CellAverage Worklet on Explicit data" << std::endl;
|
|
|
|
vtkm::cont::testing::MakeTestDataSet testDataSet;
|
|
vtkm::cont::DataSet dataSet = testDataSet.Make3DExplicitDataSet0();
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Float32> result;
|
|
|
|
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellAverage> dispatcher;
|
|
dispatcher.Invoke(dataSet.GetField("pointvar").GetData(),
|
|
dataSet.GetCellSet(),
|
|
result);
|
|
|
|
vtkm::Float32 expected[2] = { 20.1333f, 35.2f };
|
|
for (int i = 0; i < 2; ++i)
|
|
{
|
|
VTKM_TEST_ASSERT(
|
|
test_equal(result.GetPortalConstControl().Get(i), expected[i]),
|
|
"Wrong result for CellAverage worklet on 3D explicit data");
|
|
}
|
|
}
|
|
|
|
|
|
void TestCellAverage()
|
|
{
|
|
TestCellAverageUniform2D();
|
|
TestCellAverageUniform3D();
|
|
TestCellAverageExplicit();
|
|
}
|
|
|
|
}
|
|
|
|
int UnitTestCellAverage(int, char *[])
|
|
{
|
|
return vtkm::cont::testing::Testing::Run(TestCellAverage);
|
|
}
|