2015-08-20 16:57:19 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2015-08-20 16:57:19 +00:00
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//============================================================================
|
|
|
|
#ifndef vtk_m_exec_Derivative_h
|
|
|
|
#define vtk_m_exec_Derivative_h
|
|
|
|
|
|
|
|
#include <vtkm/CellShape.h>
|
2020-03-12 23:38:27 +00:00
|
|
|
#include <vtkm/ErrorCode.h>
|
2017-07-05 19:58:35 +00:00
|
|
|
#include <vtkm/VecAxisAlignedPointCoordinates.h>
|
2019-09-09 19:01:03 +00:00
|
|
|
#include <vtkm/VecTraits.h>
|
2015-08-20 16:57:19 +00:00
|
|
|
|
2015-08-21 04:29:54 +00:00
|
|
|
#include <vtkm/exec/CellInterpolate.h>
|
2015-08-20 16:57:19 +00:00
|
|
|
#include <vtkm/exec/FunctorBase.h>
|
2019-09-25 01:22:10 +00:00
|
|
|
|
2019-10-07 19:38:36 +00:00
|
|
|
#include <lcl/lcl.h>
|
2015-08-20 16:57:19 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace exec
|
|
|
|
{
|
2015-08-20 16:57:19 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2019-09-25 01:22:10 +00:00
|
|
|
namespace internal
|
2015-08-20 16:57:19 +00:00
|
|
|
{
|
|
|
|
|
2020-03-12 23:38:27 +00:00
|
|
|
template <typename LclCellShapeTag,
|
2019-09-25 01:22:10 +00:00
|
|
|
typename FieldVecType,
|
|
|
|
typename WorldCoordType,
|
|
|
|
typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
VTKM_EXEC vtkm::ErrorCode CellDerivativeImpl(
|
|
|
|
LclCellShapeTag tag,
|
2017-05-26 17:53:28 +00:00
|
|
|
const FieldVecType& field,
|
|
|
|
const WorldCoordType& wCoords,
|
2019-09-25 01:22:10 +00:00
|
|
|
const ParametricCoordType& pcoords,
|
2020-03-12 23:38:27 +00:00
|
|
|
vtkm::Vec<typename FieldVecType::ComponentType, 3>& result)
|
2016-12-06 00:18:46 +00:00
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
result = { 0 };
|
2020-03-12 23:38:27 +00:00
|
|
|
if ((field.GetNumberOfComponents() != tag.numberOfPoints()) ||
|
|
|
|
(wCoords.GetNumberOfComponents() != tag.numberOfPoints()))
|
|
|
|
{
|
|
|
|
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
|
|
|
}
|
2016-12-06 00:18:46 +00:00
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
using FieldType = typename FieldVecType::ComponentType;
|
2016-12-06 00:18:46 +00:00
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
auto fieldNumComponents = vtkm::VecTraits<FieldType>::GetNumberOfComponents(field[0]);
|
2019-10-07 19:38:36 +00:00
|
|
|
auto status = lcl::derivative(tag,
|
|
|
|
lcl::makeFieldAccessorNestedSOA(wCoords, 3),
|
|
|
|
lcl::makeFieldAccessorNestedSOA(field, fieldNumComponents),
|
|
|
|
pcoords,
|
2020-03-12 23:38:27 +00:00
|
|
|
result[0],
|
|
|
|
result[1],
|
|
|
|
result[2]);
|
|
|
|
return vtkm::internal::LclErrorToVtkmError(status);
|
2016-12-06 00:18:46 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
} // namespace internal
|
2016-12-06 00:18:46 +00:00
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
template <typename FieldVecType,
|
|
|
|
typename WorldCoordType,
|
|
|
|
typename ParametricCoordType,
|
|
|
|
typename CellShapeTag>
|
2020-03-12 23:38:27 +00:00
|
|
|
VTKM_EXEC vtkm::ErrorCode CellDerivative(const FieldVecType& field,
|
|
|
|
const WorldCoordType& wCoords,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>& pcoords,
|
|
|
|
CellShapeTag shape,
|
|
|
|
vtkm::Vec<typename FieldVecType::ComponentType, 3>& result)
|
2015-08-20 16:57:19 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
return internal::CellDerivativeImpl(
|
2020-03-12 23:38:27 +00:00
|
|
|
vtkm::internal::make_LclCellShapeTag(shape), field, wCoords, pcoords, result);
|
2015-08-20 16:57:19 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
template <typename FieldVecType, typename WorldCoordType, typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
VTKM_EXEC vtkm::ErrorCode CellDerivative(const FieldVecType&,
|
|
|
|
const WorldCoordType&,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>&,
|
|
|
|
vtkm::CellShapeTagEmpty,
|
2020-03-14 01:20:45 +00:00
|
|
|
vtkm::Vec<typename FieldVecType::ComponentType, 3>& result)
|
2015-09-01 22:30:03 +00:00
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
result = { 0 };
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::ErrorCode::OperationOnEmptyCell;
|
2015-09-01 22:30:03 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 17:35:35 +00:00
|
|
|
template <typename FieldVecType, typename WorldCoordType, typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
VTKM_EXEC vtkm::ErrorCode CellDerivative(const FieldVecType& field,
|
|
|
|
const WorldCoordType& wCoords,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>& pcoords,
|
|
|
|
vtkm::CellShapeTagPolyLine,
|
|
|
|
vtkm::Vec<typename FieldVecType::ComponentType, 3>& result)
|
2019-05-17 17:35:35 +00:00
|
|
|
{
|
|
|
|
vtkm::IdComponent numPoints = field.GetNumberOfComponents();
|
2020-03-12 23:38:27 +00:00
|
|
|
if (numPoints != wCoords.GetNumberOfComponents())
|
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
result = { 0 };
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
|
|
|
}
|
2019-05-28 17:25:23 +00:00
|
|
|
|
2019-05-17 17:35:35 +00:00
|
|
|
switch (numPoints)
|
|
|
|
{
|
|
|
|
case 1:
|
2020-03-12 23:38:27 +00:00
|
|
|
return CellDerivative(field, wCoords, pcoords, vtkm::CellShapeTagVertex(), result);
|
2019-05-17 17:35:35 +00:00
|
|
|
case 2:
|
2020-03-12 23:38:27 +00:00
|
|
|
return CellDerivative(field, wCoords, pcoords, vtkm::CellShapeTagLine(), result);
|
2019-05-17 17:35:35 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
auto dt = static_cast<ParametricCoordType>(1) / static_cast<ParametricCoordType>(numPoints - 1);
|
|
|
|
auto idx = static_cast<vtkm::IdComponent>(vtkm::Ceil(pcoords[0] / dt));
|
2019-05-28 17:25:23 +00:00
|
|
|
if (idx == 0)
|
2019-05-17 17:35:35 +00:00
|
|
|
{
|
|
|
|
idx = 1;
|
2016-11-09 22:22:06 +00:00
|
|
|
}
|
2019-09-25 01:22:10 +00:00
|
|
|
if (idx > numPoints - 1)
|
2016-11-09 22:22:06 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
idx = numPoints - 1;
|
2015-08-20 16:57:19 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
auto lineField = vtkm::make_Vec(field[idx - 1], field[idx]);
|
|
|
|
auto lineWCoords = vtkm::make_Vec(wCoords[idx - 1], wCoords[idx]);
|
|
|
|
auto pc = (pcoords[0] - static_cast<ParametricCoordType>(idx) * dt) / dt;
|
2020-03-12 23:38:27 +00:00
|
|
|
return internal::CellDerivativeImpl(lcl::Line{}, lineField, lineWCoords, &pc, result);
|
2016-11-09 22:22:06 +00:00
|
|
|
}
|
|
|
|
|
2015-08-20 16:57:19 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename FieldVecType, typename WorldCoordType, typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
VTKM_EXEC vtkm::ErrorCode CellDerivative(const FieldVecType& field,
|
|
|
|
const WorldCoordType& wCoords,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>& pcoords,
|
|
|
|
vtkm::CellShapeTagPolygon,
|
|
|
|
vtkm::Vec<typename FieldVecType::ComponentType, 3>& result)
|
2016-11-09 22:22:06 +00:00
|
|
|
{
|
|
|
|
const vtkm::IdComponent numPoints = field.GetNumberOfComponents();
|
2020-03-12 23:38:27 +00:00
|
|
|
if ((numPoints <= 0) || (numPoints != wCoords.GetNumberOfComponents()))
|
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
result = { 0 };
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
|
|
|
}
|
2016-11-09 22:22:06 +00:00
|
|
|
|
|
|
|
switch (field.GetNumberOfComponents())
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
case 1:
|
2020-03-12 23:38:27 +00:00
|
|
|
return CellDerivative(field, wCoords, pcoords, vtkm::CellShapeTagVertex(), result);
|
2017-05-18 14:29:41 +00:00
|
|
|
case 2:
|
2020-03-12 23:38:27 +00:00
|
|
|
return CellDerivative(field, wCoords, pcoords, vtkm::CellShapeTagLine(), result);
|
2019-09-25 01:22:10 +00:00
|
|
|
default:
|
2020-03-12 23:38:27 +00:00
|
|
|
return internal::CellDerivativeImpl(lcl::Polygon(numPoints), field, wCoords, pcoords, result);
|
2016-11-09 22:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename FieldVecType, typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
VTKM_EXEC vtkm::ErrorCode CellDerivative(const FieldVecType& field,
|
|
|
|
const vtkm::VecAxisAlignedPointCoordinates<2>& wCoords,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>& pcoords,
|
|
|
|
vtkm::CellShapeTagQuad,
|
|
|
|
vtkm::Vec<typename FieldVecType::ComponentType, 3>& result)
|
2015-08-20 16:57:19 +00:00
|
|
|
{
|
2020-03-12 23:38:27 +00:00
|
|
|
return internal::CellDerivativeImpl(lcl::Pixel{}, field, wCoords, pcoords, result);
|
2015-08-20 16:57:19 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename FieldVecType, typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
VTKM_EXEC vtkm::ErrorCode CellDerivative(const FieldVecType& field,
|
|
|
|
const vtkm::VecAxisAlignedPointCoordinates<3>& wCoords,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>& pcoords,
|
|
|
|
vtkm::CellShapeTagHexahedron,
|
|
|
|
vtkm::Vec<typename FieldVecType::ComponentType, 3>& result)
|
2015-08-20 16:57:19 +00:00
|
|
|
{
|
2020-03-12 23:38:27 +00:00
|
|
|
return internal::CellDerivativeImpl(lcl::Voxel{}, field, wCoords, pcoords, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/// \brief Take the derivative (get the gradient) of a point field in a cell.
|
|
|
|
///
|
|
|
|
/// Given the point field values for each node and the parametric coordinates
|
|
|
|
/// of a point within the cell, finds the derivative with respect to each
|
|
|
|
/// coordinate (i.e. the gradient) at that point. The derivative is not always
|
|
|
|
/// constant in some "linear" cells.
|
|
|
|
///
|
|
|
|
template <typename FieldVecType, typename WorldCoordType, typename ParametricCoordType>
|
|
|
|
VTKM_EXEC vtkm::ErrorCode CellDerivative(const FieldVecType& pointFieldValues,
|
|
|
|
const WorldCoordType& worldCoordinateValues,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>& parametricCoords,
|
|
|
|
vtkm::CellShapeTagGeneric shape,
|
|
|
|
vtkm::Vec<typename FieldVecType::ComponentType, 3>& result)
|
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
vtkm::ErrorCode status;
|
2020-03-12 23:38:27 +00:00
|
|
|
switch (shape.Id)
|
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
vtkmGenericCellShapeMacro(
|
|
|
|
status = CellDerivative(
|
|
|
|
pointFieldValues, worldCoordinateValues, parametricCoords, CellShapeTag(), result));
|
2020-03-12 23:38:27 +00:00
|
|
|
default:
|
2020-03-14 01:20:45 +00:00
|
|
|
result = { 0 };
|
|
|
|
status = vtkm::ErrorCode::InvalidShapeId;
|
2020-03-12 23:38:27 +00:00
|
|
|
}
|
2020-03-14 01:20:45 +00:00
|
|
|
return status;
|
2015-08-20 16:57:19 +00:00
|
|
|
}
|
2020-03-11 23:56:05 +00:00
|
|
|
|
2015-08-20 16:57:19 +00:00
|
|
|
}
|
|
|
|
} // namespace vtkm::exec
|
|
|
|
|
|
|
|
#endif //vtk_m_exec_Derivative_h
|