VTK-m  2.0
worklet/Gradient.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 
11 #ifndef vtk_m_worklet_Gradient_h
12 #define vtk_m_worklet_Gradient_h
13 
16 
25 
26 // Required for instantiations
27 #include <vtkm/cont/ArrayHandle.h>
34 
35 #ifndef vtkm_GradientInstantiation
36 // Turn this on to check to see if all the instances of the gradient worklet are covered
37 // in external instances. If they are not, you will get a compile error.
38 //#define VTKM_GRADIENT_CHECK_WORKLET_INSTANCES
39 #endif
40 
41 namespace vtkm
42 {
43 namespace worklet
44 {
45 
46 template <typename T>
48 
49 namespace gradient
50 {
51 
52 //-----------------------------------------------------------------------------
53 template <typename CoordinateSystem, typename T, typename S>
55 {
56  DeducedPointGrad(const CoordinateSystem& coords,
57  const vtkm::cont::ArrayHandle<T, S>& field,
59  : Points(&coords)
60  , Field(&field)
61  , Result(result)
62  {
63  }
64 
65  template <typename CellSetType>
66  void operator()(const CellSetType& cellset) const;
67 
68  template <typename CellSetType>
69  void Go(const CellSetType& cellset) const
70  {
72  dispatcher.Invoke(cellset, //topology to iterate on a per point basis
73  cellset, //whole cellset in
74  *this->Points,
75  *this->Field,
76  *this->Result);
77  }
78 
79  void Go(const vtkm::cont::CellSetStructured<3>& cellset) const
80  {
82  dispatcher.Invoke(cellset, //topology to iterate on a per point basis
83  *this->Points,
84  *this->Field,
85  *this->Result);
86  }
87 
88  template <typename PermIterType>
90  cellset) const
91  {
93  dispatcher.Invoke(cellset, //topology to iterate on a per point basis
94  *this->Points,
95  *this->Field,
96  *this->Result);
97  }
98 
99  void Go(const vtkm::cont::CellSetStructured<2>& cellset) const
100  {
102  dispatcher.Invoke(cellset, //topology to iterate on a per point basis
103  *this->Points,
104  *this->Field,
105  *this->Result);
106  }
107 
108  template <typename PermIterType>
110  cellset) const
111  {
113  dispatcher.Invoke(cellset, //topology to iterate on a per point basis
114  *this->Points,
115  *this->Field,
116  *this->Result);
117  }
118 
119 
120  const CoordinateSystem* const Points;
123 
124 private:
126 };
127 
128 #ifndef VTKM_GRADIENT_CHECK_WORKLET_INSTANCES
129 // Declare the methods that get instances outside of the class so that they are not inline.
130 // If they are inline, the compiler may decide to compile them anyway.
131 template <typename CoordinateSystem, typename T, typename S>
132 template <typename CellSetType>
133 void DeducedPointGrad<CoordinateSystem, T, S>::operator()(const CellSetType& cellset) const
134 {
135  this->Go(cellset);
136 }
137 #endif
138 
139 } //namespace gradient
140 
141 template <typename T>
143 {
144 
145  using ValueType = T;
147 
148  template <typename DeviceAdapter>
150  {
152  };
153 
155  : Gradient()
156  , Divergence()
157  , Vorticity()
158  , QCriterion()
159  , StoreGradient(true)
160  , ComputeDivergence(false)
161  , ComputeVorticity(false)
162  , ComputeQCriterion(false)
163  {
164  }
165 
166  GradientOutputFields(bool store, bool divergence, bool vorticity, bool qc)
167  : Gradient()
168  , Divergence()
169  , Vorticity()
170  , QCriterion()
171  , StoreGradient(store)
172  , ComputeDivergence(divergence)
173  , ComputeVorticity(vorticity)
174  , ComputeQCriterion(qc)
175  {
176  }
177 
181  void SetComputeDivergence(bool enable) { ComputeDivergence = enable; }
182  bool GetComputeDivergence() const { return ComputeDivergence; }
183 
187  void SetComputeVorticity(bool enable) { ComputeVorticity = enable; }
188  bool GetComputeVorticity() const { return ComputeVorticity; }
189 
193  void SetComputeQCriterion(bool enable) { ComputeQCriterion = enable; }
194  bool GetComputeQCriterion() const { return ComputeQCriterion; }
195 
199  void SetComputeGradient(bool enable) { StoreGradient = enable; }
200  bool GetComputeGradient() const { return StoreGradient; }
201 
202  //todo fix this for scalar
204  {
206  this->ComputeDivergence,
207  this->ComputeVorticity,
208  this->ComputeQCriterion,
209  this->Gradient,
210  this->Divergence,
211  this->Vorticity,
212  this->QCriterion,
213  size);
214  return portal;
215  }
216 
221 
222 private:
227 };
229 {
230 public:
231  template <typename CellSetType, typename CoordinateSystem, typename T, typename S>
232  vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>> Run(const CellSetType& cells,
233  const CoordinateSystem& coords,
234  const vtkm::cont::ArrayHandle<T, S>& field,
235  GradientOutputFields<T>& extraOutput)
236  {
237  //we are using cast and call here as we pass the cells twice to the invoke
238  //and want the type resolved once before hand instead of twice
239  //by the dispatcher ( that will cost more in time and binary size )
240  gradient::DeducedPointGrad<CoordinateSystem, T, S> func(coords, field, &extraOutput);
241  vtkm::cont::CastAndCall(cells, func);
242  return extraOutput.Gradient;
243  }
244 };
245 
247 {
248 public:
249  template <typename CellSetType, typename CoordinateSystem, typename T, typename S>
250  static vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>> Run(const CellSetType& cells,
251  const CoordinateSystem& coords,
252  const vtkm::cont::ArrayHandle<T, S>& field,
253  GradientOutputFields<T>& extraOutput);
254 };
255 
256 #ifndef VTKM_GRADIENT_CHECK_WORKLET_INSTANCES
257 // Declare the methods that get instances outside of the class so that they are not inline.
258 // If they are inline, the compiler may decide to compile them anyway.
259 template <typename CellSetType, typename CoordinateSystem, typename T, typename S>
261  const CellSetType& cells,
262  const CoordinateSystem& coords,
263  const vtkm::cont::ArrayHandle<T, S>& field,
264  GradientOutputFields<T>& extraOutput)
265 {
267  dispatcher.Invoke(cells, coords, field, extraOutput);
268  return extraOutput.Gradient;
269 }
270 #endif
271 
272 }
273 } // namespace vtkm::worklet
274 
275 //==============================================================================
276 //---------------------------------------------------------------------------
278 extern template void vtkm::worklet::gradient::DeducedPointGrad<
284 extern template void vtkm::worklet::gradient::DeducedPointGrad<
290 extern template void vtkm::worklet::gradient::DeducedPointGrad<
296 extern template void vtkm::worklet::gradient::DeducedPointGrad<
301 
303 extern template void vtkm::worklet::gradient::DeducedPointGrad<
309 extern template void vtkm::worklet::gradient::DeducedPointGrad<
314 
316 extern template void vtkm::worklet::gradient::DeducedPointGrad<
322 operator()(const vtkm::cont::CellSetStructured<3>&) const;
325 extern template void vtkm::worklet::gradient::DeducedPointGrad<
331 operator()(const vtkm::cont::CellSetStructured<3>&) const;
333 
335 extern template void vtkm::worklet::gradient::DeducedPointGrad<
337  vtkm::Vec3f,
340 
341 
342 //---------------------------------------------------------------------------
344 extern template void vtkm::worklet::gradient::DeducedPointGrad<
350 extern template void vtkm::worklet::gradient::DeducedPointGrad<
356 extern template void vtkm::worklet::gradient::DeducedPointGrad<
362 extern template void vtkm::worklet::gradient::DeducedPointGrad<
367 
369 extern template void vtkm::worklet::gradient::DeducedPointGrad<
375 extern template void vtkm::worklet::gradient::DeducedPointGrad<
380 
382 extern template void vtkm::worklet::gradient::DeducedPointGrad<
388 operator()(const vtkm::cont::CellSetStructured<2>&) const;
391 extern template void vtkm::worklet::gradient::DeducedPointGrad<
397 operator()(const vtkm::cont::CellSetStructured<2>&) const;
399 
401 extern template void vtkm::worklet::gradient::DeducedPointGrad<
403  vtkm::Vec3f,
406 
407 
408 //---------------------------------------------------------------------------
410 extern template void vtkm::worklet::gradient::DeducedPointGrad<
416 extern template void vtkm::worklet::gradient::DeducedPointGrad<
422 extern template void vtkm::worklet::gradient::DeducedPointGrad<
428 extern template void vtkm::worklet::gradient::DeducedPointGrad<
433 
435 extern template void vtkm::worklet::gradient::DeducedPointGrad<
438  vtkm::cont::StorageTagSOA>::operator()(const vtkm::cont::CellSetExplicit<>&) const;
441 extern template void vtkm::worklet::gradient::DeducedPointGrad<
444  vtkm::cont::StorageTagSOA>::operator()(const vtkm::cont::CellSetExplicit<>&) const;
446 
448 extern template void vtkm::worklet::gradient::DeducedPointGrad<
454 operator()(const vtkm::cont::CellSetExplicit<>&) const;
457 extern template void vtkm::worklet::gradient::DeducedPointGrad<
463 operator()(const vtkm::cont::CellSetExplicit<>&) const;
465 
467 extern template void vtkm::worklet::gradient::DeducedPointGrad<
469  vtkm::Vec3f,
472 
473 
474 //---------------------------------------------------------------------------
476 extern template void vtkm::worklet::gradient::DeducedPointGrad<
482 extern template void vtkm::worklet::gradient::DeducedPointGrad<
488 extern template void vtkm::worklet::gradient::DeducedPointGrad<
494 extern template void vtkm::worklet::gradient::DeducedPointGrad<
499 
501 extern template void vtkm::worklet::gradient::DeducedPointGrad<
507 extern template void vtkm::worklet::gradient::DeducedPointGrad<
512 
514 extern template void vtkm::worklet::gradient::DeducedPointGrad<
520 operator()(const vtkm::cont::CellSetSingleType<>&) const;
523 extern template void vtkm::worklet::gradient::DeducedPointGrad<
529 operator()(const vtkm::cont::CellSetSingleType<>&) const;
531 
533 extern template void vtkm::worklet::gradient::DeducedPointGrad<
535  vtkm::Vec3f,
538 
539 
540 
541 //==============================================================================
542 //---------------------------------------------------------------------------
549  GradientOutputFields<vtkm::Float32>&);
557  GradientOutputFields<vtkm::Float64>&);
565  GradientOutputFields<vtkm::Vec3f_32>&);
573  GradientOutputFields<vtkm::Vec3f_64>&);
575 
582  GradientOutputFields<vtkm::Vec3f_32>&);
590  GradientOutputFields<vtkm::Vec3f_64>&);
592 
603  GradientOutputFields<vtkm::Vec3f_32>&);
615  GradientOutputFields<vtkm::Vec3f_64>&);
617 
623  GradientOutputFields<vtkm::Vec3f>&);
625 
626 #endif
vtkm::worklet::GradientOutputFields::GradientOutputFields
GradientOutputFields(bool store, bool divergence, bool vorticity, bool qc)
Definition: worklet/Gradient.h:166
vtkm::worklet::GradientOutputFields::PrepareForOutput
vtkm::exec::GradientOutput< T > PrepareForOutput(vtkm::Id size)
Definition: worklet/Gradient.h:203
vtkm::cont::ArrayHandle< T, S >
ArrayHandle.h
vtkm::worklet::PointGradient
Definition: worklet/Gradient.h:228
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::worklet::GradientOutputFields::ComputeDivergence
bool ComputeDivergence
Definition: worklet/Gradient.h:224
vtkm::cont::CellSetPermutation
Definition: CastAndCall.h:38
vtkm::worklet::GradientOutputFields::GetComputeDivergence
bool GetComputeDivergence() const
Definition: worklet/Gradient.h:182
vtkm::worklet::GradientOutputFields::ComputeQCriterion
bool ComputeQCriterion
Definition: worklet/Gradient.h:226
CellGradient.h
UnknownCellSet.h
vtkm::cont::CellSetStructured< 3 >
vtkm::worklet::GradientOutputFields::ValueType
T ValueType
Definition: worklet/Gradient.h:145
Instantiations.h
vtkm::cont::StorageTagSOA
Definition: ArrayHandleSOA.h:124
vtkm::worklet::gradient::DeducedPointGrad::Result
GradientOutputFields< T > * Result
Definition: worklet/Gradient.h:122
vtkm::worklet::GradientOutputFields::GetComputeQCriterion
bool GetComputeQCriterion() const
Definition: worklet/Gradient.h:194
vtkm::worklet::gradient::DeducedPointGrad::Go
void Go(const vtkm::cont::CellSetStructured< 2 > &cellset) const
Definition: worklet/Gradient.h:99
DispatcherPointNeighborhood.h
vtkm::cont::CellSetSingleType
Definition: CastAndCall.h:34
vtkm::cont::StorageTagCartesianProduct
Definition: ArrayHandleCartesianProduct.h:159
vtkm::worklet::GradientOutputFields::BaseTType
typename vtkm::VecTraits< T >::BaseComponentType BaseTType
Definition: worklet/Gradient.h:146
vtkm::Vec3f_32
vtkm::Vec< vtkm::Float32, 3 > Vec3f_32
Vec3f_32 corresponds to a 3-dimensional vector of 32-bit floating point values.
Definition: Types.h:1020
PointGradient.h
vtkm::worklet::gradient::DeducedPointGrad::Points
const CoordinateSystem *const Points
Definition: worklet/Gradient.h:120
vtkm::cont::UnknownCellSet
A CellSet of an unknown type.
Definition: UnknownCellSet.h:48
vtkm::cont::CastAndCall
void CastAndCall(const DynamicObject &dynamicObject, Functor &&f, Args &&... args)
A Generic interface to CastAndCall.
Definition: CastAndCall.h:47
CoordinateSystem.h
vtkm::worklet::GradientOutputFields::Gradient
vtkm::cont::ArrayHandle< vtkm::Vec< T, 3 > > Gradient
Definition: worklet/Gradient.h:217
vtkm::worklet::GradientOutputFields::Vorticity
vtkm::cont::ArrayHandle< vtkm::Vec< BaseTType, 3 > > Vorticity
Definition: worklet/Gradient.h:219
vtkm::VecTraits::BaseComponentType
typename vtkm::VecTraits< ComponentType >::BaseComponentType BaseComponentType
Base component type in the vector.
Definition: VecTraits.h:80
vtkm::worklet::gradient::DeducedPointGrad::DeducedPointGrad
DeducedPointGrad(const CoordinateSystem &coords, const vtkm::cont::ArrayHandle< T, S > &field, GradientOutputFields< T > *result)
Definition: worklet/Gradient.h:56
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::GradientOutputFields::GetComputeGradient
bool GetComputeGradient() const
Definition: worklet/Gradient.h:200
vtkm::worklet::GradientOutputFields::ComputeVorticity
bool ComputeVorticity
Definition: worklet/Gradient.h:225
vtkm::cont::CoordinateSystem
Definition: CoordinateSystem.h:25
vtkm::worklet::gradient::DeducedPointGrad::operator=
void operator=(const DeducedPointGrad< CoordinateSystem, T, S > &)=delete
ArrayHandleUniformPointCoordinates.h
vtkm::Vec3f_64
vtkm::Vec< vtkm::Float64, 3 > Vec3f_64
Vec3f_64 corresponds to a 3-dimensional vector of 64-bit floating point values.
Definition: Types.h:1026
ArrayHandleSOA.h
GradientOutput.h
vtkm::worklet::CellGradient
Definition: worklet/Gradient.h:246
vtkm::worklet::gradient::DeducedPointGrad::operator()
void operator()(const CellSetType &cellset) const
Definition: worklet/Gradient.h:133
Vorticity.h
vtkm::worklet::CellGradient::Run
static vtkm::cont::ArrayHandle< vtkm::Vec< T, 3 > > Run(const CellSetType &cells, const CoordinateSystem &coords, const vtkm::cont::ArrayHandle< T, S > &field, GradientOutputFields< T > &extraOutput)
Definition: worklet/Gradient.h:260
vtkm::worklet::DispatcherMapTopology
Dispatcher for worklets that inherit from WorkletMapTopology.
Definition: DispatcherMapTopology.h:31
Divergence.h
vtkm::worklet::GradientOutputFields
Definition: worklet/Gradient.h:47
vtkm::cont::StorageTagUniformPoints
Definition: ArrayHandleUniformPointCoordinates.h:22
VTKM_INSTANTIATION_END
#define VTKM_INSTANTIATION_END
Definition: Instantiations.h:48
ArrayHandleCartesianProduct.h
vtkm::worklet::GradientOutputFields::GradientOutputFields
GradientOutputFields()
Definition: worklet/Gradient.h:154
vtkm::worklet::GradientOutputFields::StoreGradient
bool StoreGradient
Definition: worklet/Gradient.h:223
vtkm::worklet::GradientOutputFields::SetComputeQCriterion
void SetComputeQCriterion(bool enable)
Add Q-criterion field to the output data.
Definition: worklet/Gradient.h:193
vtkm::worklet::GradientOutputFields::Divergence
vtkm::cont::ArrayHandle< BaseTType > Divergence
Definition: worklet/Gradient.h:218
Transpose.h
vtkm::worklet::GradientOutputFields::SetComputeGradient
void SetComputeGradient(bool enable)
Add gradient field to the output data.
Definition: worklet/Gradient.h:199
vtkm::Vec3f
vtkm::Vec< vtkm::FloatDefault, 3 > Vec3f
Vec3f corresponds to a 3-dimensional vector of floating point values.
Definition: Types.h:1014
vtkm::cont::ExecutionObjectBase
Base ExecutionObjectBase for execution objects to inherit from so that you can use an arbitrary objec...
Definition: ExecutionObjectBase.h:31
vtkm::Vec< vtkm::Float32, 3 >
vtkm::worklet::GradientOutputFields::ExecutionTypes
Definition: worklet/Gradient.h:149
vtkm::exec::GradientOutput
Definition: GradientOutput.h:237
vtkm::worklet::gradient::DeducedPointGrad::Go
void Go(const vtkm::cont::CellSetPermutation< vtkm::cont::CellSetStructured< 2 >, PermIterType > &cellset) const
Definition: worklet/Gradient.h:109
vtkm::worklet::GradientOutputFields::SetComputeDivergence
void SetComputeDivergence(bool enable)
Add divergence field to the output data.
Definition: worklet/Gradient.h:181
vtkm::worklet::gradient::DeducedPointGrad::Go
void Go(const vtkm::cont::CellSetPermutation< vtkm::cont::CellSetStructured< 3 >, PermIterType > &cellset) const
Definition: worklet/Gradient.h:89
vtkm::worklet::GradientOutputFields::GetComputeVorticity
bool GetComputeVorticity() const
Definition: worklet/Gradient.h:188
vtkm::cont::CellSetExplicit
Definition: CastAndCall.h:36
vtkm::worklet::PointGradient::Run
vtkm::cont::ArrayHandle< vtkm::Vec< T, 3 > > Run(const CellSetType &cells, const CoordinateSystem &coords, const vtkm::cont::ArrayHandle< T, S > &field, GradientOutputFields< T > &extraOutput)
Definition: worklet/Gradient.h:232
vtkm::worklet::GradientOutputFields::SetComputeVorticity
void SetComputeVorticity(bool enable)
Add voriticity/curl field to the output data.
Definition: worklet/Gradient.h:187
vtkm::Float32
float Float32
Definition: Types.h:154
vtkm::worklet::DispatcherPointNeighborhood
Dispatcher for worklets that inherit from WorkletPointNeighborhood.
Definition: DispatcherPointNeighborhood.h:26
vtkm::cont::StorageTagBasic
A tag for the basic implementation of a Storage object.
Definition: ArrayHandle.h:45
vtkm::Float64
double Float64
Definition: Types.h:155
vtkm::worklet::gradient::DeducedPointGrad
Definition: worklet/Gradient.h:54
QCriterion.h
vtkm::worklet::gradient::DeducedPointGrad::Go
void Go(const CellSetType &cellset) const
Definition: worklet/Gradient.h:69
DispatcherMapTopology.h
vtkm::worklet::gradient::DeducedPointGrad::Field
const vtkm::cont::ArrayHandle< T, S > *const Field
Definition: worklet/Gradient.h:121
vtkm::worklet::gradient::DeducedPointGrad::Go
void Go(const vtkm::cont::CellSetStructured< 3 > &cellset) const
Definition: worklet/Gradient.h:79
VTKM_INSTANTIATION_BEGIN
#define VTKM_INSTANTIATION_BEGIN
The following empty macros are instantiation delimiters used by vtk_add_instantiations at CMake/VTKmW...
Definition: Instantiations.h:47
StructuredPointGradient.h
vtkm::worklet::GradientOutputFields::QCriterion
vtkm::cont::ArrayHandle< BaseTType > QCriterion
Definition: worklet/Gradient.h:220