VTK-m  2.2
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>
16 #include <vtkm/filter/flow/worklet/TemporalGridEvaluators.h>
17 
18 namespace vtkm
19 {
20 namespace filter
21 {
22 namespace flow
23 {
24 namespace internal
25 {
26 namespace detail
27 {
28 template <typename ParticleType,
29  typename FieldType,
30  typename TerminationType,
31  typename AnalysisType>
32 class AdvectHelperUnsteadyState
33 {
34 public:
35  using WorkletType = vtkm::worklet::flow::ParticleAdvection;
36  using UnsteadyStateGridEvalType = vtkm::worklet::flow::TemporalGridEvaluator<FieldType>;
37 
38  template <template <typename> class SolverType>
39  static void DoAdvect(vtkm::cont::ArrayHandle<ParticleType>& seedArray,
40  const FieldType& field1,
41  const vtkm::cont::DataSet& ds1,
43  const FieldType& field2,
44  const vtkm::cont::DataSet& ds2,
46  const TerminationType& termination,
47  vtkm::FloatDefault stepSize,
48  AnalysisType& analysis)
49 
50  {
51  using StepperType = vtkm::worklet::flow::Stepper<SolverType<UnsteadyStateGridEvalType>,
52  UnsteadyStateGridEvalType>;
53  WorkletType worklet;
54  UnsteadyStateGridEvalType eval(ds1, t1, field1, ds2, t2, field2);
55  StepperType stepper(eval, stepSize);
56  worklet.Run(stepper, seedArray, termination, analysis);
57  }
58 
59  static void Advect(vtkm::cont::ArrayHandle<ParticleType>& seedArray,
60  const FieldType& field1,
61  const vtkm::cont::DataSet& ds1,
63  const FieldType& field2,
64  const vtkm::cont::DataSet& ds2,
66  const TerminationType& termination,
67  const IntegrationSolverType& solverType,
68  vtkm::FloatDefault stepSize,
69  AnalysisType& analysis)
70  {
71  if (solverType == IntegrationSolverType::RK4_TYPE)
72  {
73  DoAdvect<vtkm::worklet::flow::RK4Integrator>(
74  seedArray, field1, ds1, t1, field2, ds2, t2, termination, stepSize, analysis);
75  }
76  else if (solverType == IntegrationSolverType::EULER_TYPE)
77  {
78  DoAdvect<vtkm::worklet::flow::EulerIntegrator>(
79  seedArray, field1, ds1, t1, field2, ds2, t2, termination, stepSize, analysis);
80  }
81  else
82  throw vtkm::cont::ErrorFilterExecution("Unsupported Integrator type");
83  }
84 };
85 } //namespace detail
86 
87 template <typename ParticleType,
88  typename FieldType,
89  typename TerminationType,
90  typename AnalysisType>
91 class DataSetIntegratorUnsteadyState
92  : public vtkm::filter::flow::internal::DataSetIntegrator<
93  DataSetIntegratorUnsteadyState<ParticleType, FieldType, TerminationType, AnalysisType>,
94  ParticleType>
95 {
96 public:
97  using BaseType = vtkm::filter::flow::internal::DataSetIntegrator<
98  DataSetIntegratorUnsteadyState<ParticleType, FieldType, TerminationType, AnalysisType>,
99  ParticleType>;
100  using PType = ParticleType;
101  using FType = FieldType;
102  using TType = TerminationType;
103  using AType = AnalysisType;
104 
105  DataSetIntegratorUnsteadyState(vtkm::Id id,
106  const FieldType& field1,
107  const FieldType& field2,
108  const vtkm::cont::DataSet& ds1,
109  const vtkm::cont::DataSet& ds2,
113  const TerminationType& termination,
114  const AnalysisType& analysis)
115  : BaseType(id, solverType)
116  , Field1(field1)
117  , Field2(field2)
118  , DataSet1(ds1)
119  , DataSet2(ds2)
120  , Time1(t1)
121  , Time2(t2)
122  , Termination(termination)
123  , Analysis(analysis)
124  {
125  }
126 
127  VTKM_CONT inline void DoAdvect(vtkm::filter::flow::internal::DSIHelperInfo<ParticleType>& block,
128  vtkm::FloatDefault stepSize)
129  {
130  auto copyFlag = (this->CopySeedArray ? vtkm::CopyFlag::On : vtkm::CopyFlag::Off);
131  auto seedArray = vtkm::cont::make_ArrayHandle(block.Particles, copyFlag);
132 
133  using AdvectionHelper =
134  detail::AdvectHelperUnsteadyState<ParticleType, FieldType, TerminationType, AnalysisType>;
135  AnalysisType analysis;
136  analysis.UseAsTemplate(this->Analysis);
137 
138  AdvectionHelper::Advect(seedArray,
139  this->Field1,
140  this->DataSet1,
141  this->Time1,
142  this->Field2,
143  this->DataSet2,
144  this->Time2,
145  this->Termination,
146  this->SolverType,
147  stepSize,
148  analysis);
149  this->UpdateResult(analysis, block);
150  }
151 
152  VTKM_CONT void UpdateResult(AnalysisType& analysis,
153  vtkm::filter::flow::internal::DSIHelperInfo<ParticleType>& dsiInfo)
154  {
155  this->ClassifyParticles(analysis.Particles, dsiInfo);
156  if (std::is_same<AnalysisType, vtkm::worklet::flow::NoAnalysis<ParticleType>>::value)
157  {
158  if (dsiInfo.TermIdx.empty())
159  return;
160  auto indicesAH = vtkm::cont::make_ArrayHandle(dsiInfo.TermIdx, vtkm::CopyFlag::Off);
161  auto termPerm = vtkm::cont::make_ArrayHandlePermutation(indicesAH, analysis.Particles);
163  vtkm::cont::Algorithm::Copy(termPerm, termParticles);
164  analysis.FinalizeAnalysis(termParticles);
165  this->Analyses.emplace_back(analysis);
166  }
167  else
168  {
169  this->Analyses.emplace_back(analysis);
170  }
171  }
172 
173  VTKM_CONT bool GetOutput(vtkm::cont::DataSet& ds) const
174  {
175  std::size_t nAnalyses = this->Analyses.size();
176  if (nAnalyses == 0)
177  return false;
178  return AnalysisType::MakeDataSet(ds, this->Analyses);
179  }
180 
181 private:
182  FieldType Field1;
183  FieldType Field2;
184  vtkm::cont::DataSet DataSet1;
185  vtkm::cont::DataSet DataSet2;
186  vtkm::FloatDefault Time1;
187  vtkm::FloatDefault Time2;
188  TerminationType Termination;
189  AnalysisType Analysis;
190  std::vector<AnalysisType> Analyses;
191 };
192 
193 }
194 }
195 }
196 } //vtkm::filter::flow::internal
197 
198 #endif //vtk_m_filter_flow_internal_DataSetIntegratorUnsteadyState_h
vtkm::filter::flow::IntegrationSolverType::RK4_TYPE
@ RK4_TYPE
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:300
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::filter::flow::IntegrationSolverType::EULER_TYPE
@ EULER_TYPE
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::cont::DataSet
Contains and manages the geometric data structures that VTK-m operates on.
Definition: DataSet.h:57
DataSetIntegrator.h
ArrayCopy.h
vtkm::filter::flow::IntegrationSolverType
IntegrationSolverType
Definition: FlowTypes.h:19
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::CopyFlag::On
@ On
vtkm::cont::Algorithm::Copy
static bool Copy(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< U, COut > &output)
Definition: Algorithm.h:411
vtkm::CopyFlag::Off
@ Off
vtkm::FloatDefault
vtkm::Float32 FloatDefault
The floating point type to use when no other precision is specified.
Definition: Types.h:236
vtkm::cont::make_ArrayHandle
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:270
vtkm::cont::make_ArrayHandlePermutation
vtkm::cont::ArrayHandlePermutation< IndexArrayHandleType, ValueArrayHandleType > make_ArrayHandlePermutation(IndexArrayHandleType indexArray, ValueArrayHandleType valueArray)
make_ArrayHandleTransform is convenience function to generate an ArrayHandleTransform.
Definition: ArrayHandlePermutation.h:291