templating topology worklet to support mappings other than point-to-cell.

This commit is contained in:
Jeremy Meredith 2015-08-25 15:37:53 -04:00
parent d014b13432
commit 6df4c2e4f1
7 changed files with 65 additions and 31 deletions

@ -20,7 +20,6 @@
#ifndef vtk_m_cont_arg_TransportTagTopologyIn_h
#define vtk_m_cont_arg_TransportTagTopologyIn_h
#include <vtkm/TopologyElementTag.h>
#include <vtkm/Types.h>
#include <vtkm/cont/CellSet.h>
@ -36,16 +35,19 @@ namespace arg {
/// \c TransportTagTopologyIn is a tag used with the \c Transport class to
/// transport topology objects for input data.
///
template<typename FromTopology,typename ToTopology>
struct TransportTagTopologyIn { };
template<typename ContObjectType, typename Device>
struct Transport<vtkm::cont::arg::TransportTagTopologyIn, ContObjectType, Device>
template<typename FromTopology,
typename ToTopology,
typename ContObjectType, typename Device>
struct Transport<vtkm::cont::arg::TransportTagTopologyIn<FromTopology,ToTopology>, ContObjectType, Device>
{
VTKM_IS_CELL_SET(ContObjectType);
typedef typename ContObjectType
::template ExecutionTypes<
Device,vtkm::TopologyElementTagPoint,vtkm::TopologyElementTagCell>
Device,FromTopology,ToTopology>
::ExecObjectType ExecObjectType;
VTKM_CONT_EXPORT
@ -53,8 +55,8 @@ struct Transport<vtkm::cont::arg::TransportTagTopologyIn, ContObjectType, Device
{
//create CUDA version of connectivity array.
return object.PrepareForInput(Device(),
vtkm::TopologyElementTagPoint(),
vtkm::TopologyElementTagCell());
FromTopology(),
ToTopology());
}
};

