VTK-m  2.2
GridMetaData.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 #ifndef vtkm_filter_flow_internal_GridMetaData_h
11 #define vtkm_filter_flow_internal_GridMetaData_h
12 
13 namespace vtkm
14 {
15 namespace filter
16 {
17 namespace flow
18 {
19 namespace internal
20 {
21 
22 class GridMetaData
23 {
24 public:
25  using Structured2DType = vtkm::cont::CellSetStructured<2>;
26  using Structured3DType = vtkm::cont::CellSetStructured<3>;
27 
28  VTKM_CONT
29  GridMetaData(const vtkm::cont::UnknownCellSet cellSet)
30  {
31  if (cellSet.CanConvert<Structured2DType>())
32  {
33  this->cellSet2D = true;
34  vtkm::Id2 dims =
35  cellSet.AsCellSet<Structured2DType>().GetSchedulingRange(vtkm::TopologyElementTagPoint());
36  this->Dims = vtkm::Id3(dims[0], dims[1], 1);
37  }
38  else
39  {
40  this->cellSet2D = false;
41  this->Dims =
42  cellSet.AsCellSet<Structured3DType>().GetSchedulingRange(vtkm::TopologyElementTagPoint());
43  }
44  this->PlaneSize = Dims[0] * Dims[1];
45  this->RowSize = Dims[0];
46  }
47 
48  VTKM_EXEC
49  bool IsCellSet2D() const { return this->cellSet2D; }
50 
51  VTKM_EXEC
52  void GetLogicalIndex(const vtkm::Id index, vtkm::Id3& logicalIndex) const
53  {
54  logicalIndex[0] = index % Dims[0];
55  logicalIndex[1] = (index / Dims[0]) % Dims[1];
56  if (this->cellSet2D)
57  logicalIndex[2] = 0;
58  else
59  logicalIndex[2] = index / (Dims[0] * Dims[1]);
60  }
61 
62  VTKM_EXEC
63  const vtkm::Vec<vtkm::Id, 6> GetNeighborIndices(const vtkm::Id index) const
64  {
65  vtkm::Vec<vtkm::Id, 6> indices;
66  vtkm::Id3 logicalIndex;
67  GetLogicalIndex(index, logicalIndex);
68 
69  // For differentials w.r.t delta in x
70  indices[0] = (logicalIndex[0] == 0) ? index : index - 1;
71  indices[1] = (logicalIndex[0] == Dims[0] - 1) ? index : index + 1;
72  // For differentials w.r.t delta in y
73  indices[2] = (logicalIndex[1] == 0) ? index : index - RowSize;
74  indices[3] = (logicalIndex[1] == Dims[1] - 1) ? index : index + RowSize;
75  if (!this->cellSet2D)
76  {
77  // For differentials w.r.t delta in z
78  indices[4] = (logicalIndex[2] == 0) ? index : index - PlaneSize;
79  indices[5] = (logicalIndex[2] == Dims[2] - 1) ? index : index + PlaneSize;
80  }
81  return indices;
82  }
83 
84 private:
85  bool cellSet2D = false;
86  vtkm::Id3 Dims;
87  vtkm::Id PlaneSize;
88  vtkm::Id RowSize;
89 };
90 
91 }
92 }
93 }
94 } //vtkm::filter::flow::internal
95 
96 #endif //vtkm_filter_flow_internal_GridMetaData_h
vtkm::TopologyElementTagPoint
A tag used to identify the point elements in a topology.
Definition: TopologyElementTag.h:34
vtkm::cont::UnknownCellSet::CanConvert
bool CanConvert() const
Returns true if this cell set can be retrieved as the given type.
Definition: UnknownCellSet.h:161
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::cont::CellSetStructured
Defines a 1-, 2-, or 3-dimensional structured grid of points.
Definition: CastAndCall.h:32
vtkm::cont::UnknownCellSet
A CellSet of an unknown type.
Definition: UnknownCellSet.h:48
vtkm::cont::UnknownCellSet::AsCellSet
void AsCellSet(CellSetType &cellSet) const
Get the cell set as a known type.
Definition: UnknownCellSet.h:178
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::Id3
vtkm::Vec< vtkm::Id, 3 > Id3
Id3 corresponds to a 3-dimensional index for 3d arrays.
Definition: Types.h:1041
vtkm::Vec< vtkm::Id, 2 >