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>
|
|
|
|
|
|
|
|
#include <vtkm/cont/DataSet.h>
|
|
|
|
|
2015-05-19 19:16:13 +00:00
|
|
|
#include <vtkm/exec/TopologyData.h>
|
2015-05-18 21:08:15 +00:00
|
|
|
#include <vtkm/exec/arg/TopologyIdSet.h>
|
|
|
|
#include <vtkm/exec/arg/TopologyIdCount.h>
|
|
|
|
#include <vtkm/exec/arg/TopologyElementType.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-05-19 18:11:26 +00:00
|
|
|
class MaxNodeOrCellValue : public vtkm::worklet::WorkletMapTopology
|
2015-05-18 21:08:15 +00:00
|
|
|
{
|
|
|
|
static const int LEN_IDS = 4;
|
|
|
|
public:
|
2015-05-19 18:11:26 +00:00
|
|
|
typedef void ControlSignature(FieldDestIn<Scalar> inCells,
|
|
|
|
FieldSrcIn<Scalar> inNodes,
|
|
|
|
TopologyIn<LEN_IDS> topology,
|
|
|
|
FieldDestOut<Scalar> outCells);
|
2015-05-18 21:08:15 +00:00
|
|
|
//Todo: we need a way to mark what control signature item each execution signature for topology comes from
|
2015-06-04 14:44:24 +00:00
|
|
|
typedef void ExecutionSignature(_1, _4, _2,
|
2015-05-19 18:11:26 +00:00
|
|
|
vtkm::exec::arg::TopologyIdCount,
|
|
|
|
vtkm::exec::arg::TopologyElementType,
|
|
|
|
vtkm::exec::arg::TopologyIdSet);
|
2015-05-18 21:08:15 +00:00
|
|
|
typedef _3 InputDomain;
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
2015-05-19 18:11:26 +00:00
|
|
|
MaxNodeOrCellValue() { };
|
2015-05-18 21:08:15 +00:00
|
|
|
|
2015-06-04 14:44:24 +00:00
|
|
|
template<typename T>
|
2015-05-18 21:08:15 +00:00
|
|
|
VTKM_EXEC_EXPORT
|
2015-06-04 14:44:24 +00:00
|
|
|
void operator()(const T &cellval,
|
|
|
|
T& max_value,
|
|
|
|
const vtkm::exec::TopologyData<T,LEN_IDS> &nodevals,
|
|
|
|
const vtkm::Id &count,
|
|
|
|
const vtkm::Id & vtkmNotUsed(type),
|
|
|
|
const vtkm::exec::TopologyData<vtkm::Id,LEN_IDS> & vtkmNotUsed(nodeIDs)) const
|
2015-05-18 21:08:15 +00:00
|
|
|
{
|
|
|
|
//simple functor that returns the max of CellValue and nodeValue
|
2015-06-04 14:44:24 +00:00
|
|
|
max_value = cellval;
|
2015-05-18 21:08:15 +00:00
|
|
|
for (vtkm::Id i=0; i<count; ++i)
|
2015-06-04 14:44:24 +00:00
|
|
|
{
|
|
|
|
max_value = nodevals[i] > max_value ? nodevals[i] : max_value;
|
|
|
|
}
|
2015-05-18 21:08:15 +00:00
|
|
|
}
|
|
|
|
|
2015-06-04 14:44:24 +00:00
|
|
|
template<typename T1, typename T2, typename T3>
|
|
|
|
VTKM_EXEC_EXPORT
|
|
|
|
void operator()(const T1 &,
|
|
|
|
T2 &,
|
|
|
|
const vtkm::exec::TopologyData<T3,LEN_IDS> &,
|
|
|
|
const vtkm::Id &,
|
|
|
|
const vtkm::Id &,
|
|
|
|
const vtkm::exec::TopologyData<vtkm::Id,LEN_IDS> &) const
|
|
|
|
{
|
|
|
|
this->RaiseError("Cannot call this worklet with different types.");
|
|
|
|
}
|
2015-05-18 21:08:15 +00:00
|
|
|
|
2015-06-04 14:44:24 +00:00
|
|
|
};
|
2015-05-19 18:11:26 +00:00
|
|
|
|
|
|
|
class AvgNodeToCellValue : public vtkm::worklet::WorkletMapTopology
|
|
|
|
{
|
|
|
|
static const int LEN_IDS = 4;
|
|
|
|
public:
|
|
|
|
typedef void ControlSignature(FieldSrcIn<Scalar> inNodes,
|
|
|
|
TopologyIn<LEN_IDS> topology,
|
|
|
|
FieldDestOut<Scalar> outCells);
|
2015-06-04 14:44:24 +00:00
|
|
|
typedef void ExecutionSignature(_1,
|
|
|
|
_3,
|
|
|
|
vtkm::exec::arg::TopologyIdCount);
|
2015-05-19 18:11:26 +00:00
|
|
|
typedef _2 InputDomain;
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
AvgNodeToCellValue() { };
|
|
|
|
|
2015-06-04 14:44:24 +00:00
|
|
|
template<typename T>
|
2015-05-19 18:11:26 +00:00
|
|
|
VTKM_EXEC_EXPORT
|
2015-06-04 14:44:24 +00:00
|
|
|
void operator()(const vtkm::exec::TopologyData<T,LEN_IDS> &nodevals,
|
|
|
|
T& avgVal,
|
|
|
|
const vtkm::Id &count) const
|
2015-05-19 18:11:26 +00:00
|
|
|
{
|
2015-06-04 14:44:24 +00:00
|
|
|
//simple functor that returns the average nodeValue.
|
|
|
|
avgVal = nodevals[0];
|
|
|
|
for (vtkm::Id i=1; i<count; ++i)
|
|
|
|
{
|
|
|
|
avgVal += nodevals[i];
|
|
|
|
}
|
|
|
|
avgVal = avgVal / count;
|
|
|
|
}
|
2015-05-19 18:11:26 +00:00
|
|
|
|
2015-06-04 14:44:24 +00:00
|
|
|
template<typename T1, typename T2>
|
|
|
|
VTKM_EXEC_EXPORT
|
|
|
|
void operator()(const T1 &, T2 &, const vtkm::Id &) const
|
|
|
|
{
|
|
|
|
this->RaiseError("Cannot call this worklet with different types.");
|
2015-05-19 18:11:26 +00:00
|
|
|
}
|
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-05-19 18:11:26 +00:00
|
|
|
static void TestMaxNodeOrCell();
|
|
|
|
static void TestAvgNodeToCell();
|
|
|
|
|
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-05-19 18:11:26 +00:00
|
|
|
TestMaxNodeOrCell();
|
|
|
|
TestAvgNodeToCell();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
TestMaxNodeOrCell()
|
|
|
|
{
|
|
|
|
std::cout<<"Testing MaxNodeOfCell worklet"<<std::endl;
|
|
|
|
vtkm::cont::testing::MakeTestDataSet tds;
|
2015-05-28 19:35:19 +00:00
|
|
|
vtkm::cont::DataSet ds = tds.Make2DRegularDataSet0();
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-05-28 19:35:19 +00:00
|
|
|
boost::shared_ptr<vtkm::cont::CellSet> scs = ds.GetCellSet(0);
|
2015-05-28 19:30:13 +00:00
|
|
|
vtkm::cont::CellSetStructured<2> *cs =
|
|
|
|
dynamic_cast<vtkm::cont::CellSetStructured<2> *>(scs.get());
|
2015-05-19 18:11:26 +00:00
|
|
|
VTKM_TEST_ASSERT(cs, "Structured cell set not found");
|
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-04 13:06:47 +00:00
|
|
|
vtkm::Float32 outcellVals[2] = {-1.4f, -1.7f};
|
2015-05-28 19:35:19 +00:00
|
|
|
ds.AddField(vtkm::cont::Field("outcellvar", 1, vtkm::cont::Field::ASSOC_CELL_SET, "cells", outcellVals, 2));
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-05-28 19:35:19 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(ds.GetNumberOfCellSets(), 1),
|
2015-05-19 18:11:26 +00:00
|
|
|
"Incorrect number of cell sets");
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-05-28 19:35:19 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(ds.GetNumberOfFields(), 5),
|
2015-05-19 18:11:26 +00:00
|
|
|
"Incorrect number of fields");
|
|
|
|
//Todo:
|
|
|
|
//the scheduling should just be passed a CellSet, and not the
|
|
|
|
//derived implementation. The vtkm::cont::CellSet should have
|
|
|
|
//a method that return the nodesOfCellsConnectivity / structure
|
|
|
|
//for that derived type. ( talk to robert for how dax did this )
|
2015-06-08 13:02:23 +00:00
|
|
|
vtkm::worklet::DispatcherMapTopology< ::test_regular::MaxNodeOrCellValue > dispatcher;
|
2015-05-28 19:35:19 +00:00
|
|
|
dispatcher.Invoke(ds.GetField("cellvar").GetData(),
|
|
|
|
ds.GetField("nodevar").GetData(),
|
2015-05-19 18:11:26 +00:00
|
|
|
cs->GetNodeToCellConnectivity(),
|
2015-05-28 19:35:19 +00:00
|
|
|
ds.GetField(4).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-05-28 19:35:19 +00:00
|
|
|
res = ds.GetField(4).GetData().CastToArrayHandle(vtkm::Float32(),
|
2015-05-19 18:11:26 +00:00
|
|
|
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-05-19 18:11:26 +00:00
|
|
|
"Wrong result for MaxNodeOrCell worklet");
|
2015-06-04 13:06:47 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(res.GetPortalConstControl().Get(1), 200.1f),
|
2015-05-19 18:11:26 +00:00
|
|
|
"Wrong result for MaxNodeOrCell worklet");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
TestAvgNodeToCell()
|
|
|
|
{
|
|
|
|
std::cout<<"Testing AvgNodeToCell worklet"<<std::endl;
|
|
|
|
vtkm::cont::testing::MakeTestDataSet tds;
|
2015-05-28 19:35:19 +00:00
|
|
|
vtkm::cont::DataSet ds = tds.Make2DRegularDataSet0();
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-05-28 19:35:19 +00:00
|
|
|
boost::shared_ptr<vtkm::cont::CellSet> scs = ds.GetCellSet(0);
|
2015-05-28 19:30:13 +00:00
|
|
|
vtkm::cont::CellSetStructured<2> *cs =
|
|
|
|
dynamic_cast<vtkm::cont::CellSetStructured<2> *>(scs.get());
|
2015-05-19 18:11:26 +00:00
|
|
|
VTKM_TEST_ASSERT(cs, "Structured cell set not found");
|
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-04 13:06:47 +00:00
|
|
|
vtkm::Float32 outcellVals[2] = {-1.4f, -1.7f};
|
2015-05-28 19:35:19 +00:00
|
|
|
ds.AddField(vtkm::cont::Field("outcellvar", 1, vtkm::cont::Field::ASSOC_CELL_SET, "cells", outcellVals, 2));
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-05-28 19:35:19 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(ds.GetNumberOfCellSets(), 1),
|
2015-05-19 18:11:26 +00:00
|
|
|
"Incorrect number of cell sets");
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-05-28 19:35:19 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(ds.GetNumberOfFields(), 5),
|
2015-05-19 18:11:26 +00:00
|
|
|
"Incorrect number of fields");
|
|
|
|
//Todo:
|
|
|
|
//the scheduling should just be passed a CellSet, and not the
|
|
|
|
//derived implementation. The vtkm::cont::CellSet should have
|
|
|
|
//a method that return the nodesOfCellsConnectivity / structure
|
|
|
|
//for that derived type. ( talk to robert for how dax did this )
|
2015-06-08 13:02:23 +00:00
|
|
|
vtkm::worklet::DispatcherMapTopology< ::test_regular::AvgNodeToCellValue > dispatcher;
|
2015-05-28 19:35:19 +00:00
|
|
|
dispatcher.Invoke(ds.GetField("nodevar").GetData(),
|
2015-05-19 18:11:26 +00:00
|
|
|
cs->GetNodeToCellConnectivity(),
|
2015-05-28 19:35:19 +00:00
|
|
|
ds.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-05-28 19:35:19 +00:00
|
|
|
res = ds.GetField(4).GetData().CastToArrayHandle(vtkm::Float32(),
|
2015-05-19 18:11:26 +00:00
|
|
|
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-05-19 18:11:26 +00:00
|
|
|
"Wrong result for NodeToCellAverage worklet");
|
2015-06-04 13:06:47 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(res.GetPortalConstControl().Get(1), 40.1f),
|
2015-05-19 18:11:26 +00:00
|
|
|
"Wrong result for NodeToCellAverage worklet");
|
2015-05-18 21:08:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
int UnitTestWorkletMapTopologyRegular(int, char *[])
|
|
|
|
{
|
|
|
|
return vtkm::cont::testing::Testing::Run(TestWorkletMapTopologyRegular);
|
|
|
|
}
|