Viskores  1.0
CellDerivative.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_exec_Derivative_h
19 #define viskores_exec_Derivative_h
20 
21 #include <viskores/CellShape.h>
22 #include <viskores/ErrorCode.h>
24 #include <viskores/VecTraits.h>
25 
28 
29 #include <lcl/lcl.h>
30 
31 namespace viskores
32 {
33 namespace exec
34 {
35 
36 //-----------------------------------------------------------------------------
37 namespace internal
38 {
39 
40 template <typename LclCellShapeTag,
41  typename FieldVecType,
42  typename WorldCoordType,
43  typename ParametricCoordType>
44 VISKORES_EXEC viskores::ErrorCode CellDerivativeImpl(
45  LclCellShapeTag tag,
46  const FieldVecType& field,
47  const WorldCoordType& wCoords,
48  const ParametricCoordType& pcoords,
50 {
51  result = { 0 };
52  if ((field.GetNumberOfComponents() != tag.numberOfPoints()) ||
53  (wCoords.GetNumberOfComponents() != tag.numberOfPoints()))
54  {
56  }
57 
58  using FieldType = typename FieldVecType::ComponentType;
59 
60  auto fieldNumComponents = viskores::VecTraits<FieldType>::GetNumberOfComponents(field[0]);
61  auto status = lcl::derivative(tag,
62  lcl::makeFieldAccessorNestedSOA(wCoords, 3),
63  lcl::makeFieldAccessorNestedSOA(field, fieldNumComponents),
64  pcoords,
65  result[0],
66  result[1],
67  result[2]);
68  return viskores::internal::LclErrorToViskoresError(status);
69 }
70 
71 } // namespace internal
72 
73 template <typename FieldVecType,
74  typename WorldCoordType,
75  typename ParametricCoordType,
76  typename CellShapeTag>
78  const FieldVecType& field,
79  const WorldCoordType& wCoords,
81  CellShapeTag shape,
83 {
84  return internal::CellDerivativeImpl(
85  viskores::internal::make_LclCellShapeTag(shape), field, wCoords, pcoords, result);
86 }
87 
88 template <typename FieldVecType, typename WorldCoordType, typename ParametricCoordType>
90  const FieldVecType&,
91  const WorldCoordType&,
95 {
96  result = { 0 };
98 }
99 
100 template <typename FieldVecType, typename WorldCoordType, typename ParametricCoordType>
102  const FieldVecType& field,
103  const WorldCoordType& wCoords,
107 {
108  viskores::IdComponent numPoints = field.GetNumberOfComponents();
109  if (numPoints != wCoords.GetNumberOfComponents())
110  {
111  result = { 0 };
113  }
114 
115  switch (numPoints)
116  {
117  case 1:
118  return CellDerivative(field, wCoords, pcoords, viskores::CellShapeTagVertex(), result);
119  case 2:
120  return CellDerivative(field, wCoords, pcoords, viskores::CellShapeTagLine(), result);
121  }
122 
123  auto dt = static_cast<ParametricCoordType>(1) / static_cast<ParametricCoordType>(numPoints - 1);
124  auto idx = static_cast<viskores::IdComponent>(viskores::Ceil(pcoords[0] / dt));
125  if (idx == 0)
126  {
127  idx = 1;
128  }
129  if (idx > numPoints - 1)
130  {
131  idx = numPoints - 1;
132  }
133 
134  auto lineField = viskores::make_Vec(field[idx - 1], field[idx]);
135  auto lineWCoords = viskores::make_Vec(wCoords[idx - 1], wCoords[idx]);
136  auto pc = (pcoords[0] - static_cast<ParametricCoordType>(idx) * dt) / dt;
137  return internal::CellDerivativeImpl(lcl::Line{}, lineField, lineWCoords, &pc, result);
138 }
139 
140 //-----------------------------------------------------------------------------
141 template <typename FieldVecType, typename WorldCoordType, typename ParametricCoordType>
143  const FieldVecType& field,
144  const WorldCoordType& wCoords,
148 {
149  const viskores::IdComponent numPoints = field.GetNumberOfComponents();
150  if ((numPoints <= 0) || (numPoints != wCoords.GetNumberOfComponents()))
151  {
152  result = { 0 };
154  }
155 
156  switch (field.GetNumberOfComponents())
157  {
158  case 1:
159  return CellDerivative(field, wCoords, pcoords, viskores::CellShapeTagVertex(), result);
160  case 2:
161  return CellDerivative(field, wCoords, pcoords, viskores::CellShapeTagLine(), result);
162  default:
163  return internal::CellDerivativeImpl(lcl::Polygon(numPoints), field, wCoords, pcoords, result);
164  }
165 }
166 
167 //-----------------------------------------------------------------------------
168 template <typename FieldVecType, typename ParametricCoordType>
170  const FieldVecType& field,
175 {
176  return internal::CellDerivativeImpl(lcl::Pixel{}, field, wCoords, pcoords, result);
177 }
178 
179 template <typename FieldVecType, typename ParametricCoordType>
181  const FieldVecType& field,
186 {
187  return internal::CellDerivativeImpl(lcl::Voxel{}, field, wCoords, pcoords, result);
188 }
189 
190 //-----------------------------------------------------------------------------
212 template <typename FieldVecType, typename WorldCoordType, typename ParametricCoordType>
214  const FieldVecType& pointFieldValues,
215  const WorldCoordType& worldCoordinateValues,
216  const viskores::Vec<ParametricCoordType, 3>& parametricCoords,
219 {
220  viskores::ErrorCode status;
221  switch (shape.Id)
222  {
224  status = CellDerivative(
225  pointFieldValues, worldCoordinateValues, parametricCoords, CellShapeTag(), result));
226  default:
227  result = { 0 };
229  }
230  return status;
231 }
232 
233 }
234 } // namespace viskores::exec
235 
236 #endif //viskores_exec_Derivative_h
viskores::CellShapeTagGeneric::Id
viskores::UInt8 Id
An identifier that corresponds to one of the CELL_SHAPE_* identifiers.
Definition: CellShape.h:188
viskores::VecAxisAlignedPointCoordinates
An implicit vector for point coordinates in axis aligned cells.
Definition: VecAxisAlignedPointCoordinates.h:86
viskores::CellShapeTagLine
Definition: CellShape.h:158
viskores::CellShapeTagHexahedron
Definition: CellShape.h:167
viskoresGenericCellShapeMacro
#define viskoresGenericCellShapeMacro(call)
A macro used in a switch statement to determine cell shape.
Definition: CellShape.h:257
viskores::ErrorCode
ErrorCode
Identifies whether an operation was successful or what type of error it had.
Definition: ErrorCode.h:36
viskores::ErrorCode::InvalidNumberOfPoints
@ InvalidNumberOfPoints
The wrong number of points was provided for a given cell type.
CellInterpolate.h
viskores::Ceil
viskores::Float32 Ceil(viskores::Float32 x)
Definition: Math.h:2177
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
CellShape.h
viskores::CellShapeTagGeneric
A special cell shape tag that holds a cell shape that is not known at compile time.
Definition: CellShape.h:178
ErrorCode.h
viskores::ErrorCode::InvalidShapeId
@ InvalidShapeId
A unknown shape identifier was encountered.
viskores::Line
Ray< CoordType, Dim, true > Line
Lines are two-sided rays:
Definition: Geometry.h:338
viskores::CellShapeTagEmpty
Definition: CellShape.h:155
viskores::VecTraits::GetNumberOfComponents
static constexpr viskores::IdComponent GetNumberOfComponents(const T &)
Returns the number of components in the given vector.
Definition: VecTraits.h:102
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
FunctorBase.h
viskores::CellShapeTagVertex
Definition: CellShape.h:156
viskores::CellShapeTagQuad
Definition: CellShape.h:164
viskores::ErrorCode::OperationOnEmptyCell
@ OperationOnEmptyCell
An operation was attempted on a cell with an empty shape.
viskores::make_Vec
constexpr viskores::Vec< T, viskores::IdComponent(sizeof...(Ts)+1)> make_Vec(T value0, Ts &&... args)
Initializes and returns a Vec containing all the arguments.
Definition: Types.h:1262
viskores::exec::CellDerivative
viskores::ErrorCode CellDerivative(const FieldVecType &field, const WorldCoordType &wCoords, const viskores::Vec< ParametricCoordType, 3 > &pcoords, CellShapeTag shape, viskores::Vec< typename FieldVecType::ComponentType, 3 > &result)
Definition: CellDerivative.h:77
viskores::CellShapeTagPolygon
Definition: CellShape.h:162
viskores::CellShapeTagPolyLine
Definition: CellShape.h:159
VecAxisAlignedPointCoordinates.h
viskores::Vec
A short fixed-length array.
Definition: Types.h:365
VISKORES_EXEC
#define VISKORES_EXEC
Definition: ExportMacros.h:59
VecTraits.h