VTK-m  2.0
TemporalGridEvaluators.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_worklet_TemporalGridEvaluators_h
12 #define vtk_m_filter_flow_worklet_TemporalGridEvaluators_h
13 
16 
17 namespace vtkm
18 {
19 namespace worklet
20 {
21 namespace flow
22 {
23 
24 template <typename FieldType>
26 {
27 private:
30 
31 public:
32  VTKM_CONT
34 
35  VTKM_CONT
37  const vtkm::FloatDefault timeOne,
38  const GridEvaluator& evaluatorTwo,
39  const vtkm::FloatDefault timeTwo,
41  vtkm::cont::Token& token)
42  : EvaluatorOne(evaluatorOne.PrepareForExecution(device, token))
43  , EvaluatorTwo(evaluatorTwo.PrepareForExecution(device, token))
44  , TimeOne(timeOne)
45  , TimeTwo(timeTwo)
46  , TimeDiff(timeTwo - timeOne)
47  {
48  }
49 
50  template <typename Point>
51  VTKM_EXEC bool IsWithinSpatialBoundary(const Point point) const
52  {
53  return this->EvaluatorOne.IsWithinSpatialBoundary(point) &&
55  }
56 
57  VTKM_EXEC
59  {
60  return time >= this->TimeOne && time <= this->TimeTwo;
61  }
62 
63  VTKM_EXEC
65 
68  {
69  return direction > 0 ? this->TimeTwo : this->TimeOne;
70  }
71 
72  template <typename Point>
73  VTKM_EXEC GridEvaluatorStatus Evaluate(const Point& particle,
74  vtkm::FloatDefault time,
75  vtkm::VecVariable<Point, 2>& out) const
76  {
77  // Validate time is in bounds for the current two slices.
78  GridEvaluatorStatus status;
79 
80  if (!(time >= TimeOne && time <= TimeTwo))
81  {
82  status.SetFail();
83  status.SetTemporalBounds();
84  return status;
85  }
86 
88  status = this->EvaluatorOne.Evaluate(particle, time, e1);
89  if (status.CheckFail())
90  return status;
91  status = this->EvaluatorTwo.Evaluate(particle, time, e2);
92  if (status.CheckFail())
93  return status;
94 
95  // LERP between the two values of calculated fields to obtain the new value
96  vtkm::FloatDefault proportion = (time - this->TimeOne) / this->TimeDiff;
100  for (vtkm::IdComponent index = 0; index < e1.GetNumberOfComponents(); ++index)
101  out.Append(vtkm::Lerp(e1[index], e2[index], proportion));
102 
103  status.SetOk();
104  return status;
105  }
106 
107 private:
113 };
114 
115 template <typename FieldType>
117 {
118 private:
120 
121 public:
122  VTKM_CONT TemporalGridEvaluator() = default;
123 
125  const vtkm::FloatDefault t1,
126  const FieldType& field1,
127  const vtkm::cont::DataSet& ds2,
128  const vtkm::FloatDefault t2,
129  const FieldType& field2)
130  : EvaluatorOne(GridEvaluator(ds1, field1))
131  , EvaluatorTwo(GridEvaluator(ds2, field2))
132  , TimeOne(t1)
133  , TimeTwo(t2)
134 
135  {
136  }
137 
138 
140  const vtkm::FloatDefault timeOne,
141  GridEvaluator& evaluatorTwo,
142  const vtkm::FloatDefault timeTwo)
143  : EvaluatorOne(evaluatorOne)
144  , EvaluatorTwo(evaluatorTwo)
145  , TimeOne(timeOne)
146  , TimeTwo(timeTwo)
147  {
148  }
149 
151  const vtkm::cont::UnknownCellSet& cellsetOne,
152  const FieldType& fieldOne,
153  const vtkm::FloatDefault timeOne,
154  const vtkm::cont::CoordinateSystem& coordinatesTwo,
155  const vtkm::cont::UnknownCellSet& cellsetTwo,
156  const FieldType& fieldTwo,
157  const vtkm::FloatDefault timeTwo)
158  : EvaluatorOne(GridEvaluator(coordinatesOne, cellsetOne, fieldOne))
159  , EvaluatorTwo(GridEvaluator(coordinatesTwo, cellsetTwo, fieldTwo))
160  , TimeOne(timeOne)
161  , TimeTwo(timeTwo)
162  {
163  }
164 
167  vtkm::cont::Token& token) const
168  {
170  this->EvaluatorOne, this->TimeOne, this->EvaluatorTwo, this->TimeTwo, device, token);
171  }
172 
173 private:
178 };
179 
180 }
181 }
182 } //vtkm::worklet::flow
183 
184 #endif // vtk_m_filter_flow_worklet_TemporalGridEvaluators_h
vtkm::worklet::flow::TemporalGridEvaluator::TemporalGridEvaluator
VTKM_CONT TemporalGridEvaluator(const vtkm::cont::DataSet &ds1, const vtkm::FloatDefault t1, const FieldType &field1, const vtkm::cont::DataSet &ds2, const vtkm::FloatDefault t2, const FieldType &field2)
Definition: TemporalGridEvaluators.h:124
vtkm::worklet::flow::TemporalGridEvaluator::TemporalGridEvaluator
VTKM_CONT TemporalGridEvaluator(const vtkm::cont::CoordinateSystem &coordinatesOne, const vtkm::cont::UnknownCellSet &cellsetOne, const FieldType &fieldOne, const vtkm::FloatDefault timeOne, const vtkm::cont::CoordinateSystem &coordinatesTwo, const vtkm::cont::UnknownCellSet &cellsetTwo, const FieldType &fieldTwo, const vtkm::FloatDefault timeTwo)
Definition: TemporalGridEvaluators.h:150
vtkm::worklet::flow::TemporalGridEvaluator::TemporalGridEvaluator
VTKM_CONT TemporalGridEvaluator()=default
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::worklet::flow::ExecutionTemporalGridEvaluator::IsWithinSpatialBoundary
VTKM_EXEC bool IsWithinSpatialBoundary(const Point point) const
Definition: TemporalGridEvaluators.h:51
vtkm::worklet::flow::GridEvaluator
Definition: GridEvaluators.h:161
VTKM_ASSERT
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::worklet::flow::ExecutionGridEvaluator::GetSpatialBoundary
VTKM_EXEC vtkm::Bounds GetSpatialBoundary() const
Definition: GridEvaluators.h:78
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
GridEvaluatorStatus.h
vtkm::worklet::flow::GridEvaluatorStatus::CheckFail
VTKM_EXEC_CONT bool CheckFail() const
Definition: GridEvaluatorStatus.h:39
vtkm::worklet::flow::ExecutionTemporalGridEvaluator::GetSpatialBoundary
VTKM_EXEC vtkm::Bounds GetSpatialBoundary() const
Definition: TemporalGridEvaluators.h:64
vtkm::cont::DataSet
Definition: DataSet.h:34
vtkm::worklet::flow::ExecutionTemporalGridEvaluator::GetTemporalBoundary
VTKM_EXEC_CONT vtkm::FloatDefault GetTemporalBoundary(vtkm::Id direction) const
Definition: TemporalGridEvaluators.h:67
vtkm::cont::UnknownCellSet
A CellSet of an unknown type.
Definition: UnknownCellSet.h:48
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::flow::ExecutionTemporalGridEvaluator::TimeDiff
vtkm::FloatDefault TimeDiff
Definition: TemporalGridEvaluators.h:112
vtkm::worklet::flow::ExecutionGridEvaluator::Evaluate
VTKM_EXEC GridEvaluatorStatus Evaluate(const Point &point, const vtkm::FloatDefault &time, vtkm::VecVariable< Point, 2 > &out) const
Definition: GridEvaluators.h:89
vtkm::worklet::flow::TemporalGridEvaluator::EvaluatorTwo
GridEvaluator EvaluatorTwo
Definition: TemporalGridEvaluators.h:175
vtkm::cont::CoordinateSystem
Definition: CoordinateSystem.h:25
vtkm::worklet::flow::ExecutionTemporalGridEvaluator::IsWithinTemporalBoundary
VTKM_EXEC bool IsWithinTemporalBoundary(const vtkm::FloatDefault time) const
Definition: TemporalGridEvaluators.h:58
vtkm::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
vtkm::worklet::flow::TemporalGridEvaluator::TimeOne
vtkm::FloatDefault TimeOne
Definition: TemporalGridEvaluators.h:176
vtkm::VecVariable::GetNumberOfComponents
VTKM_EXEC_CONT vtkm::IdComponent GetNumberOfComponents() const
Definition: VecVariable.h:53
vtkm::worklet::flow::TemporalGridEvaluator
Definition: TemporalGridEvaluators.h:116
vtkm::worklet::flow::TemporalGridEvaluator::TemporalGridEvaluator
VTKM_CONT TemporalGridEvaluator(GridEvaluator &evaluatorOne, const vtkm::FloatDefault timeOne, GridEvaluator &evaluatorTwo, const vtkm::FloatDefault timeTwo)
Definition: TemporalGridEvaluators.h:139
vtkm::VecVariable::Append
VTKM_EXEC_CONT void Append(ComponentType value)
Definition: VecVariable.h:80
vtkm::VecVariable
A short variable-length array with maximum length.
Definition: VecVariable.h:30
vtkm::worklet::flow::TemporalGridEvaluator::TimeTwo
vtkm::FloatDefault TimeTwo
Definition: TemporalGridEvaluators.h:177
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::Bounds
Represent an axis-aligned 3D bounds in space.
Definition: Bounds.h:29
vtkm::worklet::flow::TemporalGridEvaluator::EvaluatorOne
GridEvaluator EvaluatorOne
Definition: TemporalGridEvaluators.h:174
GridEvaluators.h
vtkm::Lerp
VTKM_EXEC_CONT ValueType Lerp(const ValueType &value0, const ValueType &value1, const WeightType &weight)
Returns the linear interpolation of two values based on weight.
Definition: VectorAnalysis.h:32
vtkm::cont::ExecutionObjectBase
Base ExecutionObjectBase for execution objects to inherit from so that you can use an arbitrary objec...
Definition: ExecutionObjectBase.h:31
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
vtkm::worklet::flow::GridEvaluatorStatus::SetFail
VTKM_EXEC_CONT void SetFail()
Definition: GridEvaluatorStatus.h:38
vtkm::worklet::flow::ExecutionTemporalGridEvaluator::EvaluatorTwo
ExecutionGridEvaluator EvaluatorTwo
Definition: TemporalGridEvaluators.h:109
vtkm::FloatDefault
vtkm::Float32 FloatDefault
The floating point type to use when no other precision is specified.
Definition: Types.h:198
vtkm::worklet::flow::ExecutionTemporalGridEvaluator::ExecutionTemporalGridEvaluator
VTKM_CONT ExecutionTemporalGridEvaluator()=default
vtkm::worklet::flow::GridEvaluatorStatus::SetOk
VTKM_EXEC_CONT void SetOk()
Definition: GridEvaluatorStatus.h:35
vtkm::worklet::flow::GridEvaluatorStatus::SetTemporalBounds
VTKM_EXEC_CONT void SetTemporalBounds()
Definition: GridEvaluatorStatus.h:44
vtkm::worklet::flow::TemporalGridEvaluator::PrepareForExecution
VTKM_CONT ExecutionTemporalGridEvaluator< FieldType > PrepareForExecution(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Definition: TemporalGridEvaluators.h:165
vtkm::worklet::flow::ExecutionTemporalGridEvaluator::EvaluatorOne
ExecutionGridEvaluator EvaluatorOne
Definition: TemporalGridEvaluators.h:108
vtkm::worklet::flow::ExecutionTemporalGridEvaluator::Evaluate
VTKM_EXEC GridEvaluatorStatus Evaluate(const Point &particle, vtkm::FloatDefault time, vtkm::VecVariable< Point, 2 > &out) const
Definition: TemporalGridEvaluators.h:73
vtkm::worklet::flow::ExecutionTemporalGridEvaluator::ExecutionTemporalGridEvaluator
VTKM_CONT ExecutionTemporalGridEvaluator(const GridEvaluator &evaluatorOne, const vtkm::FloatDefault timeOne, const GridEvaluator &evaluatorTwo, const vtkm::FloatDefault timeTwo, vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token)
Definition: TemporalGridEvaluators.h:36
vtkm::worklet::flow::ExecutionTemporalGridEvaluator
Definition: TemporalGridEvaluators.h:25
vtkm::worklet::flow::ExecutionGridEvaluator::IsWithinSpatialBoundary
VTKM_EXEC bool IsWithinSpatialBoundary(const Point &point) const
Definition: GridEvaluators.h:61
vtkm::worklet::flow::ExecutionTemporalGridEvaluator::TimeTwo
vtkm::FloatDefault TimeTwo
Definition: TemporalGridEvaluators.h:111
vtkm::worklet::flow::ExecutionTemporalGridEvaluator::TimeOne
vtkm::FloatDefault TimeOne
Definition: TemporalGridEvaluators.h:110
vtkm::worklet::flow::ExecutionGridEvaluator
Definition: GridEvaluators.h:35
vtkm::worklet::flow::GridEvaluatorStatus
Definition: GridEvaluatorStatus.h:23