VTK-m  2.2
DataSetIntegratorSteadyState.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_DataSetIntegratorSteadyState_h
12 #define vtk_m_filter_flow_internal_DataSetIntegratorSteadyState_h
13 
14 #include <vtkm/cont/ArrayCopy.h>
16 
17 namespace vtkm
18 {
19 namespace filter
20 {
21 namespace flow
22 {
23 namespace internal
24 {
25 namespace detail
26 {
27 template <typename ParticleType,
28  typename FieldType,
29  typename TerminationType,
30  typename AnalysisType>
31 class AdvectHelperSteadyState
32 {
33 public:
34  using WorkletType = vtkm::worklet::flow::ParticleAdvection;
35  using SteadyStateGridEvalType = vtkm::worklet::flow::GridEvaluator<FieldType>;
36 
37  template <template <typename> class SolverType>
38  static void DoAdvect(vtkm::cont::ArrayHandle<ParticleType>& seedArray,
39  const FieldType& field,
40  const vtkm::cont::DataSet& dataset,
41  const TerminationType& termination,
42  vtkm::FloatDefault stepSize,
43  AnalysisType& analysis)
44  {
45  using StepperType =
46  vtkm::worklet::flow::Stepper<SolverType<SteadyStateGridEvalType>, SteadyStateGridEvalType>;
47  SteadyStateGridEvalType eval(dataset, field);
48  StepperType stepper(eval, stepSize);
49 
50  WorkletType worklet;
51  worklet.Run(stepper, seedArray, termination, analysis);
52  }
53 
54  static void Advect(vtkm::cont::ArrayHandle<ParticleType>& seedArray,
55  const FieldType& field,
56  const vtkm::cont::DataSet& dataset,
57  const TerminationType& termination,
58  const IntegrationSolverType& solverType,
59  vtkm::FloatDefault stepSize,
60  AnalysisType& analysis)
61  {
62  if (solverType == IntegrationSolverType::RK4_TYPE)
63  {
64  DoAdvect<vtkm::worklet::flow::RK4Integrator>(
65  seedArray, field, dataset, termination, stepSize, analysis);
66  }
67  else if (solverType == IntegrationSolverType::EULER_TYPE)
68  {
69  DoAdvect<vtkm::worklet::flow::EulerIntegrator>(
70  seedArray, field, dataset, termination, stepSize, analysis);
71  }
72  else
73  throw vtkm::cont::ErrorFilterExecution("Unsupported Integrator type");
74  }
75 };
76 } // namespace detail
77 
78 template <typename ParticleType,
79  typename FieldType,
80  typename TerminationType,
81  typename AnalysisType>
82 class DataSetIntegratorSteadyState
83  : public vtkm::filter::flow::internal::DataSetIntegrator<
84  DataSetIntegratorSteadyState<ParticleType, FieldType, TerminationType, AnalysisType>,
85  ParticleType>
86 {
87 public:
88  using BaseType = vtkm::filter::flow::internal::DataSetIntegrator<
89  DataSetIntegratorSteadyState<ParticleType, FieldType, TerminationType, AnalysisType>,
90  ParticleType>;
91  using PType = ParticleType;
92  using FType = FieldType;
93  using TType = TerminationType;
94  using AType = AnalysisType;
95 
96  DataSetIntegratorSteadyState(vtkm::Id id,
97  const FieldType& field,
98  const vtkm::cont::DataSet& dataset,
100  const TerminationType& termination,
101  const AnalysisType& analysis)
102  : BaseType(id, solverType)
103  , Field(field)
104  , Dataset(dataset)
105  , Termination(termination)
106  , Analysis(analysis)
107  {
108  }
109 
110  VTKM_CONT inline void DoAdvect(vtkm::filter::flow::internal::DSIHelperInfo<ParticleType>& block,
111  vtkm::FloatDefault stepSize)
112  {
113  auto copyFlag = (this->CopySeedArray ? vtkm::CopyFlag::On : vtkm::CopyFlag::Off);
114  auto seedArray = vtkm::cont::make_ArrayHandle(block.Particles, copyFlag);
115 
116  using AdvectionHelper =
117  detail::AdvectHelperSteadyState<ParticleType, FieldType, TerminationType, AnalysisType>;
118  AnalysisType analysis;
119  analysis.UseAsTemplate(this->Analysis);
120 
121  AdvectionHelper::Advect(seedArray,
122  this->Field,
123  this->Dataset,
124  this->Termination,
125  this->SolverType,
126  stepSize,
127  analysis);
128 
129  this->UpdateResult(analysis, block);
130  }
131 
132  VTKM_CONT void UpdateResult(AnalysisType& analysis,
133  vtkm::filter::flow::internal::DSIHelperInfo<ParticleType>& dsiInfo)
134  {
135  this->ClassifyParticles(analysis.Particles, dsiInfo);
136  if (std::is_same<AnalysisType, vtkm::worklet::flow::NoAnalysis<ParticleType>>::value)
137  {
138  if (dsiInfo.TermIdx.empty())
139  return;
140  auto indicesAH = vtkm::cont::make_ArrayHandle(dsiInfo.TermIdx, vtkm::CopyFlag::Off);
141  auto termPerm = vtkm::cont::make_ArrayHandlePermutation(indicesAH, analysis.Particles);
143  vtkm::cont::Algorithm::Copy(termPerm, termParticles);
144  analysis.FinalizeAnalysis(termParticles);
145  this->Analyses.emplace_back(analysis);
146  }
147  else
148  {
149  this->Analyses.emplace_back(analysis);
150  }
151  }
152 
153  VTKM_CONT bool GetOutput(vtkm::cont::DataSet& ds) const
154  {
155  std::size_t nAnalyses = this->Analyses.size();
156  if (nAnalyses == 0)
157  return false;
158  return AnalysisType::MakeDataSet(ds, this->Analyses);
159  }
160 
161 private:
162  FieldType Field;
163  vtkm::cont::DataSet Dataset;
164  TerminationType Termination;
165  // Used as a template to initialize successive analysis objects.
166  AnalysisType Analysis;
167  std::vector<AnalysisType> Analyses;
168 };
169 
170 }
171 }
172 }
173 } //vtkm::filter::flow::internal
174 
175 #endif //vtk_m_filter_flow_internal_DataSetIntegratorSteadyState_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