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