Special implementation of cell interpolate for rectilinear cells

This commit is contained in:
Kenneth Moreland 2015-09-01 14:29:07 -07:00
parent 493656e419
commit 284fda03fd
2 changed files with 90 additions and 8 deletions

@ -22,6 +22,7 @@
#include <vtkm/CellShape.h>
#include <vtkm/Math.h>
#include <vtkm/VecRectilinearPointCoordinates.h>
#include <vtkm/VectorAnalysis.h>
#include <vtkm/exec/Assert.h>
#include <vtkm/exec/FunctorBase.h>
@ -198,6 +199,24 @@ CellInterpolate(const FieldVecType &pointFieldValues,
parametricCoords[0]);
}
template<typename ParametricCoordType>
VTKM_EXEC_EXPORT
vtkm::Vec<vtkm::FloatDefault,3>
CellInterpolate(const vtkm::VecRectilinearPointCoordinates<1> &field,
const vtkm::Vec<ParametricCoordType,3> &pcoords,
vtkm::CellShapeTagLine,
const vtkm::exec::FunctorBase &)
{
typedef vtkm::Vec<vtkm::FloatDefault,3> T;
const T &origin = field.GetOrigin();
const T &spacing = field.GetSpacing();
return T(origin[0] + static_cast<vtkm::FloatDefault>(pcoords[0])*spacing[0],
origin[1],
origin[2]);
}
//-----------------------------------------------------------------------------
template<typename FieldVecType,
typename ParametricCoordType>
@ -331,6 +350,24 @@ CellInterpolate(const FieldVecType &field,
return vtkm::Lerp(bottomInterp, topInterp, pcoords[1]);
}
template<typename ParametricCoordType>
VTKM_EXEC_EXPORT
vtkm::Vec<vtkm::FloatDefault,3>
CellInterpolate(const vtkm::VecRectilinearPointCoordinates<2> &field,
const vtkm::Vec<ParametricCoordType,3> &pcoords,
vtkm::CellShapeTagQuad,
const vtkm::exec::FunctorBase &)
{
typedef vtkm::Vec<vtkm::FloatDefault,3> T;
const T &origin = field.GetOrigin();
const T &spacing = field.GetSpacing();
return T(origin[0] + static_cast<vtkm::FloatDefault>(pcoords[0])*spacing[0],
origin[1] + static_cast<vtkm::FloatDefault>(pcoords[1])*spacing[1],
origin[2]);
}
//-----------------------------------------------------------------------------
template<typename FieldVecType,
typename ParametricCoordType>
@ -374,6 +411,22 @@ CellInterpolate(const FieldVecType &field,
return vtkm::Lerp(bottomInterp, topInterp, pcoords[2]);
}
template<typename ParametricCoordType>
VTKM_EXEC_EXPORT
vtkm::Vec<vtkm::FloatDefault,3>
CellInterpolate(const vtkm::VecRectilinearPointCoordinates<3> &field,
const vtkm::Vec<ParametricCoordType,3> &pcoords,
vtkm::CellShapeTagHexahedron,
const vtkm::exec::FunctorBase &)
{
vtkm::Vec<vtkm::FloatDefault,3> pcoordsCast(
static_cast<vtkm::FloatDefault>(pcoords[0]),
static_cast<vtkm::FloatDefault>(pcoords[1]),
static_cast<vtkm::FloatDefault>(pcoords[2]));
return field.GetOrigin() + pcoordsCast*field.GetSpacing();
}
//-----------------------------------------------------------------------------
template<typename FieldVecType,
typename ParametricCoordType>

@ -24,6 +24,7 @@
#include <vtkm/exec/internal/ErrorMessageBuffer.h>
#include <vtkm/CellTraits.h>
#include <vtkm/VecRectilinearPointCoordinates.h>
#include <vtkm/VecVariable.h>
#include <vtkm/testing/Testing.h>
@ -61,18 +62,17 @@ void GetMinMaxPoints(CellShapeTag,
template<typename FieldType>
struct TestInterpolateFunctor
{
template<typename CellShapeTag>
void DoTest(CellShapeTag shape, vtkm::IdComponent numPoints) const
{
typedef typename vtkm::VecTraits<FieldType>::ComponentType ComponentType;
typedef typename vtkm::VecTraits<FieldType>::ComponentType ComponentType;
vtkm::VecVariable<FieldType, MAX_POINTS> fieldValues;
template<typename CellShapeTag, typename FieldVecType>
void DoTestWithField(CellShapeTag shape,
const FieldVecType &fieldValues) const
{
vtkm::IdComponent numPoints = fieldValues.GetNumberOfComponents();
FieldType averageValue = vtkm::TypeTraits<FieldType>::ZeroInitialization();
for (vtkm::IdComponent pointIndex = 0; pointIndex < numPoints; pointIndex++)
{
FieldType value = TestValue(pointIndex+1, FieldType());
fieldValues.Append(value);
averageValue = averageValue + value;
averageValue = averageValue + fieldValues[pointIndex];
}
averageValue = static_cast<ComponentType>(1.0/numPoints)*averageValue;
@ -121,6 +121,19 @@ struct TestInterpolateFunctor
}
}
template<typename CellShapeTag>
void DoTest(CellShapeTag shape, vtkm::IdComponent numPoints) const
{
vtkm::VecVariable<FieldType, MAX_POINTS> fieldValues;
for (vtkm::IdComponent pointIndex = 0; pointIndex < numPoints; pointIndex++)
{
FieldType value = TestValue(pointIndex+1, FieldType());
fieldValues.Append(value);
}
this->DoTestWithField(shape, fieldValues);
}
template<typename CellShapeTag>
void operator()(CellShapeTag) const
{
@ -162,6 +175,22 @@ void TestInterpolate()
vtkm::testing::Testing::TryAllCellShapes(TestInterpolateFunctor<vtkm::Vec<vtkm::Float32,3> >());
std::cout << "======== Vec<Float64,3> ===================" << std::endl;
vtkm::testing::Testing::TryAllCellShapes(TestInterpolateFunctor<vtkm::Vec<vtkm::Float64,3> >());
TestInterpolateFunctor<vtkm::Vec<vtkm::FloatDefault,3> > testFunctor;
vtkm::Vec<vtkm::FloatDefault,3> origin = TestValue(0, vtkm::Vec<vtkm::FloatDefault,3>());
vtkm::Vec<vtkm::FloatDefault,3> spacing = TestValue(1, vtkm::Vec<vtkm::FloatDefault,3>());
std::cout << "======== Uniform Point Coordinates 1D =====" << std::endl;
testFunctor.DoTestWithField(
vtkm::CellShapeTagLine(),
vtkm::VecRectilinearPointCoordinates<1>(origin, spacing));
std::cout << "======== Uniform Point Coordinates 2D =====" << std::endl;
testFunctor.DoTestWithField(
vtkm::CellShapeTagQuad(),
vtkm::VecRectilinearPointCoordinates<2>(origin, spacing));
std::cout << "======== Uniform Point Coordinates 3D =====" << std::endl;
testFunctor.DoTestWithField(
vtkm::CellShapeTagHexahedron(),
vtkm::VecRectilinearPointCoordinates<3>(origin, spacing));
}
} // anonymous namespace