2015-08-20 12:50:19 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2015-08-20 12:50:19 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
|
2015-08-21 04:29:54 +00:00
|
|
|
#include <vtkm/exec/CellInterpolate.h>
|
2015-08-20 12:50:19 +00:00
|
|
|
#include <vtkm/exec/FunctorBase.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/exec/ParametricCoordinates.h>
|
2015-08-20 12:50:19 +00:00
|
|
|
#include <vtkm/exec/internal/ErrorMessageBuffer.h>
|
|
|
|
|
|
|
|
#include <vtkm/CellTraits.h>
|
2015-09-17 19:45:35 +00:00
|
|
|
#include <vtkm/StaticAssert.h>
|
2017-07-05 19:58:35 +00:00
|
|
|
#include <vtkm/VecAxisAlignedPointCoordinates.h>
|
2015-08-20 12:50:19 +00:00
|
|
|
#include <vtkm/VecVariable.h>
|
|
|
|
|
|
|
|
#include <vtkm/testing/Testing.h>
|
|
|
|
|
2020-08-17 14:18:24 +00:00
|
|
|
#define CHECK_CALL(call) \
|
2020-03-12 23:38:27 +00:00
|
|
|
VTKM_TEST_ASSERT((call) == vtkm::ErrorCode::Success, "Call resulted in error.")
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2015-08-20 12:50:19 +00:00
|
|
|
|
2018-02-27 14:25:25 +00:00
|
|
|
static constexpr vtkm::IdComponent MAX_POINTS = 8;
|
2015-08-20 12:50:19 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename CellShapeTag>
|
2017-05-26 17:53:28 +00:00
|
|
|
void GetMinMaxPoints(CellShapeTag,
|
|
|
|
vtkm::CellTraitsTagSizeFixed,
|
|
|
|
vtkm::IdComponent& minPoints,
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::IdComponent& maxPoints)
|
2015-08-20 12:50:19 +00:00
|
|
|
{
|
|
|
|
// If this line fails, then MAX_POINTS is not large enough to support all
|
|
|
|
// cell shapes.
|
2015-09-17 19:45:35 +00:00
|
|
|
VTKM_STATIC_ASSERT((vtkm::CellTraits<CellShapeTag>::NUM_POINTS <= MAX_POINTS));
|
2015-08-20 12:50:19 +00:00
|
|
|
minPoints = maxPoints = vtkm::CellTraits<CellShapeTag>::NUM_POINTS;
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename CellShapeTag>
|
2017-05-26 17:53:28 +00:00
|
|
|
void GetMinMaxPoints(CellShapeTag,
|
|
|
|
vtkm::CellTraitsTagSizeVariable,
|
|
|
|
vtkm::IdComponent& minPoints,
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::IdComponent& maxPoints)
|
2015-08-20 12:50:19 +00:00
|
|
|
{
|
|
|
|
minPoints = 1;
|
|
|
|
maxPoints = MAX_POINTS;
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename FieldType>
|
2015-08-20 12:50:19 +00:00
|
|
|
struct TestInterpolateFunctor
|
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using ComponentType = typename vtkm::VecTraits<FieldType>::ComponentType;
|
2015-08-20 12:50:19 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename CellShapeTag, typename FieldVecType>
|
|
|
|
void DoTestWithField(CellShapeTag shape, const FieldVecType& fieldValues) const
|
2015-09-01 21:29:07 +00:00
|
|
|
{
|
|
|
|
vtkm::IdComponent numPoints = fieldValues.GetNumberOfComponents();
|
2021-07-12 13:08:33 +00:00
|
|
|
if (numPoints < 1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-20 12:50:19 +00:00
|
|
|
FieldType averageValue = vtkm::TypeTraits<FieldType>::ZeroInitialization();
|
|
|
|
for (vtkm::IdComponent pointIndex = 0; pointIndex < numPoints; pointIndex++)
|
|
|
|
{
|
2015-09-01 21:29:07 +00:00
|
|
|
averageValue = averageValue + fieldValues[pointIndex];
|
2015-08-20 12:50:19 +00:00
|
|
|
}
|
2017-05-18 14:29:41 +00:00
|
|
|
averageValue = static_cast<ComponentType>(1.0 / numPoints) * averageValue;
|
2015-08-20 12:50:19 +00:00
|
|
|
|
|
|
|
for (vtkm::IdComponent pointIndex = 0; pointIndex < numPoints; pointIndex++)
|
|
|
|
{
|
2020-03-12 23:38:27 +00:00
|
|
|
vtkm::Vec3f pcoord;
|
|
|
|
CHECK_CALL(vtkm::exec::ParametricCoordinatesPoint(numPoints, pointIndex, shape, pcoord));
|
|
|
|
FieldType interpolatedValue;
|
|
|
|
CHECK_CALL(vtkm::exec::CellInterpolate(fieldValues, pcoord, shape, interpolatedValue));
|
2015-08-20 12:50:19 +00:00
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(test_equal(fieldValues[pointIndex], interpolatedValue),
|
|
|
|
"Interpolation at point not point value.");
|
|
|
|
}
|
|
|
|
|
2021-07-12 13:08:33 +00:00
|
|
|
vtkm::Vec3f pcoord;
|
|
|
|
CHECK_CALL(vtkm::exec::ParametricCoordinatesCenter(numPoints, shape, pcoord));
|
|
|
|
FieldType interpolatedValue;
|
|
|
|
CHECK_CALL(vtkm::exec::CellInterpolate(fieldValues, pcoord, shape, interpolatedValue));
|
2015-08-20 12:50:19 +00:00
|
|
|
|
2021-07-12 13:08:33 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(averageValue, interpolatedValue),
|
|
|
|
"Interpolation at center not average value.");
|
2015-08-20 12:50:19 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename CellShapeTag>
|
2015-09-01 21:29:07 +00:00
|
|
|
void DoTest(CellShapeTag shape, vtkm::IdComponent numPoints) const
|
|
|
|
{
|
|
|
|
vtkm::VecVariable<FieldType, MAX_POINTS> fieldValues;
|
|
|
|
for (vtkm::IdComponent pointIndex = 0; pointIndex < numPoints; pointIndex++)
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
FieldType value = TestValue(pointIndex + 1, FieldType());
|
2015-09-01 21:29:07 +00:00
|
|
|
fieldValues.Append(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->DoTestWithField(shape, fieldValues);
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename CellShapeTag>
|
2015-08-20 12:50:19 +00:00
|
|
|
void operator()(CellShapeTag) const
|
|
|
|
{
|
|
|
|
vtkm::IdComponent minPoints;
|
|
|
|
vtkm::IdComponent maxPoints;
|
2017-05-26 17:53:28 +00:00
|
|
|
GetMinMaxPoints(
|
|
|
|
CellShapeTag(), typename vtkm::CellTraits<CellShapeTag>::IsSizeFixed(), minPoints, maxPoints);
|
2015-08-20 12:50:19 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent numPoints = minPoints; numPoints <= maxPoints; numPoints++)
|
2015-08-20 12:50:19 +00:00
|
|
|
{
|
|
|
|
this->DoTest(CellShapeTag(), numPoints);
|
|
|
|
}
|
|
|
|
|
|
|
|
vtkm::CellShapeTagGeneric genericShape(CellShapeTag::Id);
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent numPoints = minPoints; numPoints <= maxPoints; numPoints++)
|
2015-08-20 12:50:19 +00:00
|
|
|
{
|
|
|
|
this->DoTest(genericShape, numPoints);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void TestInterpolate()
|
|
|
|
{
|
|
|
|
std::cout << "======== Float32 ==========================" << std::endl;
|
|
|
|
vtkm::testing::Testing::TryAllCellShapes(TestInterpolateFunctor<vtkm::Float32>());
|
|
|
|
std::cout << "======== Float64 ==========================" << std::endl;
|
|
|
|
vtkm::testing::Testing::TryAllCellShapes(TestInterpolateFunctor<vtkm::Float64>());
|
|
|
|
std::cout << "======== Vec<Float32,3> ===================" << std::endl;
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::testing::Testing::TryAllCellShapes(TestInterpolateFunctor<vtkm::Vec3f_32>());
|
2015-08-20 12:50:19 +00:00
|
|
|
std::cout << "======== Vec<Float64,3> ===================" << std::endl;
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::testing::Testing::TryAllCellShapes(TestInterpolateFunctor<vtkm::Vec3f_64>());
|
2015-09-01 21:29:07 +00:00
|
|
|
|
2019-07-31 16:20:38 +00:00
|
|
|
TestInterpolateFunctor<vtkm::Vec3f> testFunctor;
|
|
|
|
vtkm::Vec3f origin = TestValue(0, vtkm::Vec3f());
|
|
|
|
vtkm::Vec3f spacing = TestValue(1, vtkm::Vec3f());
|
2015-09-01 21:29:07 +00:00
|
|
|
std::cout << "======== Uniform Point Coordinates 1D =====" << std::endl;
|
2017-05-18 14:29:41 +00:00
|
|
|
testFunctor.DoTestWithField(vtkm::CellShapeTagLine(),
|
2017-07-05 19:58:35 +00:00
|
|
|
vtkm::VecAxisAlignedPointCoordinates<1>(origin, spacing));
|
2015-09-01 21:29:07 +00:00
|
|
|
std::cout << "======== Uniform Point Coordinates 2D =====" << std::endl;
|
2017-05-18 14:29:41 +00:00
|
|
|
testFunctor.DoTestWithField(vtkm::CellShapeTagQuad(),
|
2017-07-05 19:58:35 +00:00
|
|
|
vtkm::VecAxisAlignedPointCoordinates<2>(origin, spacing));
|
2015-09-01 21:29:07 +00:00
|
|
|
std::cout << "======== Uniform Point Coordinates 3D =====" << std::endl;
|
2017-05-18 14:29:41 +00:00
|
|
|
testFunctor.DoTestWithField(vtkm::CellShapeTagHexahedron(),
|
2017-07-05 19:58:35 +00:00
|
|
|
vtkm::VecAxisAlignedPointCoordinates<3>(origin, spacing));
|
2015-08-20 12:50:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2019-01-01 22:19:02 +00:00
|
|
|
int UnitTestCellInterpolate(int argc, char* argv[])
|
2015-08-20 12:50:19 +00:00
|
|
|
{
|
2019-01-01 22:19:02 +00:00
|
|
|
return vtkm::testing::Testing::Run(TestInterpolate, argc, argv);
|
2015-08-20 12:50:19 +00:00
|
|
|
}
|