2015-05-18 21:08:15 +00:00
|
|
|
//============================================================================
|
|
|
|
// 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.
|
2015-06-03 19:06:43 +00:00
|
|
|
// Copyright 2014 Los Alamos National Security.
|
2015-05-18 21:08:15 +00:00
|
|
|
//
|
|
|
|
// 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/DispatcherMapTopology.h>
|
|
|
|
#include <vtkm/worklet/WorkletMapTopology.h>
|
|
|
|
|
2015-08-14 15:06:11 +00:00
|
|
|
#include <vtkm/Math.h>
|
|
|
|
|
2015-05-18 21:08:15 +00:00
|
|
|
#include <vtkm/cont/DataSet.h>
|
|
|
|
|
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
|
|
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
|
|
|
|
2015-06-08 13:02:23 +00:00
|
|
|
namespace test_regular {
|
2015-05-18 21:08:15 +00:00
|
|
|
|
2015-08-25 19:37:53 +00:00
|
|
|
class MaxPointOrCellValue :
|
2015-08-27 18:36:55 +00:00
|
|
|
public vtkm::worklet::WorkletMapTopologyPointToCell
|
2015-05-18 21:08:15 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-08-03 16:48:50 +00:00
|
|
|
typedef void ControlSignature(FieldInTo<Scalar> inCells,
|
|
|
|
FieldInFrom<Scalar> inPoints,
|
2015-08-14 15:06:11 +00:00
|
|
|
TopologyIn topology,
|
2015-08-03 16:48:50 +00:00
|
|
|
FieldOut<Scalar> outCells);
|
2015-08-03 16:06:59 +00:00
|
|
|
typedef void ExecutionSignature(_1, _4, _2, FromCount, CellShape, FromIndices);
|
2015-05-18 21:08:15 +00:00
|
|
|
typedef _3 InputDomain;
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
2015-08-03 16:06:59 +00:00
|
|
|
MaxPointOrCellValue() { }
|
2015-05-18 21:08:15 +00:00
|
|
|
|
2015-08-14 15:06:11 +00:00
|
|
|
template<typename InCellType,
|
|
|
|
typename OutCellType,
|
|
|
|
typename InPointVecType,
|
2015-08-19 16:32:01 +00:00
|
|
|
typename CellShapeTag,
|
2015-08-14 15:06:11 +00:00
|
|
|
typename FromIndexType>
|
2015-05-18 21:08:15 +00:00
|
|
|
VTKM_EXEC_EXPORT
|
2015-08-14 15:06:11 +00:00
|
|
|
void operator()(const InCellType &cellValue,
|
|
|
|
OutCellType &maxValue,
|
|
|
|
const InPointVecType &pointValues,
|
|
|
|
const vtkm::IdComponent &numPoints,
|
2015-08-19 16:32:01 +00:00
|
|
|
const CellShapeTag &vtkmNotUsed(type),
|
2015-08-14 15:06:11 +00:00
|
|
|
const FromIndexType &vtkmNotUsed(pointIDs)) const
|
2015-05-18 21:08:15 +00:00
|
|
|
{
|
2015-08-14 15:06:11 +00:00
|
|
|
//simple functor that returns the max of cellValue and pointValue
|
|
|
|
maxValue = static_cast<OutCellType>(cellValue);
|
|
|
|
for (vtkm::IdComponent pointIndex = 0; pointIndex < numPoints; ++pointIndex)
|
2015-06-04 14:44:24 +00:00
|
|
|
{
|
2015-08-14 15:06:11 +00:00
|
|
|
maxValue = vtkm::Max(maxValue,
|
|
|
|
static_cast<OutCellType>(pointValues[pointIndex]));
|
2015-06-04 14:44:24 +00:00
|
|
|
}
|
2015-05-18 21:08:15 +00:00
|
|
|
}
|
2015-06-04 14:44:24 +00:00
|
|
|
};
|
2015-05-19 18:11:26 +00:00
|
|
|
|
2015-08-27 18:36:55 +00:00
|
|
|
class AveragePointToCellValue :
|
|
|
|
public vtkm::worklet::WorkletMapTopologyPointToCell
|
2015-05-19 18:11:26 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-08-03 16:48:50 +00:00
|
|
|
typedef void ControlSignature(FieldInFrom<Scalar> inPoints,
|
2015-08-14 15:06:11 +00:00
|
|
|
TopologyIn topology,
|
2015-08-03 16:48:50 +00:00
|
|
|
FieldOut<Scalar> outCells);
|
2015-08-03 16:06:59 +00:00
|
|
|
typedef void ExecutionSignature(_1, _3, FromCount);
|
2015-05-19 18:11:26 +00:00
|
|
|
typedef _2 InputDomain;
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
2015-08-03 16:06:59 +00:00
|
|
|
AveragePointToCellValue() { }
|
2015-05-19 18:11:26 +00:00
|
|
|
|
2015-08-14 15:06:11 +00:00
|
|
|
template<typename PointVecType, typename OutType>
|
2015-05-19 18:11:26 +00:00
|
|
|
VTKM_EXEC_EXPORT
|
2015-08-14 15:06:11 +00:00
|
|
|
void operator()(const PointVecType &pointValues,
|
|
|
|
OutType &avgVal,
|
|
|
|
const vtkm::IdComponent &numPoints) const
|
2015-05-19 18:11:26 +00:00
|
|
|
{
|
2015-08-03 16:06:59 +00:00
|
|
|
//simple functor that returns the average pointValue.
|
2015-08-14 15:06:11 +00:00
|
|
|
avgVal = static_cast<OutType>(pointValues[0]);
|
|
|
|
for (vtkm::IdComponent pointIndex = 1; pointIndex < numPoints; ++pointIndex)
|
2015-06-04 14:44:24 +00:00
|
|
|
{
|
2015-08-14 15:06:11 +00:00
|
|
|
avgVal += static_cast<OutType>(pointValues[pointIndex]);
|
2015-06-04 14:44:24 +00:00
|
|
|
}
|
2015-08-14 15:06:11 +00:00
|
|
|
avgVal = avgVal / static_cast<OutType>(numPoints);
|
2015-06-04 14:44:24 +00:00
|
|
|
}
|
2015-05-19 18:11:26 +00:00
|
|
|
};
|
|
|
|
|
2015-05-18 21:08:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-08-03 16:06:59 +00:00
|
|
|
static void TestMaxPointOrCell();
|
|
|
|
static void TestAvgPointToCell();
|
2015-05-19 18:11:26 +00:00
|
|
|
|
2015-05-18 21:08:15 +00:00
|
|
|
void TestWorkletMapTopologyRegular()
|
|
|
|
{
|
2015-05-19 18:11:26 +00:00
|
|
|
typedef vtkm::cont::internal::DeviceAdapterTraits<
|
|
|
|
VTKM_DEFAULT_DEVICE_ADAPTER_TAG> DeviceAdapterTraits;
|
|
|
|
std::cout << "Testing Topology Worklet ( Regular ) on device adapter: "
|
|
|
|
<< DeviceAdapterTraits::GetId() << std::endl;
|
2015-05-18 21:08:15 +00:00
|
|
|
|
2015-08-03 16:06:59 +00:00
|
|
|
TestMaxPointOrCell();
|
|
|
|
TestAvgPointToCell();
|
2015-05-19 18:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-08-03 16:06:59 +00:00
|
|
|
TestMaxPointOrCell()
|
2015-05-19 18:11:26 +00:00
|
|
|
{
|
2015-08-03 16:06:59 +00:00
|
|
|
std::cout<<"Testing MaxPointOfCell worklet"<<std::endl;
|
2015-07-28 23:33:52 +00:00
|
|
|
vtkm::cont::testing::MakeTestDataSet testDataSet;
|
|
|
|
vtkm::cont::DataSet dataSet = testDataSet.Make2DRegularDataSet0();
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-05-19 18:11:26 +00:00
|
|
|
//Run a worklet to populate a cell centered field.
|
|
|
|
//Here, we're filling it with test values.
|
2015-06-08 20:14:49 +00:00
|
|
|
vtkm::cont::Field f("outcellvar",
|
|
|
|
1,
|
|
|
|
vtkm::cont::Field::ASSOC_CELL_SET,
|
|
|
|
std::string("cells"),
|
|
|
|
vtkm::Float32());
|
|
|
|
|
2015-07-28 23:33:52 +00:00
|
|
|
dataSet.AddField(f);
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-07-28 23:33:52 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(dataSet.GetNumberOfCellSets(), 1),
|
2015-05-19 18:11:26 +00:00
|
|
|
"Incorrect number of cell sets");
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-08-17 18:47:46 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(dataSet.GetNumberOfFields(), 3),
|
2015-05-19 18:11:26 +00:00
|
|
|
"Incorrect number of fields");
|
2015-08-03 16:06:59 +00:00
|
|
|
vtkm::worklet::DispatcherMapTopology< ::test_regular::MaxPointOrCellValue > dispatcher;
|
2015-07-28 23:33:52 +00:00
|
|
|
dispatcher.Invoke(dataSet.GetField("cellvar").GetData(),
|
2015-08-03 16:06:59 +00:00
|
|
|
dataSet.GetField("pointvar").GetData(),
|
2015-07-28 23:33:52 +00:00
|
|
|
// We know that the cell set is a structured 2D grid and
|
|
|
|
// The worklet does not work with general types because
|
|
|
|
// of the way we get cell indices. We need to make that
|
|
|
|
// part more flexible.
|
|
|
|
dataSet.GetCellSet(0).ResetCellSetList(
|
|
|
|
vtkm::cont::CellSetListTagStructured2D()),
|
2015-08-17 18:47:46 +00:00
|
|
|
dataSet.GetField("outcellvar").GetData());
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-05-19 18:11:26 +00:00
|
|
|
//make sure we got the right answer.
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Float32> res;
|
2015-08-17 18:47:46 +00:00
|
|
|
res = dataSet.GetField("outcellvar").GetData().
|
|
|
|
CastToArrayHandle(vtkm::Float32(), VTKM_DEFAULT_STORAGE_TAG());
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-06-04 13:06:47 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(res.GetPortalConstControl().Get(0), 100.1f),
|
2015-08-03 16:06:59 +00:00
|
|
|
"Wrong result for MaxPointOrCell worklet");
|
2015-06-04 13:06:47 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(res.GetPortalConstControl().Get(1), 200.1f),
|
2015-08-03 16:06:59 +00:00
|
|
|
"Wrong result for MaxPointOrCell worklet");
|
2015-05-19 18:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-08-03 16:06:59 +00:00
|
|
|
TestAvgPointToCell()
|
2015-05-19 18:11:26 +00:00
|
|
|
{
|
2015-08-03 16:06:59 +00:00
|
|
|
std::cout<<"Testing AvgPointToCell worklet"<<std::endl;
|
2015-07-28 23:33:52 +00:00
|
|
|
vtkm::cont::testing::MakeTestDataSet testDataSet;
|
|
|
|
vtkm::cont::DataSet dataSet = testDataSet.Make2DRegularDataSet0();
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-05-19 18:11:26 +00:00
|
|
|
//Run a worklet to populate a cell centered field.
|
|
|
|
//Here, we're filling it with test values.
|
2015-06-08 20:14:49 +00:00
|
|
|
vtkm::cont::Field f("outcellvar",
|
|
|
|
1,
|
|
|
|
vtkm::cont::Field::ASSOC_CELL_SET,
|
|
|
|
std::string("cells"),
|
|
|
|
vtkm::Float32());
|
|
|
|
|
2015-07-28 23:33:52 +00:00
|
|
|
dataSet.AddField(f);
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-07-28 23:33:52 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(dataSet.GetNumberOfCellSets(), 1),
|
2015-05-19 18:11:26 +00:00
|
|
|
"Incorrect number of cell sets");
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-08-17 18:47:46 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(dataSet.GetNumberOfFields(), 3),
|
2015-05-19 18:11:26 +00:00
|
|
|
"Incorrect number of fields");
|
2015-08-03 16:06:59 +00:00
|
|
|
vtkm::worklet::DispatcherMapTopology< ::test_regular::AveragePointToCellValue > dispatcher;
|
|
|
|
dispatcher.Invoke(dataSet.GetField("pointvar").GetData(),
|
2015-07-28 23:33:52 +00:00
|
|
|
// We know that the cell set is a structured 2D grid and
|
|
|
|
// The worklet does not work with general types because
|
|
|
|
// of the way we get cell indices. We need to make that
|
|
|
|
// part more flexible.
|
|
|
|
dataSet.GetCellSet(0).ResetCellSetList(
|
|
|
|
vtkm::cont::CellSetListTagStructured2D()),
|
|
|
|
dataSet.GetField("outcellvar").GetData());
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-05-19 18:11:26 +00:00
|
|
|
//make sure we got the right answer.
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Float32> res;
|
2015-08-17 18:47:46 +00:00
|
|
|
res = dataSet.GetField("outcellvar").GetData().
|
|
|
|
CastToArrayHandle(vtkm::Float32(), VTKM_DEFAULT_STORAGE_TAG());
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-06-04 13:06:47 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(res.GetPortalConstControl().Get(0), 30.1f),
|
2015-08-03 16:06:59 +00:00
|
|
|
"Wrong result for PointToCellAverage worklet");
|
2015-06-04 13:06:47 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(res.GetPortalConstControl().Get(1), 40.1f),
|
2015-08-03 16:06:59 +00:00
|
|
|
"Wrong result for PointToCellAverage worklet");
|
2015-05-18 21:08:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
int UnitTestWorkletMapTopologyRegular(int, char *[])
|
|
|
|
{
|
|
|
|
return vtkm::cont::testing::Testing::Run(TestWorkletMapTopologyRegular);
|
|
|
|
}
|