VTK-m  2.0
CellDerivative.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_exec_Derivative_h
11 #define vtk_m_exec_Derivative_h
12 
13 #include <vtkm/CellShape.h>
14 #include <vtkm/ErrorCode.h>
16 #include <vtkm/VecTraits.h>
17 
19 #include <vtkm/exec/FunctorBase.h>
20 
21 #include <lcl/lcl.h>
22 
23 namespace vtkm
24 {
25 namespace exec
26 {
27 
28 //-----------------------------------------------------------------------------
29 namespace internal
30 {
31 
32 template <typename LclCellShapeTag,
33  typename FieldVecType,
34  typename WorldCoordType,
35  typename ParametricCoordType>
36 VTKM_EXEC vtkm::ErrorCode CellDerivativeImpl(
37  LclCellShapeTag tag,
38  const FieldVecType& field,
39  const WorldCoordType& wCoords,
40  const ParametricCoordType& pcoords,
42 {
43  result = { 0 };
44  if ((field.GetNumberOfComponents() != tag.numberOfPoints()) ||
45  (wCoords.GetNumberOfComponents() != tag.numberOfPoints()))
46  {
48  }
49 
50  using FieldType = typename FieldVecType::ComponentType;
51 
52  auto fieldNumComponents = vtkm::VecTraits<FieldType>::GetNumberOfComponents(field[0]);
53  auto status = lcl::derivative(tag,
54  lcl::makeFieldAccessorNestedSOA(wCoords, 3),
55  lcl::makeFieldAccessorNestedSOA(field, fieldNumComponents),
56  pcoords,
57  result[0],
58  result[1],
59  result[2]);
60  return vtkm::internal::LclErrorToVtkmError(status);
61 }
62 
63 } // namespace internal
64 
65 template <typename FieldVecType,
66  typename WorldCoordType,
67  typename ParametricCoordType,
68  typename CellShapeTag>
69 VTKM_EXEC vtkm::ErrorCode CellDerivative(const FieldVecType& field,
70  const WorldCoordType& wCoords,
71  const vtkm::Vec<ParametricCoordType, 3>& pcoords,
72  CellShapeTag shape,
74 {
75  return internal::CellDerivativeImpl(
76  vtkm::internal::make_LclCellShapeTag(shape), field, wCoords, pcoords, result);
77 }
78 
79 template <typename FieldVecType, typename WorldCoordType, typename ParametricCoordType>
81  const WorldCoordType&,
83  vtkm::CellShapeTagEmpty,
85 {
86  result = { 0 };
88 }
89 
90 template <typename FieldVecType, typename WorldCoordType, typename ParametricCoordType>
91 VTKM_EXEC vtkm::ErrorCode CellDerivative(const FieldVecType& field,
92  const WorldCoordType& wCoords,
93  const vtkm::Vec<ParametricCoordType, 3>& pcoords,
94  vtkm::CellShapeTagPolyLine,
96 {
97  vtkm::IdComponent numPoints = field.GetNumberOfComponents();
98  if (numPoints != wCoords.GetNumberOfComponents())
99  {
100  result = { 0 };
102  }
103 
104  switch (numPoints)
105  {
106  case 1:
107  return CellDerivative(field, wCoords, pcoords, vtkm::CellShapeTagVertex(), result);
108  case 2:
109  return CellDerivative(field, wCoords, pcoords, vtkm::CellShapeTagLine(), result);
110  }
111 
112  auto dt = static_cast<ParametricCoordType>(1) / static_cast<ParametricCoordType>(numPoints - 1);
113  auto idx = static_cast<vtkm::IdComponent>(vtkm::Ceil(pcoords[0] / dt));
114  if (idx == 0)
115  {
116  idx = 1;
117  }
118  if (idx > numPoints - 1)
119  {
120  idx = numPoints - 1;
121  }
122 
123  auto lineField = vtkm::make_Vec(field[idx - 1], field[idx]);
124  auto lineWCoords = vtkm::make_Vec(wCoords[idx - 1], wCoords[idx]);
125  auto pc = (pcoords[0] - static_cast<ParametricCoordType>(idx) * dt) / dt;
126  return internal::CellDerivativeImpl(lcl::Line{}, lineField, lineWCoords, &pc, result);
127 }
128 
129 //-----------------------------------------------------------------------------
130 template <typename FieldVecType, typename WorldCoordType, typename ParametricCoordType>
131 VTKM_EXEC vtkm::ErrorCode CellDerivative(const FieldVecType& field,
132  const WorldCoordType& wCoords,
133  const vtkm::Vec<ParametricCoordType, 3>& pcoords,
134  vtkm::CellShapeTagPolygon,
136 {
137  const vtkm::IdComponent numPoints = field.GetNumberOfComponents();
138  if ((numPoints <= 0) || (numPoints != wCoords.GetNumberOfComponents()))
139  {
140  result = { 0 };
142  }
143 
144  switch (field.GetNumberOfComponents())
145  {
146  case 1:
147  return CellDerivative(field, wCoords, pcoords, vtkm::CellShapeTagVertex(), result);
148  case 2:
149  return CellDerivative(field, wCoords, pcoords, vtkm::CellShapeTagLine(), result);
150  default:
151  return internal::CellDerivativeImpl(lcl::Polygon(numPoints), field, wCoords, pcoords, result);
152  }
153 }
154 
155 //-----------------------------------------------------------------------------
156 template <typename FieldVecType, typename ParametricCoordType>
157 VTKM_EXEC vtkm::ErrorCode CellDerivative(const FieldVecType& field,
159  const vtkm::Vec<ParametricCoordType, 3>& pcoords,
160  vtkm::CellShapeTagQuad,
162 {
163  return internal::CellDerivativeImpl(lcl::Pixel{}, field, wCoords, pcoords, result);
164 }
165 
166 template <typename FieldVecType, typename ParametricCoordType>
167 VTKM_EXEC vtkm::ErrorCode CellDerivative(const FieldVecType& field,
169  const vtkm::Vec<ParametricCoordType, 3>& pcoords,
170  vtkm::CellShapeTagHexahedron,
172 {
173  return internal::CellDerivativeImpl(lcl::Voxel{}, field, wCoords, pcoords, result);
174 }
175 
176 //-----------------------------------------------------------------------------
184 template <typename FieldVecType, typename WorldCoordType, typename ParametricCoordType>
185 VTKM_EXEC vtkm::ErrorCode CellDerivative(const FieldVecType& pointFieldValues,
186  const WorldCoordType& worldCoordinateValues,
187  const vtkm::Vec<ParametricCoordType, 3>& parametricCoords,
190 {
191  vtkm::ErrorCode status;
192  switch (shape.Id)
193  {
195  status = CellDerivative(
196  pointFieldValues, worldCoordinateValues, parametricCoords, CellShapeTag(), result));
197  default:
198  result = { 0 };
200  }
201  return status;
202 }
203 
204 }
205 } // namespace vtkm::exec
206 
207 #endif //vtk_m_exec_Derivative_h
vtkm::ErrorCode
ErrorCode
Definition: ErrorCode.h:19
vtkm::VecAxisAlignedPointCoordinates
An implicit vector for point coordinates in axis aligned cells.
Definition: VecAxisAlignedPointCoordinates.h:78
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::Ceil
VTKM_EXEC_CONT vtkm::Float32 Ceil(vtkm::Float32 x)
Round x to the smallest integer value not less than x.
Definition: Math.h:2145
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
CellInterpolate.h
CellShape.h
ErrorCode.h
vtkm::Line
Ray< CoordType, Dim, true > Line
Lines are two-sided rays:
Definition: Geometry.h:330
vtkmGenericCellShapeMacro
#define vtkmGenericCellShapeMacro(call)
A macro used in a switch statement to determine cell shape.
Definition: CellShape.h:230
FunctorBase.h
vtkm::exec::CellDerivative
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)
Definition: CellDerivative.h:69
vtkm::make_Vec
constexpr VTKM_EXEC_CONT vtkm::Vec< T, vtkm::IdComponent(sizeof...(Ts)+1)> make_Vec(T value0, Ts &&... args)
Initializes and returns a Vec containing all the arguments.
Definition: Types.h:1212
vtkm::Vec
A short fixed-length array.
Definition: Types.h:767
vtkm::CellShapeTagGeneric::Id
vtkm::UInt8 Id
Definition: CellShape.h:160
vtkm::ErrorCode::OperationOnEmptyCell
@ OperationOnEmptyCell
vtkm::CellShapeTagGeneric
A special cell shape tag that holds a cell shape that is not known at compile time.
Definition: CellShape.h:152
VecAxisAlignedPointCoordinates.h
vtkm::VecTraits::GetNumberOfComponents
static vtkm::IdComponent GetNumberOfComponents(const VecType &vec)
Number of components in the given vector.
VecTraits.h
vtkm::ErrorCode::InvalidNumberOfPoints
@ InvalidNumberOfPoints
vtkm::ErrorCode::InvalidShapeId
@ InvalidShapeId