VTK-m  2.0
GridEvaluators.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_GridEvaluators_h
12 #define vtk_m_filter_flow_worklet_GridEvaluators_h
13 
15 #include <vtkm/cont/ArrayHandle.h>
21 #include <vtkm/cont/DataSet.h>
22 
26 
27 namespace vtkm
28 {
29 namespace worklet
30 {
31 namespace flow
32 {
33 
34 template <typename FieldType>
36 {
38 
39 public:
40  VTKM_CONT
41  ExecutionGridEvaluator() = default;
42 
43  VTKM_CONT
45  const vtkm::cont::CellInterpolationHelper interpolationHelper,
46  const vtkm::Bounds& bounds,
47  const FieldType& field,
48  const GhostCellArrayType& ghostCells,
50  vtkm::cont::Token& token)
51  : Bounds(bounds)
52  , Field(field.PrepareForExecution(device, token))
53  , GhostCells(ghostCells.PrepareForInput(device, token))
54  , HaveGhostCells(ghostCells.GetNumberOfValues() > 0)
55  , InterpolationHelper(interpolationHelper.PrepareForExecution(device, token))
56  , Locator(locator.PrepareForExecution(device, token))
57  {
58  }
59 
60  template <typename Point>
61  VTKM_EXEC bool IsWithinSpatialBoundary(const Point& point) const
62  {
63  vtkm::Id cellId = -1;
64  Point parametric;
65 
66  this->Locator.FindCell(point, cellId, parametric);
67 
68  if (cellId == -1)
69  return false;
70  else
71  return !this->InGhostCell(cellId);
72  }
73 
74  VTKM_EXEC
75  bool IsWithinTemporalBoundary(const vtkm::FloatDefault& vtkmNotUsed(time)) const { return true; }
76 
77  VTKM_EXEC
78  vtkm::Bounds GetSpatialBoundary() const { return this->Bounds; }
79 
82  {
83  // Return the time of the newest time slice
84  return direction > 0 ? vtkm::Infinity<vtkm::FloatDefault>()
85  : vtkm::NegativeInfinity<vtkm::FloatDefault>();
86  }
87 
88  template <typename Point>
90  const vtkm::FloatDefault& time,
91  vtkm::VecVariable<Point, 2>& out) const
92  {
93  vtkm::Id cellId = -1;
94  Point parametric;
95  GridEvaluatorStatus status;
96 
97  status.SetOk();
98  if (!this->IsWithinTemporalBoundary(time))
99  {
100  status.SetFail();
101  status.SetTemporalBounds();
102  }
103 
104  this->Locator.FindCell(point, cellId, parametric);
105  if (cellId == -1)
106  {
107  status.SetFail();
108  status.SetSpatialBounds();
109  }
110  else if (this->InGhostCell(cellId))
111  {
112  status.SetFail();
113  status.SetInGhostCell();
114  status.SetSpatialBounds();
115  }
116 
117  //If initial checks ok, then do the evaluation.
118  if (status.CheckOk())
119  {
120  vtkm::UInt8 cellShape;
121  vtkm::IdComponent nVerts;
124 
125  if (this->Field.GetAssociation() == vtkm::cont::Field::Association::Points)
126  {
127  this->InterpolationHelper.GetCellInfo(cellId, cellShape, nVerts, ptIndices);
128  this->Field.GetValue(ptIndices, nVerts, parametric, cellShape, out);
129  }
130  else if (this->Field.GetAssociation() == vtkm::cont::Field::Association::Cells)
131  {
132  this->Field.GetValue(cellId, out);
133  }
134 
135  status.SetOk();
136  }
137 
138  return status;
139  }
140 
141 private:
142  VTKM_EXEC bool InGhostCell(const vtkm::Id& cellId) const
143  {
144  if (this->HaveGhostCells && cellId != -1)
145  return GhostCells.Get(cellId) == vtkm::CellClassification::Ghost;
146 
147  return false;
148  }
149 
151 
153  typename FieldType::ExecutionType Field;
158 };
159 
160 template <typename FieldType>
162 {
163 public:
166  using RectilinearType =
171 
172  VTKM_CONT
173  GridEvaluator() = default;
174 
175  VTKM_CONT
176  GridEvaluator(const vtkm::cont::DataSet& dataSet, const FieldType& field)
177  : Bounds(dataSet.GetCoordinateSystem().GetBounds())
178  , Field(field)
179  , GhostCellArray()
180  {
181  this->InitializeLocator(dataSet.GetCoordinateSystem(), dataSet.GetCellSet());
182 
183  if (dataSet.HasGhostCellField())
184  {
185  auto arr = dataSet.GetGhostCellField().GetData();
187  }
188  }
189 
190  VTKM_CONT
192  const vtkm::cont::UnknownCellSet& cellset,
193  const FieldType& field)
194  : Bounds(coordinates.GetBounds())
195  , Field(field)
196  , GhostCellArray()
197  {
198  this->InitializeLocator(coordinates, cellset);
199  }
200 
203  vtkm::cont::Token& token) const
204  {
206  this->InterpolationHelper,
207  this->Bounds,
208  this->Field,
209  this->GhostCellArray,
210  device,
211  token);
212  }
213 
214 private:
216  const vtkm::cont::UnknownCellSet& cellset)
217  {
218  this->Locator.SetCoordinates(coordinates);
219  this->Locator.SetCellSet(cellset);
220  this->Locator.Update();
222  }
223 
225  FieldType Field;
229 };
230 
231 }
232 }
233 } //vtkm::worklet::flow
234 
235 #endif // vtk_m_filter_flow_worklet_GridEvaluators_h
vtkm::cont::ArrayHandle< vtkm::UInt8 >
ArrayHandle.h
CellClassification.h
vtkm::worklet::flow::GridEvaluator::InterpolationHelper
vtkm::cont::CellInterpolationHelper InterpolationHelper
Definition: GridEvaluators.h:227
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::ExecutionGridEvaluator::ExecutionGridEvaluator
VTKM_CONT ExecutionGridEvaluator()=default
vtkm::worklet::flow::GridEvaluator
Definition: GridEvaluators.h:161
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::worklet::flow::ExecutionGridEvaluator::ExecutionGridEvaluator
VTKM_CONT ExecutionGridEvaluator(const vtkm::cont::CellLocatorGeneral &locator, const vtkm::cont::CellInterpolationHelper interpolationHelper, const vtkm::Bounds &bounds, const FieldType &field, const GhostCellArrayType &ghostCells, vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token)
Definition: GridEvaluators.h:44
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::worklet::flow::ExecutionGridEvaluator::IsWithinTemporalBoundary
VTKM_EXEC bool IsWithinTemporalBoundary(const vtkm::FloatDefault &vtkmNotUsed(time)) const
Definition: GridEvaluators.h:75
vtkm::cont::CellSetStructured
Definition: CastAndCall.h:32
GridEvaluatorStatus.h
vtkm::worklet::flow::GridEvaluator::GridEvaluator
VTKM_CONT GridEvaluator(const vtkm::cont::CoordinateSystem &coordinates, const vtkm::cont::UnknownCellSet &cellset, const FieldType &field)
Definition: GridEvaluators.h:191
vtkm::cont::ArrayCopyShallowIfPossible
VTKM_CONT void ArrayCopyShallowIfPossible(const vtkm::cont::UnknownArrayHandle source, vtkm::cont::ArrayHandle< T, S > &destination)
Copies from an unknown to a known array type.
Definition: ArrayCopy.h:182
vtkm::worklet::flow::ExecutionGridEvaluator::HaveGhostCells
bool HaveGhostCells
Definition: GridEvaluators.h:155
vtkm::cont::ArrayHandleCartesianProduct
ArrayHandleCartesianProduct is a specialization of ArrayHandle.
Definition: ArrayHandleCartesianProduct.h:326
vtkm::cont::DataSet
Definition: DataSet.h:34
vtkm::cont::UnknownCellSet
A CellSet of an unknown type.
Definition: UnknownCellSet.h:48
CellLocatorUniformGrid.h
vtkm::worklet::flow::GridEvaluator::GridEvaluator
VTKM_CONT GridEvaluator()=default
vtkm::cont::ArrayHandle::ReadPortalType
typename StorageType::ReadPortalType ReadPortalType
Definition: ArrayHandle.h:294
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::flow::GridEvaluator::Bounds
vtkm::Bounds Bounds
Definition: GridEvaluators.h:224
vtkm::CellClassification::Ghost
@ Ghost
Definition: CellClassification.h:40
vtkm::cont::Field::GetData
const vtkm::cont::UnknownArrayHandle & GetData() const
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::ExecutionGridEvaluator::Locator
vtkm::cont::CellLocatorGeneral::ExecObjType Locator
Definition: GridEvaluators.h:157
vtkm::worklet::flow::GridEvaluator::GridEvaluator
VTKM_CONT GridEvaluator(const vtkm::cont::DataSet &dataSet, const FieldType &field)
Definition: GridEvaluators.h:176
vtkm::cont::CoordinateSystem
Definition: CoordinateSystem.h:25
vtkm::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
vtkm::worklet::flow::GridEvaluator::InitializeLocator
VTKM_CONT void InitializeLocator(const vtkm::cont::CoordinateSystem &coordinates, const vtkm::cont::UnknownCellSet &cellset)
Definition: GridEvaluators.h:215
CellLocatorTwoLevel.h
vtkm::cont::DataSet::GetCoordinateSystem
VTKM_CONT vtkm::cont::CoordinateSystem GetCoordinateSystem(vtkm::Id index=0) const
vtkm::VecVariable
A short variable-length array with maximum length.
Definition: VecVariable.h:30
vtkm::worklet::flow::GridEvaluator::PrepareForExecution
VTKM_CONT ExecutionGridEvaluator< FieldType > PrepareForExecution(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Definition: GridEvaluators.h:201
vtkm::cont::DataSet::GetGhostCellField
const VTKM_CONT vtkm::cont::Field & GetGhostCellField() const
Returns the cell field that matches the ghost cell field name.
vtkm::exec::CellInterpolationHelper
Definition: CellInterpolationHelper.h:33
CellInterpolationHelper.h
vtkm::exec::CellInterpolationHelper::GetCellInfo
VTKM_EXEC void GetCellInfo(const vtkm::Id &cellId, vtkm::UInt8 &cellShape, vtkm::IdComponent &numVerts, vtkm::VecVariable< vtkm::Id, 8 > &indices) const
Definition: CellInterpolationHelper.h:90
vtkm::cont::Field::Association::Points
@ Points
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::Bounds
Represent an axis-aligned 3D bounds in space.
Definition: Bounds.h:29
vtkm::UInt8
uint8_t UInt8
Definition: Types.h:157
vtkmNotUsed
#define vtkmNotUsed(parameter_name)
Simple macro to identify a parameter as unused.
Definition: ExportMacros.h:128
vtkm::cont::CellLocatorGeneral::ExecObjType
vtkm::ListApply< ExecLocatorList, vtkm::exec::CellLocatorMultiplexer > ExecObjType
Definition: CellLocatorGeneral.h:56
vtkm::worklet::flow::GridEvaluatorStatus::CheckOk
VTKM_EXEC_CONT bool CheckOk() const
Definition: GridEvaluatorStatus.h:36
vtkm::cont::CellLocatorGeneral
A CellLocator that works generally well for any supported cell set.
Definition: CellLocatorGeneral.h:41
Field.h
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::FloatDefault
vtkm::Float32 FloatDefault
The floating point type to use when no other precision is specified.
Definition: Types.h:198
vtkm::worklet::flow::ExecutionGridEvaluator::InterpolationHelper
vtkm::exec::CellInterpolationHelper InterpolationHelper
Definition: GridEvaluators.h:156
vtkm::worklet::flow::GridEvaluator::Field
FieldType Field
Definition: GridEvaluators.h:225
CellLocatorRectilinearGrid.h
vtkm::cont::CellInterpolationHelper
Definition: CellInterpolationHelper.h:184
vtkm::cont::ArrayHandleUniformPointCoordinates
ArrayHandleUniformPointCoordinates is a specialization of ArrayHandle.
Definition: ArrayHandleUniformPointCoordinates.h:45
vtkm::cont::Field::Association::Cells
@ Cells
vtkm::worklet::flow::ExecutionGridEvaluator::Bounds
vtkm::Bounds Bounds
Definition: GridEvaluators.h:152
CellSetStructured.h
vtkm::worklet::flow::GridEvaluator::GhostCellArray
GhostCellArrayType GhostCellArray
Definition: GridEvaluators.h:226
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::GridEvaluator::Locator
vtkm::cont::CellLocatorGeneral Locator
Definition: GridEvaluators.h:228
vtkm::worklet::flow::ExecutionGridEvaluator::GetTemporalBoundary
VTKM_EXEC_CONT vtkm::FloatDefault GetTemporalBoundary(vtkm::Id direction) const
Definition: GridEvaluators.h:81
vtkm::worklet::flow::ExecutionGridEvaluator::GhostCells
GhostCellPortal GhostCells
Definition: GridEvaluators.h:154
vtkm::worklet::flow::ExecutionGridEvaluator::InGhostCell
VTKM_EXEC bool InGhostCell(const vtkm::Id &cellId) const
Definition: GridEvaluators.h:142
vtkm::worklet::flow::GridEvaluatorStatus::SetInGhostCell
VTKM_EXEC_CONT void SetInGhostCell()
Definition: GridEvaluatorStatus.h:47
vtkm::worklet::flow::ExecutionGridEvaluator::Field
FieldType::ExecutionType Field
Definition: GridEvaluators.h:153
CellLocatorGeneral.h
vtkm::worklet::flow::GridEvaluatorStatus::SetSpatialBounds
VTKM_EXEC_CONT void SetSpatialBounds()
Definition: GridEvaluatorStatus.h:41
vtkm::cont::DataSet::HasGhostCellField
VTKM_CONT bool HasGhostCellField() const
vtkm::cont::DataSet::GetCellSet
const VTKM_CONT vtkm::cont::UnknownCellSet & GetCellSet() const
Definition: DataSet.h:362
vtkm::worklet::flow::ExecutionGridEvaluator::GhostCellPortal
typename vtkm::cont::ArrayHandle< vtkm::UInt8 >::ReadPortalType GhostCellPortal
Definition: GridEvaluators.h:150
DataSet.h
vtkm::worklet::flow::ExecutionGridEvaluator::IsWithinSpatialBoundary
VTKM_EXEC bool IsWithinSpatialBoundary(const Point &point) const
Definition: GridEvaluators.h:61
vtkm::worklet::flow::ExecutionGridEvaluator
Definition: GridEvaluators.h:35
vtkm::worklet::flow::GridEvaluatorStatus
Definition: GridEvaluatorStatus.h:23