mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Move BaseComponentOf to vtkm::BaseComponent
This commit is contained in:
parent
fa04226b05
commit
b455636bcd
74
vtkm/BaseComponent.h
Normal file
74
vtkm/BaseComponent.h
Normal file
@ -0,0 +1,74 @@
|
||||
//============================================================================
|
||||
// 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_BaseComponent_h
|
||||
#define vtk_m_BaseComponent_h
|
||||
|
||||
|
||||
#include <vtkm/Matrix.h>
|
||||
#include <vtkm/TypeTraits.h>
|
||||
#include <vtkm/VecTraits.h>
|
||||
|
||||
namespace vtkm {
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename VecType, typename DimensionalityTag>
|
||||
struct BaseComponentImpl;
|
||||
|
||||
template<typename VecType>
|
||||
struct BaseComponentImpl<VecType, vtkm::TypeTraitsVectorTag>
|
||||
{
|
||||
private:
|
||||
using ComponentType = typename vtkm::VecTraits<VecType>::ComponentType;
|
||||
public:
|
||||
using Type =
|
||||
typename BaseComponentImpl<
|
||||
ComponentType,
|
||||
typename vtkm::TypeTraits<ComponentType>::DimensionalityTag
|
||||
>::Type;
|
||||
};
|
||||
|
||||
template<typename VecType>
|
||||
struct BaseComponentImpl<VecType, vtkm::TypeTraitsMatrixTag>
|
||||
: BaseComponentImpl<VecType, vtkm::TypeTraitsVectorTag>
|
||||
{ };
|
||||
|
||||
template<typename ScalarType>
|
||||
struct BaseComponentImpl<ScalarType, vtkm::TypeTraitsScalarTag>
|
||||
{
|
||||
using Type = ScalarType;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// Finds the base component type of a Vec. If you have a Vec of Vecs, it will
|
||||
// descend all Vecs until you get to the scalar type.
|
||||
template<typename VecType>
|
||||
struct BaseComponent
|
||||
{
|
||||
using Type =
|
||||
typename detail::BaseComponentImpl<
|
||||
VecType,
|
||||
typename vtkm::TypeTraits<VecType>::DimensionalityTag>::Type;
|
||||
};
|
||||
|
||||
} // namespace vtkm
|
||||
|
||||
#endif //vtk_m_BaseComponent_h
|
@ -28,6 +28,7 @@ vtkm_install_headers(
|
||||
|
||||
set(headers
|
||||
Assert.h
|
||||
BaseComponent.h
|
||||
BinaryPredicates.h
|
||||
BinaryOperators.h
|
||||
Bounds.h
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define vtk_m_exec_Derivative_h
|
||||
|
||||
#include <vtkm/Assert.h>
|
||||
#include <vtkm/BaseComponent.h>
|
||||
#include <vtkm/CellShape.h>
|
||||
#include <vtkm/Math.h>
|
||||
#include <vtkm/Matrix.h>
|
||||
@ -34,51 +35,6 @@
|
||||
namespace vtkm {
|
||||
namespace exec {
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename VecType, typename DimensionalityTag>
|
||||
struct BaseComponentOfImpl;
|
||||
|
||||
template<typename VecType>
|
||||
struct BaseComponentOfImpl<VecType, vtkm::TypeTraitsVectorTag>
|
||||
{
|
||||
private:
|
||||
using ComponentType = typename vtkm::VecTraits<VecType>::ComponentType;
|
||||
public:
|
||||
using type =
|
||||
typename BaseComponentOfImpl<
|
||||
ComponentType,
|
||||
typename vtkm::TypeTraits<ComponentType>::DimensionalityTag
|
||||
>::type;
|
||||
};
|
||||
|
||||
template<typename VecType>
|
||||
struct BaseComponentOfImpl<VecType, vtkm::TypeTraitsMatrixTag>
|
||||
: BaseComponentOfImpl<VecType, vtkm::TypeTraitsVectorTag>
|
||||
{ };
|
||||
|
||||
template<typename ScalarType>
|
||||
struct BaseComponentOfImpl<ScalarType, vtkm::TypeTraitsScalarTag>
|
||||
{
|
||||
using type = ScalarType;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/// Finds the base component type of a Vec. If you have a Vec of Vecs, it will
|
||||
/// descend all Vecs until you get to the scalar type.
|
||||
///
|
||||
// If this becomes useful outside of CellDerivative, then this should probably
|
||||
// be moved to a different header file.
|
||||
template<typename VecType>
|
||||
struct BaseComponentOf
|
||||
{
|
||||
using type =
|
||||
typename detail::BaseComponentOfImpl<
|
||||
VecType,
|
||||
typename vtkm::TypeTraits<VecType>::DimensionalityTag>::type;
|
||||
};
|
||||
|
||||
// The derivative for a 2D polygon in 3D space is underdetermined since there
|
||||
// is no information in the direction perpendicular to the polygon. To compute
|
||||
// derivatives for general polygons, we build a 2D space for the polygon's
|
||||
@ -410,7 +366,7 @@ CellDerivativeFor2DCell(const FieldVecType &field,
|
||||
CellShapeTag)
|
||||
{
|
||||
using FieldType = typename FieldVecType::ComponentType;
|
||||
using BaseFieldType = typename BaseComponentOf<FieldType>::type;
|
||||
using BaseFieldType = typename BaseComponent<FieldType>::Type;
|
||||
|
||||
// We have an underdetermined system in 3D, so create a 2D space in the
|
||||
// plane that the polygon sits.
|
||||
@ -617,7 +573,7 @@ CellDerivative(const FieldVecType &field,
|
||||
VTKM_ASSERT(wCoords.GetNumberOfComponents() == 2);
|
||||
|
||||
using FieldType = typename FieldVecType::ComponentType;
|
||||
using BaseComponentType = typename BaseComponentOf<FieldType>::type;
|
||||
using BaseComponentType = typename BaseComponent<FieldType>::Type;
|
||||
|
||||
FieldType deltaField(field[1] - field[0]);
|
||||
vtkm::Vec<BaseComponentType,3> vec(wCoords[1] - wCoords[0]);
|
||||
@ -724,7 +680,7 @@ vtkm::Vec<ValueType,3>
|
||||
TriangleDerivative(const vtkm::Vec<ValueType, 3> &field,
|
||||
const vtkm::Vec<WCoordType, 3> &wCoords)
|
||||
{
|
||||
using BaseComponentType = typename BaseComponentOf<ValueType>::type;
|
||||
using BaseComponentType = typename BaseComponent<ValueType>::Type;
|
||||
|
||||
// The scalar values of the three points in a triangle completely specify a
|
||||
// linear field (with constant gradient) assuming the field is constant in
|
||||
@ -1067,7 +1023,7 @@ vtkm::Vec<ValueType,3>
|
||||
TetraDerivative(const vtkm::Vec<ValueType,4> &field,
|
||||
const vtkm::Vec<WorldCoordType,4> &wCoords)
|
||||
{
|
||||
using BaseComponentType = typename BaseComponentOf<ValueType>::type;
|
||||
using BaseComponentType = typename BaseComponent<ValueType>::Type;
|
||||
|
||||
// The scalar values of the four points in a tetrahedron completely specify a
|
||||
// linear field (with constant gradient). The field, defined by the 3-vector
|
||||
|
@ -204,7 +204,7 @@ struct PointGradient : public vtkm::worklet::WorkletMapCellToPoint
|
||||
this->ComputeGradient(cellShape, pointIndexForCell, wCoords, field, gradient);
|
||||
}
|
||||
|
||||
using BaseGradientType = typename vtkm::exec::BaseComponentOf<ValueType>::type;
|
||||
using BaseGradientType = typename vtkm::BaseComponent<ValueType>::Type;
|
||||
const BaseGradientType invNumCells =
|
||||
static_cast<BaseGradientType>(1.) /
|
||||
static_cast<BaseGradientType>(numCells);
|
||||
|
Loading…
Reference in New Issue
Block a user