@ -27,7 +27,9 @@ namespace vtkm {
namespace worklet {
//simple functor that returns the average point value.
class CellAverage : public vtkm::worklet::WorkletMapTopology
class CellAverage :
public vtkm::worklet::WorkletMapTopology<TopologyElementTagPoint,
TopologyElementTagCell>
{
public:
typedef void ControlSignature(FieldInFrom<Scalar> inPoints,

@ -30,19 +30,21 @@ namespace worklet {
/// \brief Dispatcher for worklets that inherit from \c WorkletMapTopology.
///
template<typename WorkletType,
template<typename FromTopology,
typename ToTopology,
typename WorkletType,
typename Device = VTKM_DEFAULT_DEVICE_ADAPTER_TAG>
class DispatcherMapTopology :
public vtkm::worklet::internal::DispatcherBase<
DispatcherMapTopology<WorkletType,Device>,
DispatcherMapTopology<FromTopology,ToTopology,WorkletType,Device>,
WorkletType,
vtkm::worklet::WorkletMapTopology,
vtkm::worklet::WorkletMapTopology<FromTopology,ToTopology>,
Device>
{
typedef vtkm::worklet::internal::DispatcherBase<
DispatcherMapTopology<WorkletType,Device>,
DispatcherMapTopology<FromTopology,ToTopology,WorkletType,Device>,
WorkletType,
vtkm::worklet::WorkletMapTopology,
vtkm::worklet::WorkletMapTopology<FromTopology,ToTopology>,
Device> Superclass;
public:
@ -85,7 +87,7 @@ public:
// scheduling and call BadicInvoke.
this->BasicInvoke(invocation,
inputDomain.GetSchedulingRange(
vtkm::TopologyElementTagCell()));
ToTopology()));
}
};

@ -23,6 +23,7 @@
#include <vtkm/worklet/internal/WorkletBase.h>
#include <vtkm/TypeListTag.h>
#include <vtkm/TopologyElementTag.h>
#include <vtkm/cont/arg/ControlSignatureTagBase.h>
#include <vtkm/cont/arg/TransportTagArrayIn.h>
@ -48,12 +49,10 @@ namespace worklet {
/// inputs and outputs are on the same domain. That is, all the arrays are the
/// same size.
///
/// TODO: Although the nomenclature of this class suggests it handles general
/// topological links, it really only handles point to cell operations for
/// now. This worklet needs to be templated to handle generic from/to topology
/// links. I also suggest having convenience subclasses for common (supported?)
/// TODO: I also suggest having convenience subclasses for common (supported?)
/// link directions.
///
template<typename FromTopology, typename ToTopology>
class WorkletMapTopology : public vtkm::worklet::internal::WorkletBase
{
public:
@ -85,7 +84,7 @@ public:
///
struct TopologyIn : vtkm::cont::arg::ControlSignatureTagBase {
typedef vtkm::cont::arg::TypeCheckTagTopology TypeCheckTag;
typedef vtkm::cont::arg::TransportTagTopologyIn TransportTag;
typedef vtkm::cont::arg::TransportTagTopologyIn<FromTopology,ToTopology> TransportTag;
typedef vtkm::exec::arg::FetchTagTopologyIn FetchTag;
};

@ -43,7 +43,10 @@ void TestCellAverageRegular3D()
std::string("cells"),
vtkm::Float32());
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellAverage> dispatcher;
vtkm::worklet::DispatcherMapTopology<
vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell,
vtkm::worklet::CellAverage> dispatcher;
dispatcher.Invoke(dataSet.GetField("pointvar").GetData(),
dataSet.GetCellSet(),
result.GetData());
@ -72,7 +75,10 @@ void TestCellAverageRegular2D()
std::string("cells"),
vtkm::Float32());
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellAverage> dispatcher;
vtkm::worklet::DispatcherMapTopology<
vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell,
vtkm::worklet::CellAverage> dispatcher;
dispatcher.Invoke(dataSet.GetField("pointvar").GetData(),
dataSet.GetCellSet(),
result.GetData());
@ -101,7 +107,10 @@ void TestCellAverageExplicit()
std::string("cells"),
vtkm::Float32());
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellAverage> dispatcher;
vtkm::worklet::DispatcherMapTopology<
vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell,
vtkm::worklet::CellAverage> dispatcher;
dispatcher.Invoke(dataSet.GetField("pointvar").GetData(),
dataSet.GetCellSet(),
result.GetData());

@ -30,7 +30,9 @@
namespace test_explicit {
class MaxPointOrCellValue : public vtkm::worklet::WorkletMapTopology
class MaxPointOrCellValue :
public vtkm::worklet::WorkletMapTopology<vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell>
{
public:
typedef void ControlSignature(FieldInTo<Scalar> inCells,
@ -65,7 +67,9 @@ public:
}
};
class AveragePointToCellValue : public vtkm::worklet::WorkletMapTopology
class AveragePointToCellValue :
public vtkm::worklet::WorkletMapTopology<vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell>
{
public:
typedef void ControlSignature(FieldInFrom<Scalar> inPoints,
@ -122,7 +126,7 @@ TestMaxPointOrCell()
//Run a worklet to populate a cell centered field.
//Here, we're filling it with test values.
vtkm::cont::Field f("outcellvar",
1,
0,
vtkm::cont::Field::ASSOC_CELL_SET,
std::string("cells"),
vtkm::Float32());
@ -135,7 +139,10 @@ TestMaxPointOrCell()
VTKM_TEST_ASSERT(dataSet.GetNumberOfFields() == 6,
"Incorrect number of fields");
vtkm::worklet::DispatcherMapTopology< ::test_explicit::MaxPointOrCellValue >
vtkm::worklet::DispatcherMapTopology<
vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell,
::test_explicit::MaxPointOrCellValue >
dispatcher;
dispatcher.Invoke(dataSet.GetField("cellvar").GetData(),
dataSet.GetField("pointvar").GetData(),
@ -163,7 +170,7 @@ TestAvgPointToCell()
//Run a worklet to populate a cell centered field.
//Here, we're filling it with test values.
vtkm::cont::Field f("outcellvar",
1,
0,
vtkm::cont::Field::ASSOC_CELL_SET,
std::string("cells"),
vtkm::Float32());
@ -176,7 +183,10 @@ TestAvgPointToCell()
VTKM_TEST_ASSERT(dataSet.GetNumberOfFields() == 6,
"Incorrect number of fields");
vtkm::worklet::DispatcherMapTopology< ::test_explicit::AveragePointToCellValue > dispatcher;
vtkm::worklet::DispatcherMapTopology<
vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell,
::test_explicit::AveragePointToCellValue > dispatcher;
dispatcher.Invoke(dataSet.GetField("pointvar").GetData(),
dataSet.GetCellSet(),
dataSet.GetField("outcellvar").GetData());

@ -30,7 +30,9 @@
namespace test_regular {
class MaxPointOrCellValue : public vtkm::worklet::WorkletMapTopology
class MaxPointOrCellValue :
public vtkm::worklet::WorkletMapTopology<vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell>
{
public:
typedef void ControlSignature(FieldInTo<Scalar> inCells,
@ -65,7 +67,9 @@ public:
}
};
class AveragePointToCellValue : public vtkm::worklet::WorkletMapTopology
class AveragePointToCellValue :
public vtkm::worklet::WorkletMapTopology<vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell>
{
public:
typedef void ControlSignature(FieldInFrom<Scalar> inPoints,
@ -133,7 +137,10 @@ TestMaxPointOrCell()
VTKM_TEST_ASSERT(test_equal(dataSet.GetNumberOfFields(), 5),
"Incorrect number of fields");
vtkm::worklet::DispatcherMapTopology< ::test_regular::MaxPointOrCellValue > dispatcher;
vtkm::worklet::DispatcherMapTopology<
vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell,
::test_regular::MaxPointOrCellValue > dispatcher;
dispatcher.Invoke(dataSet.GetField("cellvar").GetData(),
dataSet.GetField("pointvar").GetData(),
// We know that the cell set is a structured 2D grid and
@ -177,7 +184,10 @@ TestAvgPointToCell()
VTKM_TEST_ASSERT(test_equal(dataSet.GetNumberOfFields(), 5),
"Incorrect number of fields");
vtkm::worklet::DispatcherMapTopology< ::test_regular::AveragePointToCellValue > dispatcher;
vtkm::worklet::DispatcherMapTopology<
vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell,
::test_regular::AveragePointToCellValue > dispatcher;
dispatcher.Invoke(dataSet.GetField("pointvar").GetData(),
// We know that the cell set is a structured 2D grid and
// The worklet does not work with general types because