//============================================================================ // 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 #include #include #include #include #include #include #include namespace test_uniform { class MaxPointOrCellValue : public vtkm::worklet::WorkletMapPointToCell { public: typedef void ControlSignature(FieldInCell inCells, FieldInPoint inPoints, CellSetIn topology, FieldOutCell outCells); typedef void ExecutionSignature(_1, _4, _2, PointCount, CellShape, PointIndices); typedef _3 InputDomain; VTKM_CONT MaxPointOrCellValue() { } template VTKM_EXEC void operator()(const InCellType &cellValue, OutCellType &maxValue, const InPointVecType &pointValues, const vtkm::IdComponent &numPoints, const CellShapeTag &vtkmNotUsed(type), const PointIndexType &vtkmNotUsed(pointIDs)) const { //simple functor that returns the max of cellValue and pointValue maxValue = static_cast(cellValue); for (vtkm::IdComponent pointIndex = 0; pointIndex < numPoints; ++pointIndex) { maxValue = vtkm::Max(maxValue, static_cast(pointValues[pointIndex])); } } }; struct CheckStructuredUniformPointCoords : public vtkm::worklet::WorkletMapPointToCell { typedef void ControlSignature(CellSetIn topology, FieldInPoint pointCoords); typedef void ExecutionSignature(_2); VTKM_CONT CheckStructuredUniformPointCoords() { } template VTKM_EXEC void operator()( const vtkm::VecRectilinearPointCoordinates & vtkmNotUsed(coords)) const { // Success if here. } template VTKM_EXEC void operator()(const PointCoordsVecType &vtkmNotUsed(coords)) const { this->RaiseError("Got wrong point coordinates type."); } }; } namespace { static void TestMaxPointOrCell(); static void TestAvgPointToCell(); static void TestAvgCellToPoint(); static void TestStructuredUniformPointCoords(); void TestWorkletMapTopologyUniform() { typedef vtkm::cont::DeviceAdapterTraits< VTKM_DEFAULT_DEVICE_ADAPTER_TAG> DeviceAdapterTraits; std::cout << "Testing Topology Worklet ( Uniform ) on device adapter: " << DeviceAdapterTraits::GetName() << std::endl; TestMaxPointOrCell(); TestAvgPointToCell(); TestAvgCellToPoint(); TestStructuredUniformPointCoords(); } static void TestMaxPointOrCell() { std::cout<<"Testing MaxPointOfCell worklet"< result; vtkm::worklet::DispatcherMapTopology< ::test_uniform::MaxPointOrCellValue > dispatcher; dispatcher.Invoke(dataSet.GetField("cellvar"), dataSet.GetField("pointvar"), // 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()), result); //make sure we got the right answer. VTKM_TEST_ASSERT(test_equal(result.GetPortalConstControl().Get(0), 100.1f), "Wrong result for MaxPointOrCell worklet"); VTKM_TEST_ASSERT(test_equal(result.GetPortalConstControl().Get(1), 200.1f), "Wrong result for MaxPointOrCell worklet"); } static void TestAvgPointToCell() { std::cout<<"Testing AvgPointToCell worklet"< result; vtkm::worklet::DispatcherMapTopology< vtkm::worklet::CellAverage > dispatcher; dispatcher.Invoke( // 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("pointvar"), result); //make sure we got the right answer. VTKM_TEST_ASSERT(test_equal(result.GetPortalConstControl().Get(0), 30.1f), "Wrong result for PointToCellAverage worklet"); VTKM_TEST_ASSERT(test_equal(result.GetPortalConstControl().Get(1), 40.1f), "Wrong result for PointToCellAverage worklet"); } static void TestAvgCellToPoint() { std::cout<<"Testing AvgCellToPoint worklet"< result; vtkm::worklet::DispatcherMapTopology< vtkm::worklet::PointAverage > dispatcher; dispatcher.Invoke( // 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("cellvar"), result); //make sure we got the right answer. VTKM_TEST_ASSERT(test_equal(result.GetPortalConstControl().Get(0), 100.1f), "Wrong result for CellToPointAverage worklet"); VTKM_TEST_ASSERT(test_equal(result.GetPortalConstControl().Get(1), 150.1f), "Wrong result for CellToPointAverage worklet"); } static void TestStructuredUniformPointCoords() { std::cout << "Testing uniform point coordinates in structured grids" << std::endl; vtkm::cont::testing::MakeTestDataSet testDataSet; vtkm::worklet::DispatcherMapTopology< ::test_uniform::CheckStructuredUniformPointCoords> dispatcher; vtkm::cont::DataSet dataSet3D = testDataSet.Make3DUniformDataSet0(); dispatcher.Invoke(dataSet3D.GetCellSet(), dataSet3D.GetCoordinateSystem()); vtkm::cont::DataSet dataSet2D = testDataSet.Make2DUniformDataSet0(); dispatcher.Invoke(dataSet2D.GetCellSet(), dataSet2D.GetCoordinateSystem()); } } // anonymous namespace int UnitTestWorkletMapTopologyUniform(int, char *[]) { return vtkm::cont::testing::Testing::Run(TestWorkletMapTopologyUniform); }