mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Add tests for interpolate functions.
Also tests the current parametric coordinates methods. The added test lead to some minor corrections and additions.
This commit is contained in:
parent
29766bd3a2
commit
5a896c6ce7
@ -31,6 +31,14 @@ namespace vtkm {
|
||||
template<vtkm::IdComponent dimension>
|
||||
struct CellTopologicalDimensionsTag { };
|
||||
|
||||
/// \brief Tag for cell shapes with a fixed number of points.
|
||||
///
|
||||
struct CellTraitsTagSizeFixed { };
|
||||
|
||||
/// \brief Tag for cell shapes that can have a variable number of points.
|
||||
///
|
||||
struct CellTraitsTagSizeVariable { };
|
||||
|
||||
/// \brief Information about a cell based on its tag.
|
||||
///
|
||||
/// The templated CellTraits struct provides the basic high level information
|
||||
@ -53,6 +61,21 @@ struct CellTraits
|
||||
///
|
||||
typedef vtkm::CellTopologicalDimensionsTag<TOPOLOGICAL_DIMENSIONS>
|
||||
TopologicalDimensionsTag;
|
||||
|
||||
/// \brief A tag specifying whether the number of points is fixed.
|
||||
///
|
||||
/// If set to \c CellTraitsTagSizeFixed, then \c NUM_POINTS is set. If set to
|
||||
/// \c CellTraitsTagSizeVariable, then the number of points is not known at
|
||||
/// compile time.
|
||||
///
|
||||
typedef vtkm::CellTraitsTagSizeFixed IsSizeFixed;
|
||||
|
||||
/// \brief Number of points in the cell.
|
||||
///
|
||||
/// This is only defined for cell shapes of a fixed number of points (i.e.
|
||||
/// \c IsSizedFixed is set to \c CellTraitsTagSizeFixed.
|
||||
///
|
||||
static const vtkm::IdComponent NUM_POINTS = 3;
|
||||
};
|
||||
#else // VTKM_DOXYGEN_ONLY
|
||||
;
|
||||
@ -62,29 +85,40 @@ struct CellTraits
|
||||
|
||||
// Define traits for every cell type.
|
||||
|
||||
#define VTKM_DEFINE_CELL_TRAITS(name, dimensions) \
|
||||
#define VTKM_DEFINE_CELL_TRAITS(name, dimensions, numPoints) \
|
||||
template<> \
|
||||
struct CellTraits<vtkm::CellShapeTag ## name> { \
|
||||
const static vtkm::IdComponent TOPOLOGICAL_DIMENSIONS = dimensions; \
|
||||
typedef vtkm::CellTopologicalDimensionsTag<TOPOLOGICAL_DIMENSIONS> \
|
||||
TopologicalDimensionsTag; \
|
||||
typedef vtkm::CellTraitsTagSizeFixed IsSizeFixed; \
|
||||
static const vtkm::IdComponent NUM_POINTS = numPoints; \
|
||||
}
|
||||
|
||||
VTKM_DEFINE_CELL_TRAITS(Empty, 0);
|
||||
VTKM_DEFINE_CELL_TRAITS(Vertex, 0);
|
||||
//VTKM_DEFINE_CELL_TRAITS(PolyVertex, 0);
|
||||
VTKM_DEFINE_CELL_TRAITS(Line, 1);
|
||||
//VTKM_DEFINE_CELL_TRAITS(PolyLine, 1);
|
||||
VTKM_DEFINE_CELL_TRAITS(Triangle, 2);
|
||||
//VTKM_DEFINE_CELL_TRAITS(TriangleStrip, 2);
|
||||
VTKM_DEFINE_CELL_TRAITS(Polygon, 2);
|
||||
VTKM_DEFINE_CELL_TRAITS(Pixel, 2);
|
||||
VTKM_DEFINE_CELL_TRAITS(Quad, 2);
|
||||
VTKM_DEFINE_CELL_TRAITS(Tetra, 3);
|
||||
VTKM_DEFINE_CELL_TRAITS(Voxel, 3);
|
||||
VTKM_DEFINE_CELL_TRAITS(Hexahedron, 3);
|
||||
VTKM_DEFINE_CELL_TRAITS(Wedge, 3);
|
||||
VTKM_DEFINE_CELL_TRAITS(Pyramid, 3);
|
||||
#define VTKM_DEFINE_CELL_TRAITS_VARIABLE(name, dimensions) \
|
||||
template<> \
|
||||
struct CellTraits<vtkm::CellShapeTag ## name> { \
|
||||
const static vtkm::IdComponent TOPOLOGICAL_DIMENSIONS = dimensions; \
|
||||
typedef vtkm::CellTopologicalDimensionsTag<TOPOLOGICAL_DIMENSIONS> \
|
||||
TopologicalDimensionsTag; \
|
||||
typedef vtkm::CellTraitsTagSizeVariable IsSizeFixed; \
|
||||
}
|
||||
|
||||
VTKM_DEFINE_CELL_TRAITS(Empty, 0, 0);
|
||||
VTKM_DEFINE_CELL_TRAITS(Vertex, 0, 1);
|
||||
//VTKM_DEFINE_CELL_TRAITS_VARIABLE(PolyVertex, 0);
|
||||
VTKM_DEFINE_CELL_TRAITS(Line, 1, 2);
|
||||
//VTKM_DEFINE_CELL_TRAITS_VARIABLE(PolyLine, 1);
|
||||
VTKM_DEFINE_CELL_TRAITS(Triangle, 2, 3);
|
||||
//VTKM_DEFINE_CELL_TRAITS_VARIABLE(TriangleStrip, 2);
|
||||
VTKM_DEFINE_CELL_TRAITS_VARIABLE(Polygon, 2);
|
||||
VTKM_DEFINE_CELL_TRAITS(Pixel, 2, 4);
|
||||
VTKM_DEFINE_CELL_TRAITS(Quad, 2, 4);
|
||||
VTKM_DEFINE_CELL_TRAITS(Tetra, 3, 4);
|
||||
VTKM_DEFINE_CELL_TRAITS(Voxel, 3, 8);
|
||||
VTKM_DEFINE_CELL_TRAITS(Hexahedron, 3, 8);
|
||||
VTKM_DEFINE_CELL_TRAITS(Wedge, 3, 6);
|
||||
VTKM_DEFINE_CELL_TRAITS(Pyramid, 3, 5);
|
||||
|
||||
#undef VTKM_DEFINE_CELL_TRAITS
|
||||
|
||||
|
@ -74,8 +74,9 @@ struct VecTraits
|
||||
///
|
||||
typedef typename VecType::ComponentType ComponentType;
|
||||
|
||||
/// Number of components in the vector. This is only defined for vectors
|
||||
/// of a static size.
|
||||
/// \brief Number of components in the vector.
|
||||
///
|
||||
/// This is only defined for vectors of a static size.
|
||||
///
|
||||
static const vtkm::IdComponent NUM_COMPONENTS = VecType::NUM_COMPONENTS;
|
||||
|
||||
@ -83,18 +84,19 @@ struct VecTraits
|
||||
///
|
||||
static vtkm::IdComponent GetNumberOfComponents(const VecType &vec);
|
||||
|
||||
/// A tag specifying whether this vector has multiple components (i.e. is a
|
||||
/// "real" vector). This tag can be useful for creating specialized functions
|
||||
/// when a vector is really just a scalar.
|
||||
/// \brief A tag specifying whether this vector has multiple components (i.e. is a "real" vector).
|
||||
///
|
||||
/// This tag can be useful for creating specialized functions when a vector
|
||||
/// is really just a scalar.
|
||||
///
|
||||
typedef typename internal::VecTraitsMultipleComponentChooser<
|
||||
NUM_COMPONENTS>::Type HasMultipleComponents;
|
||||
|
||||
/// A tag specifying whether the size of this vector is known at compile
|
||||
/// time. If set to \c VecTraitsTagSizeStatic, then \c NUM_COMPONENTS is set.
|
||||
/// If set to \c VecTraitsTagSizeVariable, then the number of components is
|
||||
/// not known at compile time and must be queried with \c
|
||||
/// GetNumberOfComponents.
|
||||
/// \brief A tag specifying whether the size of this vector is known at compile time.
|
||||
///
|
||||
/// If set to \c VecTraitsTagSizeStatic, then \c NUM_COMPONENTS is set. If
|
||||
/// set to \c VecTraitsTagSizeVariable, then the number of components is not
|
||||
/// known at compile time and must be queried with \c GetNumberOfComponents.
|
||||
///
|
||||
typedef vtkm::VecTraitsTagSizeStatic IsSizeStatic;
|
||||
|
||||
|
@ -40,19 +40,29 @@ namespace vtkm {
|
||||
/// vector of the same length as x and y. If w is outside [0,1] then lerp
|
||||
/// extrapolates. If w=0 => v0 is returned if w=1 => v1 is returned.
|
||||
///
|
||||
template<typename T>
|
||||
template<typename ValueType, typename WeightType>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
T Lerp(const T &v0, const T & v1, const T &w)
|
||||
ValueType Lerp(const ValueType &value0,
|
||||
const ValueType & value1,
|
||||
const WeightType &weight)
|
||||
{
|
||||
return v0 + w * (v1-v0);
|
||||
return static_cast<ValueType>(value0 + weight * (value1-value0));
|
||||
}
|
||||
template<typename T, vtkm::IdComponent N>
|
||||
template<typename ValueType, vtkm::IdComponent N, typename WeightType>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T,N> Lerp(const vtkm::Vec<T,N> &v0,
|
||||
const vtkm::Vec<T,N> &v1,
|
||||
const T &w)
|
||||
vtkm::Vec<ValueType,N> Lerp(const vtkm::Vec<ValueType,N> &value0,
|
||||
const vtkm::Vec<ValueType,N> &value1,
|
||||
const WeightType &weight)
|
||||
{
|
||||
return v0 + w * (v1-v0);
|
||||
return value0 + static_cast<ValueType>(weight) * (value1-value0);
|
||||
}
|
||||
template<typename ValueType, vtkm::IdComponent N>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<ValueType,N> Lerp(const vtkm::Vec<ValueType,N> &value0,
|
||||
const vtkm::Vec<ValueType,N> &value1,
|
||||
const vtkm::Vec<ValueType,N> &weight)
|
||||
{
|
||||
return value0 + weight * (value1-value0);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -43,4 +43,4 @@ endif ()
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# add_subdirectory(testing)
|
||||
add_subdirectory(testing)
|
||||
|
@ -52,6 +52,7 @@ CellInterpolate(const FieldVecType &pointFieldValues,
|
||||
worklet));
|
||||
default:
|
||||
worklet.RaiseError("Unknown cell shape sent to interpolate.");
|
||||
return typename FieldVecType::ComponentType();
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,7 +67,7 @@ CellInterpolate(const FieldVecType &,
|
||||
const vtkm::exec::FunctorBase &worklet)
|
||||
{
|
||||
worklet.RaiseError("Attempted to interpolate an empty cell.");
|
||||
return vtkm::Nan<typename FieldVecType::ComponentType>();
|
||||
return typename FieldVecType::ComponentType();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -79,7 +80,7 @@ CellInterpolate(const FieldVecType &pointFieldValues,
|
||||
vtkm::CellShapeTagVertex,
|
||||
const vtkm::exec::FunctorBase &worklet)
|
||||
{
|
||||
VTKM_ASSERT_EXEC(pointFieldValues.GetNumberOfValues() == 1, worklet);
|
||||
VTKM_ASSERT_EXEC(pointFieldValues.GetNumberOfComponents() == 1, worklet);
|
||||
return pointFieldValues[0];
|
||||
}
|
||||
|
||||
@ -93,7 +94,7 @@ CellInterpolate(const FieldVecType &pointFieldValues,
|
||||
vtkm::CellShapeTagLine,
|
||||
const vtkm::exec::FunctorBase &worklet)
|
||||
{
|
||||
VTKM_ASSERT_EXEC(pointFieldValues.GetNumberOfValues() == 2, worklet);
|
||||
VTKM_ASSERT_EXEC(pointFieldValues.GetNumberOfComponents() == 2, worklet);
|
||||
return vtkm::Lerp(pointFieldValues[0],
|
||||
pointFieldValues[1],
|
||||
parametricCoords[0]);
|
||||
@ -109,13 +110,11 @@ CellInterpolate(const FieldVecType &field,
|
||||
vtkm::CellShapeTagTriangle,
|
||||
const vtkm::exec::FunctorBase &worklet)
|
||||
{
|
||||
VTKM_ASSERT_EXEC(field.GetNumberOfValues() == 3, worklet);
|
||||
VTKM_ASSERT_EXEC(field.GetNumberOfComponents() == 3, worklet);
|
||||
typedef typename FieldVecType::ComponentType T;
|
||||
T result;
|
||||
result = static_cast<T>(field[0] * (1 - pcoords[0] - pcoords[1]));
|
||||
result += static_cast<T>(field[1] * pcoords[0]);
|
||||
result += static_cast<T>(field[2] * pcoords[1]);
|
||||
return result;
|
||||
return static_cast<T>( (field[0] * (1 - pcoords[0] - pcoords[1]))
|
||||
+ (field[1] * pcoords[0])
|
||||
+ (field[2] * pcoords[1]));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -128,7 +127,7 @@ CellInterpolate(const FieldVecType &field,
|
||||
vtkm::CellShapeTagPolygon,
|
||||
const vtkm::exec::FunctorBase &worklet)
|
||||
{
|
||||
vtkm::IdComponent numPoints = field.GetNumberOfValues();
|
||||
vtkm::IdComponent numPoints = field.GetNumberOfComponents();
|
||||
VTKM_ASSERT_EXEC(numPoints > 0, worklet);
|
||||
switch (numPoints)
|
||||
{
|
||||
@ -162,8 +161,8 @@ CellInterpolate(const FieldVecType &field,
|
||||
|
||||
for (vtkm::IdComponent nodeIndex = 0; nodeIndex < numPoints; nodeIndex++)
|
||||
{
|
||||
vtkm::Vec<ParametricCoordType,2> nodePCoords(0.5*(vtkm::Cos(angle)+1),
|
||||
0.5*(vtkm::Sin(angle)+1));
|
||||
vtkm::Vec<ParametricCoordType,2> nodePCoords(0.5f*(vtkm::Cos(angle)+1),
|
||||
0.5f*(vtkm::Sin(angle)+1));
|
||||
ParametricCoordType distanceSqr =
|
||||
vtkm::MagnitudeSquared(pcoords2-nodePCoords);
|
||||
if (distanceSqr < epsilon) { return field[nodeIndex]; }
|
||||
@ -188,7 +187,7 @@ CellInterpolate(const FieldVecType &field,
|
||||
vtkm::CellShapeTagPixel,
|
||||
const vtkm::exec::FunctorBase &worklet)
|
||||
{
|
||||
VTKM_ASSERT_EXEC(field.GetNumberOfValues() == 4, worklet);
|
||||
VTKM_ASSERT_EXEC(field.GetNumberOfComponents() == 4, worklet);
|
||||
|
||||
typedef typename FieldVecType::ComponentType T;
|
||||
|
||||
@ -208,7 +207,7 @@ CellInterpolate(const FieldVecType &field,
|
||||
vtkm::CellShapeTagQuad,
|
||||
const vtkm::exec::FunctorBase &worklet)
|
||||
{
|
||||
VTKM_ASSERT_EXEC(field.GetNumberOfValues() == 4, worklet);
|
||||
VTKM_ASSERT_EXEC(field.GetNumberOfComponents() == 4, worklet);
|
||||
|
||||
typedef typename FieldVecType::ComponentType T;
|
||||
|
||||
@ -228,14 +227,12 @@ CellInterpolate(const FieldVecType &field,
|
||||
vtkm::CellShapeTagTetra,
|
||||
const vtkm::exec::FunctorBase &worklet)
|
||||
{
|
||||
VTKM_ASSERT_EXEC(field.GetNumberOfValues() == 4, worklet);
|
||||
VTKM_ASSERT_EXEC(field.GetNumberOfComponents() == 4, worklet);
|
||||
typedef typename FieldVecType::ComponentType T;
|
||||
T result;
|
||||
result = static_cast<T>(field[0] * (1-pcoords[0]-pcoords[1]-pcoords[2]));
|
||||
result += static_cast<T>(field[1] * pcoords[0]);
|
||||
result += static_cast<T>(field[2] * pcoords[1]);
|
||||
result += static_cast<T>(field[3] * pcoords[2]);
|
||||
return result;
|
||||
return static_cast<T>( (field[0] * (1-pcoords[0]-pcoords[1]-pcoords[2]))
|
||||
+ (field[1] * pcoords[0])
|
||||
+ (field[2] * pcoords[1])
|
||||
+ (field[3] * pcoords[2]));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -248,7 +245,7 @@ CellInterpolate(const FieldVecType &field,
|
||||
vtkm::CellShapeTagVoxel,
|
||||
const vtkm::exec::FunctorBase &worklet)
|
||||
{
|
||||
VTKM_ASSERT_EXEC(field.GetNumberOfValues() == 8, worklet);
|
||||
VTKM_ASSERT_EXEC(field.GetNumberOfComponents() == 8, worklet);
|
||||
|
||||
typedef typename FieldVecType::ComponentType T;
|
||||
|
||||
@ -273,7 +270,7 @@ CellInterpolate(const FieldVecType &field,
|
||||
vtkm::CellShapeTagHexahedron,
|
||||
const vtkm::exec::FunctorBase &worklet)
|
||||
{
|
||||
VTKM_ASSERT_EXEC(field.GetNumberOfValues() == 8, worklet);
|
||||
VTKM_ASSERT_EXEC(field.GetNumberOfComponents() == 8, worklet);
|
||||
|
||||
typedef typename FieldVecType::ComponentType T;
|
||||
|
||||
@ -298,19 +295,17 @@ CellInterpolate(const FieldVecType &field,
|
||||
vtkm::CellShapeTagWedge,
|
||||
const vtkm::exec::FunctorBase &worklet)
|
||||
{
|
||||
VTKM_ASSERT_EXEC(field.GetNumberOfValues() == 6, worklet);
|
||||
VTKM_ASSERT_EXEC(field.GetNumberOfComponents() == 6, worklet);
|
||||
|
||||
typedef typename FieldVecType::ComponentType T;
|
||||
|
||||
T bottomInterp;
|
||||
bottomInterp = static_cast<T>(field[0] * (1 - pcoords[0] - pcoords[1]));
|
||||
bottomInterp += static_cast<T>(field[1] * pcoords[1]);
|
||||
bottomInterp += static_cast<T>(field[2] * pcoords[0]);
|
||||
T bottomInterp = static_cast<T>( (field[0] * (1 - pcoords[0] - pcoords[1]))
|
||||
+ (field[1] * pcoords[1])
|
||||
+ (field[2] * pcoords[0]));
|
||||
|
||||
T topInterp;
|
||||
topInterp = static_cast<T>(field[3] * (1 - pcoords[0] - pcoords[1]));
|
||||
topInterp += static_cast<T>(field[4] * pcoords[1]);
|
||||
topInterp += static_cast<T>(field[5] * pcoords[0]);
|
||||
T topInterp = static_cast<T>( (field[3] * (1 - pcoords[0] - pcoords[1]))
|
||||
+ (field[4] * pcoords[1])
|
||||
+ (field[5] * pcoords[0]));
|
||||
|
||||
return vtkm::Lerp(bottomInterp, topInterp, pcoords[2]);
|
||||
}
|
||||
@ -325,7 +320,7 @@ CellInterpolate(const FieldVecType &field,
|
||||
vtkm::CellShapeTagPyramid,
|
||||
const vtkm::exec::FunctorBase &worklet)
|
||||
{
|
||||
VTKM_ASSERT_EXEC(field.GetNumberOfValues() == 5, worklet);
|
||||
VTKM_ASSERT_EXEC(field.GetNumberOfComponents() == 5, worklet);
|
||||
|
||||
typedef typename FieldVecType::ComponentType T;
|
||||
|
||||
|
@ -227,9 +227,10 @@ void ParametricCoordinatesCenter(vtkm::CellShapeTagGeneric shape,
|
||||
/// Returns the parametric center of the given cell shape with the given number
|
||||
/// of points.
|
||||
///
|
||||
template<typename CellShapeTag>
|
||||
VTKM_EXEC_EXPORT
|
||||
vtkm::Vec<vtkm::FloatDefault,3>
|
||||
ParametricCoordinatesCenter(vtkm::CellShapeTagGeneric shape,
|
||||
ParametricCoordinatesCenter(CellShapeTag shape,
|
||||
vtkm::IdComponent numPoints,
|
||||
const vtkm::exec::FunctorBase &worklet)
|
||||
{
|
||||
@ -348,8 +349,8 @@ void ParametricCoordinatesPoint(vtkm::CellShapeTagPolygon,
|
||||
const ParametricCoordType angle =
|
||||
static_cast<ParametricCoordType>(pointIndex*2*vtkm::Pi()/numPoints);
|
||||
|
||||
pcoords[0] = 0.5*(vtkm::Cos(angle)+1);
|
||||
pcoords[1] = 0.5*(vtkm::Sin(angle)+1);
|
||||
pcoords[0] = 0.5f*(vtkm::Cos(angle)+1);
|
||||
pcoords[1] = 0.5f*(vtkm::Sin(angle)+1);
|
||||
pcoords[2] = 0;
|
||||
}
|
||||
|
||||
@ -540,9 +541,10 @@ void ParametricCoordinatesPoint(vtkm::CellShapeTagGeneric shape,
|
||||
/// Returns the parametric coordinate of a cell point of the given shape with
|
||||
/// the given number of points.
|
||||
///
|
||||
template<typename CellShapeTag>
|
||||
VTKM_EXEC_EXPORT
|
||||
vtkm::Vec<vtkm::FloatDefault,3>
|
||||
ParametricCoordinatesPoint(vtkm::CellShapeTagGeneric shape,
|
||||
ParametricCoordinatesPoint(CellShapeTag shape,
|
||||
vtkm::IdComponent numPoints,
|
||||
vtkm::IdComponent pointIndex,
|
||||
const vtkm::exec::FunctorBase &worklet)
|
||||
|
26
vtkm/exec/testing/CMakeLists.txt
Normal file
26
vtkm/exec/testing/CMakeLists.txt
Normal file
@ -0,0 +1,26 @@
|
||||
##=============================================================================
|
||||
##
|
||||
## 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.
|
||||
##
|
||||
##=============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestInterpolate.cxx
|
||||
)
|
||||
vtkm_unit_tests(SOURCES ${unit_tests})
|
172
vtkm/exec/testing/UnitTestInterpolate.cxx
Normal file
172
vtkm/exec/testing/UnitTestInterpolate.cxx
Normal file
@ -0,0 +1,172 @@
|
||||
//============================================================================
|
||||
// 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 2015 Sandia Corporation.
|
||||
// Copyright 2015 UT-Battelle, LLC.
|
||||
// Copyright 2015 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 <vtkm/exec/Interpolate.h>
|
||||
#include <vtkm/exec/ParametricCoordinates.h>
|
||||
#include <vtkm/exec/FunctorBase.h>
|
||||
#include <vtkm/exec/internal/ErrorMessageBuffer.h>
|
||||
|
||||
#include <vtkm/CellTraits.h>
|
||||
#include <vtkm/VecVariable.h>
|
||||
|
||||
#include <vtkm/testing/Testing.h>
|
||||
|
||||
VTKM_THIRDPARTY_PRE_INCLUDE
|
||||
#include <boost/static_assert.hpp>
|
||||
VTKM_THIRDPARTY_POST_INCLUDE
|
||||
|
||||
namespace {
|
||||
|
||||
static const vtkm::IdComponent MAX_POINTS = 8;
|
||||
|
||||
template<typename CellShapeTag>
|
||||
void GetMinMaxPoints(CellShapeTag,
|
||||
vtkm::CellTraitsTagSizeFixed,
|
||||
vtkm::IdComponent &minPoints,
|
||||
vtkm::IdComponent &maxPoints)
|
||||
{
|
||||
// If this line fails, then MAX_POINTS is not large enough to support all
|
||||
// cell shapes.
|
||||
BOOST_STATIC_ASSERT((vtkm::CellTraits<CellShapeTag>::NUM_POINTS <= MAX_POINTS));
|
||||
minPoints = maxPoints = vtkm::CellTraits<CellShapeTag>::NUM_POINTS;
|
||||
}
|
||||
|
||||
template<typename CellShapeTag>
|
||||
void GetMinMaxPoints(CellShapeTag,
|
||||
vtkm::CellTraitsTagSizeVariable,
|
||||
vtkm::IdComponent &minPoints,
|
||||
vtkm::IdComponent &maxPoints)
|
||||
{
|
||||
minPoints = 1;
|
||||
maxPoints = MAX_POINTS;
|
||||
}
|
||||
|
||||
template<typename FieldType>
|
||||
struct TestInterpolateFunctor
|
||||
{
|
||||
template<typename CellShapeTag>
|
||||
void DoTest(CellShapeTag shape, vtkm::IdComponent numPoints) const
|
||||
{
|
||||
typedef typename vtkm::VecTraits<FieldType>::ComponentType ComponentType;
|
||||
|
||||
vtkm::VecVariable<FieldType, MAX_POINTS> fieldValues;
|
||||
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 = static_cast<ComponentType>(1.0/numPoints)*averageValue;
|
||||
|
||||
// Stuff to fake running in the execution environment.
|
||||
char messageBuffer[256];
|
||||
messageBuffer[0] = '\0';
|
||||
vtkm::exec::internal::ErrorMessageBuffer errorMessage(messageBuffer, 256);
|
||||
vtkm::exec::FunctorBase workletProxy;
|
||||
workletProxy.SetErrorMessageBuffer(errorMessage);
|
||||
|
||||
std::cout << " Test interpolated value at each cell node." << std::endl;
|
||||
for (vtkm::IdComponent pointIndex = 0; pointIndex < numPoints; pointIndex++)
|
||||
{
|
||||
vtkm::Vec<vtkm::FloatDefault,3> pcoord =
|
||||
vtkm::exec::ParametricCoordinatesPoint(shape,
|
||||
numPoints,
|
||||
pointIndex,
|
||||
workletProxy);
|
||||
VTKM_TEST_ASSERT(!errorMessage.IsErrorRaised(), messageBuffer);
|
||||
FieldType interpolatedValue =
|
||||
vtkm::exec::CellInterpolate(fieldValues,
|
||||
pcoord,
|
||||
shape,
|
||||
workletProxy);
|
||||
VTKM_TEST_ASSERT(!errorMessage.IsErrorRaised(), messageBuffer);
|
||||
|
||||
VTKM_TEST_ASSERT(test_equal(fieldValues[pointIndex], interpolatedValue),
|
||||
"Interpolation at point not point value.");
|
||||
}
|
||||
|
||||
if (numPoints > 0)
|
||||
{
|
||||
std::cout << " Test interpolated value at cell center." << std::endl;
|
||||
vtkm::Vec<vtkm::FloatDefault,3> pcoord =
|
||||
vtkm::exec::ParametricCoordinatesCenter(shape,numPoints,workletProxy);
|
||||
VTKM_TEST_ASSERT(!errorMessage.IsErrorRaised(), messageBuffer);
|
||||
FieldType interpolatedValue =
|
||||
vtkm::exec::CellInterpolate(fieldValues,
|
||||
pcoord,
|
||||
shape,
|
||||
workletProxy);
|
||||
VTKM_TEST_ASSERT(!errorMessage.IsErrorRaised(), messageBuffer);
|
||||
|
||||
VTKM_TEST_ASSERT(test_equal(averageValue, interpolatedValue),
|
||||
"Interpolation at center not average value.");
|
||||
}
|
||||
}
|
||||
|
||||
template<typename CellShapeTag>
|
||||
void operator()(CellShapeTag) const
|
||||
{
|
||||
vtkm::IdComponent minPoints;
|
||||
vtkm::IdComponent maxPoints;
|
||||
GetMinMaxPoints(CellShapeTag(),
|
||||
typename vtkm::CellTraits<CellShapeTag>::IsSizeFixed(),
|
||||
minPoints,
|
||||
maxPoints);
|
||||
|
||||
std::cout << "--- Test shape tag directly" << std::endl;
|
||||
for (vtkm::IdComponent numPoints = minPoints;
|
||||
numPoints <= maxPoints;
|
||||
numPoints++)
|
||||
{
|
||||
std::cout << numPoints << " points" << std::endl;
|
||||
this->DoTest(CellShapeTag(), numPoints);
|
||||
}
|
||||
|
||||
std::cout << "--- Test generic shape tag" << std::endl;
|
||||
vtkm::CellShapeTagGeneric genericShape(CellShapeTag::Id);
|
||||
for (vtkm::IdComponent numPoints = minPoints;
|
||||
numPoints <= maxPoints;
|
||||
numPoints++)
|
||||
{
|
||||
std::cout << numPoints << " points" << std::endl;
|
||||
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;
|
||||
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> >());
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestInterpolate(int, char *[])
|
||||
{
|
||||
return vtkm::testing::Testing::Run(TestInterpolate);
|
||||
}
|
Loading…
Reference in New Issue
Block a user