VTK-m  2.0
Particles.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_filter_flow_worklet_Particles_h
12 #define vtk_m_filter_flow_worklet_Particles_h
13 
16 
17 namespace vtkm
18 {
19 namespace worklet
20 {
21 namespace flow
22 {
23 
24 template <typename ParticleType>
26 {
27 public:
30  : Particles()
31  , MaxSteps(0)
32  {
33  }
34 
36  vtkm::Id maxSteps,
38  vtkm::cont::Token& token)
39  {
40  Particles = particleArray.PrepareForInPlace(device, token);
41  MaxSteps = maxSteps;
42  }
43 
44  VTKM_EXEC
45  ParticleType GetParticle(const vtkm::Id& idx) { return this->Particles.Get(idx); }
46 
47  VTKM_EXEC
48  void PreStepUpdate(const vtkm::Id& vtkmNotUsed(idx)) {}
49 
50  VTKM_EXEC
51  void StepUpdate(const vtkm::Id& idx,
52  const ParticleType& particle,
53  vtkm::FloatDefault time,
54  const vtkm::Vec3f& pt)
55  {
56  ParticleType newParticle(particle);
57  newParticle.SetPosition(pt);
58  newParticle.SetTime(time);
59  newParticle.SetNumberOfSteps(particle.GetNumberOfSteps() + 1);
60  this->Particles.Set(idx, newParticle);
61  }
62 
63  VTKM_EXEC
64  void StatusUpdate(const vtkm::Id& idx,
66  vtkm::Id maxSteps)
67  {
68  ParticleType p(this->GetParticle(idx));
69 
70  if (p.GetNumberOfSteps() == maxSteps)
71  p.GetStatus().SetTerminate();
72 
73  if (status.CheckFail())
74  p.GetStatus().SetFail();
75  if (status.CheckSpatialBounds())
76  p.GetStatus().SetSpatialBounds();
77  if (status.CheckTemporalBounds())
78  p.GetStatus().SetTemporalBounds();
79  if (status.CheckInGhostCell())
80  p.GetStatus().SetInGhostCell();
81  if (status.CheckZeroVelocity())
82  {
83  p.GetStatus().SetZeroVelocity();
84  p.GetStatus().SetTerminate();
85  }
86 
87  this->Particles.Set(idx, p);
88  }
89 
90  VTKM_EXEC
91  bool CanContinue(const vtkm::Id& idx) { return this->GetParticle(idx).GetStatus().CanContinue(); }
92 
93  VTKM_EXEC
94  void UpdateTookSteps(const vtkm::Id& idx, bool val)
95  {
96  ParticleType p(this->GetParticle(idx));
97  if (val)
98  p.GetStatus().SetTookAnySteps();
99  else
100  p.GetStatus().ClearTookAnySteps();
101  this->Particles.Set(idx, p);
102  }
103 
104 protected:
106 
109 };
110 
111 template <typename ParticleType>
113 {
114 public:
117  vtkm::cont::Token& token) const
118  {
120  this->ParticleArray, this->MaxSteps, device, token);
121  }
122 
123  VTKM_CONT
125  : ParticleArray(pArray)
126  , MaxSteps(maxSteps)
127  {
128  }
129 
131 
132 protected:
135 };
136 
137 
138 template <typename ParticleType>
140 {
141 public:
144  : ParticleExecutionObject<ParticleType>()
145  , History()
146  , Length(0)
147  , StepCount()
148  , ValidPoint()
149  {
150  }
151 
154  vtkm::cont::ArrayHandle<vtkm::Id> validPointArray,
155  vtkm::cont::ArrayHandle<vtkm::Id> stepCountArray,
156  vtkm::Id maxSteps,
158  vtkm::cont::Token& token)
159  : ParticleExecutionObject<ParticleType>(pArray, maxSteps, device, token)
160  , Length(maxSteps + 1)
161  {
162  vtkm::Id numPos = pArray.GetNumberOfValues();
163  History = historyArray.PrepareForOutput(numPos * Length, device, token);
164  ValidPoint = validPointArray.PrepareForInPlace(device, token);
165  StepCount = stepCountArray.PrepareForInPlace(device, token);
166  }
167 
168  VTKM_EXEC
169  void PreStepUpdate(const vtkm::Id& idx)
170  {
171  ParticleType p = this->ParticleExecutionObject<ParticleType>::GetParticle(idx);
172  if (this->StepCount.Get(idx) == 0)
173  {
174  vtkm::Id loc = idx * Length;
175  this->History.Set(loc, p.GetPosition());
176  this->ValidPoint.Set(loc, 1);
177  this->StepCount.Set(idx, 1);
178  }
179  }
180 
181  VTKM_EXEC
182  void StepUpdate(const vtkm::Id& idx,
183  const ParticleType& particle,
184  vtkm::FloatDefault time,
185  const vtkm::Vec3f& pt)
186  {
187  this->ParticleExecutionObject<ParticleType>::StepUpdate(idx, particle, time, pt);
188  //local step count.
189  vtkm::Id stepCount = this->StepCount.Get(idx);
190  vtkm::Id loc = idx * Length + stepCount;
191  this->History.Set(loc, pt);
192  this->ValidPoint.Set(loc, 1);
193  this->StepCount.Set(idx, stepCount + 1);
194  }
195 
196 protected:
199 
204 };
205 
206 template <typename ParticleType>
208 {
209 public:
210  //Helper functor for compacting history
211  struct IsOne
212  {
213  template <typename T>
214  VTKM_EXEC_CONT bool operator()(const T& x) const
215  {
216  return x == T(1);
217  }
218  };
219 
220 
223  {
225  this->ParticleArray,
226  this->HistoryArray,
227  this->ValidPointArray,
228  this->StepCountArray,
229  this->MaxSteps,
230  device,
231  token);
232  }
233  VTKM_CONT
235  : MaxSteps(maxSteps)
236  , ParticleArray(pArray)
237  {
238  vtkm::Id numParticles = static_cast<vtkm::Id>(pArray.GetNumberOfValues());
239 
240  //Create ValidPointArray initialized to zero.
241  vtkm::cont::ArrayHandleConstant<vtkm::Id> tmp(0, (this->MaxSteps + 1) * numParticles);
243 
244  //Create StepCountArray initialized to zero.
245  vtkm::cont::ArrayHandleConstant<vtkm::Id> tmp2(0, numParticles);
247  }
248 
249  VTKM_CONT
252  vtkm::cont::ArrayHandle<vtkm::Id>& validPointArray,
253  vtkm::Id& maxSteps)
254  {
255  ParticleArray = pArray;
256  HistoryArray = historyArray;
257  ValidPointArray = validPointArray;
258  MaxSteps = maxSteps;
259  }
260 
261  VTKM_CONT
263  {
265  }
266 
267 protected:
273 };
274 
275 
276 }
277 }
278 } //vtkm::worklet::flow
279 
280 #endif // vtk_m_filter_flow_worklet_Particles_h
281 //============================================================================
vtkm::cont::ArrayHandle::GetNumberOfValues
VTKM_CONT vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:448
vtkm::worklet::flow::IntegratorStatus::CheckZeroVelocity
VTKM_EXEC_CONT bool CheckZeroVelocity() const
Definition: IntegratorStatus.h:75
vtkm::worklet::flow::ParticleExecutionObject::ParticleExecutionObject
ParticleExecutionObject(vtkm::cont::ArrayHandle< ParticleType > particleArray, vtkm::Id maxSteps, vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token)
Definition: Particles.h:35
vtkm::cont::ArrayHandle< ParticleType >
vtkm::worklet::flow::ParticleExecutionObject::ParticleExecutionObject
VTKM_EXEC_CONT ParticleExecutionObject()
Definition: Particles.h:29
vtkm::worklet::flow::ParticleExecutionObject::StatusUpdate
VTKM_EXEC void StatusUpdate(const vtkm::Id &idx, const vtkm::worklet::flow::IntegratorStatus &status, vtkm::Id maxSteps)
Definition: Particles.h:64
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::ParticleExecutionObject::GetParticle
VTKM_EXEC ParticleType GetParticle(const vtkm::Id &idx)
Definition: Particles.h:45
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::worklet::flow::StateRecordingParticles::PrepareForExecution
VTKM_CONT vtkm::worklet::flow::StateRecordingParticleExecutionObject< ParticleType > PrepareForExecution(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Definition: Particles.h:222
vtkm::worklet::flow::ParticleExecutionObject::PreStepUpdate
VTKM_EXEC void PreStepUpdate(const vtkm::Id &vtkmNotUsed(idx))
Definition: Particles.h:48
vtkm::worklet::flow::StateRecordingParticles::IsOne::operator()
VTKM_EXEC_CONT bool operator()(const T &x) const
Definition: Particles.h:214
vtkm::worklet::flow::Particles
Definition: Particles.h:112
vtkm::worklet::flow::StateRecordingParticleExecutionObject::IdPortal
typename vtkm::cont::ArrayHandle< vtkm::Id >::WritePortalType IdPortal
Definition: Particles.h:197
vtkm::worklet::flow::StateRecordingParticleExecutionObject::PreStepUpdate
VTKM_EXEC void PreStepUpdate(const vtkm::Id &idx)
Definition: Particles.h:169
vtkm::worklet::flow::IntegratorStatus::CheckSpatialBounds
VTKM_EXEC_CONT bool CheckSpatialBounds() const
Definition: IntegratorStatus.h:67
vtkm::worklet::flow::StateRecordingParticleExecutionObject::StateRecordingParticleExecutionObject
StateRecordingParticleExecutionObject(vtkm::cont::ArrayHandle< ParticleType > pArray, vtkm::cont::ArrayHandle< vtkm::Vec3f > historyArray, vtkm::cont::ArrayHandle< vtkm::Id > validPointArray, vtkm::cont::ArrayHandle< vtkm::Id > stepCountArray, vtkm::Id maxSteps, vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token)
Definition: Particles.h:152
vtkm::worklet::flow::StateRecordingParticles::ParticleArray
vtkm::cont::ArrayHandle< ParticleType > ParticleArray
Definition: Particles.h:270
vtkm::cont::ArrayHandle::PrepareForInPlace
VTKM_CONT WritePortalType PrepareForInPlace(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Prepares this array to be used in an in-place operation (both as input and output) in the execution e...
Definition: ArrayHandle.h:593
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::flow::StateRecordingParticleExecutionObject::History
HistoryPortal History
Definition: Particles.h:200
vtkm::worklet::flow::StateRecordingParticleExecutionObject::HistoryPortal
typename vtkm::cont::ArrayHandle< vtkm::Vec3f >::WritePortalType HistoryPortal
Definition: Particles.h:198
vtkm::worklet::flow::Particles::Particles
VTKM_CONT Particles(vtkm::cont::ArrayHandle< ParticleType > &pArray, vtkm::Id &maxSteps)
Definition: Particles.h:124
vtkm::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
vtkm::worklet::flow::StateRecordingParticles::StepCountArray
vtkm::cont::ArrayHandle< vtkm::Id > StepCountArray
Definition: Particles.h:271
vtkm::worklet::flow::ParticleExecutionObject::StepUpdate
VTKM_EXEC void StepUpdate(const vtkm::Id &idx, const ParticleType &particle, vtkm::FloatDefault time, const vtkm::Vec3f &pt)
Definition: Particles.h:51
vtkm::worklet::flow::Particles::PrepareForExecution
VTKM_CONT vtkm::worklet::flow::ParticleExecutionObject< ParticleType > PrepareForExecution(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Definition: Particles.h:115
vtkm::worklet::flow::IntegratorStatus::CheckFail
VTKM_EXEC_CONT bool CheckFail() const
Definition: IntegratorStatus.h:64
vtkm::worklet::flow::StateRecordingParticleExecutionObject::StateRecordingParticleExecutionObject
VTKM_EXEC_CONT StateRecordingParticleExecutionObject()
Definition: Particles.h:143
vtkm::worklet::flow::Particles::ParticleArray
vtkm::cont::ArrayHandle< ParticleType > ParticleArray
Definition: Particles.h:133
vtkm::worklet::flow::StateRecordingParticles::StateRecordingParticles
VTKM_CONT StateRecordingParticles(vtkm::cont::ArrayHandle< ParticleType > &pArray, const vtkm::Id &maxSteps)
Definition: Particles.h:234
vtkm::worklet::flow::ParticleExecutionObject
Definition: Particles.h:25
vtkm::worklet::flow::StateRecordingParticleExecutionObject::StepUpdate
VTKM_EXEC void StepUpdate(const vtkm::Id &idx, const ParticleType &particle, vtkm::FloatDefault time, const vtkm::Vec3f &pt)
Definition: Particles.h:182
vtkm::worklet::flow::StateRecordingParticleExecutionObject
Definition: Particles.h:139
vtkm::worklet::flow::IntegratorStatus
Definition: IntegratorStatus.h:33
vtkm::worklet::flow::IntegratorStatus::CheckInGhostCell
VTKM_EXEC_CONT bool CheckInGhostCell() const
Definition: IntegratorStatus.h:73
vtkm::cont::ArrayCopy
void ArrayCopy(const SourceArrayType &source, DestArrayType &destination)
Does a deep copy from one array to another array.
Definition: ArrayCopy.h:142
vtkm::cont::Algorithm::CopyIf
static VTKM_CONT void CopyIf(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, const vtkm::cont::ArrayHandle< U, CStencil > &stencil, vtkm::cont::ArrayHandle< T, COut > &output)
Definition: Algorithm.h:435
vtkm::worklet::flow::StateRecordingParticles::ValidPointArray
vtkm::cont::ArrayHandle< vtkm::Id > ValidPointArray
Definition: Particles.h:272
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::ArrayHandle::WritePortalType
typename StorageType::WritePortalType WritePortalType
Definition: ArrayHandle.h:295
vtkm::cont::ArrayHandleConstant
An array handle with a constant value.
Definition: ArrayHandleConstant.h:63
vtkm::worklet::flow::StateRecordingParticleExecutionObject::StepCount
IdPortal StepCount
Definition: Particles.h:202
vtkm::worklet::flow::Particles::Particles
Particles()
Definition: Particles.h:130
vtkm::worklet::flow::StateRecordingParticles::MaxSteps
vtkm::Id MaxSteps
Definition: Particles.h:269
vtkmNotUsed
#define vtkmNotUsed(parameter_name)
Simple macro to identify a parameter as unused.
Definition: ExportMacros.h:128
vtkm::worklet::flow::StateRecordingParticleExecutionObject::Length
vtkm::Id Length
Definition: Particles.h:201
vtkm::worklet::flow::StateRecordingParticles::IsOne
Definition: Particles.h:211
vtkm::worklet::flow::ParticleExecutionObject::CanContinue
VTKM_EXEC bool CanContinue(const vtkm::Id &idx)
Definition: Particles.h:91
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::Vec< vtkm::FloatDefault, 3 >
vtkm::FloatDefault
vtkm::Float32 FloatDefault
The floating point type to use when no other precision is specified.
Definition: Types.h:198
vtkm::worklet::flow::Particles::MaxSteps
vtkm::Id MaxSteps
Definition: Particles.h:134
vtkm::worklet::flow::ParticleExecutionObject::MaxSteps
vtkm::Id MaxSteps
Definition: Particles.h:108
vtkm::cont::ArrayHandle::PrepareForOutput
VTKM_CONT WritePortalType PrepareForOutput(vtkm::Id numberOfValues, vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Prepares (allocates) this array to be used as an output from an operation in the execution environmen...
Definition: ArrayHandle.h:613
vtkm::worklet::flow::IntegratorStatus::CheckTemporalBounds
VTKM_EXEC_CONT bool CheckTemporalBounds() const
Definition: IntegratorStatus.h:70
vtkm::worklet::flow::ParticleExecutionObject::ParticlePortal
typename vtkm::cont::ArrayHandle< ParticleType >::WritePortalType ParticlePortal
Definition: Particles.h:105
vtkm::worklet::flow::StateRecordingParticles
Definition: Particles.h:207
vtkm::worklet::flow::StateRecordingParticleExecutionObject::ValidPoint
IdPortal ValidPoint
Definition: Particles.h:203
IntegratorStatus.h
ExecutionObjectBase.h
vtkm::worklet::flow::ParticleExecutionObject::UpdateTookSteps
VTKM_EXEC void UpdateTookSteps(const vtkm::Id &idx, bool val)
Definition: Particles.h:94
vtkm::worklet::flow::StateRecordingParticles::GetCompactedHistory
VTKM_CONT void GetCompactedHistory(vtkm::cont::ArrayHandle< vtkm::Vec3f > &positions)
Definition: Particles.h:262
vtkm::worklet::flow::StateRecordingParticles::HistoryArray
vtkm::cont::ArrayHandle< vtkm::Vec3f > HistoryArray
Definition: Particles.h:268
vtkm::worklet::flow::ParticleExecutionObject::Particles
ParticlePortal Particles
Definition: Particles.h:107
vtkm::worklet::flow::StateRecordingParticles::StateRecordingParticles
VTKM_CONT StateRecordingParticles(vtkm::cont::ArrayHandle< ParticleType > &pArray, vtkm::cont::ArrayHandle< vtkm::Vec3f > &historyArray, vtkm::cont::ArrayHandle< vtkm::Id > &validPointArray, vtkm::Id &maxSteps)
Definition: Particles.h:250