VTK
vtkmConnectivityExec.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 // This software is distributed WITHOUT ANY WARRANTY; without even
6 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7 // PURPOSE. See the above copyright notice for more information.
8 //
9 // Copyright 2015 Sandia Corporation.
10 // Copyright 2015 UT-Battelle, LLC.
11 // Copyright 2015 Los Alamos National Security.
12 //
13 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
14 // the U.S. Government retains certain rights in this software.
15 //
16 // Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
17 // Laboratory (LANL), the U.S. Government retains certain rights in
18 // this software.
19 //============================================================================
20 #ifndef vtkmConnectivityExec_h
21 #define vtkmConnectivityExec_h
22 
23 #include "vtkmTags.h"
24 
25 #include <vtkm/CellShape.h>
26 #include <vtkm/TopologyElementTag.h>
27 #include <vtkm/cont/ArrayHandle.h>
28 #include <vtkm/VecFromPortal.h>
29 
30 #include <vtkm/cont/serial/DeviceAdapterSerial.h>
31 #include <vtkm/cont/cuda/DeviceAdapterCuda.h>
32 #include <vtkm/cont/tbb/DeviceAdapterTBB.h>
33 
34 namespace vtkm {
35 namespace exec {
36 
37 template <typename Device> class VTKM_ALWAYS_EXPORT ConnectivityVTKAOS
38 {
39  typedef vtkm::cont::ArrayHandle<vtkm::UInt8, tovtkm::vtkAOSArrayContainerTag>
40  ShapeHandleType;
41  typedef vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkCellArrayContainerTag>
42  ConnectivityHandleType;
43  typedef vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkAOSArrayContainerTag>
44  OffsetHandleType;
45 
46  typedef typename ShapeHandleType::template ExecutionTypes<Device>::PortalConst
47  ShapePortalType;
48  typedef typename ConnectivityHandleType::template ExecutionTypes<
49  Device>::PortalConst ConnectivityPortalType;
50  typedef
51  typename OffsetHandleType::template ExecutionTypes<Device>::PortalConst
52  IndexOffsetPortalType;
53 
54 public:
55  typedef typename vtkm::Id SchedulingRangeType;
56 
57  VTKM_SUPPRESS_EXEC_WARNINGS
58  VTKM_EXEC_CONT
60 
61  VTKM_EXEC_CONT
62  ConnectivityVTKAOS(const ShapePortalType& shapePortal,
63  const ConnectivityPortalType& connPortal,
64  const IndexOffsetPortalType& indexOffsetPortal);
65 
66  VTKM_SUPPRESS_EXEC_WARNINGS
67  VTKM_EXEC
68  vtkm::Id GetNumberOfElements() const;
69 
70  typedef vtkm::CellShapeTagGeneric CellShapeTag;
71 
72  VTKM_EXEC
73  CellShapeTag GetCellShape(vtkm::Id index) const;
74 
75  typedef vtkm::VecFromPortal<ConnectivityPortalType> IndicesType;
76 
82  VTKM_EXEC
83  IndicesType GetIndices(vtkm::Id index) const;
84 
85 private:
86  ShapePortalType Shapes;
87  ConnectivityPortalType Connectivity;
88  IndexOffsetPortalType IndexOffsets;
89 };
90 
91 
92 template <typename Device> class VTKM_ALWAYS_EXPORT ConnectivityVTKSingleType
93 {
94  typedef vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkCellArrayContainerTag>
95  ConnectivityHandleType;
96  typedef typename ConnectivityHandleType::template ExecutionTypes<
97  Device>::PortalConst ConnectivityPortalType;
98 
99 public:
100  typedef typename vtkm::Id SchedulingRangeType;
101 
102  VTKM_SUPPRESS_EXEC_WARNINGS
103  VTKM_EXEC_CONT
105 
106  VTKM_EXEC_CONT
107  ConnectivityVTKSingleType(const ConnectivityPortalType& connPortal,
108  vtkm::Id numCells,
109  vtkm::IdComponent numPointsPerCell,
110  vtkm::UInt8 shapeType);
111 
112  VTKM_EXEC
113  vtkm::Id GetNumberOfElements() const;
114 
115  typedef vtkm::CellShapeTagGeneric CellShapeTag;
116 
117  VTKM_EXEC
118  CellShapeTag GetCellShape(vtkm::Id index) const;
119 
120  typedef vtkm::VecFromPortal<ConnectivityPortalType> IndicesType;
121 
127  VTKM_EXEC
128  IndicesType GetIndices(vtkm::Id index) const;
129 
130 private:
131  ConnectivityPortalType Connectivity;
132  vtkm::Id NumberOfCells;
133  vtkm::IdComponent NumberOfPointsPerCell;
134  vtkm::UInt8 ShapeType;
135 };
136 
137 
138 template <typename Device> class VTKM_ALWAYS_EXPORT ReverseConnectivityVTK
139 {
140  typedef vtkm::cont::ArrayHandle<vtkm::Id> ConnectivityHandleType;
141  typedef vtkm::cont::ArrayHandle<vtkm::IdComponent> NumIndicesHandleType;
142  typedef vtkm::cont::ArrayHandle<vtkm::Id> OffsetHandleType;
143 
144  typedef typename ConnectivityHandleType::template ExecutionTypes<
145  Device>::PortalConst ConnectivityPortalType;
146 
147  typedef typename OffsetHandleType::template ExecutionTypes<Device>::PortalConst
148  IndexOffsetPortalType;
149 
150  typedef typename NumIndicesHandleType::template ExecutionTypes<Device>::PortalConst
151  NumIndicesPortalType;
152 
153 public:
154  typedef typename vtkm::Id SchedulingRangeType;
155 
156  VTKM_SUPPRESS_EXEC_WARNINGS
157  VTKM_EXEC_CONT
159 
160  VTKM_EXEC_CONT
161  ReverseConnectivityVTK(const ConnectivityPortalType& connPortal,
162  const NumIndicesPortalType& numIndicesPortal,
163  const IndexOffsetPortalType& indexOffsetPortal);
164 
165  VTKM_EXEC
166  vtkm::Id GetNumberOfElements() const;
167 
168  typedef vtkm::CellShapeTagVertex CellShapeTag;
169 
170  VTKM_EXEC
171  CellShapeTag GetCellShape(vtkm::Id) const { return vtkm::CellShapeTagVertex(); }
172 
173  typedef vtkm::VecFromPortal<ConnectivityPortalType> IndicesType;
174 
180  VTKM_EXEC
181  IndicesType GetIndices(vtkm::Id index) const;
182 
183 private:
184  ConnectivityPortalType Connectivity;
185  NumIndicesPortalType NumIndices;
186  IndexOffsetPortalType IndexOffsets;
187 };
188 
189 // template methods we want to compile only once
190 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT ConnectivityVTKAOS<vtkm::cont::DeviceAdapterTagSerial>;
191 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT ConnectivityVTKSingleType<vtkm::cont::DeviceAdapterTagSerial>;
192 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT ReverseConnectivityVTK<vtkm::cont::DeviceAdapterTagSerial>;
193 
194 #ifdef VTKM_ENABLE_TBB
195 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT ConnectivityVTKAOS<vtkm::cont::DeviceAdapterTagTBB>;
196 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT ConnectivityVTKSingleType<vtkm::cont::DeviceAdapterTagTBB>;
197 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT ReverseConnectivityVTK<vtkm::cont::DeviceAdapterTagTBB>;
198 #endif
199 
200 //only when cuda is enabled, and the compiler is cuda
201 #if defined(VTKM_ENABLE_CUDA) && defined(VTKM_CUDA)
202 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT ConnectivityVTKAOS<vtkm::cont::DeviceAdapterTagCuda>;
203 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT ConnectivityVTKSingleType<vtkm::cont::DeviceAdapterTagCuda>;
204 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT ReverseConnectivityVTK<vtkm::cont::DeviceAdapterTagCuda>;
205 #endif
206 }
207 }
208 
209 
210 #endif
211 // VTK-HeaderTest-Exclude: vtkmConnectivityExec.h
vtkm::CellShapeTagGeneric CellShapeTag
vtkm::VecFromPortal< ConnectivityPortalType > IndicesType
vtkm::VecFromPortal< ConnectivityPortalType > IndicesType
VTKM_EXEC CellShapeTag GetCellShape(vtkm::Id) const
vtkm::VecFromPortal< ConnectivityPortalType > IndicesType