VTK-m  2.0
filter/flow/worklet/Field.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 vtkm_filter_flow_worklet_Field_h
12 #define vtkm_filter_flow_worklet_Field_h
13 
14 #include <vtkm/Types.h>
15 
16 #include <vtkm/VecVariable.h>
17 #include <vtkm/cont/ArrayHandle.h>
20 
21 namespace vtkm
22 {
23 namespace worklet
24 {
25 namespace flow
26 {
27 
28 template <typename FieldArrayType>
30 {
31 public:
32  using FieldPortalType = typename FieldArrayType::ReadPortalType;
34 
35  VTKM_CONT
36  ExecutionVelocityField(const FieldArrayType& velocityValues,
37  const Association assoc,
39  vtkm::cont::Token& token)
40  : VelocityValues(velocityValues.PrepareForInput(device, token))
41  , Assoc(assoc)
42  {
43  }
44 
45  VTKM_EXEC Association GetAssociation() const { return this->Assoc; }
46 
48  {
50 
51  vtkm::Vec3f velocity = VelocityValues.Get(cellId);
52  value = vtkm::make_Vec(velocity);
53  }
54 
56  const vtkm::Id vertices,
57  const vtkm::Vec3f& parametric,
58  const vtkm::UInt8 cellShape,
60  {
62 
63  vtkm::Vec3f velocityInterp;
65  for (vtkm::IdComponent i = 0; i < vertices; i++)
66  velocities.Append(VelocityValues.Get(indices[i]));
67  vtkm::exec::CellInterpolate(velocities, parametric, cellShape, velocityInterp);
68  value = vtkm::make_Vec(velocityInterp);
69  }
70 
71 private:
74 };
75 
76 template <typename FieldArrayType>
78 {
79 public:
80  using FieldPortalType = typename FieldArrayType::ReadPortalType;
82 
83  VTKM_CONT
84  ExecutionElectroMagneticField(const FieldArrayType& electricValues,
85  const FieldArrayType& magneticValues,
86  const Association assoc,
88  vtkm::cont::Token& token)
89  : ElectricValues(electricValues.PrepareForInput(device, token))
90  , MagneticValues(magneticValues.PrepareForInput(device, token))
91  , Assoc(assoc)
92  {
93  }
94 
95  VTKM_EXEC Association GetAssociation() const { return this->Assoc; }
96 
98  {
100 
101  auto electric = this->ElectricValues.Get(cellId);
102  auto magnetic = this->MagneticValues.Get(cellId);
103  value = vtkm::make_Vec(electric, magnetic);
104  }
105 
107  const vtkm::Id vertices,
108  const vtkm::Vec3f& parametric,
109  const vtkm::UInt8 cellShape,
111  {
113 
114  vtkm::Vec3f electricInterp, magneticInterp;
117  for (vtkm::IdComponent i = 0; i < vertices; i++)
118  {
119  electric.Append(ElectricValues.Get(indices[i]));
120  magnetic.Append(MagneticValues.Get(indices[i]));
121  }
122  vtkm::exec::CellInterpolate(electric, parametric, cellShape, electricInterp);
123  vtkm::exec::CellInterpolate(magnetic, parametric, cellShape, magneticInterp);
124  value = vtkm::make_Vec(electricInterp, magneticInterp);
125  }
126 
127 private:
131 };
132 
133 template <typename FieldArrayType>
135 {
136 public:
139 
140  VTKM_CONT
141  VelocityField() = default;
142 
143  VTKM_CONT
144  VelocityField(const FieldArrayType& fieldValues)
145  : FieldValues(fieldValues)
146  , Assoc(vtkm::cont::Field::Association::Points)
147  {
148  }
149 
150  VTKM_CONT
151  VelocityField(const FieldArrayType& fieldValues, const Association assoc)
152  : FieldValues(fieldValues)
153  , Assoc(assoc)
154  {
155  if (assoc != Association::Points && assoc != Association::Cells)
156  throw("Unsupported field association");
157  }
158 
159  VTKM_CONT
161  vtkm::cont::Token& token) const
162  {
163  return ExecutionType(this->FieldValues, this->Assoc, device, token);
164  }
165 
166 private:
167  FieldArrayType FieldValues;
169 };
170 
171 template <typename FieldArrayType>
173 {
174 public:
177 
178  VTKM_CONT
179  ElectroMagneticField() = default;
180 
181  VTKM_CONT
182  ElectroMagneticField(const FieldArrayType& electricField, const FieldArrayType& magneticField)
183  : ElectricField(electricField)
184  , MagneticField(magneticField)
185  , Assoc(vtkm::cont::Field::Association::Points)
186  {
187  }
188 
189  VTKM_CONT
190  ElectroMagneticField(const FieldArrayType& electricField,
191  const FieldArrayType& magneticField,
192  const Association assoc)
193  : ElectricField(electricField)
194  , MagneticField(magneticField)
195  , Assoc(assoc)
196  {
197  }
198 
199  VTKM_CONT
201  vtkm::cont::Token& token) const
202  {
203  return ExecutionType(this->ElectricField, this->MagneticField, this->Assoc, device, token);
204  }
205 
206 private:
207  FieldArrayType ElectricField;
208  FieldArrayType MagneticField;
210 };
211 
212 }
213 }
214 } //vtkm::worklet::flow
215 
216 #endif //vtkm_filter_flow_worklet_Field_h
ArrayHandle.h
vtkm::worklet::flow::ExecutionElectroMagneticField::FieldPortalType
typename FieldArrayType::ReadPortalType FieldPortalType
Definition: filter/flow/worklet/Field.h:80
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::flow::ExecutionElectroMagneticField::GetAssociation
VTKM_EXEC Association GetAssociation() const
Definition: filter/flow/worklet/Field.h:95
Types.h
vtkm::worklet::flow::VelocityField::FieldValues
FieldArrayType FieldValues
Definition: filter/flow/worklet/Field.h:167
VTKM_ASSERT
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::worklet::flow::ExecutionVelocityField::GetValue
VTKM_EXEC void GetValue(const vtkm::VecVariable< vtkm::Id, 8 > &indices, const vtkm::Id vertices, const vtkm::Vec3f &parametric, const vtkm::UInt8 cellShape, vtkm::VecVariable< vtkm::Vec3f, 2 > &value) const
Definition: filter/flow/worklet/Field.h:55
vtkm::worklet::flow::VelocityField::VelocityField
VTKM_CONT VelocityField(const FieldArrayType &fieldValues)
Definition: filter/flow/worklet/Field.h:144
vtkm::worklet::flow::ExecutionVelocityField::ExecutionVelocityField
VTKM_CONT ExecutionVelocityField(const FieldArrayType &velocityValues, const Association assoc, vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token)
Definition: filter/flow/worklet/Field.h:36
vtkm::cont::Field::Association
Association
Definition: cont/Field.h:34
vtkm::worklet::flow::ExecutionElectroMagneticField::GetValue
VTKM_EXEC void GetValue(const vtkm::VecVariable< vtkm::Id, 8 > &indices, const vtkm::Id vertices, const vtkm::Vec3f &parametric, const vtkm::UInt8 cellShape, vtkm::VecVariable< vtkm::Vec3f, 2 > &value) const
Definition: filter/flow/worklet/Field.h:106
vtkm::worklet::flow::ElectroMagneticField::Assoc
Association Assoc
Definition: filter/flow/worklet/Field.h:209
vtkm::worklet::flow::ExecutionElectroMagneticField::ElectricValues
FieldPortalType ElectricValues
Definition: filter/flow/worklet/Field.h:128
vtkm::worklet::flow::ElectroMagneticField
Definition: filter/flow/worklet/Field.h:172
CellInterpolate.h
vtkm::worklet::flow::VelocityField::PrepareForExecution
const VTKM_CONT ExecutionType PrepareForExecution(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Definition: filter/flow/worklet/Field.h:160
vtkm::worklet::flow::ExecutionElectroMagneticField::MagneticValues
FieldPortalType MagneticValues
Definition: filter/flow/worklet/Field.h:129
vtkm::worklet::flow::ExecutionElectroMagneticField::Assoc
Association Assoc
Definition: filter/flow/worklet/Field.h:130
vtkm::worklet::flow::VelocityField::VelocityField
VTKM_CONT VelocityField()=default
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::flow::ExecutionElectroMagneticField::GetValue
VTKM_EXEC void GetValue(const vtkm::Id cellId, vtkm::VecVariable< vtkm::Vec3f, 2 > &value) const
Definition: filter/flow/worklet/Field.h:97
vtkm::worklet::flow::ExecutionVelocityField
Definition: filter/flow/worklet/Field.h:29
vtkm::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
vtkm::VecVariable::Append
VTKM_EXEC_CONT void Append(ComponentType value)
Definition: VecVariable.h:80
vtkm::VecVariable
A short variable-length array with maximum length.
Definition: VecVariable.h:30
vtkm::worklet::flow::ExecutionVelocityField::FieldPortalType
typename FieldArrayType::ReadPortalType FieldPortalType
Definition: filter/flow/worklet/Field.h:32
vtkm::worklet::flow::ExecutionVelocityField::GetAssociation
VTKM_EXEC Association GetAssociation() const
Definition: filter/flow/worklet/Field.h:45
vtkm::cont::Field::Association::Points
@ Points
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::exec::CellInterpolate
VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType &pointFieldValues, const vtkm::Vec< ParametricCoordType, 3 > &pcoords, CellShapeTag tag, typename FieldVecType::ComponentType &result)
Definition: CellInterpolate.h:56
vtkm::worklet::flow::ExecutionVelocityField::Assoc
Association Assoc
Definition: filter/flow/worklet/Field.h:73
vtkm::worklet::flow::ExecutionElectroMagneticField
Definition: filter/flow/worklet/Field.h:77
vtkm::UInt8
uint8_t UInt8
Definition: Types.h:157
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::worklet::flow::VelocityField::ExecutionType
ExecutionVelocityField< FieldArrayType > ExecutionType
Definition: filter/flow/worklet/Field.h:137
vtkm::worklet::flow::ExecutionVelocityField::GetValue
VTKM_EXEC void GetValue(const vtkm::Id cellId, vtkm::VecVariable< vtkm::Vec3f, 2 > &value) const
Definition: filter/flow/worklet/Field.h:47
vtkm::cont::ExecutionObjectBase
Base ExecutionObjectBase for execution objects to inherit from so that you can use an arbitrary objec...
Definition: ExecutionObjectBase.h:31
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
vtkm::worklet::flow::ElectroMagneticField::ExecutionType
ExecutionElectroMagneticField< FieldArrayType > ExecutionType
Definition: filter/flow/worklet/Field.h:175
vtkm::Vec< vtkm::FloatDefault, 3 >
vtkm::worklet::flow::ElectroMagneticField::ElectroMagneticField
VTKM_CONT ElectroMagneticField(const FieldArrayType &electricField, const FieldArrayType &magneticField)
Definition: filter/flow/worklet/Field.h:182
VecVariable.h
vtkm::worklet::flow::ElectroMagneticField::ElectroMagneticField
VTKM_CONT ElectroMagneticField()=default
vtkm::worklet::flow::ElectroMagneticField::ElectricField
FieldArrayType ElectricField
Definition: filter/flow/worklet/Field.h:207
vtkm::cont::Field::Association::Cells
@ Cells
vtkm::worklet::flow::ElectroMagneticField::ElectroMagneticField
VTKM_CONT ElectroMagneticField(const FieldArrayType &electricField, const FieldArrayType &magneticField, const Association assoc)
Definition: filter/flow/worklet/Field.h:190
vtkm::worklet::flow::VelocityField
Definition: filter/flow/worklet/Field.h:134
vtkm::worklet::flow::VelocityField::Assoc
Association Assoc
Definition: filter/flow/worklet/Field.h:168
ExecutionObjectBase.h
vtkm::worklet::flow::ElectroMagneticField::PrepareForExecution
const VTKM_CONT ExecutionType PrepareForExecution(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Definition: filter/flow/worklet/Field.h:200
vtkm::worklet::flow::ElectroMagneticField::MagneticField
FieldArrayType MagneticField
Definition: filter/flow/worklet/Field.h:208
vtkm::worklet::flow::ExecutionVelocityField::VelocityValues
FieldPortalType VelocityValues
Definition: filter/flow/worklet/Field.h:72
vtkm::worklet::flow::ExecutionElectroMagneticField::ExecutionElectroMagneticField
VTKM_CONT ExecutionElectroMagneticField(const FieldArrayType &electricValues, const FieldArrayType &magneticValues, const Association assoc, vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token)
Definition: filter/flow/worklet/Field.h:84
vtkm::worklet::flow::VelocityField::VelocityField
VTKM_CONT VelocityField(const FieldArrayType &fieldValues, const Association assoc)
Definition: filter/flow/worklet/Field.h:151