Viskores  1.0
DataSetIntegratorUnsteadyState.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 
19 #ifndef viskores_filter_flow_internal_DataSetIntegratorUnsteadyState_h
20 #define viskores_filter_flow_internal_DataSetIntegratorUnsteadyState_h
21 
24 #include <viskores/filter/flow/worklet/TemporalGridEvaluators.h>
25 
26 namespace viskores
27 {
28 namespace filter
29 {
30 namespace flow
31 {
32 namespace internal
33 {
34 namespace detail
35 {
36 template <typename ParticleType,
37  typename FieldType,
38  typename TerminationType,
39  typename AnalysisType>
40 class AdvectHelperUnsteadyState
41 {
42 public:
43  using WorkletType = viskores::worklet::flow::ParticleAdvection;
44  using UnsteadyStateGridEvalType = viskores::worklet::flow::TemporalGridEvaluator<FieldType>;
45 
46  template <template <typename> class SolverType>
47  static void DoAdvect(viskores::cont::ArrayHandle<ParticleType>& seedArray,
48  const FieldType& field1,
49  const viskores::cont::DataSet& ds1,
51  const FieldType& field2,
52  const viskores::cont::DataSet& ds2,
54  const TerminationType& termination,
55  viskores::FloatDefault stepSize,
56  AnalysisType& analysis)
57 
58  {
59  using StepperType = viskores::worklet::flow::Stepper<SolverType<UnsteadyStateGridEvalType>,
60  UnsteadyStateGridEvalType>;
61  WorkletType worklet;
62  UnsteadyStateGridEvalType eval(ds1, t1, field1, ds2, t2, field2);
63  StepperType stepper(eval, stepSize);
64  worklet.Run(stepper, seedArray, termination, analysis);
65  }
66 
67  static void Advect(viskores::cont::ArrayHandle<ParticleType>& seedArray,
68  const FieldType& field1,
69  const viskores::cont::DataSet& ds1,
71  const FieldType& field2,
72  const viskores::cont::DataSet& ds2,
74  const TerminationType& termination,
75  const IntegrationSolverType& solverType,
76  viskores::FloatDefault stepSize,
77  AnalysisType& analysis)
78  {
79  if (solverType == IntegrationSolverType::RK4_TYPE)
80  {
81  DoAdvect<viskores::worklet::flow::RK4Integrator>(
82  seedArray, field1, ds1, t1, field2, ds2, t2, termination, stepSize, analysis);
83  }
84  else if (solverType == IntegrationSolverType::EULER_TYPE)
85  {
86  DoAdvect<viskores::worklet::flow::EulerIntegrator>(
87  seedArray, field1, ds1, t1, field2, ds2, t2, termination, stepSize, analysis);
88  }
89  else
90  throw viskores::cont::ErrorFilterExecution("Unsupported Integrator type");
91  }
92 };
93 } //namespace detail
94 
95 template <typename ParticleType,
96  typename FieldType,
97  typename TerminationType,
98  typename AnalysisType>
99 class DataSetIntegratorUnsteadyState
100  : public viskores::filter::flow::internal::DataSetIntegrator<
101  DataSetIntegratorUnsteadyState<ParticleType, FieldType, TerminationType, AnalysisType>,
102  ParticleType>
103 {
104 public:
105  using BaseType = viskores::filter::flow::internal::DataSetIntegrator<
106  DataSetIntegratorUnsteadyState<ParticleType, FieldType, TerminationType, AnalysisType>,
107  ParticleType>;
108  using PType = ParticleType;
109  using FType = FieldType;
110  using TType = TerminationType;
111  using AType = AnalysisType;
112 
113  DataSetIntegratorUnsteadyState(viskores::Id id,
114  const FieldType& field1,
115  const FieldType& field2,
116  const viskores::cont::DataSet& ds1,
117  const viskores::cont::DataSet& ds2,
121  const TerminationType& termination,
122  const AnalysisType& analysis)
123  : BaseType(id, solverType)
124  , Field1(field1)
125  , Field2(field2)
126  , DataSet1(ds1)
127  , DataSet2(ds2)
128  , Time1(t1)
129  , Time2(t2)
130  , Termination(termination)
131  , Analysis(analysis)
132  {
133  }
134 
135  VISKORES_CONT inline void DoAdvect(
136  viskores::filter::flow::internal::DSIHelperInfo<ParticleType>& block,
137  viskores::FloatDefault stepSize)
138  {
139  auto copyFlag = (this->CopySeedArray ? viskores::CopyFlag::On : viskores::CopyFlag::Off);
140  auto seedArray = viskores::cont::make_ArrayHandle(block.Particles, copyFlag);
141 
142  using AdvectionHelper =
143  detail::AdvectHelperUnsteadyState<ParticleType, FieldType, TerminationType, AnalysisType>;
144  AnalysisType analysis;
145  analysis.UseAsTemplate(this->Analysis);
146 
147  AdvectionHelper::Advect(seedArray,
148  this->Field1,
149  this->DataSet1,
150  this->Time1,
151  this->Field2,
152  this->DataSet2,
153  this->Time2,
154  this->Termination,
155  this->SolverType,
156  stepSize,
157  analysis);
158  this->UpdateResult(analysis, block);
159  }
160 
161  VISKORES_CONT void UpdateResult(
162  AnalysisType& analysis,
163  viskores::filter::flow::internal::DSIHelperInfo<ParticleType>& dsiInfo)
164  {
165  this->ClassifyParticles(analysis.Particles, dsiInfo);
166  if (std::is_same<AnalysisType, viskores::worklet::flow::NoAnalysis<ParticleType>>::value)
167  {
168  if (dsiInfo.TermIdx.empty())
169  return;
170  auto indicesAH = viskores::cont::make_ArrayHandle(dsiInfo.TermIdx, viskores::CopyFlag::Off);
171  auto termPerm = viskores::cont::make_ArrayHandlePermutation(indicesAH, analysis.Particles);
173  viskores::cont::Algorithm::Copy(termPerm, termParticles);
174  analysis.FinalizeAnalysis(termParticles);
175  this->Analyses.emplace_back(analysis);
176  }
177  else
178  {
179  this->Analyses.emplace_back(analysis);
180  }
181  }
182 
183  VISKORES_CONT bool GetOutput(viskores::cont::DataSet& ds) const
184  {
185  std::size_t nAnalyses = this->Analyses.size();
186  if (nAnalyses == 0)
187  return false;
188  return AnalysisType::MakeDataSet(ds, this->Analyses);
189  }
190 
191 private:
192  FieldType Field1;
193  FieldType Field2;
194  viskores::cont::DataSet DataSet1;
195  viskores::cont::DataSet DataSet2;
198  TerminationType Termination;
199  AnalysisType Analysis;
200  std::vector<AnalysisType> Analyses;
201 };
202 
203 }
204 }
205 }
206 } //viskores::filter::flow::internal
207 
208 #endif //viskores_filter_flow_internal_DataSetIntegratorUnsteadyState_h
viskores::CopyFlag::Off
@ Off
viskores::cont::DataSet
Contains and manages the geometric data structures that Viskores operates on.
Definition: DataSet.h:66
viskores::filter::flow::IntegrationSolverType
IntegrationSolverType
Definition: FlowTypes.h:27
viskores::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:313
DataSetIntegrator.h
viskores::cont::ErrorFilterExecution
This class is primarily intended to filters to throw in the control environment to indicate an execut...
Definition: ErrorFilterExecution.h:35
viskores::filter::flow::IntegrationSolverType::EULER_TYPE
@ EULER_TYPE
ArrayCopy.h
viskores::cont::Algorithm::Copy
static bool Copy(viskores::cont::DeviceAdapterId devId, const viskores::cont::ArrayHandle< T, CIn > &input, viskores::cont::ArrayHandle< U, COut > &output)
Definition: Algorithm.h:422
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::CopyFlag::On
@ On
viskores::FloatDefault
viskores::Float32 FloatDefault
The floating point type to use when no other precision is specified.
Definition: Types.h:244
viskores::cont::make_ArrayHandle
viskores::cont::ArrayHandleBasic< T > make_ArrayHandle(const T *array, viskores::Id numberOfValues, viskores::CopyFlag copy)
A convenience function for creating an ArrayHandle from a standard C array.
Definition: ArrayHandleBasic.h:285
viskores::cont::make_ArrayHandlePermutation
viskores::cont::ArrayHandlePermutation< IndexArrayHandleType, ValueArrayHandleType > make_ArrayHandlePermutation(IndexArrayHandleType indexArray, ValueArrayHandleType valueArray)
make_ArrayHandleTransform is convenience function to generate an ArrayHandleTransform.
Definition: ArrayHandlePermutation.h:300
viskores::filter::flow::IntegrationSolverType::RK4_TYPE
@ RK4_TYPE