VTK-m  2.2
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&,
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,
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,
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,
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,
172 {
173  return internal::CellDerivativeImpl(lcl::Voxel{}, field, wCoords, pcoords, result);
174 }
175 
176 //-----------------------------------------------------------------------------
198 template <typename FieldVecType, typename WorldCoordType, typename ParametricCoordType>
199 VTKM_EXEC vtkm::ErrorCode CellDerivative(const FieldVecType& pointFieldValues,
200  const WorldCoordType& worldCoordinateValues,
201  const vtkm::Vec<ParametricCoordType, 3>& parametricCoords,
204 {
205  vtkm::ErrorCode status;
206  switch (shape.Id)
207  {
209  status = CellDerivative(
210  pointFieldValues, worldCoordinateValues, parametricCoords, CellShapeTag(), result));
211  default:
212  result = { 0 };
214  }
215  return status;
216 }
217 
218 }
219 } // namespace vtkm::exec
220 
221 #endif //vtk_m_exec_Derivative_h
vtkm::CellShapeTagQuad
Definition: CellShape.h:156
vtkm::ErrorCode
ErrorCode
Identifies whether an operation was successful or what type of error it had.
Definition: ErrorCode.h:28
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::make_Vec
constexpr 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:1253
vtkm::IdComponent
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
CellInterpolate.h
CellShape.h
vtkm::CellShapeTagPolygon
Definition: CellShape.h:154
ErrorCode.h
vtkm::exec::CellDerivative
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::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:250
vtkm::CellShapeTagVertex
Definition: CellShape.h:148
vtkm::Ceil
vtkm::Float32 Ceil(vtkm::Float32 x)
Definition: Math.h:2169
vtkm::VecTraits::GetNumberOfComponents
static constexpr vtkm::IdComponent GetNumberOfComponents(const T &)
Returns the number of components in the given vector.
Definition: VecTraits.h:94
vtkm::CellShapeTagPolyLine
Definition: CellShape.h:151
FunctorBase.h
vtkm::CellShapeTagLine
Definition: CellShape.h:150
vtkm::CellShapeTagEmpty
Definition: CellShape.h:147
vtkm::CellShapeTagHexahedron
Definition: CellShape.h:159
vtkm::Vec
A short fixed-length array.
Definition: Types.h:357
vtkm::CellShapeTagGeneric::Id
vtkm::UInt8 Id
An identifier that corresponds to one of the CELL_SHAPE_* identifiers.
Definition: CellShape.h:180
vtkm::ErrorCode::OperationOnEmptyCell
@ OperationOnEmptyCell
An operation was attempted on a cell with an empty shape.
vtkm::CellShapeTagGeneric
A special cell shape tag that holds a cell shape that is not known at compile time.
Definition: CellShape.h:170
VecAxisAlignedPointCoordinates.h
VecTraits.h
vtkm::ErrorCode::InvalidNumberOfPoints
@ InvalidNumberOfPoints
The wrong number of points was provided for a given cell type.
vtkm::ErrorCode::InvalidShapeId
@ InvalidShapeId
A unknown shape identifier was encountered.