VTK-m  2.0
worklet/CellAverage.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_CellAverage_h
12 #define vtk_m_worklet_CellAverage_h
13 
15 
16 #include <vtkm/VecTraits.h>
17 
18 namespace vtkm
19 {
20 namespace worklet
21 {
22 
23 //simple functor that returns the average point value as a cell field
25 {
26 public:
27  using ControlSignature = void(CellSetIn cellset, FieldInPoint inPoints, FieldOutCell outCells);
28  using ExecutionSignature = void(PointCount, _2, _3);
29  using InputDomain = _1;
30 
31  template <typename PointValueVecType, typename OutType>
32  VTKM_EXEC void operator()(const vtkm::IdComponent& numPoints,
33  const PointValueVecType& pointValues,
34  OutType& average) const
35  {
36  using PointValueType = typename PointValueVecType::ComponentType;
37 
38  using InVecSize =
39  std::integral_constant<vtkm::IdComponent, vtkm::VecTraits<PointValueType>::NUM_COMPONENTS>;
40  using OutVecSize =
41  std::integral_constant<vtkm::IdComponent, vtkm::VecTraits<OutType>::NUM_COMPONENTS>;
42  using SameLengthVectors = typename std::is_same<InVecSize, OutVecSize>::type;
43 
44  this->DoAverage(numPoints, pointValues, average, SameLengthVectors());
45  }
46 
47 private:
48  template <typename PointValueVecType, typename OutType>
49  VTKM_EXEC void DoAverage(const vtkm::IdComponent& numPoints,
50  const PointValueVecType& pointValues,
51  OutType& average,
52  std::true_type) const
53  {
54  using OutComponentType = typename vtkm::VecTraits<OutType>::ComponentType;
55  OutType sum = OutType(pointValues[0]);
56  for (vtkm::IdComponent pointIndex = 1; pointIndex < numPoints; ++pointIndex)
57  {
58  // OutType constructor is for when OutType is a Vec.
59  // static_cast is for when OutType is a small int that gets promoted to int32.
60  sum = static_cast<OutType>(sum + OutType(pointValues[pointIndex]));
61  }
62 
63  // OutType constructor is for when OutType is a Vec.
64  // static_cast is for when OutType is a small int that gets promoted to int32.
65  average = static_cast<OutType>(sum / OutType(static_cast<OutComponentType>(numPoints)));
66  }
67 
68  template <typename PointValueVecType, typename OutType>
70  const PointValueVecType& vtkmNotUsed(pointValues),
71  OutType& vtkmNotUsed(average),
72  std::false_type) const
73  {
74  this->RaiseError("CellAverage called with mismatched Vec sizes for CellAverage.");
75  }
76 };
77 }
78 } // namespace vtkm::worklet
79 
80 #endif // vtk_m_worklet_CellAverage_h
vtkm::worklet::CellAverage::DoAverage
VTKM_EXEC void DoAverage(const vtkm::IdComponent &numPoints, const PointValueVecType &pointValues, OutType &average, std::true_type) const
Definition: worklet/CellAverage.h:49
vtkm::worklet::CellAverage::ControlSignature
void(CellSetIn cellset, FieldInPoint inPoints, FieldOutCell outCells) ControlSignature
Definition: worklet/CellAverage.h:27
vtkm::worklet::CellAverage::DoAverage
VTKM_EXEC void DoAverage(const vtkm::IdComponent &vtkmNotUsed(numPoints), const PointValueVecType &vtkmNotUsed(pointValues), OutType &vtkmNotUsed(average), std::false_type) const
Definition: worklet/CellAverage.h:69
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::worklet::WorkletVisitCellsWithPoints::PointCount
IncidentElementCount PointCount
Definition: WorkletMapTopology.h:267
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::worklet::CellAverage::operator()
VTKM_EXEC void operator()(const vtkm::IdComponent &numPoints, const PointValueVecType &pointValues, OutType &average) const
Definition: worklet/CellAverage.h:32
vtkm::worklet::CellAverage::InputDomain
_1 InputDomain
Definition: worklet/CellAverage.h:29
vtkm::worklet::CellAverage
Definition: worklet/CellAverage.h:24
vtkm::worklet::WorkletVisitCellsWithPoints
Base class for worklets that map from Points to Cells.
Definition: WorkletMapTopology.h:255
vtkm::worklet::WorkletVisitCellsWithPoints::FieldInPoint
FieldInIncident FieldInPoint
Definition: WorkletMapTopology.h:259
vtkmNotUsed
#define vtkmNotUsed(parameter_name)
Simple macro to identify a parameter as unused.
Definition: ExportMacros.h:128
vtkm::VecTraits::ComponentType
typename VecType::ComponentType ComponentType
Type of the components in the vector.
Definition: VecTraits.h:73
WorkletMapTopology.h
vtkm::worklet::CellAverage::ExecutionSignature
void(PointCount, _2, _3) ExecutionSignature
Definition: worklet/CellAverage.h:28
VecTraits.h
vtkm::exec::FunctorBase::RaiseError
VTKM_EXEC void RaiseError(const char *message) const
Definition: FunctorBase.h:40
vtkm::worklet::WorkletVisitCellsWithPoints::FieldOutCell
FieldOut FieldOutCell
Definition: WorkletMapTopology.h:263