VTK-m  2.0
CellInterpolationHelper.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_CellInterpolationHelper_h
12 #define vtk_m_filter_flow_worklet_CellInterpolationHelper_h
13 
14 #include <vtkm/CellShape.h>
15 #include <vtkm/Types.h>
16 #include <vtkm/VecVariable.h>
17 
23 
24 /*
25  * Interface to define the helper classes that can return mesh data
26  * on a cell by cell basis.
27  */
28 namespace vtkm
29 {
30 namespace exec
31 {
32 
34 {
35 private:
42 
43 public:
44  enum class HelperType
45  {
46  STRUCTURED,
47  EXPSINGLE,
48  EXPLICIT
49  };
50 
51  VTKM_CONT
52  CellInterpolationHelper() = default;
53 
54  VTKM_CONT
55  CellInterpolationHelper(const vtkm::Id3& cellDims, const vtkm::Id3& pointDims, bool is3D)
56  : CellDims(cellDims)
57  , PointDims(pointDims)
58  , Is3D(is3D)
59  {
61  }
62 
64  const vtkm::IdComponent pointsPerCell,
65  const ConnType& connectivity,
67  vtkm::cont::Token& token)
68  : CellShape(cellShape)
69  , PointsPerCell(pointsPerCell)
70  , Connectivity(connectivity.PrepareForInput(device, token))
71  {
73  }
74 
75 
76  VTKM_CONT
78  const OffsetType& offset,
79  const ConnType& connectivity,
81  vtkm::cont::Token& token)
82  : Shape(shape.PrepareForInput(device, token))
83  , Offset(offset.PrepareForInput(device, token))
84  , Connectivity(connectivity.PrepareForInput(device, token))
85  {
86  this->Type = HelperType::EXPLICIT;
87  }
88 
89  VTKM_EXEC
90  void GetCellInfo(const vtkm::Id& cellId,
91  vtkm::UInt8& cellShape,
92  vtkm::IdComponent& numVerts,
93  vtkm::VecVariable<vtkm::Id, 8>& indices) const
94  {
95  switch (this->Type)
96  {
98  {
99  vtkm::Id3 logicalCellId;
100  logicalCellId[0] = cellId % this->CellDims[0];
101  logicalCellId[1] = (cellId / this->CellDims[0]) % this->CellDims[1];
102  if (this->Is3D)
103  {
104  logicalCellId[2] = cellId / (this->CellDims[0] * this->CellDims[1]);
105  indices.Append((logicalCellId[2] * this->PointDims[1] + logicalCellId[1]) *
106  this->PointDims[0] +
107  logicalCellId[0]);
108  indices.Append(indices[0] + 1);
109  indices.Append(indices[1] + this->PointDims[0]);
110  indices.Append(indices[2] - 1);
111  indices.Append(indices[0] + this->PointDims[0] * this->PointDims[1]);
112  indices.Append(indices[4] + 1);
113  indices.Append(indices[5] + this->PointDims[0]);
114  indices.Append(indices[6] - 1);
115  cellShape = static_cast<vtkm::UInt8>(vtkm::CELL_SHAPE_HEXAHEDRON);
116  numVerts = 8;
117  }
118  else
119  {
120  indices.Append(logicalCellId[1] * this->PointDims[0] + logicalCellId[0]);
121  indices.Append(indices[0] + 1);
122  indices.Append(indices[1] + this->PointDims[0]);
123  indices.Append(indices[2] - 1);
124  cellShape = static_cast<vtkm::UInt8>(vtkm::CELL_SHAPE_QUAD);
125  numVerts = 4;
126  }
127  }
128  break;
129 
131  {
132  cellShape = this->CellShape;
133  numVerts = this->PointsPerCell;
134  vtkm::Id n = static_cast<vtkm::Id>(PointsPerCell);
135  vtkm::Id offset = cellId * n;
136  for (vtkm::Id i = 0; i < n; i++)
137  indices.Append(Connectivity.Get(offset + i));
138  }
139  break;
140 
142  {
143  cellShape = this->Shape.Get(cellId);
144  const vtkm::Id offset = this->Offset.Get(cellId);
145  numVerts = static_cast<vtkm::IdComponent>(this->Offset.Get(cellId + 1) - offset);
146  for (vtkm::IdComponent i = 0; i < numVerts; i++)
147  indices.Append(this->Connectivity.Get(offset + i));
148  }
149  break;
150 
151  default:
152  {
153  // Code path not expected to execute in correct cases
154  // Supress unused variable warning
155  cellShape = vtkm::UInt8(0);
156  numVerts = vtkm::IdComponent(0);
157  }
158  }
159  }
160 
161 private:
163  // variables for structured type
166  bool Is3D = true;
167  // variables for single explicit type
170  // variables for explicit type
174 };
175 
176 } // namespace exec
177 
178 /*
179  * Control side base object.
180  */
181 namespace cont
182 {
183 
185 {
186 private:
192 
193 public:
194  VTKM_CONT
195  CellInterpolationHelper() = default;
196 
197  VTKM_CONT
199  {
200  if (cellSet.CanConvert<Structured2DType>())
201  {
202  this->Is3D = false;
203  vtkm::Id2 cellDims =
204  cellSet.AsCellSet<Structured2DType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
205  vtkm::Id2 pointDims =
206  cellSet.AsCellSet<Structured2DType>().GetSchedulingRange(vtkm::TopologyElementTagPoint());
207  this->CellDims = vtkm::Id3(cellDims[0], cellDims[1], 0);
208  this->PointDims = vtkm::Id3(pointDims[0], pointDims[1], 1);
210  }
211  else if (cellSet.CanConvert<Structured3DType>())
212  {
213  this->Is3D = true;
214  this->CellDims =
215  cellSet.AsCellSet<Structured3DType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
216  this->PointDims =
217  cellSet.AsCellSet<Structured3DType>().GetSchedulingRange(vtkm::TopologyElementTagPoint());
219  }
220  else if (cellSet.CanConvert<SingleExplicitType>())
221  {
223  const auto cellShapes =
225  const auto numIndices =
227  CellShape = vtkm::cont::ArrayGetValue(0, cellShapes);
228  PointsPerCell = vtkm::cont::ArrayGetValue(0, numIndices);
229  Connectivity = CellSet.GetConnectivityArray(vtkm::TopologyElementTagCell(),
232  }
233  else if (cellSet.CanConvert<ExplicitType>())
234  {
236  Shape =
238  Offset =
240  Connectivity = CellSet.GetConnectivityArray(vtkm::TopologyElementTagCell(),
243  }
244  else
245  throw vtkm::cont::ErrorInternal("Unsupported cellset type");
246  }
247 
248  VTKM_CONT
250  vtkm::cont::Token& token) const
251  {
252  switch (this->Type)
253  {
255  return ExecutionType(this->CellDims, this->PointDims, this->Is3D);
256 
258  return ExecutionType(
259  this->CellShape, this->PointsPerCell, this->Connectivity, device, token);
260 
262  return ExecutionType(this->Shape, this->Offset, this->Connectivity, device, token);
263  }
264  throw vtkm::cont::ErrorInternal("Undefined case for building cell interpolation helper");
265  }
266 
267 private:
268  // Variables required for strucutred grids
271  bool Is3D = true;
272  // variables for single explicit type
275  // Variables required for unstructured grids
280 };
281 
282 } //namespace cont
283 } //namespace vtkm
284 
285 #endif //vtk_m_filter_flow_worklet_CellInterpolationHelper_h
vtkm::TopologyElementTagPoint
A tag used to identify the point elements in a topology.
Definition: TopologyElementTag.h:34
vtkm::exec::CellInterpolationHelper::HelperType
HelperType
Definition: CellInterpolationHelper.h:44
vtkm::cont::CellInterpolationHelper::Shape
vtkm::cont::ArrayHandle< vtkm::UInt8 > Shape
Definition: CellInterpolationHelper.h:276
vtkm::exec::CellInterpolationHelper::PointsPerCell
vtkm::IdComponent PointsPerCell
Definition: CellInterpolationHelper.h:169
vtkm::cont::ArrayHandle< vtkm::UInt8 >
vtkm::cont::CellInterpolationHelper::PrepareForExecution
const VTKM_CONT ExecutionType PrepareForExecution(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Definition: CellInterpolationHelper.h:249
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm::exec::CellInterpolationHelper::CellInterpolationHelper
VTKM_CONT CellInterpolationHelper(const vtkm::Id3 &cellDims, const vtkm::Id3 &pointDims, bool is3D)
Definition: CellInterpolationHelper.h:55
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
Types.h
vtkm::exec::CellInterpolationHelper::ConnPortalType
typename ConnType::ReadPortalType ConnPortalType
Definition: CellInterpolationHelper.h:41
vtkm::cont::UnknownCellSet::CanConvert
VTKM_CONT bool CanConvert() const
Returns true if this cell set can be retrieved as the given type.
Definition: UnknownCellSet.h:161
UnknownCellSet.h
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::cont::CellSetStructured
Definition: CastAndCall.h:32
vtkm::exec::CellInterpolationHelper::CellInterpolationHelper
CellInterpolationHelper(const vtkm::UInt8 cellShape, const vtkm::IdComponent pointsPerCell, const ConnType &connectivity, vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token)
Definition: CellInterpolationHelper.h:63
vtkm::exec::CellInterpolationHelper::ShapePortalType
typename ShapeType::ReadPortalType ShapePortalType
Definition: CellInterpolationHelper.h:39
vtkm::exec::CellInterpolationHelper::PointDims
vtkm::Id3 PointDims
Definition: CellInterpolationHelper.h:165
vtkm::cont::CellSetSingleType
Definition: CastAndCall.h:34
vtkm::cont::ArrayGetValue
VTKM_CONT T ArrayGetValue(vtkm::Id id, const vtkm::cont::ArrayHandle< T, S > &data)
Obtain a small set of values from an ArrayHandle with minimal device transfers.
Definition: ArrayGetValues.h:264
CellInterpolate.h
vtkm::cont::UnknownCellSet
A CellSet of an unknown type.
Definition: UnknownCellSet.h:48
CellShape.h
vtkm::cont::ArrayHandle< vtkm::UInt8 >::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::exec::CellInterpolationHelper::Offset
OffsetPortalType Offset
Definition: CellInterpolationHelper.h:172
vtkm::cont::CellInterpolationHelper::PointDims
vtkm::Id3 PointDims
Definition: CellInterpolationHelper.h:270
vtkm::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
vtkm::exec::CellInterpolationHelper::Type
HelperType Type
Definition: CellInterpolationHelper.h:162
vtkm::cont::UnknownCellSet::AsCellSet
VTKM_CONT void AsCellSet(CellSetType &cellSet) const
Get the cell set as a known type.
Definition: UnknownCellSet.h:178
vtkm::cont::ErrorInternal
This class is thrown when VTKm detects an internal state that should never be reached.
Definition: ErrorInternal.h:26
vtkm::cont::CellInterpolationHelper::Offset
vtkm::cont::ArrayHandle< vtkm::Id > Offset
Definition: CellInterpolationHelper.h:277
vtkm::cont::CellInterpolationHelper::PointsPerCell
vtkm::IdComponent PointsPerCell
Definition: CellInterpolationHelper.h:274
vtkm::cont::CellInterpolationHelper::CellInterpolationHelper
VTKM_CONT CellInterpolationHelper()=default
vtkm::exec::CellInterpolationHelper::HelperType::STRUCTURED
@ STRUCTURED
vtkm::exec::CellInterpolationHelper::Is3D
bool Is3D
Definition: CellInterpolationHelper.h:166
vtkm::VecVariable::Append
VTKM_EXEC_CONT void Append(ComponentType value)
Definition: VecVariable.h:80
vtkm::cont::CellInterpolationHelper::ExecutionType
vtkm::exec::CellInterpolationHelper ExecutionType
Definition: CellInterpolationHelper.h:187
vtkm::exec::CellInterpolationHelper::CellInterpolationHelper
VTKM_CONT CellInterpolationHelper(const ShapeType &shape, const OffsetType &offset, const ConnType &connectivity, vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token)
Definition: CellInterpolationHelper.h:77
vtkm::VecVariable
A short variable-length array with maximum length.
Definition: VecVariable.h:30
vtkm::exec::CellInterpolationHelper::Connectivity
ConnPortalType Connectivity
Definition: CellInterpolationHelper.h:173
vtkm::exec::CellInterpolationHelper
Definition: CellInterpolationHelper.h:33
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::CellInterpolationHelper::CellDims
vtkm::Id3 CellDims
Definition: CellInterpolationHelper.h:269
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::CellInterpolationHelper::Is3D
bool Is3D
Definition: CellInterpolationHelper.h:271
vtkm::cont::CellSet
Definition: CellSet.h:24
vtkm::CELL_SHAPE_HEXAHEDRON
@ CELL_SHAPE_HEXAHEDRON
Definition: CellShape.h:48
vtkm::exec::CellInterpolationHelper::HelperType::EXPLICIT
@ EXPLICIT
vtkm::UInt8
uint8_t UInt8
Definition: Types.h:157
ArrayGetValues.h
vtkm::Id3
vtkm::Vec< vtkm::Id, 3 > Id3
Id3 corresponds to a 3-dimensional index for 3d arrays.
Definition: Types.h:1003
vtkm::exec::CellInterpolationHelper::Shape
ShapePortalType Shape
Definition: CellInterpolationHelper.h:171
vtkm::exec::CellInterpolationHelper::CellShape
vtkm::UInt8 CellShape
Definition: CellInterpolationHelper.h:168
vtkm::exec::CellInterpolationHelper::CellInterpolationHelper
VTKM_CONT CellInterpolationHelper()=default
vtkm::cont::CellInterpolationHelper::Connectivity
vtkm::cont::ArrayHandle< vtkm::Id > Connectivity
Definition: CellInterpolationHelper.h:278
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::Vec< vtkm::Id, 3 >
VecVariable.h
vtkm::cont::CellInterpolationHelper
Definition: CellInterpolationHelper.h:184
vtkm::cont::CellSetExplicit
Definition: CastAndCall.h:36
vtkm::exec::CellInterpolationHelper::OffsetPortalType
typename OffsetType::ReadPortalType OffsetPortalType
Definition: CellInterpolationHelper.h:40
vtkm::cont::CellInterpolationHelper::CellShape
vtkm::UInt8 CellShape
Definition: CellInterpolationHelper.h:273
CellSetStructured.h
vtkm::TopologyElementTagCell
A tag used to identify the cell elements in a topology.
Definition: TopologyElementTag.h:24
vtkm::exec::CellInterpolationHelper::CellDims
vtkm::Id3 CellDims
Definition: CellInterpolationHelper.h:164
vtkm::cont::CellInterpolationHelper::CellInterpolationHelper
VTKM_CONT CellInterpolationHelper(const vtkm::cont::UnknownCellSet &cellSet)
Definition: CellInterpolationHelper.h:198
vtkm::exec::CellInterpolationHelper::HelperType::EXPSINGLE
@ EXPSINGLE
ExecutionObjectBase.h
vtkm::cont::CellInterpolationHelper::Type
ExecutionType::HelperType Type
Definition: CellInterpolationHelper.h:279
vtkm::CELL_SHAPE_QUAD
@ CELL_SHAPE_QUAD
Definition: CellShape.h:45