Merge branch 'variable-topology-fields' into 'master'
Variable topology fields Changes to fetching in topology maps that lets you properly deal with cases where you do not know how many values are being fetched at compile time. For example, explicit cell sets can have any number of cell shapes that have different numbers of nodes. This change should resolve issue #26. See merge request !128
This commit is contained in:
commit
cf6af174eb
@ -35,6 +35,7 @@ set(headers
|
||||
TypeTraits.h
|
||||
VectorAnalysis.h
|
||||
VecTraits.h
|
||||
VecVariable.h
|
||||
UnaryPredicates.h
|
||||
)
|
||||
|
||||
|
@ -557,6 +557,12 @@ public:
|
||||
typedef T ComponentType;
|
||||
static const vtkm::IdComponent NUM_COMPONENTS = NumRow*NumCol;
|
||||
typedef vtkm::VecTraitsTagMultipleComponents HasMultipleComponents;
|
||||
typedef vtkm::VecTraitsTagSizeStatic IsSizeStatic;
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static vtkm::IdComponent GetNumberOfComponents(const MatrixType &) {
|
||||
return NUM_COMPONENTS;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static const ComponentType &GetComponent(const MatrixType &matrix,
|
||||
|
18
vtkm/Types.h
18
vtkm/Types.h
@ -735,6 +735,9 @@ struct Negate
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Pre declaration
|
||||
template<typename T, vtkm::IdComponent Size> class Vec;
|
||||
|
||||
namespace detail {
|
||||
|
||||
/// Base implementation of all Vec classes.
|
||||
@ -766,6 +769,21 @@ protected:
|
||||
}
|
||||
|
||||
public:
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::IdComponent GetNumberOfComponents() { return NUM_COMPONENTS; }
|
||||
|
||||
template<vtkm::IdComponent OtherSize>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
void CopyInto(vtkm::Vec<ComponentType,OtherSize> &dest) const
|
||||
{
|
||||
for (vtkm::IdComponent index = 0;
|
||||
(index < NUM_COMPONENTS) && (index < OtherSize);
|
||||
index++)
|
||||
{
|
||||
dest[index] = (*this)[index];
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
DerivedClass &operator=(const DerivedClass &src)
|
||||
{
|
||||
|
@ -38,6 +38,15 @@ struct VecTraitsTagMultipleComponents { };
|
||||
///
|
||||
struct VecTraitsTagSingleComponent { };
|
||||
|
||||
/// A tag for vectors where the number of components are known at compile time.
|
||||
///
|
||||
struct VecTraitsTagSizeStatic { };
|
||||
|
||||
/// A tag for vectors where the number of components are not determined until
|
||||
/// run time.
|
||||
///
|
||||
struct VecTraitsTagSizeVariable { };
|
||||
|
||||
namespace internal {
|
||||
|
||||
template<vtkm::IdComponent numComponents>
|
||||
@ -65,10 +74,15 @@ struct VecTraits
|
||||
///
|
||||
typedef typename VecType::ComponentType ComponentType;
|
||||
|
||||
/// Number of components in the vector.
|
||||
/// 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;
|
||||
|
||||
/// Number of components in the given vector.
|
||||
///
|
||||
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.
|
||||
@ -76,6 +90,14 @@ struct VecTraits
|
||||
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.
|
||||
///
|
||||
typedef vtkm::VecTraitsTagSizeStatic IsSizeStatic;
|
||||
|
||||
/// Returns the value in a given component of the vector.
|
||||
///
|
||||
VTKM_EXEC_CONT_EXPORT static const ComponentType &GetComponent(
|
||||
@ -91,11 +113,12 @@ struct VecTraits
|
||||
vtkm::IdComponent component,
|
||||
ComponentType value);
|
||||
|
||||
/// Converts whatever type this vector is into the standard VTK-m Vec.
|
||||
/// Copies the components in the given vector into a given Vec object.
|
||||
///
|
||||
template<vktm::IdComponent destSize>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static vtkm::Vec<ComponentType,NUM_COMPONENTS>
|
||||
ToVec(const VecType &vector);
|
||||
static void
|
||||
CopyInto(const VecType &src, vtkm::Vec<ComponentType,destSize> &dest);
|
||||
};
|
||||
#else // VTKM_DOXYGEN_ONLY
|
||||
;
|
||||
@ -121,6 +144,13 @@ struct VecTraits<vtkm::Vec<T,Size> >
|
||||
///
|
||||
static const vtkm::IdComponent NUM_COMPONENTS = VecType::NUM_COMPONENTS;
|
||||
|
||||
/// Number of components in the given vector.
|
||||
///
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static vtkm::IdComponent GetNumberOfComponents(const VecType &) {
|
||||
return NUM_COMPONENTS;
|
||||
}
|
||||
|
||||
/// 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.
|
||||
@ -128,6 +158,14 @@ struct VecTraits<vtkm::Vec<T,Size> >
|
||||
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.
|
||||
///
|
||||
typedef vtkm::VecTraitsTagSizeStatic IsSizeStatic;
|
||||
|
||||
/// Returns the value in a given component of the vector.
|
||||
///
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
@ -151,11 +189,12 @@ struct VecTraits<vtkm::Vec<T,Size> >
|
||||
|
||||
/// Converts whatever type this vector is into the standard VTKm Tuple.
|
||||
///
|
||||
template<vtkm::IdComponent destSize>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static vtkm::Vec<ComponentType,NUM_COMPONENTS>
|
||||
ToVec(const VecType &vector)
|
||||
static void
|
||||
CopyInto(const VecType &src, vtkm::Vec<ComponentType,destSize> &dest)
|
||||
{
|
||||
return vector;
|
||||
src.CopyInto(dest);
|
||||
}
|
||||
};
|
||||
|
||||
@ -167,6 +206,11 @@ struct VecTraitsBasic {
|
||||
typedef ScalarType ComponentType;
|
||||
static const vtkm::IdComponent NUM_COMPONENTS = 1;
|
||||
typedef VecTraitsTagSingleComponent HasMultipleComponents;
|
||||
typedef vtkm::VecTraitsTagSizeStatic IsSizeStatic;
|
||||
|
||||
static vtkm::IdComponent GetNumberOfComponents(const ScalarType &) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT static const ComponentType &GetComponent(
|
||||
const ScalarType &vector,
|
||||
@ -184,10 +228,12 @@ struct VecTraitsBasic {
|
||||
vector = value;
|
||||
}
|
||||
|
||||
template<vtkm::IdComponent destSize>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static vtkm::Vec<ScalarType,1> ToVec(const ScalarType &vector)
|
||||
static void CopyInto(const ScalarType &src,
|
||||
vtkm::Vec<ScalarType,destSize> &dest)
|
||||
{
|
||||
return vtkm::Vec<ScalarType,1>(vector);
|
||||
dest[0] = src;
|
||||
}
|
||||
};
|
||||
} // namespace internal
|
||||
|
167
vtkm/VecVariable.h
Normal file
167
vtkm/VecVariable.h
Normal file
@ -0,0 +1,167 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_VecVariable_h
|
||||
#define vtk_m_VecVariable_h
|
||||
|
||||
#include <vtkm/Math.h>
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/TypeTraits.h>
|
||||
#include <vtkm/VecTraits.h>
|
||||
|
||||
namespace vtkm {
|
||||
|
||||
/// \brief A short variable-length array with maximum length.
|
||||
///
|
||||
/// The \c VecVariable class is a Vec-like class that holds a short array of
|
||||
/// some maximum length. To avoid dynamic allocations, the maximum length is
|
||||
/// specified at compile time. Internally, \c VecVariable holds a \c Vec of
|
||||
/// the maximum length and exposes a subsection of it.
|
||||
///
|
||||
template<typename T, vtkm::IdComponent MaxSize>
|
||||
class VecVariable
|
||||
{
|
||||
public:
|
||||
typedef T ComponentType;
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
VecVariable() : NumComponents(0) { }
|
||||
|
||||
template<vtkm::IdComponent SrcSize>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
VecVariable(const vtkm::VecVariable<ComponentType,SrcSize> &src)
|
||||
: NumComponents(src.GetNumberOfComponents())
|
||||
{
|
||||
for (vtkm::IdComponent index = 0; index < this->NumComponents; index++)
|
||||
{
|
||||
this->Data[index] = src[index];
|
||||
}
|
||||
}
|
||||
|
||||
template<vtkm::IdComponent SrcSize>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
VecVariable(const vtkm::Vec<ComponentType,SrcSize> &src)
|
||||
: NumComponents(SrcSize)
|
||||
{
|
||||
for (vtkm::IdComponent index = 0; index < this->NumComponents; index++)
|
||||
{
|
||||
this->Data[index] = src[index];
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::IdComponent GetNumberOfComponents() const {
|
||||
return this->NumComponents;
|
||||
}
|
||||
|
||||
template<vtkm::IdComponent DestSize>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
void CopyInto(vtkm::Vec<ComponentType,DestSize> &dest) const
|
||||
{
|
||||
vtkm::IdComponent numComponents = vtkm::Min(DestSize, this->NumComponents);
|
||||
for (vtkm::IdComponent index = 0; index < numComponents; index++)
|
||||
{
|
||||
dest[index] = this->Data[index];
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
const ComponentType &operator[](vtkm::IdComponent index) const
|
||||
{
|
||||
return this->Data[index];
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
ComponentType &operator[](vtkm::IdComponent index)
|
||||
{
|
||||
return this->Data[index];
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
void Append(ComponentType value)
|
||||
{
|
||||
this->Data[this->NumComponents] = value;
|
||||
this->NumComponents++;
|
||||
}
|
||||
|
||||
private:
|
||||
vtkm::Vec<T,MaxSize> Data;
|
||||
vtkm::IdComponent NumComponents;
|
||||
};
|
||||
|
||||
template<typename T, vtkm::IdComponent MaxSize>
|
||||
struct TypeTraits<vtkm::VecVariable<T,MaxSize> >
|
||||
{
|
||||
typedef typename vtkm::TypeTraits<T>::NumericTag NumericTag;
|
||||
typedef TypeTraitsVectorTag DimensionalityTag;
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static vtkm::VecVariable<T,MaxSize> ZeroInitialization()
|
||||
{
|
||||
return vtkm::VecVariable<T,MaxSize>();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, vtkm::IdComponent MaxSize>
|
||||
struct VecTraits<vtkm::VecVariable<T,MaxSize> >
|
||||
{
|
||||
typedef vtkm::VecVariable<T,MaxSize> VecType;
|
||||
|
||||
typedef typename VecType::ComponentType ComponentType;
|
||||
typedef vtkm::VecTraitsTagMultipleComponents HasMultipleComponents;
|
||||
typedef vtkm::VecTraitsTagSizeVariable IsSizeStatic;
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static vtkm::IdComponent GetNumberOfComponents(const VecType &vector) {
|
||||
return vector.GetNumberOfComponents();
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static const ComponentType &GetComponent(const VecType &vector,
|
||||
vtkm::IdComponent componentIndex)
|
||||
{
|
||||
return vector[componentIndex];
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static ComponentType &GetComponent(VecType &vector,
|
||||
vtkm::IdComponent componentIndex)
|
||||
{
|
||||
return vector[componentIndex];
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static void SetComponent(VecType &vector,
|
||||
vtkm::IdComponent componentIndex,
|
||||
const ComponentType &value)
|
||||
{
|
||||
vector[componentIndex] = value;
|
||||
}
|
||||
|
||||
template<vtkm::IdComponent destSize>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static void CopyInto(const VecType &src,
|
||||
vtkm::Vec<ComponentType,destSize> &dest)
|
||||
{
|
||||
src.CopyInto(dest);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace vtkm
|
||||
|
||||
#endif //vtk_m_VecVariable_h
|
@ -89,10 +89,9 @@ TwoDimRegularTest()
|
||||
|
||||
|
||||
vtkm::Id cells[2][4] = {{0,1,3,4}, {1,2,4,5}};
|
||||
vtkm::Vec<vtkm::Id,4> pointIds;
|
||||
for (vtkm::Id cellIndex = 0; cellIndex < 2; cellIndex++)
|
||||
{
|
||||
pointToCell.GetIndices(cellIndex, pointIds);
|
||||
vtkm::Vec<vtkm::Id,4> pointIds = pointToCell.GetIndices(cellIndex);
|
||||
for (vtkm::IdComponent localPointIndex = 0;
|
||||
localPointIndex < 4;
|
||||
localPointIndex++)
|
||||
@ -112,8 +111,8 @@ TwoDimRegularTest()
|
||||
|
||||
for (vtkm::Id pointIndex = 0; pointIndex < 6; pointIndex++)
|
||||
{
|
||||
vtkm::Vec<vtkm::Id,4> retrievedCellIds;
|
||||
cellToPoint.GetIndices(pointIndex, retrievedCellIds);
|
||||
vtkm::Vec<vtkm::Id,4> retrievedCellIds =
|
||||
cellToPoint.GetIndices(pointIndex);
|
||||
for (vtkm::IdComponent cellIndex = 0; cellIndex < 4; cellIndex++)
|
||||
VTKM_TEST_ASSERT(
|
||||
retrievedCellIds[cellIndex] == expectedCellIds[pointIndex][cellIndex],
|
||||
@ -163,8 +162,7 @@ ThreeDimRegularTest()
|
||||
vtkm::TopologyElementTagPoint(),
|
||||
vtkm::TopologyElementTagCell());
|
||||
vtkm::Id expectedPointIds[8] = {0,1,3,4,6,7,9,10};
|
||||
vtkm::Vec<vtkm::Id,8> retrievedPointIds;
|
||||
pointToCell.GetIndices(0, retrievedPointIds);
|
||||
vtkm::Vec<vtkm::Id,8> retrievedPointIds = pointToCell.GetIndices(0);
|
||||
for (vtkm::IdComponent localPointIndex = 0;
|
||||
localPointIndex < 8;
|
||||
localPointIndex++)
|
||||
@ -182,11 +180,10 @@ ThreeDimRegularTest()
|
||||
vtkm::cont::DeviceAdapterTagSerial(),
|
||||
vtkm::TopologyElementTagCell(),
|
||||
vtkm::TopologyElementTagPoint());
|
||||
vtkm::Vec<vtkm::Id,8> expectedCellIds;
|
||||
vtkm::Id retrievedCellIds[8] = {0,-1,-1,-1,-1,-1,-1,-1};
|
||||
cellToPoint.GetIndices(0, expectedCellIds);
|
||||
vtkm::Id retrievedCellIds[6] = {0,-1,-1,-1,-1,-1};
|
||||
vtkm::Vec<vtkm::Id,6> expectedCellIds = cellToPoint.GetIndices(0);
|
||||
for (vtkm::IdComponent localPointIndex = 0;
|
||||
localPointIndex < 8;
|
||||
localPointIndex < 6;
|
||||
localPointIndex++)
|
||||
{
|
||||
VTKM_TEST_ASSERT(
|
||||
|
@ -25,7 +25,6 @@ set(headers
|
||||
ExecutionObjectBase.h
|
||||
ExecutionWholeArray.h
|
||||
FunctorBase.h
|
||||
TopologyData.h
|
||||
)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
@ -20,9 +20,10 @@
|
||||
#ifndef vtk_m_exec_ConnectivityExplicit_h
|
||||
#define vtk_m_exec_ConnectivityExplicit_h
|
||||
|
||||
#include <vtkm/CellType.h>
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
|
||||
#include <vtkm/exec/internal/VecFromPortal.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace exec {
|
||||
@ -51,38 +52,48 @@ public:
|
||||
}
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
vtkm::Id GetNumberOfElements()
|
||||
vtkm::Id GetNumberOfElements() const
|
||||
{
|
||||
return Shapes.GetNumberOfValues();
|
||||
return this->Shapes.GetNumberOfValues();
|
||||
}
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
vtkm::Id GetNumberOfIndices(vtkm::Id index)
|
||||
vtkm::IdComponent GetNumberOfIndices(vtkm::Id index) const
|
||||
{
|
||||
return NumIndices.Get(index);
|
||||
// Should the NumIndices array be typed as vtkm::IdComponent instead of
|
||||
// vtkm::Id? (NumIndices is really defined in
|
||||
// vtkm::cont::internal::ConnectivityExplicitInternals.)
|
||||
return static_cast<vtkm::IdComponent>(this->NumIndices.Get(index));
|
||||
}
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
vtkm::Id GetCellShape(vtkm::Id index)
|
||||
vtkm::CellType GetCellShape(vtkm::Id index) const
|
||||
{
|
||||
return Shapes.Get(index);
|
||||
// Likewise, should Shapes be vtkm::Id or something smaller?
|
||||
return static_cast<vtkm::CellType>(this->Shapes.Get(index));
|
||||
}
|
||||
|
||||
template <vtkm::IdComponent ItemTupleLength>
|
||||
typedef vtkm::exec::internal::VecFromPortal<ConnectivityPortalType>
|
||||
IndicesType;
|
||||
|
||||
/// Returns a Vec-like object containing the indices for the given index.
|
||||
/// The object returned is not an actual array, but rather an object that
|
||||
/// loads the indices lazily out of the connectivity array. This prevents
|
||||
/// us from having to know the number of indices at compile time.
|
||||
///
|
||||
VTKM_EXEC_EXPORT
|
||||
void GetIndices(vtkm::Id index, vtkm::Vec<vtkm::Id,ItemTupleLength> &ids)
|
||||
IndicesType GetIndices(vtkm::Id index) const
|
||||
{
|
||||
vtkm::Id n = GetNumberOfIndices(index);
|
||||
vtkm::Id start = IndexOffset.Get(index);
|
||||
for (vtkm::IdComponent i=0; i<n && i<ItemTupleLength; i++)
|
||||
ids[i] = Connectivity.Get(start+i);
|
||||
vtkm::Id offset = this->IndexOffset.Get(index);
|
||||
vtkm::IdComponent length = this->GetNumberOfIndices(index);
|
||||
return IndicesType(this->Connectivity, length, offset);
|
||||
}
|
||||
|
||||
private:
|
||||
ShapePortalType Shapes;
|
||||
NumIndicesPortalType NumIndices;
|
||||
ConnectivityPortalType Connectivity;
|
||||
IndexOffsetPortalType IndexOffset;
|
||||
ShapePortalType Shapes;
|
||||
NumIndicesPortalType NumIndices;
|
||||
ConnectivityPortalType Connectivity;
|
||||
IndexOffsetPortalType IndexOffset;
|
||||
};
|
||||
|
||||
} // namespace exec
|
||||
|
@ -40,6 +40,8 @@ class ConnectivityStructured
|
||||
typedef vtkm::internal::ConnectivityStructuredInternals<Dimension>
|
||||
InternalsType;
|
||||
|
||||
typedef vtkm::internal::ConnectivityStructuredIndexHelper<
|
||||
FromTopology,ToTopology,Dimension> Helper;
|
||||
public:
|
||||
typedef typename InternalsType::SchedulingRangeType SchedulingRangeType;
|
||||
|
||||
@ -63,9 +65,7 @@ public:
|
||||
}
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
vtkm::Id GetNumberOfIndices(vtkm::Id index) const {
|
||||
typedef vtkm::internal::ConnectivityStructuredIndexHelper<
|
||||
FromTopology,ToTopology,Dimension> Helper;
|
||||
vtkm::IdComponent GetNumberOfIndices(vtkm::Id index) const {
|
||||
return Helper::GetNumberOfIndices(this->Internals, index);
|
||||
}
|
||||
// This needs some thought. What does cell shape mean when the to topology
|
||||
@ -75,13 +75,12 @@ public:
|
||||
return Internals.GetCellShape();
|
||||
}
|
||||
|
||||
template <vtkm::IdComponent ItemTupleLength>
|
||||
typedef typename Helper::IndicesType IndicesType;
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
void GetIndices(vtkm::Id index, vtkm::Vec<vtkm::Id,ItemTupleLength> &ids)
|
||||
IndicesType GetIndices(vtkm::Id index) const
|
||||
{
|
||||
typedef vtkm::internal::ConnectivityStructuredIndexHelper<
|
||||
FromTopology,ToTopology,Dimension> Helper;
|
||||
Helper::GetIndices(this->Internals,index,ids);
|
||||
return Helper::GetIndices(this->Internals,index);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -1,51 +0,0 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_exec_TopologyData_h
|
||||
#define vtk_m_exec_TopologyData_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace exec {
|
||||
|
||||
template<typename T, vtkm::IdComponent ITEM_TUPLE_LENGTH = 8>
|
||||
class TopologyData
|
||||
{
|
||||
public:
|
||||
VTKM_EXEC_EXPORT T &operator[](vtkm::IdComponent index) { return vec[index]; }
|
||||
VTKM_EXEC_EXPORT const T &operator[](vtkm::IdComponent index) const { return vec[index]; }
|
||||
|
||||
VTKM_EXEC_EXPORT TopologyData()
|
||||
{
|
||||
}
|
||||
template <typename T2>
|
||||
VTKM_EXEC_EXPORT TopologyData(const TopologyData<T2,ITEM_TUPLE_LENGTH> &other)
|
||||
: vec(other.vec)
|
||||
{
|
||||
}
|
||||
|
||||
vtkm::Vec<T, ITEM_TUPLE_LENGTH> vec;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
} // namespace vtkm::exec
|
||||
|
||||
#endif //vtk_m_exec_FunctorBase_h
|
@ -22,11 +22,8 @@
|
||||
|
||||
#include <vtkm/exec/arg/AspectTagDefault.h>
|
||||
#include <vtkm/exec/arg/Fetch.h>
|
||||
#include <vtkm/exec/TopologyData.h>
|
||||
|
||||
VTKM_THIRDPARTY_PRE_INCLUDE
|
||||
#include <boost/type_traits.hpp>
|
||||
VTKM_THIRDPARTY_POST_INCLUDE
|
||||
#include <vtkm/exec/internal/VecFromPortalPermute.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace exec {
|
||||
@ -40,6 +37,40 @@ namespace arg {
|
||||
///
|
||||
struct FetchTagArrayTopologyMapIn { };
|
||||
|
||||
namespace detail {
|
||||
|
||||
// This internal class defines how a TopologyMapIn fetch loads from field data
|
||||
// based on the connectivity class and the object holding the field data. The
|
||||
// default implementation gets a Vec of indices and an array portal for the
|
||||
// field and delivers a VecFromPortalPermute. Specializations could have more
|
||||
// efficient implementations. For example, if the connectivity is structured
|
||||
// and the field is regular point coordinates, it is much faster to compute the
|
||||
// field directly.
|
||||
|
||||
template<typename ConnectivityType, typename FieldExecObjectType>
|
||||
struct FetchArrayTopologyMapInImplementation
|
||||
{
|
||||
// The connectivity classes are expected to have an IndicesType that is
|
||||
// is Vec-like class that will be returned from a GetIndices method.
|
||||
typedef typename ConnectivityType::IndicesType IndexVecType;
|
||||
|
||||
// The FieldExecObjectType is expected to behave like an ArrayPortal.
|
||||
typedef FieldExecObjectType PortalType;
|
||||
|
||||
typedef vtkm::exec::internal::VecFromPortalPermute<
|
||||
IndexVecType,PortalType> ValueType;
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
static ValueType Load(vtkm::Id index,
|
||||
const ConnectivityType &connectivity,
|
||||
const FieldExecObjectType &field)
|
||||
{
|
||||
return ValueType(connectivity.GetIndices(index), field);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<typename Invocation, vtkm::IdComponent ParameterIndex>
|
||||
struct Fetch<
|
||||
vtkm::exec::arg::FetchTagArrayTopologyMapIn,
|
||||
@ -47,45 +78,37 @@ struct Fetch<
|
||||
Invocation,
|
||||
ParameterIndex>
|
||||
{
|
||||
// The parameter for the input domain is stored in the Invocation. (It is
|
||||
// also in the worklet, but it is safer to get it from the Invocation
|
||||
// in case some other dispatch operation had to modify it.)
|
||||
static const vtkm::IdComponent InputDomainIndex =
|
||||
Invocation::InputDomainIndex;
|
||||
|
||||
typedef typename Invocation::ControlInterface::template
|
||||
ParameterType<InputDomainIndex>::type ControlSignatureTag;
|
||||
|
||||
static const vtkm::IdComponent ITEM_TUPLE_LENGTH =
|
||||
ControlSignatureTag::ITEM_TUPLE_LENGTH;
|
||||
// Assuming that this fetch is used in a topology map, which is its
|
||||
// intention, InputDomainIndex points to a connectivity object. Thus,
|
||||
// ConnectivityType is one of the vtkm::exec::Connectivity* classes.
|
||||
typedef typename Invocation::ParameterInterface::
|
||||
template ParameterType<InputDomainIndex>::type ConnectivityType;
|
||||
|
||||
// The execution object associated with this parameter is expected to be
|
||||
// an array portal containing the field values.
|
||||
typedef typename Invocation::ParameterInterface::
|
||||
template ParameterType<ParameterIndex>::type ExecObjectType;
|
||||
|
||||
typedef boost::remove_const<typename ExecObjectType::ValueType> NonConstType;
|
||||
typedef vtkm::exec::TopologyData<typename NonConstType::type,
|
||||
ITEM_TUPLE_LENGTH> ValueType;
|
||||
typedef detail::FetchArrayTopologyMapInImplementation<
|
||||
ConnectivityType,ExecObjectType> Implementation;
|
||||
|
||||
typedef typename Implementation::ValueType ValueType;
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
ValueType Load(vtkm::Id index, const Invocation &invocation) const
|
||||
{
|
||||
typedef typename Invocation::ParameterInterface ParameterInterface;
|
||||
typedef typename ParameterInterface::
|
||||
template ParameterType<InputDomainIndex>::type TopologyType;
|
||||
TopologyType topology =
|
||||
const ConnectivityType &connectivity =
|
||||
invocation.Parameters.template GetParameter<InputDomainIndex>();
|
||||
const ExecObjectType &field =
|
||||
invocation.Parameters.template GetParameter<ParameterIndex>();
|
||||
|
||||
|
||||
vtkm::IdComponent nids =
|
||||
static_cast<vtkm::IdComponent>(topology.GetNumberOfIndices(index));
|
||||
|
||||
vtkm::Vec<vtkm::Id,ITEM_TUPLE_LENGTH> ids;
|
||||
topology.GetIndices(index,ids);
|
||||
|
||||
ValueType v;
|
||||
for (vtkm::IdComponent i=0; i<nids && i<ITEM_TUPLE_LENGTH; ++i)
|
||||
{
|
||||
v[i] = invocation.Parameters.template GetParameter<ParameterIndex>().
|
||||
Get(ids[i]);
|
||||
}
|
||||
return v;
|
||||
return Implementation::Load(index, connectivity, field);
|
||||
}
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
|
@ -51,7 +51,7 @@ struct FromCount : vtkm::exec::arg::ExecutionSignatureTagBase
|
||||
template<typename FetchTag, typename Invocation>
|
||||
struct Fetch<FetchTag, vtkm::exec::arg::AspectTagFromCount, Invocation, 1>
|
||||
{
|
||||
typedef vtkm::Id ValueType;
|
||||
typedef vtkm::IdComponent ValueType;
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
ValueType Load(vtkm::Id index, const Invocation &invocation) const
|
||||
|
@ -23,8 +23,6 @@
|
||||
#include <vtkm/exec/arg/Fetch.h>
|
||||
#include <vtkm/exec/arg/ExecutionSignatureTagBase.h>
|
||||
|
||||
#include <vtkm/exec/TopologyData.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace exec {
|
||||
namespace arg {
|
||||
@ -50,8 +48,11 @@ struct FromIndices : vtkm::exec::arg::ExecutionSignatureTagBase
|
||||
typedef vtkm::exec::arg::AspectTagFromIndices AspectTag;
|
||||
};
|
||||
|
||||
template<typename FetchTag, typename Invocation>
|
||||
struct Fetch<FetchTag, vtkm::exec::arg::AspectTagFromIndices, Invocation, 1>
|
||||
template<typename FetchTag,
|
||||
typename Invocation,
|
||||
vtkm::IdComponent ParameterIndex>
|
||||
struct Fetch<
|
||||
FetchTag, vtkm::exec::arg::AspectTagFromIndices, Invocation, ParameterIndex>
|
||||
{
|
||||
// The parameter for the input domain is stored in the Invocation. (It is
|
||||
// also in the worklet, but it is safer to get it from the Invocation
|
||||
@ -59,37 +60,23 @@ struct Fetch<FetchTag, vtkm::exec::arg::AspectTagFromIndices, Invocation, 1>
|
||||
static const vtkm::IdComponent InputDomainIndex =
|
||||
Invocation::InputDomainIndex;
|
||||
|
||||
typedef typename Invocation::ControlInterface::template
|
||||
ParameterType<InputDomainIndex>::type InputDomainTag;
|
||||
// Assuming that this fetch is used in a topology map, which is its
|
||||
// intention, InputDomainIndex points to a connectivity object. Thus,
|
||||
// ConnectivityType is one of the vtkm::exec::Connectivity* classes.
|
||||
typedef typename Invocation::ParameterInterface::
|
||||
template ParameterType<InputDomainIndex>::type ConnectivityType;
|
||||
|
||||
static const vtkm::IdComponent ITEM_TUPLE_LENGTH =
|
||||
InputDomainTag::ITEM_TUPLE_LENGTH;
|
||||
|
||||
typedef vtkm::exec::TopologyData<vtkm::Id,ITEM_TUPLE_LENGTH> ValueType;
|
||||
typedef typename ConnectivityType::IndicesType ValueType;
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
ValueType Load(vtkm::Id index, const Invocation &invocation) const
|
||||
{
|
||||
// ParameterInterface (from Invocation) is a FunctionInterface type
|
||||
// containing types for all objects passed to the Invoke method (with
|
||||
// some dynamic casting performed so objects like DynamicArrayHandle get
|
||||
// cast to ArrayHandle).
|
||||
typedef typename Invocation::ParameterInterface ParameterInterface;
|
||||
|
||||
// This is the type for the input domain (derived from the last two things
|
||||
// we got from the Invocation).
|
||||
typedef typename ParameterInterface::
|
||||
template ParameterType<InputDomainIndex>::type TopologyType;
|
||||
|
||||
// We can pull the input domain parameter (the data specifying the input
|
||||
// domain) from the invocation object.
|
||||
TopologyType topology =
|
||||
const ConnectivityType &connectivity =
|
||||
invocation.Parameters.template GetParameter<InputDomainIndex>();
|
||||
|
||||
ValueType v;
|
||||
topology.GetIndices(index,v.vec);
|
||||
|
||||
return v;
|
||||
return connectivity.GetIndices(index);
|
||||
}
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
set(headers
|
||||
ErrorMessageBuffer.h
|
||||
VecFromPortal.h
|
||||
VecFromPortalPermute.h
|
||||
WorkletInvokeFunctor.h
|
||||
WorkletInvokeFunctorDetail.h
|
||||
)
|
||||
|
138
vtkm/exec/internal/VecFromPortal.h
Normal file
138
vtkm/exec/internal/VecFromPortal.h
Normal file
@ -0,0 +1,138 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_exec_internal_VecFromPortal_h
|
||||
#define vtk_m_exec_internal_VecFromPortal_h
|
||||
|
||||
#include <vtkm/Math.h>
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/TypeTraits.h>
|
||||
#include <vtkm/VecTraits.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace exec {
|
||||
namespace internal {
|
||||
|
||||
/// \brief A short variable-length array from a window in an ArrayPortal.
|
||||
///
|
||||
/// The \c VecFromPortal class is a Vec-like class that holds an array portal
|
||||
/// and exposes a small window of that portal as if it were a \c Vec.
|
||||
///
|
||||
template<typename PortalType>
|
||||
class VecFromPortal
|
||||
{
|
||||
public:
|
||||
typedef typename PortalType::ValueType ComponentType;
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
VecFromPortal() : NumComponents(0), Offset(0) { }
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
VecFromPortal(const PortalType &portal,
|
||||
vtkm::IdComponent numComponents = 0,
|
||||
vtkm::Id offset = 0)
|
||||
: Portal(portal), NumComponents(numComponents), Offset(offset) { }
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
vtkm::IdComponent GetNumberOfComponents() const {
|
||||
return this->NumComponents;
|
||||
}
|
||||
|
||||
template<vtkm::IdComponent DestSize>
|
||||
VTKM_EXEC_EXPORT
|
||||
void CopyInto(vtkm::Vec<ComponentType,DestSize> &dest) const
|
||||
{
|
||||
vtkm::IdComponent numComponents = vtkm::Min(DestSize, this->NumComponents);
|
||||
for (vtkm::IdComponent index = 0; index < numComponents; index++)
|
||||
{
|
||||
dest[index] = this->Portal.Get(index + this->Offset);
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
ComponentType operator[](vtkm::IdComponent index) const
|
||||
{
|
||||
return this->Portal.Get(index + this->Offset);
|
||||
}
|
||||
|
||||
private:
|
||||
PortalType Portal;
|
||||
vtkm::IdComponent NumComponents;
|
||||
vtkm::Id Offset;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::exec::internal
|
||||
|
||||
// Implementations of traits classes, which by definition are in the vtkm
|
||||
// namespace.
|
||||
|
||||
namespace vtkm {
|
||||
|
||||
template<typename PortalType>
|
||||
struct TypeTraits<vtkm::exec::internal::VecFromPortal<PortalType> >
|
||||
{
|
||||
private:
|
||||
typedef typename PortalType::ValueType ComponentType;
|
||||
|
||||
public:
|
||||
typedef typename vtkm::TypeTraits<ComponentType>::NumericTag NumericTag;
|
||||
typedef TypeTraitsVectorTag DimensionalityTag;
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
static vtkm::exec::internal::VecFromPortal<PortalType> ZeroInitialization()
|
||||
{
|
||||
return vtkm::exec::internal::VecFromPortal<PortalType>();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename PortalType>
|
||||
struct VecTraits<vtkm::exec::internal::VecFromPortal<PortalType> >
|
||||
{
|
||||
typedef vtkm::exec::internal::VecFromPortal<PortalType> VecType;
|
||||
|
||||
typedef typename VecType::ComponentType ComponentType;
|
||||
typedef vtkm::VecTraitsTagMultipleComponents HasMultipleComponents;
|
||||
typedef vtkm::VecTraitsTagSizeVariable IsSizeStatic;
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
static vtkm::IdComponent GetNumberOfComponents(const VecType &vector) {
|
||||
return vector.GetNumberOfComponents();
|
||||
}
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
static ComponentType GetComponent(const VecType &vector,
|
||||
vtkm::IdComponent componentIndex)
|
||||
{
|
||||
return vector[componentIndex];
|
||||
}
|
||||
|
||||
template<vtkm::IdComponent destSize>
|
||||
VTKM_EXEC_EXPORT
|
||||
static void CopyInto(const VecType &src,
|
||||
vtkm::Vec<ComponentType,destSize> &dest)
|
||||
{
|
||||
src.CopyInto(dest);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace vtkm
|
||||
|
||||
#endif //vtk_m_exec_internal_VecFromPortal_h
|
142
vtkm/exec/internal/VecFromPortalPermute.h
Normal file
142
vtkm/exec/internal/VecFromPortalPermute.h
Normal file
@ -0,0 +1,142 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_exec_internal_VecFromPortalPermute_h
|
||||
#define vtk_m_exec_internal_VecFromPortalPermute_h
|
||||
|
||||
#include <vtkm/Math.h>
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/TypeTraits.h>
|
||||
#include <vtkm/VecTraits.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace exec {
|
||||
namespace internal {
|
||||
|
||||
/// \brief A short vector from an ArrayPortal and a vector of indices.
|
||||
///
|
||||
/// The \c VecFromPortalPermute class is a Vec-like class that holds an array
|
||||
/// portal and a second Vec-like containing indices into the array. Each value
|
||||
/// of this vector is the value from the array with the respective index.
|
||||
///
|
||||
template<typename IndexVecType, typename PortalType>
|
||||
class VecFromPortalPermute
|
||||
{
|
||||
public:
|
||||
typedef typename PortalType::ValueType ComponentType;
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
VecFromPortalPermute() { }
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
VecFromPortalPermute(const IndexVecType &indices, const PortalType &portal)
|
||||
: Indices(indices), Portal(portal) { }
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
vtkm::IdComponent GetNumberOfComponents() const {
|
||||
return this->Indices.GetNumberOfComponents();
|
||||
}
|
||||
|
||||
template<vtkm::IdComponent DestSize>
|
||||
VTKM_EXEC_EXPORT
|
||||
void CopyInto(vtkm::Vec<ComponentType,DestSize> &dest) const
|
||||
{
|
||||
vtkm::IdComponent numComponents =
|
||||
vtkm::Min(DestSize, this->GetNumberOfComponents());
|
||||
for (vtkm::IdComponent index = 0; index < numComponents; index++)
|
||||
{
|
||||
dest[index] = this->Portal.Get(this->Indices[index]);
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
ComponentType operator[](vtkm::IdComponent index) const
|
||||
{
|
||||
return this->Portal.Get(this->Indices[index]);
|
||||
}
|
||||
|
||||
private:
|
||||
IndexVecType Indices;
|
||||
PortalType Portal;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::exec::internal
|
||||
|
||||
// Implementations of traits classes, which by definition are in the vtkm
|
||||
// namespace.
|
||||
|
||||
namespace vtkm {
|
||||
|
||||
template<typename IndexVecType, typename PortalType>
|
||||
struct TypeTraits<
|
||||
vtkm::exec::internal::VecFromPortalPermute<IndexVecType,PortalType> >
|
||||
{
|
||||
private:
|
||||
typedef vtkm::exec::internal::VecFromPortalPermute<IndexVecType,PortalType>
|
||||
VecType;
|
||||
typedef typename PortalType::ValueType ComponentType;
|
||||
|
||||
public:
|
||||
typedef typename vtkm::TypeTraits<ComponentType>::NumericTag NumericTag;
|
||||
typedef TypeTraitsVectorTag DimensionalityTag;
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
static VecType ZeroInitialization()
|
||||
{
|
||||
return VecType();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename IndexVecType, typename PortalType>
|
||||
struct VecTraits<
|
||||
vtkm::exec::internal::VecFromPortalPermute<IndexVecType,PortalType> >
|
||||
{
|
||||
typedef vtkm::exec::internal::VecFromPortalPermute<IndexVecType,PortalType>
|
||||
VecType;
|
||||
|
||||
typedef typename VecType::ComponentType ComponentType;
|
||||
typedef vtkm::VecTraitsTagMultipleComponents HasMultipleComponents;
|
||||
typedef vtkm::VecTraitsTagSizeVariable IsSizeStatic;
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
static vtkm::IdComponent GetNumberOfComponents(const VecType &vector) {
|
||||
return vector.GetNumberOfComponents();
|
||||
}
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
static ComponentType GetComponent(const VecType &vector,
|
||||
vtkm::IdComponent componentIndex)
|
||||
{
|
||||
return vector[componentIndex];
|
||||
}
|
||||
|
||||
template<vtkm::IdComponent destSize>
|
||||
VTKM_EXEC_EXPORT
|
||||
static void CopyInto(const VecType &src,
|
||||
vtkm::Vec<ComponentType,destSize> &dest)
|
||||
{
|
||||
src.CopyInto(dest);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace vtkm
|
||||
|
||||
#endif //vtk_m_exec_internal_VecFromPortalPermute_h
|
@ -22,6 +22,8 @@
|
||||
|
||||
set(unit_tests
|
||||
UnitTestErrorMessageBuffer.cxx
|
||||
UnitTestVecFromPortal.cxx
|
||||
UnitTestVecFromPortalPermute.cxx
|
||||
UnitTestWorkletInvokeFunctor.cxx
|
||||
)
|
||||
vtkm_unit_tests(SOURCES ${unit_tests})
|
||||
|
120
vtkm/exec/internal/testing/UnitTestVecFromPortal.cxx
Normal file
120
vtkm/exec/internal/testing/UnitTestVecFromPortal.cxx
Normal file
@ -0,0 +1,120 @@
|
||||
//============================================================================
|
||||
// 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/internal/VecFromPortal.h>
|
||||
|
||||
#include <vtkm/testing/Testing.h>
|
||||
|
||||
namespace UnitTestVecFromPortalNamespace {
|
||||
|
||||
static const vtkm::IdComponent ARRAY_SIZE = 10;
|
||||
|
||||
template<typename T>
|
||||
void CheckType(T, T)
|
||||
{
|
||||
// Check passes if this function is called correctly.
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class TestPortal
|
||||
{
|
||||
public:
|
||||
typedef T ValueType;
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
vtkm::Id GetNumberOfValues() const { return ARRAY_SIZE; }
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
ValueType Get(vtkm::Id index) const { return TestValue(index, ValueType()); }
|
||||
};
|
||||
|
||||
struct VecFromPortalTestFunctor
|
||||
{
|
||||
template<typename T>
|
||||
void operator()(T) const
|
||||
{
|
||||
typedef TestPortal<T> PortalType;
|
||||
typedef vtkm::exec::internal::VecFromPortal<PortalType> VecType;
|
||||
typedef vtkm::TypeTraits<VecType> TTraits;
|
||||
typedef vtkm::VecTraits<VecType> VTraits;
|
||||
|
||||
std::cout << "Checking VecFromPortal traits" << std::endl;
|
||||
|
||||
// The statements will fail to compile if the traits is not working as
|
||||
// expected.
|
||||
CheckType(typename TTraits::DimensionalityTag(),
|
||||
vtkm::TypeTraitsVectorTag());
|
||||
CheckType(typename VTraits::ComponentType(), T());
|
||||
CheckType(typename VTraits::HasMultipleComponents(),
|
||||
vtkm::VecTraitsTagMultipleComponents());
|
||||
CheckType(typename VTraits::IsSizeStatic(),
|
||||
vtkm::VecTraitsTagSizeVariable());
|
||||
|
||||
std::cout << "Checking VecFromPortal contents" << std::endl;
|
||||
|
||||
PortalType portal;
|
||||
|
||||
for (vtkm::Id offset = 0; offset < ARRAY_SIZE; offset++)
|
||||
{
|
||||
for (vtkm::IdComponent length = 0; length < ARRAY_SIZE-offset; length++)
|
||||
{
|
||||
VecType vec(portal, length, offset);
|
||||
|
||||
VTKM_TEST_ASSERT(vec.GetNumberOfComponents() == length,
|
||||
"Wrong length.");
|
||||
VTKM_TEST_ASSERT(VTraits::GetNumberOfComponents(vec) == length,
|
||||
"Wrong length.");
|
||||
|
||||
vtkm::Vec<T,ARRAY_SIZE> copyDirect;
|
||||
vec.CopyInto(copyDirect);
|
||||
|
||||
vtkm::Vec<T,ARRAY_SIZE> copyTraits;
|
||||
VTraits::CopyInto(vec, copyTraits);
|
||||
|
||||
for (vtkm::IdComponent index = 0; index < length; index++)
|
||||
{
|
||||
T expected = TestValue(index+offset, T());
|
||||
VTKM_TEST_ASSERT(test_equal(vec[index], expected), "Wrong value.");
|
||||
VTKM_TEST_ASSERT(
|
||||
test_equal(VTraits::GetComponent(vec, index), expected),
|
||||
"Wrong value.");
|
||||
VTKM_TEST_ASSERT(test_equal(copyDirect[index], expected),
|
||||
"Wrong copied value.");
|
||||
VTKM_TEST_ASSERT(test_equal(copyTraits[index], expected),
|
||||
"Wrong copied value.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void VecFromPortalTest()
|
||||
{
|
||||
vtkm::testing::Testing::TryTypes(VecFromPortalTestFunctor(),
|
||||
vtkm::TypeListTagCommon());
|
||||
}
|
||||
|
||||
} // namespace UnitTestVecFromPortalNamespace
|
||||
|
||||
int UnitTestVecFromPortal(int, char *[])
|
||||
{
|
||||
return vtkm::testing::Testing::Run(
|
||||
UnitTestVecFromPortalNamespace::VecFromPortalTest);
|
||||
}
|
132
vtkm/exec/internal/testing/UnitTestVecFromPortalPermute.cxx
Normal file
132
vtkm/exec/internal/testing/UnitTestVecFromPortalPermute.cxx
Normal file
@ -0,0 +1,132 @@
|
||||
//============================================================================
|
||||
// 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/internal/VecFromPortalPermute.h>
|
||||
|
||||
#include <vtkm/VecVariable.h>
|
||||
|
||||
#include <vtkm/testing/Testing.h>
|
||||
|
||||
namespace UnitTestVecFromPortalPermuteNamespace {
|
||||
|
||||
static const vtkm::IdComponent ARRAY_SIZE = 10;
|
||||
|
||||
template<typename T>
|
||||
void CheckType(T, T)
|
||||
{
|
||||
// Check passes if this function is called correctly.
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class TestPortal
|
||||
{
|
||||
public:
|
||||
typedef T ValueType;
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
vtkm::Id GetNumberOfValues() const { return ARRAY_SIZE; }
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
ValueType Get(vtkm::Id index) const { return TestValue(index, ValueType()); }
|
||||
};
|
||||
|
||||
struct VecFromPortalPermuteTestFunctor
|
||||
{
|
||||
template<typename T>
|
||||
void operator()(T) const
|
||||
{
|
||||
typedef TestPortal<T> PortalType;
|
||||
typedef vtkm::VecVariable<vtkm::Id,ARRAY_SIZE> IndexVecType;
|
||||
typedef vtkm::exec::internal::VecFromPortalPermute<IndexVecType,PortalType>
|
||||
VecType;
|
||||
typedef vtkm::TypeTraits<VecType> TTraits;
|
||||
typedef vtkm::VecTraits<VecType> VTraits;
|
||||
|
||||
std::cout << "Checking VecFromPortal traits" << std::endl;
|
||||
|
||||
// The statements will fail to compile if the traits is not working as
|
||||
// expected.
|
||||
CheckType(typename TTraits::DimensionalityTag(),
|
||||
vtkm::TypeTraitsVectorTag());
|
||||
CheckType(typename VTraits::ComponentType(), T());
|
||||
CheckType(typename VTraits::HasMultipleComponents(),
|
||||
vtkm::VecTraitsTagMultipleComponents());
|
||||
CheckType(typename VTraits::IsSizeStatic(),
|
||||
vtkm::VecTraitsTagSizeVariable());
|
||||
|
||||
std::cout << "Checking VecFromPortal contents" << std::endl;
|
||||
|
||||
PortalType portal;
|
||||
|
||||
for (vtkm::Id offset = 0; offset < ARRAY_SIZE; offset++)
|
||||
{
|
||||
for (vtkm::IdComponent length = 0;
|
||||
2*length + offset < ARRAY_SIZE;
|
||||
length++)
|
||||
{
|
||||
IndexVecType indices;
|
||||
for (vtkm::IdComponent index = 0; index < length; index++)
|
||||
{
|
||||
indices.Append(offset + 2*index);
|
||||
}
|
||||
|
||||
VecType vec(indices, portal);
|
||||
|
||||
VTKM_TEST_ASSERT(vec.GetNumberOfComponents() == length,
|
||||
"Wrong length.");
|
||||
VTKM_TEST_ASSERT(VTraits::GetNumberOfComponents(vec) == length,
|
||||
"Wrong length.");
|
||||
|
||||
vtkm::Vec<T,ARRAY_SIZE> copyDirect;
|
||||
vec.CopyInto(copyDirect);
|
||||
|
||||
vtkm::Vec<T,ARRAY_SIZE> copyTraits;
|
||||
VTraits::CopyInto(vec, copyTraits);
|
||||
|
||||
for (vtkm::IdComponent index = 0; index < length; index++)
|
||||
{
|
||||
T expected = TestValue(2*index+offset, T());
|
||||
VTKM_TEST_ASSERT(test_equal(vec[index], expected), "Wrong value.");
|
||||
VTKM_TEST_ASSERT(
|
||||
test_equal(VTraits::GetComponent(vec, index), expected),
|
||||
"Wrong value.");
|
||||
VTKM_TEST_ASSERT(test_equal(copyDirect[index], expected),
|
||||
"Wrong copied value.");
|
||||
VTKM_TEST_ASSERT(test_equal(copyTraits[index], expected),
|
||||
"Wrong copied value.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void VecFromPortalPermuteTest()
|
||||
{
|
||||
vtkm::testing::Testing::TryTypes(VecFromPortalPermuteTestFunctor(),
|
||||
vtkm::TypeListTagCommon());
|
||||
}
|
||||
|
||||
} // namespace UnitTestVecFromPortalPermuteNamespace
|
||||
|
||||
int UnitTestVecFromPortalPermute(int, char *[])
|
||||
{
|
||||
return vtkm::testing::Testing::Run(
|
||||
UnitTestVecFromPortalPermuteNamespace::VecFromPortalPermuteTest);
|
||||
}
|
@ -73,39 +73,52 @@ public:
|
||||
return this->GetNumberOfPoints();
|
||||
}
|
||||
|
||||
static const vtkm::IdComponent NUM_POINTS_IN_CELL = 2;
|
||||
static const vtkm::IdComponent MAX_CELL_TO_POINT = 2;
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Id GetNumberOfPoints() const {return this->PointDimensions;}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Id GetNumberOfCells() const {return this->PointDimensions-1;}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::IdComponent GetNumberOfPointsInCell() const {return 2;}
|
||||
vtkm::IdComponent GetNumberOfPointsInCell() const {return NUM_POINTS_IN_CELL;}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::CellType GetCellShape() const {return VTKM_LINE;}
|
||||
|
||||
template <vtkm::IdComponent IdsLength>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
void GetPointsOfCell(vtkm::Id index, vtkm::Vec<vtkm::Id,IdsLength> &ids) const
|
||||
vtkm::Vec<vtkm::Id,NUM_POINTS_IN_CELL> GetPointsOfCell(vtkm::Id index) const
|
||||
{
|
||||
BOOST_STATIC_ASSERT(IdsLength >= 2);
|
||||
ids[0] = index;
|
||||
ids[1] = ids[0] + 1;
|
||||
vtkm::Vec<vtkm::Id,NUM_POINTS_IN_CELL> pointIds;
|
||||
pointIds[0] = index;
|
||||
pointIds[1] = pointIds[0] + 1;
|
||||
return pointIds;
|
||||
}
|
||||
|
||||
template <vtkm::IdComponent IdsLength>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
void GetCellsOfPoint(vtkm::Id index, vtkm::Vec<vtkm::Id,IdsLength> &ids) const
|
||||
vtkm::IdComponent GetNumberOfCellsIncidentOnPoint(vtkm::Id pointIndex) const
|
||||
{
|
||||
BOOST_STATIC_ASSERT(IdsLength >= 2);
|
||||
ids[0] = ids[1] = -1;
|
||||
return
|
||||
(static_cast<vtkm::IdComponent>(pointIndex > 0)
|
||||
+ static_cast<vtkm::IdComponent>(pointIndex < this->PointDimensions-1));
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<vtkm::Id,MAX_CELL_TO_POINT> GetCellsOfPoint(vtkm::Id index) const
|
||||
{
|
||||
vtkm::Vec<vtkm::Id,MAX_CELL_TO_POINT> cellIds;
|
||||
|
||||
cellIds[0] = cellIds[1] = -1;
|
||||
vtkm::IdComponent idx = 0;
|
||||
if (index > 0)
|
||||
{
|
||||
ids[idx++] = index-1;
|
||||
cellIds[idx++] = index-1;
|
||||
}
|
||||
if (index < this->PointDimensions-1)
|
||||
{
|
||||
ids[idx++] = index;
|
||||
cellIds[idx++] = index;
|
||||
}
|
||||
|
||||
return cellIds;
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
@ -158,57 +171,73 @@ public:
|
||||
return this->GetPointDimensions();
|
||||
}
|
||||
|
||||
static const vtkm::IdComponent NUM_POINTS_IN_CELL = 4;
|
||||
static const vtkm::IdComponent MAX_CELL_TO_POINT = 4;
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Id GetNumberOfCells() const
|
||||
{
|
||||
return vtkm::internal::VecProduct<2>()(this->GetCellDimensions());
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::IdComponent GetNumberOfPointsInCell() const { return 4; }
|
||||
vtkm::IdComponent GetNumberOfPointsInCell() const {return NUM_POINTS_IN_CELL;}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::CellType GetCellShape() const { return VTKM_PIXEL; }
|
||||
|
||||
template <vtkm::IdComponent IdsLength>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
void GetPointsOfCell(vtkm::Id index, vtkm::Vec<vtkm::Id,IdsLength> &ids) const
|
||||
vtkm::Vec<vtkm::Id,NUM_POINTS_IN_CELL> GetPointsOfCell(vtkm::Id index) const
|
||||
{
|
||||
BOOST_STATIC_ASSERT(IdsLength >= 4);
|
||||
|
||||
vtkm::Id i, j;
|
||||
this->CalculateLogicalPointIndices(index, i, j);
|
||||
|
||||
ids[0] = j*this->PointDimensions[0] + i;
|
||||
ids[1] = ids[0] + 1;
|
||||
ids[2] = ids[0] + this->PointDimensions[0];
|
||||
ids[3] = ids[2] + 1;
|
||||
vtkm::Vec<vtkm::Id,NUM_POINTS_IN_CELL> pointIds;
|
||||
pointIds[0] = j*this->PointDimensions[0] + i;
|
||||
pointIds[1] = pointIds[0] + 1;
|
||||
pointIds[2] = pointIds[0] + this->PointDimensions[0];
|
||||
pointIds[3] = pointIds[2] + 1;
|
||||
return pointIds;
|
||||
}
|
||||
|
||||
template <vtkm::IdComponent IdsLength>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
void GetCellsOfPoint(vtkm::Id index, vtkm::Vec<vtkm::Id,IdsLength> &ids) const
|
||||
vtkm::IdComponent GetNumberOfCellsIncidentOnPoint(vtkm::Id pointIndex) const
|
||||
{
|
||||
BOOST_STATIC_ASSERT(IdsLength >= 4);
|
||||
vtkm::Id i, j;
|
||||
this->CalculateLogicalPointIndices(pointIndex, i, j);
|
||||
return
|
||||
(static_cast<vtkm::IdComponent>((i > 0) && (j > 0))
|
||||
+ static_cast<vtkm::IdComponent>((i < this->PointDimensions[0]-1) && (j > 0))
|
||||
+ static_cast<vtkm::IdComponent>((i > 0) && (j < this->PointDimensions[1]-1))
|
||||
+ static_cast<vtkm::IdComponent>(
|
||||
(i < this->PointDimensions[0]-1) && (j < this->PointDimensions[1]-1)));
|
||||
}
|
||||
|
||||
ids[0] = ids[1] = ids[2] = ids[3] = -1;
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<vtkm::Id,MAX_CELL_TO_POINT> GetCellsOfPoint(vtkm::Id index) const
|
||||
{
|
||||
vtkm::Vec<vtkm::Id,MAX_CELL_TO_POINT> cellIds;
|
||||
|
||||
cellIds[0] = cellIds[1] = cellIds[2] = cellIds[3] = -1;
|
||||
vtkm::Id i, j;
|
||||
vtkm::IdComponent idx = 0;
|
||||
CalculateLogicalPointIndices(index, i, j);
|
||||
this->CalculateLogicalPointIndices(index, i, j);
|
||||
if ((i > 0) && (j > 0))
|
||||
{
|
||||
ids[idx++] = this->CalculateCellIndex(i-1, j-1);
|
||||
cellIds[idx++] = this->CalculateCellIndex(i-1, j-1);
|
||||
}
|
||||
if ((i < this->PointDimensions[0]-1) && (j > 0))
|
||||
{
|
||||
ids[idx++] = this->CalculateCellIndex(i , j-1);
|
||||
cellIds[idx++] = this->CalculateCellIndex(i , j-1);
|
||||
}
|
||||
if ((i > 0) && (j < this->PointDimensions[1]-1))
|
||||
{
|
||||
ids[idx++] = this->CalculateCellIndex(i-1, j );
|
||||
cellIds[idx++] = this->CalculateCellIndex(i-1, j );
|
||||
}
|
||||
if ((i < this->PointDimensions[0]-1) && (j < this->PointDimensions[1]-1))
|
||||
{
|
||||
ids[idx++] = this->CalculateCellIndex(i , j );
|
||||
cellIds[idx++] = this->CalculateCellIndex(i , j );
|
||||
}
|
||||
|
||||
return cellIds;
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
@ -279,22 +308,22 @@ public:
|
||||
return this->GetPointDimensions();
|
||||
}
|
||||
|
||||
static const vtkm::IdComponent NUM_POINTS_IN_CELL = 8;
|
||||
static const vtkm::IdComponent MAX_CELL_TO_POINT = 6;
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Id GetNumberOfCells() const
|
||||
{
|
||||
return vtkm::internal::VecProduct<3>()(this->GetCellDimensions());
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::IdComponent GetNumberOfPointsInCell() const { return 8; }
|
||||
vtkm::IdComponent GetNumberOfPointsInCell() const {return NUM_POINTS_IN_CELL;}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::CellType GetCellShape() const { return VTKM_VOXEL; }
|
||||
|
||||
template <vtkm::IdComponent IdsLength>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
void GetPointsOfCell(vtkm::Id index, vtkm::Vec<vtkm::Id,IdsLength> &ids) const
|
||||
vtkm::Vec<vtkm::Id,NUM_POINTS_IN_CELL> GetPointsOfCell(vtkm::Id index) const
|
||||
{
|
||||
BOOST_STATIC_ASSERT(IdsLength >= 8);
|
||||
|
||||
vtkm::Id3 cellDimensions = this->GetCellDimensions();
|
||||
|
||||
vtkm::Id cellDims01 = cellDimensions[0] * cellDimensions[1];
|
||||
@ -303,23 +332,25 @@ public:
|
||||
vtkm::Id j = indexij / cellDimensions[0];
|
||||
vtkm::Id i = indexij % cellDimensions[0];
|
||||
|
||||
ids[0] = (k * this->PointDimensions[1] + j) * this->PointDimensions[0] + i;
|
||||
ids[1] = ids[0] + 1;
|
||||
ids[2] = ids[0] + this->PointDimensions[0];
|
||||
ids[3] = ids[2] + 1;
|
||||
ids[4] = ids[0] + this->PointDimensions[0]*this->PointDimensions[1];
|
||||
ids[5] = ids[4] + 1;
|
||||
ids[6] = ids[4] + this->PointDimensions[0];
|
||||
ids[7] = ids[6] + 1;
|
||||
vtkm::Vec<vtkm::Id,NUM_POINTS_IN_CELL> pointIds;
|
||||
pointIds[0] = (k * this->PointDimensions[1] + j) * this->PointDimensions[0] + i;
|
||||
pointIds[1] = pointIds[0] + 1;
|
||||
pointIds[2] = pointIds[0] + this->PointDimensions[0];
|
||||
pointIds[3] = pointIds[2] + 1;
|
||||
pointIds[4] = pointIds[0] + this->PointDimensions[0]*this->PointDimensions[1];
|
||||
pointIds[5] = pointIds[4] + 1;
|
||||
pointIds[6] = pointIds[4] + this->PointDimensions[0];
|
||||
pointIds[7] = pointIds[6] + 1;
|
||||
|
||||
return pointIds;
|
||||
}
|
||||
|
||||
template <vtkm::IdComponent IdsLength>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
void GetCellsOfPoint(vtkm::Id index, vtkm::Vec<vtkm::Id,IdsLength> &ids) const
|
||||
vtkm::Vec<vtkm::Id,MAX_CELL_TO_POINT> GetCellsOfPoint(vtkm::Id index) const
|
||||
{
|
||||
BOOST_STATIC_ASSERT(IdsLength >= 8);
|
||||
vtkm::Vec<vtkm::Id,MAX_CELL_TO_POINT> cellIds;
|
||||
|
||||
ids[0]=ids[1]=ids[2]=ids[3]=ids[4]=ids[5]=ids[6]=ids[7]=-1;
|
||||
cellIds[0]=cellIds[1]=cellIds[2]=cellIds[3]=cellIds[4]=cellIds[5]=-1;
|
||||
|
||||
vtkm::Id i, j, k;
|
||||
vtkm::IdComponent idx=0;
|
||||
@ -327,45 +358,47 @@ public:
|
||||
this->CalculateLogicalPointIndices(index, i, j, k);
|
||||
if ((i > 0) && (j > 0) && (k > 0))
|
||||
{
|
||||
ids[idx++] = this->CalculateCellIndex(i-1, j-1, k-1);
|
||||
cellIds[idx++] = this->CalculateCellIndex(i-1, j-1, k-1);
|
||||
}
|
||||
if ((i < this->PointDimensions[0]-1) && (j > 0) && (k > 0))
|
||||
{
|
||||
ids[idx++] = this->CalculateCellIndex(i , j-1, k-1);
|
||||
cellIds[idx++] = this->CalculateCellIndex(i , j-1, k-1);
|
||||
}
|
||||
if ((i > 0) && (j < this->PointDimensions[1]-1) && (k > 0))
|
||||
{
|
||||
ids[idx++] = this->CalculateCellIndex(i-1, j , k-1);
|
||||
cellIds[idx++] = this->CalculateCellIndex(i-1, j , k-1);
|
||||
}
|
||||
if ((i < this->PointDimensions[0]-1) &&
|
||||
(j < this->PointDimensions[1]-1) &&
|
||||
(k > 0))
|
||||
{
|
||||
ids[idx++] = this->CalculateCellIndex(i , j , k-1);
|
||||
cellIds[idx++] = this->CalculateCellIndex(i , j , k-1);
|
||||
}
|
||||
|
||||
if ((i > 0) && (j > 0) && (k < this->PointDimensions[2]-1))
|
||||
{
|
||||
ids[idx++] = this->CalculateCellIndex(i-1, j-1, k);
|
||||
cellIds[idx++] = this->CalculateCellIndex(i-1, j-1, k);
|
||||
}
|
||||
if ((i < this->PointDimensions[0]-1) &&
|
||||
(j > 0) &&
|
||||
(k < this->PointDimensions[2]-1))
|
||||
{
|
||||
ids[idx++] = this->CalculateCellIndex(i , j-1, k);
|
||||
cellIds[idx++] = this->CalculateCellIndex(i , j-1, k);
|
||||
}
|
||||
if ((i > 0) &&
|
||||
(j < this->PointDimensions[1]-1) &&
|
||||
(k < this->PointDimensions[2]-1))
|
||||
{
|
||||
ids[idx++] = this->CalculateCellIndex(i-1, j , k);
|
||||
cellIds[idx++] = this->CalculateCellIndex(i-1, j , k);
|
||||
}
|
||||
if ((i < this->PointDimensions[0]-1) &&
|
||||
(j < this->PointDimensions[1]-1) &&
|
||||
(k < this->PointDimensions[2]-1))
|
||||
{
|
||||
ids[idx++] = this->CalculateCellIndex(i , j , k);
|
||||
cellIds[idx++] = this->CalculateCellIndex(i , j , k);
|
||||
}
|
||||
|
||||
return cellIds;
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
@ -417,19 +450,21 @@ template<vtkm::IdComponent Dimension>
|
||||
struct ConnectivityStructuredIndexHelper<
|
||||
vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell, Dimension>
|
||||
{
|
||||
template <vtkm::IdComponent ItemTupleLength>
|
||||
typedef vtkm::internal::ConnectivityStructuredInternals<Dimension>
|
||||
ConnectivityType;
|
||||
|
||||
typedef vtkm::Vec<vtkm::Id,ConnectivityType::NUM_POINTS_IN_CELL> IndicesType;
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static void GetIndices(
|
||||
const vtkm::internal::ConnectivityStructuredInternals<Dimension> &connectivity,
|
||||
vtkm::Id cellIndex,
|
||||
vtkm::Vec<vtkm::Id,ItemTupleLength> &ids)
|
||||
static IndicesType GetIndices(const ConnectivityType &connectivity,
|
||||
vtkm::Id cellIndex)
|
||||
{
|
||||
connectivity.GetPointsOfCell(cellIndex, ids);
|
||||
return connectivity.GetPointsOfCell(cellIndex);
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static vtkm::IdComponent GetNumberOfIndices(
|
||||
const vtkm::internal::ConnectivityStructuredInternals<Dimension> &connectivity,
|
||||
const ConnectivityType &connectivity,
|
||||
vtkm::Id vtkmNotUsed(cellIndex))
|
||||
{
|
||||
return connectivity.GetNumberOfPointsInCell();
|
||||
@ -440,18 +475,27 @@ template<vtkm::IdComponent Dimension>
|
||||
struct ConnectivityStructuredIndexHelper<
|
||||
vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint, Dimension>
|
||||
{
|
||||
template <vtkm::IdComponent ItemTupleLength>
|
||||
typedef vtkm::internal::ConnectivityStructuredInternals<Dimension>
|
||||
ConnectivityType;
|
||||
|
||||
// TODO: This needs to change to a Vec-like that supports a max size.
|
||||
// Likewise, all the GetCellsOfPoint methods need to use it as well.
|
||||
typedef vtkm::Vec<vtkm::Id,ConnectivityType::MAX_CELL_TO_POINT> IndicesType;
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static void GetIndices(
|
||||
const vtkm::internal::ConnectivityStructuredInternals<Dimension> &connectivity,
|
||||
vtkm::Id pointIndex,
|
||||
vtkm::Vec<vtkm::Id,ItemTupleLength> &ids)
|
||||
static IndicesType GetIndices(const ConnectivityType &connectivity,
|
||||
vtkm::Id pointIndex)
|
||||
{
|
||||
connectivity.GetCellsOfPoint(pointIndex,ids);
|
||||
return connectivity.GetCellsOfPoint(pointIndex);
|
||||
}
|
||||
|
||||
// TODO: Implement GetNumberOfIndices, which will rely on a
|
||||
// GetNumberOfCellsOnPoint method in ConnectivityStructuredInternals
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static vtkm::IdComponent GetNumberOfIndices(
|
||||
const ConnectivityType &connectivity,
|
||||
vtkm::Id pointIndex)
|
||||
{
|
||||
return connectivity.GetNumberOfCellsIncidentOnPoint(pointIndex);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ set(unit_tests
|
||||
UnitTestUnaryPredicates.cxx
|
||||
UnitTestVectorAnalysis.cxx
|
||||
UnitTestVecTraits.cxx
|
||||
UnitTestVecVariable.cxx
|
||||
)
|
||||
|
||||
VTKM_unit_tests(SOURCES ${unit_tests})
|
||||
|
@ -277,10 +277,15 @@ bool test_equal(VectorType1 vector1,
|
||||
{
|
||||
typedef typename vtkm::VecTraits<VectorType1> Traits1;
|
||||
typedef typename vtkm::VecTraits<VectorType2> Traits2;
|
||||
BOOST_STATIC_ASSERT(Traits1::NUM_COMPONENTS == Traits2::NUM_COMPONENTS);
|
||||
|
||||
if (Traits1::GetNumberOfComponents(vector1) !=
|
||||
Traits2::GetNumberOfComponents(vector2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (vtkm::IdComponent component = 0;
|
||||
component < Traits1::NUM_COMPONENTS;
|
||||
component < Traits1::GetNumberOfComponents(vector1);
|
||||
component++)
|
||||
{
|
||||
vtkm::Float64 value1 =
|
||||
|
@ -18,26 +18,6 @@
|
||||
// this software.
|
||||
//============================================================================
|
||||
|
||||
//============================================================================
|
||||
// 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 <vtkm/Types.h>
|
||||
|
||||
#include <vtkm/testing/Testing.h>
|
||||
@ -130,18 +110,26 @@ template<typename ComponentType, vtkm::IdComponent Size>
|
||||
void GeneralVecTypeTest(const vtkm::Vec<ComponentType,Size> &)
|
||||
{
|
||||
typedef vtkm::Vec<ComponentType,Size> T;
|
||||
|
||||
VTKM_TEST_ASSERT(T::NUM_COMPONENTS == Size,
|
||||
"NUM_COMPONENTS is wrong size.");
|
||||
|
||||
//grab the number of elements of T
|
||||
T a, b, c;
|
||||
ComponentType s(5);
|
||||
|
||||
VTKM_TEST_ASSERT(a.GetNumberOfComponents() == Size,
|
||||
"GetNumberOfComponents returns wrong size.");
|
||||
|
||||
for(vtkm::IdComponent i=0; i < T::NUM_COMPONENTS; ++i)
|
||||
{
|
||||
a[i]=ComponentType((i+1)*2);
|
||||
b[i]=ComponentType(i+1);
|
||||
c[i]=ComponentType((i+1)*2);
|
||||
}
|
||||
|
||||
a.CopyInto(c);
|
||||
VTKM_TEST_ASSERT(test_equal(a, c), "CopyInto does not work.");
|
||||
|
||||
//verify prefix and postfix increment and decrement
|
||||
++c[T::NUM_COMPONENTS-1];
|
||||
c[T::NUM_COMPONENTS-1]++;
|
||||
|
@ -39,7 +39,7 @@ struct TestVecTypeFunctor
|
||||
{
|
||||
Traits::SetComponent(vector, index, ComponentType(VecInit[index]));
|
||||
}
|
||||
vtkm::testing::TestVecType(vector);
|
||||
vtkm::testing::TestVecType<Traits::NUM_COMPONENTS>(vector);
|
||||
}
|
||||
};
|
||||
|
||||
|
117
vtkm/testing/UnitTestVecVariable.cxx
Normal file
117
vtkm/testing/UnitTestVecVariable.cxx
Normal file
@ -0,0 +1,117 @@
|
||||
//============================================================================
|
||||
// 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/VecVariable.h>
|
||||
|
||||
#include <vtkm/testing/Testing.h>
|
||||
|
||||
namespace {
|
||||
|
||||
struct VecVariableTestFunctor
|
||||
{
|
||||
// You will get a compile fail if this does not pass
|
||||
template<typename NumericTag>
|
||||
void CheckNumericTag(NumericTag, NumericTag) const
|
||||
{
|
||||
std::cout << "NumericTag pass" << std::endl;
|
||||
}
|
||||
|
||||
// You will get a compile fail if this does not pass
|
||||
void CheckDimensionalityTag(vtkm::TypeTraitsVectorTag) const
|
||||
{
|
||||
std::cout << "VectorTag pass" << std::endl;
|
||||
}
|
||||
|
||||
// You will get a compile fail if this does not pass
|
||||
template<typename T>
|
||||
void CheckComponentType(T, T) const
|
||||
{
|
||||
std::cout << "ComponentType pass" << std::endl;
|
||||
}
|
||||
|
||||
// You will get a compile fail if this does not pass
|
||||
void CheckHasMultipleComponents(vtkm::VecTraitsTagMultipleComponents) const
|
||||
{
|
||||
std::cout << "MultipleComponents pass" << std::endl;
|
||||
}
|
||||
|
||||
// You will get a compile fail if this does not pass
|
||||
void CheckVariableSize(vtkm::VecTraitsTagSizeVariable) const
|
||||
{
|
||||
std::cout << "VariableSize" << std::endl;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void operator()(T) const
|
||||
{
|
||||
static const vtkm::IdComponent SIZE = 5;
|
||||
typedef vtkm::Vec<T,SIZE> VecType;
|
||||
typedef vtkm::VecVariable<T,SIZE> VecVariableType;
|
||||
typedef vtkm::TypeTraits<VecVariableType> TTraits;
|
||||
typedef vtkm::VecTraits<VecVariableType> VTraits;
|
||||
|
||||
std::cout << "Check NumericTag." << std::endl;
|
||||
this->CheckNumericTag(typename TTraits::NumericTag(),
|
||||
typename vtkm::TypeTraits<T>::NumericTag());
|
||||
|
||||
std::cout << "Check DimensionalityTag." << std::endl;
|
||||
this->CheckDimensionalityTag(typename TTraits::DimensionalityTag());
|
||||
|
||||
std::cout << "Check ComponentType." << std::endl;
|
||||
this->CheckComponentType(typename VTraits::ComponentType(), T());
|
||||
|
||||
std::cout << "Check MultipleComponents." << std::endl;
|
||||
this->CheckHasMultipleComponents(typename VTraits::HasMultipleComponents());
|
||||
|
||||
std::cout << "Check VariableSize." << std::endl;
|
||||
this->CheckVariableSize(typename VTraits::IsSizeStatic());
|
||||
|
||||
VecType source = TestValue(0, VecType());
|
||||
|
||||
VecVariableType vec1(source);
|
||||
VecType vecCopy;
|
||||
vec1.CopyInto(vecCopy);
|
||||
VTKM_TEST_ASSERT(test_equal(vec1, vecCopy),
|
||||
"Bad init or copyinto.");
|
||||
|
||||
vtkm::VecVariable<T,SIZE+1> vec2;
|
||||
for (vtkm::IdComponent setIndex = 0; setIndex < SIZE; setIndex++)
|
||||
{
|
||||
VTKM_TEST_ASSERT(vec2.GetNumberOfComponents() == setIndex,
|
||||
"Report wrong number of components");
|
||||
vec2.Append(source[setIndex]);
|
||||
}
|
||||
VTKM_TEST_ASSERT(test_equal(vec2, vec1),
|
||||
"Bad values from Append.");
|
||||
}
|
||||
};
|
||||
|
||||
void TestVecVariable()
|
||||
{
|
||||
vtkm::testing::Testing::TryTypes(VecVariableTestFunctor(),
|
||||
vtkm::TypeListTagFieldScalar());
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestVecVariable(int, char *[])
|
||||
{
|
||||
return vtkm::testing::Testing::Run(TestVecVariable);
|
||||
}
|
@ -46,17 +46,38 @@ inline void CompareDimensionalityTags(vtkm::TypeTraitsVectorTag,
|
||||
// If we are here, everything is fine.
|
||||
}
|
||||
|
||||
template<vtkm::IdComponent NUM_COMPONENTS, typename T>
|
||||
inline void CheckIsStatic(const T &, vtkm::VecTraitsTagSizeStatic)
|
||||
{
|
||||
VTKM_TEST_ASSERT(vtkm::VecTraits<T>::NUM_COMPONENTS == NUM_COMPONENTS,
|
||||
"Traits returns unexpected number of components");
|
||||
}
|
||||
|
||||
template<vtkm::IdComponent NUM_COMPONENTS, typename T>
|
||||
inline void CheckIsStatic(const T &, vtkm::VecTraitsTagSizeVariable)
|
||||
{
|
||||
// If we are here, everything is fine.
|
||||
}
|
||||
|
||||
/// Compares some manual arithmetic through type traits to arithmetic with
|
||||
/// the Tuple class.
|
||||
template <class T>
|
||||
template <vtkm::IdComponent NUM_COMPONENTS, typename T>
|
||||
static void TestVecTypeImpl(
|
||||
const typename boost::remove_const<T>::type &vector)
|
||||
{
|
||||
typedef typename vtkm::VecTraits<T> Traits;
|
||||
typedef typename Traits::ComponentType ComponentType;
|
||||
static const vtkm::IdComponent NUM_COMPONENTS = Traits::NUM_COMPONENTS;
|
||||
typedef typename boost::remove_const<T>::type NonConstT;
|
||||
|
||||
CheckIsStatic<NUM_COMPONENTS>(vector, typename Traits::IsSizeStatic());
|
||||
|
||||
VTKM_TEST_ASSERT(Traits::GetNumberOfComponents(vector) == NUM_COMPONENTS,
|
||||
"Traits returned wrong number of components.");
|
||||
|
||||
vtkm::Vec<ComponentType,NUM_COMPONENTS> vectorCopy;
|
||||
Traits::CopyInto(vector, vectorCopy);
|
||||
VTKM_TEST_ASSERT(test_equal(vectorCopy, vector), "CopyInto does not work.");
|
||||
|
||||
{
|
||||
NonConstT result;
|
||||
const ComponentType multiplier = 4;
|
||||
@ -67,8 +88,9 @@ static void TestVecTypeImpl(
|
||||
ComponentType(
|
||||
multiplier*Traits::GetComponent(vector, i)));
|
||||
}
|
||||
VTKM_TEST_ASSERT(test_equal(Traits::ToVec(result),
|
||||
multiplier*Traits::ToVec(vector)),
|
||||
vtkm::Vec<ComponentType,NUM_COMPONENTS> resultCopy;
|
||||
Traits::CopyInto(result, resultCopy);
|
||||
VTKM_TEST_ASSERT(test_equal(resultCopy, multiplier*vectorCopy),
|
||||
"Got bad result for scalar multiple");
|
||||
}
|
||||
|
||||
@ -80,8 +102,9 @@ static void TestVecTypeImpl(
|
||||
Traits::GetComponent(result, i)
|
||||
= ComponentType(multiplier * Traits::GetComponent(vector, i));
|
||||
}
|
||||
VTKM_TEST_ASSERT(test_equal(Traits::ToVec(result),
|
||||
multiplier*Traits::ToVec(vector)),
|
||||
vtkm::Vec<ComponentType,NUM_COMPONENTS> resultCopy;
|
||||
Traits::CopyInto(result, resultCopy);
|
||||
VTKM_TEST_ASSERT(test_equal(resultCopy, multiplier*vectorCopy),
|
||||
"Got bad result for scalar multiple");
|
||||
}
|
||||
|
||||
@ -94,8 +117,7 @@ static void TestVecTypeImpl(
|
||||
result = ComponentType(result + (component * component));
|
||||
}
|
||||
VTKM_TEST_ASSERT(
|
||||
test_equal(result,
|
||||
vtkm::dot(Traits::ToVec(vector), Traits::ToVec(vector))),
|
||||
test_equal(result, vtkm::dot(vectorCopy, vectorCopy)),
|
||||
"Got bad result for dot product");
|
||||
}
|
||||
|
||||
@ -136,11 +158,11 @@ inline void CheckScalarComponentsTag(vtkm::VecTraitsTagSingleComponent)
|
||||
|
||||
/// Compares some manual arithmetic through type traits to arithmetic with
|
||||
/// the Tuple class.
|
||||
template <class T>
|
||||
template <vtkm::IdComponent NUM_COMPONENTS, typename T>
|
||||
static void TestVecType(const T &vector)
|
||||
{
|
||||
detail::TestVecTypeImpl<T>(vector);
|
||||
detail::TestVecTypeImpl<const T>(vector);
|
||||
detail::TestVecTypeImpl<NUM_COMPONENTS, T>(vector);
|
||||
detail::TestVecTypeImpl<NUM_COMPONENTS, const T>(vector);
|
||||
}
|
||||
|
||||
/// Checks to make sure that the HasMultipleComponents tag is actually for a
|
||||
|
@ -23,35 +23,32 @@
|
||||
|
||||
#include <vtkm/worklet/WorkletMapTopology.h>
|
||||
|
||||
#include <vtkm/exec/TopologyData.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace worklet {
|
||||
|
||||
//simple functor that returns the average point value.
|
||||
class CellAverage : public vtkm::worklet::WorkletMapTopology
|
||||
{
|
||||
static const int LEN_IDS = 8;
|
||||
public:
|
||||
typedef void ControlSignature(FieldInFrom<Scalar> inPoints,
|
||||
TopologyIn<LEN_IDS> topology,
|
||||
TopologyIn topology,
|
||||
FieldOut<Scalar> outCells);
|
||||
typedef void ExecutionSignature(_1, FromCount, _3);
|
||||
typedef _2 InputDomain;
|
||||
|
||||
template<typename T1, typename T2>
|
||||
template<typename PointValueVecType, typename OutType>
|
||||
VTKM_EXEC_EXPORT
|
||||
void operator()(const vtkm::exec::TopologyData<T1,LEN_IDS> &pointValues,
|
||||
const vtkm::Id &count,
|
||||
T2 &average) const
|
||||
void operator()(const PointValueVecType &pointValues,
|
||||
const vtkm::IdComponent &numPoints,
|
||||
OutType &average) const
|
||||
{
|
||||
T1 sum = pointValues[0];
|
||||
for (vtkm::IdComponent i=1; i< count; ++i)
|
||||
OutType sum = static_cast<OutType>(pointValues[0]);
|
||||
for (vtkm::IdComponent pointIndex = 1; pointIndex < numPoints; ++pointIndex)
|
||||
{
|
||||
sum += pointValues[i];
|
||||
sum = sum + static_cast<OutType>(pointValues[pointIndex]);
|
||||
}
|
||||
|
||||
average = static_cast<T2>(sum / static_cast<T1>(count));
|
||||
average = sum / static_cast<OutType>(numPoints);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -83,15 +83,10 @@ public:
|
||||
|
||||
/// \brief A control signature tag for input connectivity.
|
||||
///
|
||||
/// This tag takes a template argument that is a type list tag that limits
|
||||
/// the possible value types in the array.
|
||||
///
|
||||
template< vtkm::IdComponent ItemTupleLength>
|
||||
struct TopologyIn : vtkm::cont::arg::ControlSignatureTagBase {
|
||||
typedef vtkm::cont::arg::TypeCheckTagTopology TypeCheckTag;
|
||||
typedef vtkm::cont::arg::TransportTagTopologyIn TransportTag;
|
||||
typedef vtkm::exec::arg::FetchTagTopologyIn FetchTag;
|
||||
static const int ITEM_TUPLE_LENGTH = ItemTupleLength;
|
||||
};
|
||||
|
||||
/// \brief A control signature tag for output fields.
|
||||
|
@ -21,6 +21,8 @@
|
||||
#include <vtkm/worklet/DispatcherMapTopology.h>
|
||||
#include <vtkm/worklet/WorkletMapTopology.h>
|
||||
|
||||
#include <vtkm/Math.h>
|
||||
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
@ -30,11 +32,10 @@ namespace test_explicit {
|
||||
|
||||
class MaxPointOrCellValue : public vtkm::worklet::WorkletMapTopology
|
||||
{
|
||||
static const int LEN_IDS = 8;
|
||||
public:
|
||||
typedef void ControlSignature(FieldInTo<Scalar> inCells,
|
||||
FieldInFrom<Scalar> inPoints,
|
||||
TopologyIn<LEN_IDS> topology,
|
||||
TopologyIn topology,
|
||||
FieldOut<Scalar> outCells);
|
||||
typedef void ExecutionSignature(_1, _4, _2, FromCount, CellShape, FromIndices);
|
||||
typedef _3 InputDomain;
|
||||
@ -42,43 +43,33 @@ public:
|
||||
VTKM_CONT_EXPORT
|
||||
MaxPointOrCellValue() { }
|
||||
|
||||
template<typename T>
|
||||
template<typename InCellType,
|
||||
typename OutCellType,
|
||||
typename InPointVecType,
|
||||
typename FromIndexType>
|
||||
VTKM_EXEC_EXPORT
|
||||
void operator()(const T &cellValue,
|
||||
T& maxValue,
|
||||
const vtkm::exec::TopologyData<T,LEN_IDS> &pointValues,
|
||||
const vtkm::Id &count,
|
||||
const vtkm::Id & vtkmNotUsed(type),
|
||||
const vtkm::exec::TopologyData<vtkm::Id,LEN_IDS> & vtkmNotUsed(pointIDs)) const
|
||||
void operator()(const InCellType &cellValue,
|
||||
OutCellType &maxValue,
|
||||
const InPointVecType &pointValues,
|
||||
const vtkm::IdComponent &numPoints,
|
||||
const vtkm::Id &vtkmNotUsed(type),
|
||||
const FromIndexType &vtkmNotUsed(pointIDs)) const
|
||||
{
|
||||
//simple functor that returns the max of cellValue and pointValue
|
||||
maxValue = cellValue;
|
||||
for (vtkm::IdComponent i=0; i<count; ++i)
|
||||
//simple functor that returns the max of cellValue and pointValue
|
||||
maxValue = static_cast<OutCellType>(cellValue);
|
||||
for (vtkm::IdComponent pointIndex = 0; pointIndex < numPoints; ++pointIndex)
|
||||
{
|
||||
maxValue = pointValues[i] > maxValue ? pointValues[i] : maxValue;
|
||||
maxValue = vtkm::Max(maxValue,
|
||||
static_cast<OutCellType>(pointValues[pointIndex]));
|
||||
}
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class AveragePointToCellValue : public vtkm::worklet::WorkletMapTopology
|
||||
{
|
||||
static const int LEN_IDS = 8;
|
||||
public:
|
||||
typedef void ControlSignature(FieldInFrom<Scalar> inPoints,
|
||||
TopologyIn<LEN_IDS> topology,
|
||||
TopologyIn topology,
|
||||
FieldOut<Scalar> outCells);
|
||||
typedef void ExecutionSignature(_1, _3, FromCount);
|
||||
typedef _2 InputDomain;
|
||||
@ -86,28 +77,20 @@ public:
|
||||
VTKM_CONT_EXPORT
|
||||
AveragePointToCellValue() { }
|
||||
|
||||
template<typename T>
|
||||
template<typename PointVecType, typename OutType>
|
||||
VTKM_EXEC_EXPORT
|
||||
void operator()(const vtkm::exec::TopologyData<T,LEN_IDS> &pointValues,
|
||||
T& avgVal,
|
||||
const vtkm::Id &count) const
|
||||
void operator()(const PointVecType &pointValues,
|
||||
OutType &avgVal,
|
||||
const vtkm::IdComponent &numPoints) const
|
||||
{
|
||||
//simple functor that returns the average pointValue.
|
||||
avgVal = pointValues[0];
|
||||
for (vtkm::IdComponent i=1; i<count; ++i)
|
||||
avgVal = static_cast<OutType>(pointValues[0]);
|
||||
for (vtkm::IdComponent pointIndex = 1; pointIndex < numPoints; ++pointIndex)
|
||||
{
|
||||
avgVal += pointValues[i];
|
||||
avgVal += static_cast<OutType>(pointValues[pointIndex]);
|
||||
}
|
||||
avgVal = avgVal / count;
|
||||
avgVal = avgVal / static_cast<OutType>(numPoints);
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -21,9 +21,9 @@
|
||||
#include <vtkm/worklet/DispatcherMapTopology.h>
|
||||
#include <vtkm/worklet/WorkletMapTopology.h>
|
||||
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/Math.h>
|
||||
|
||||
#include <vtkm/exec/TopologyData.h>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
@ -32,56 +32,44 @@ namespace test_regular {
|
||||
|
||||
class MaxPointOrCellValue : public vtkm::worklet::WorkletMapTopology
|
||||
{
|
||||
static const int LEN_IDS = 4;
|
||||
public:
|
||||
typedef void ControlSignature(FieldInTo<Scalar> inCells,
|
||||
FieldInFrom<Scalar> inPoints,
|
||||
TopologyIn<LEN_IDS> topology,
|
||||
TopologyIn topology,
|
||||
FieldOut<Scalar> outCells);
|
||||
//Todo: we need a way to mark what control signature item each execution signature for topology comes from
|
||||
typedef void ExecutionSignature(_1, _4, _2, FromCount, CellShape, FromIndices);
|
||||
typedef _3 InputDomain;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
MaxPointOrCellValue() { }
|
||||
|
||||
template<typename T>
|
||||
template<typename InCellType,
|
||||
typename OutCellType,
|
||||
typename InPointVecType,
|
||||
typename FromIndexType>
|
||||
VTKM_EXEC_EXPORT
|
||||
void operator()(const T &cellval,
|
||||
T& max_value,
|
||||
const vtkm::exec::TopologyData<T,LEN_IDS> &pointValues,
|
||||
const vtkm::Id &count,
|
||||
const vtkm::Id & vtkmNotUsed(type),
|
||||
const vtkm::exec::TopologyData<vtkm::Id,LEN_IDS> & vtkmNotUsed(pointIDs)) const
|
||||
void operator()(const InCellType &cellValue,
|
||||
OutCellType &maxValue,
|
||||
const InPointVecType &pointValues,
|
||||
const vtkm::IdComponent &numPoints,
|
||||
const vtkm::Id &vtkmNotUsed(type),
|
||||
const FromIndexType &vtkmNotUsed(pointIDs)) const
|
||||
{
|
||||
//simple functor that returns the max of cellValue and pointValue
|
||||
max_value = cellval;
|
||||
for (vtkm::IdComponent i=0; i< count; ++i)
|
||||
//simple functor that returns the max of cellValue and pointValue
|
||||
maxValue = static_cast<OutCellType>(cellValue);
|
||||
for (vtkm::IdComponent pointIndex = 0; pointIndex < numPoints; ++pointIndex)
|
||||
{
|
||||
max_value = pointValues[i] > max_value ? pointValues[i] : max_value;
|
||||
maxValue = vtkm::Max(maxValue,
|
||||
static_cast<OutCellType>(pointValues[pointIndex]));
|
||||
}
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class AveragePointToCellValue : public vtkm::worklet::WorkletMapTopology
|
||||
{
|
||||
static const int LEN_IDS = 4;
|
||||
public:
|
||||
typedef void ControlSignature(FieldInFrom<Scalar> inPoints,
|
||||
TopologyIn<LEN_IDS> topology,
|
||||
TopologyIn topology,
|
||||
FieldOut<Scalar> outCells);
|
||||
typedef void ExecutionSignature(_1, _3, FromCount);
|
||||
typedef _2 InputDomain;
|
||||
@ -89,28 +77,20 @@ public:
|
||||
VTKM_CONT_EXPORT
|
||||
AveragePointToCellValue() { }
|
||||
|
||||
template<typename T>
|
||||
template<typename PointVecType, typename OutType>
|
||||
VTKM_EXEC_EXPORT
|
||||
void operator()(const vtkm::exec::TopologyData<T,LEN_IDS> &pointValues,
|
||||
T& avgVal,
|
||||
const vtkm::Id &count) const
|
||||
void operator()(const PointVecType &pointValues,
|
||||
OutType &avgVal,
|
||||
const vtkm::IdComponent &numPoints) const
|
||||
{
|
||||
//simple functor that returns the average pointValue.
|
||||
avgVal = pointValues[0];
|
||||
for (vtkm::IdComponent i=1; i<count; ++i)
|
||||
avgVal = static_cast<OutType>(pointValues[0]);
|
||||
for (vtkm::IdComponent pointIndex = 1; pointIndex < numPoints; ++pointIndex)
|
||||
{
|
||||
avgVal += pointValues[i];
|
||||
avgVal += static_cast<OutType>(pointValues[pointIndex]);
|
||||
}
|
||||
avgVal = avgVal / count;
|
||||
avgVal = avgVal / static_cast<OutType>(numPoints);
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user