VTK-m  2.0
DataSetIntegratorUnsteadyState.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_internal_DataSetIntegratorUnsteadyState_h
12 #define vtk_m_filter_flow_internal_DataSetIntegratorUnsteadyState_h
13 
14 #include <vtkm/cont/ArrayCopy.h>
17 
18 namespace vtkm
19 {
20 namespace filter
21 {
22 namespace flow
23 {
24 namespace internal
25 {
26 
27 class DataSetIntegratorUnsteadyState
28  : public vtkm::filter::flow::internal::DataSetIntegrator<DataSetIntegratorUnsteadyState>
29 {
30 public:
31  DataSetIntegratorUnsteadyState(const vtkm::cont::DataSet& ds1,
32  const vtkm::cont::DataSet& ds2,
35  vtkm::Id id,
36  const vtkm::filter::flow::internal::DataSetIntegrator<
37  DataSetIntegratorUnsteadyState>::FieldNameType& fieldName,
41  : vtkm::filter::flow::internal::DataSetIntegrator<DataSetIntegratorUnsteadyState>(id,
42  fieldName,
43  solverType,
44  vecFieldType,
45  resultType)
46  , DataSet1(ds1)
47  , DataSet2(ds2)
48  , Time1(t1)
49  , Time2(t2)
50  {
51  }
52 
53  VTKM_CONT inline void DoAdvect(DSIHelperInfo<vtkm::Particle>& b,
54  vtkm::FloatDefault stepSize,
55  vtkm::Id maxSteps);
56 
57  VTKM_CONT inline void DoAdvect(DSIHelperInfo<vtkm::ChargedParticle>& b,
58  vtkm::FloatDefault stepSize,
59  vtkm::Id maxSteps);
60 
61 protected:
62  template <typename ArrayType>
63  VTKM_CONT void GetVelocityFields(
66  {
67  if (this->FieldName.GetIndex() == this->FieldName.GetIndexOf<VelocityFieldNameType>())
68  {
69  const auto& fieldNm = this->FieldName.Get<VelocityFieldNameType>();
70  auto assoc = this->DataSet1.GetField(fieldNm).GetAssociation();
71  if (assoc != this->DataSet2.GetField(fieldNm).GetAssociation())
73  "Unsteady state velocity fields have differnt associations");
74 
75  ArrayType arr1, arr2;
76  vtkm::cont::ArrayCopyShallowIfPossible(this->DataSet1.GetField(fieldNm).GetData(), arr1);
77  vtkm::cont::ArrayCopyShallowIfPossible(this->DataSet2.GetField(fieldNm).GetData(), arr2);
78 
79  velocityField1 = vtkm::worklet::flow::VelocityField<ArrayType>(arr1, assoc);
80  velocityField2 = vtkm::worklet::flow::VelocityField<ArrayType>(arr2, assoc);
81  }
82  else
83  throw vtkm::cont::ErrorFilterExecution("Velocity field vector type not available");
84  }
85 
86 private:
87  vtkm::cont::DataSet DataSet1;
88  vtkm::cont::DataSet DataSet2;
89  vtkm::FloatDefault Time1;
90  vtkm::FloatDefault Time2;
91 };
92 
93 
94 
95 namespace internal
96 {
97 using ArrayType = vtkm::cont::ArrayHandle<vtkm::Vec3f>;
98 using VelocityFieldType = vtkm::worklet::flow::VelocityField<ArrayType>;
100 
101 template <typename GridEvalType, typename ParticleType>
102 class AdvectHelper;
103 
104 template <typename ParticleType>
105 class AdvectHelper<UnsteadyStateGridEvalType, ParticleType>
106 {
107 public:
108  static void Advect(const VelocityFieldType& velField1,
109  const vtkm::cont::DataSet& ds1,
111  const VelocityFieldType& velField2,
112  const vtkm::cont::DataSet& ds2,
115  vtkm::FloatDefault stepSize,
116  vtkm::Id maxSteps,
117  const IntegrationSolverType& solverType,
119  {
120  if (solverType == IntegrationSolverType::RK4_TYPE)
121  {
125  velField1, ds1, t1, velField2, ds2, t2, seedArray, stepSize, maxSteps, result);
126  }
127  else if (solverType == IntegrationSolverType::EULER_TYPE)
128  {
132  velField1, ds1, t1, velField2, ds2, t2, seedArray, stepSize, maxSteps, result);
133  }
134  else
135  throw vtkm::cont::ErrorFilterExecution("Unsupported Integrator type");
136  }
137 
138  static void Advect(const VelocityFieldType& velField1,
139  const vtkm::cont::DataSet& ds1,
141  const VelocityFieldType& velField2,
142  const vtkm::cont::DataSet& ds2,
145  vtkm::FloatDefault stepSize,
146  vtkm::Id maxSteps,
147  const IntegrationSolverType& solverType,
149  {
150  if (solverType == IntegrationSolverType::RK4_TYPE)
151  {
155  velField1, ds1, t1, velField2, ds2, t2, seedArray, stepSize, maxSteps, result);
156  }
157  else if (solverType == IntegrationSolverType::EULER_TYPE)
158  {
162  velField1, ds1, t1, velField2, ds2, t2, seedArray, stepSize, maxSteps, result);
163  }
164  else
165  throw vtkm::cont::ErrorFilterExecution("Unsupported Integrator type");
166  }
167 
168  template <typename WorkletType,
169  template <typename>
170  class ResultType,
171  template <typename>
172  class SolverType>
173  static void DoAdvect(const VelocityFieldType& velField1,
174  const vtkm::cont::DataSet& ds1,
176  const VelocityFieldType& velField2,
177  const vtkm::cont::DataSet& ds2,
180  vtkm::FloatDefault stepSize,
181  vtkm::Id maxSteps,
182  ResultType<ParticleType>& result)
183  {
185  UnsteadyStateGridEvalType>;
186 
187  WorkletType worklet;
188  UnsteadyStateGridEvalType eval(ds1, t1, velField1, ds2, t2, velField2);
189  StepperType stepper(eval, stepSize);
190  result = worklet.Run(stepper, seedArray, maxSteps);
191  }
192 };
193 
194 }
195 
196 VTKM_CONT inline void DataSetIntegratorUnsteadyState::DoAdvect(DSIHelperInfo<vtkm::Particle>& b,
197  vtkm::FloatDefault stepSize,
198  vtkm::Id maxSteps)
199 {
200  using ArrayType = vtkm::cont::ArrayHandle<vtkm::Vec3f>;
201 
202  auto copyFlag = (this->CopySeedArray ? vtkm::CopyFlag::On : vtkm::CopyFlag::Off);
203  auto seedArray = vtkm::cont::make_ArrayHandle(b.V, copyFlag);
204 
205  using AHType = internal::AdvectHelper<internal::UnsteadyStateGridEvalType, vtkm::Particle>;
206 
207  if (this->VecFieldType == VectorFieldType::VELOCITY_FIELD_TYPE)
208  {
210  FieldType velField1, velField2;
211  this->GetVelocityFields(velField1, velField2);
212 
213  if (this->IsParticleAdvectionResult())
214  {
216  AHType::Advect(velField1,
217  this->DataSet1,
218  this->Time1,
219  velField2,
220  this->DataSet2,
221  this->Time2,
222  seedArray,
223  stepSize,
224  maxSteps,
225  this->SolverType,
226  result);
227  this->UpdateResult(result, b);
228  }
229  else if (this->IsStreamlineResult())
230  {
232  AHType::Advect(velField1,
233  this->DataSet1,
234  this->Time1,
235  velField2,
236  this->DataSet2,
237  this->Time2,
238  seedArray,
239  stepSize,
240  maxSteps,
241  this->SolverType,
242  result);
243  this->UpdateResult(result, b);
244  }
245  else
246  throw vtkm::cont::ErrorFilterExecution("Unsupported result type");
247  }
248  else
249  throw vtkm::cont::ErrorFilterExecution("Unsupported vector field type");
250 }
251 
252 VTKM_CONT inline void DataSetIntegratorUnsteadyState::DoAdvect(
253  DSIHelperInfo<vtkm::ChargedParticle>& vtkmNotUsed(b),
255  vtkm::Id vtkmNotUsed(maxSteps))
256 {
258  "Unsupported operation : charged particles and electromagnetic fielfs currently only supported "
259  "for steady state");
260 }
261 
262 }
263 }
264 }
265 } //vtkm::filter::flow::internal
266 
267 #endif //vtk_m_filter_flow_internal_DataSetIntegratorUnsteadyState_h
vtkm::cont::make_ArrayHandle
VTKM_CONT vtkm::cont::ArrayHandleBasic< T > make_ArrayHandle(const T *array, vtkm::Id numberOfValues, vtkm::CopyFlag copy)
A convenience function for creating an ArrayHandle from a standard C array.
Definition: ArrayHandleBasic.h:217
vtkm::filter::flow::IntegrationSolverType::RK4_TYPE
@ RK4_TYPE
vtkm::cont::ArrayHandle< vtkm::Vec3f >
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::worklet::flow::RK4Integrator
Definition: RK4Integrator.h:94
vtkm::filter::flow::IntegrationSolverType::EULER_TYPE
@ EULER_TYPE
vtkm::worklet::flow::Streamline
Definition: worklet/ParticleAdvection.h:149
vtkm::filter::flow::VectorFieldType::VELOCITY_FIELD_TYPE
@ VELOCITY_FIELD_TYPE
vtkm::cont::ArrayCopyShallowIfPossible
VTKM_CONT void ArrayCopyShallowIfPossible(const vtkm::cont::UnknownArrayHandle source, vtkm::cont::ArrayHandle< T, S > &destination)
Copies from an unknown to a known array type.
Definition: ArrayCopy.h:182
vtkm::cont::ErrorFilterExecution
This class is primarily intended to filters to throw in the control environment to indicate an execut...
Definition: ErrorFilterExecution.h:27
vtkm::worklet::flow::ParticleAdvectionResult
Definition: worklet/ParticleAdvection.h:52
vtkm::cont::DataSet
Definition: DataSet.h:34
vtkm::worklet::flow::ParticleAdvection
Definition: worklet/ParticleAdvection.h:67
DataSetIntegrator.h
TemporalGridEvaluators.h
vtkm::worklet::flow::StreamlineResult
Definition: worklet/ParticleAdvection.h:126
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
ArrayCopy.h
vtkm::worklet::flow::EulerIntegrator
Definition: EulerIntegrator.h:59
vtkm::worklet::flow::TemporalGridEvaluator
Definition: TemporalGridEvaluators.h:116
vtkm::filter::flow::FlowResultType
FlowResultType
Definition: FlowTypes.h:31
vtkm::filter::flow::IntegrationSolverType
IntegrationSolverType
Definition: FlowTypes.h:19
vtkm::filter::flow::VectorFieldType
VectorFieldType
Definition: FlowTypes.h:25
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::CopyFlag::On
@ On
vtkmNotUsed
#define vtkmNotUsed(parameter_name)
Simple macro to identify a parameter as unused.
Definition: ExportMacros.h:128
vtkm::CopyFlag::Off
@ Off
vtkm::FloatDefault
vtkm::Float32 FloatDefault
The floating point type to use when no other precision is specified.
Definition: Types.h:198
vtkm::worklet::flow::VelocityField
Definition: filter/flow/worklet/Field.h:134
vtkm::worklet::flow::Stepper
Definition: Stepper.h:151