VTK
vtkmCellSetExplicit.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 vtkmCellSetExplicit_h
21 #define vtkmCellSetExplicit_h
22 #ifndef __VTK_WRAP__
23 #ifndef VTK_WRAPPING_CXX
24 
25 #include "vtkmTags.h"
26 
27 #include <vtkm/CellShape.h>
28 #include <vtkm/TopologyElementTag.h>
29 #include <vtkm/cont/ArrayHandle.h>
30 #include <vtkm/cont/CellSet.h>
31 
32 #include <vtkm/cont/serial/DeviceAdapterSerial.h>
33 #include <vtkm/cont/cuda/DeviceAdapterCuda.h>
34 #include <vtkm/cont/tbb/DeviceAdapterTBB.h>
35 
36 #include "vtkmConnectivityExec.h"
37 
38 namespace vtkm {
39 namespace cont {
40 
41 class VTKACCELERATORSVTKM_EXPORT vtkmCellSetExplicitAOS : public CellSet
42 {
43 public:
45  : CellSet(name)
46  , Shapes()
47  , Connectivity()
48  , IndexOffsets()
49  , ReverseConnectivityBuilt(false)
50  , RConn()
51  , RNumIndices()
52  , RIndexOffsets()
53  , NumberOfPoints(0)
54  {
55  }
56 
58  {
59  }
60 
62  : CellSet(src)
63  , Shapes(src.Shapes)
64  , Connectivity(src.Connectivity)
65  , IndexOffsets(src.IndexOffsets)
66  , ReverseConnectivityBuilt(src.ReverseConnectivityBuilt)
67  , RConn(src.RConn)
68  , RNumIndices(src.RNumIndices)
69  , RIndexOffsets(src.RIndexOffsets)
70  , NumberOfPoints(src.NumberOfPoints)
71  {
72  }
73 
75  {
76  this->CellSet::operator=(src);
77  this->Shapes = src.Shapes;
78  this->Connectivity = src.Connectivity;
79  this->IndexOffsets = src.IndexOffsets;
80  this->ReverseConnectivityBuilt = src.ReverseConnectivityBuilt;
81  this->RConn = src.RConn;
82  this->RNumIndices = src.RNumIndices;
83  this->RIndexOffsets = src.RIndexOffsets;
84  this->NumberOfPoints = src.NumberOfPoints;
85  return *this;
86  }
87 
88  vtkm::Id GetNumberOfCells() const override
89  {
90  return this->Shapes.GetNumberOfValues();
91  }
92 
93  vtkm::Id GetNumberOfPoints() const override
94  {
95  return this->NumberOfPoints;
96  }
97 
98  vtkm::Id GetNumberOfFaces() const override { return -1; }
99 
100  vtkm::Id GetNumberOfEdges() const override { return -1; }
101 
102 
103  vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagCell) const
104  {
105  return this->GetNumberOfCells();
106  }
107 
108  vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagPoint) const
109  {
110  return this->GetNumberOfPoints();
111  }
112 
113  vtkm::IdComponent GetNumberOfPointsInCell(vtkm::Id index) const;
114 
115  vtkm::Id GetCellShape(vtkm::Id index) const;
116 
119  void Fill(
120  vtkm::Id numberOfPoints,
121  const vtkm::cont::ArrayHandle<vtkm::UInt8,
123  const vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkCellArrayContainerTag>&
124  connectivity,
125  const vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkAOSArrayContainerTag>&
126  offsets);
127 
128  template <typename DeviceAdapter, typename FromTopology, typename ToTopology>
130 
131  template <typename DeviceAdapter>
132  struct ExecutionTypes<DeviceAdapter, vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell>
133  {
135  };
136 
137  template <typename DeviceAdapter>
138  struct ExecutionTypes<DeviceAdapter, vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint>
139  {
141  };
142 
143  template <typename Device>
145  PrepareForInput(Device, vtkm::TopologyElementTagPoint,
146  vtkm::TopologyElementTagCell) const;
147 
148  template <typename Device>
150  PrepareForInput(Device, vtkm::TopologyElementTagCell,
151  vtkm::TopologyElementTagPoint) const;
152 
153  const vtkm::cont::ArrayHandle<vtkm::UInt8, tovtkm::vtkAOSArrayContainerTag>&
154  GetShapesArray(vtkm::TopologyElementTagPoint,
155  vtkm::TopologyElementTagCell) const
156  {
157  return this->Shapes;
158  }
159 
160  const vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkCellArrayContainerTag>&
161  GetConnectivityArray(vtkm::TopologyElementTagPoint,
162  vtkm::TopologyElementTagCell) const
163  {
164  return this->Connectivity;
165  }
166 
167  const vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkAOSArrayContainerTag>&
168  GetIndexOffsetArray(vtkm::TopologyElementTagPoint,
169  vtkm::TopologyElementTagCell) const
170  {
171  return this->IndexOffsets;
172  }
173 
174  void PrintSummary(std::ostream& out) const override;
175 
177  {
178  this->Shapes.ReleaseResourcesExecution();
179  this->Connectivity.ReleaseResourcesExecution();
180  this->IndexOffsets.ReleaseResourcesExecution();
181  this->RConn.ReleaseResourcesExecution();
182  this->RNumIndices.ReleaseResourcesExecution();
183  this->RIndexOffsets.ReleaseResourcesExecution();
184  }
185 
186 private:
187  vtkm::cont::ArrayHandle<vtkm::UInt8, tovtkm::vtkAOSArrayContainerTag> Shapes;
188  vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkCellArrayContainerTag>
189  Connectivity;
190  vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkAOSArrayContainerTag>
191  IndexOffsets;
192 
193  //Reverse connectivity (cell -> point)
194  //Todo: Need a better way to represent that PrepareForInput is a
195  // non-const operation, but that is going to take some real
196  // code refactoring in vtk-m
197  mutable bool ReverseConnectivityBuilt;
198  mutable vtkm::cont::ArrayHandle<vtkm::Id> RConn;
199  mutable vtkm::cont::ArrayHandle<vtkm::IdComponent> RNumIndices;
200  mutable vtkm::cont::ArrayHandle<vtkm::Id> RIndexOffsets;
201  mutable vtkm::Id NumberOfPoints;
202 
203 };
204 
205 // template methods we want to compile only once
206 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
208  vtkmCellSetExplicitAOS::PrepareForInput(vtkm::cont::DeviceAdapterTagSerial,
209  vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const;
210 
211 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
213  vtkmCellSetExplicitAOS::PrepareForInput(vtkm::cont::DeviceAdapterTagSerial,
214  vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const;
215 
216 #ifdef VTKM_ENABLE_TBB
217 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
219  vtkmCellSetExplicitAOS::PrepareForInput(vtkm::cont::DeviceAdapterTagTBB,
220  vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const;
221 
222 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
224  vtkmCellSetExplicitAOS::PrepareForInput(vtkm::cont::DeviceAdapterTagTBB,
225  vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const;
226 #endif
227 
228 #ifdef VTKM_ENABLE_OPENMP
229 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
231  vtkmCellSetExplicitAOS::PrepareForInput(vtkm::cont::DeviceAdapterTagOpenMP,
232  vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const;
233 
234 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
236  vtkmCellSetExplicitAOS::PrepareForInput(vtkm::cont::DeviceAdapterTagOpenMP,
237  vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const;
238 #endif
239 
240 #if defined(VTKM_ENABLE_CUDA) && defined(VTKM_CUDA)
241 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
243  vtkmCellSetExplicitAOS::PrepareForInput(vtkm::cont::DeviceAdapterTagCuda,
244  vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const;
245 
246 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
248  vtkmCellSetExplicitAOS::PrepareForInput(vtkm::cont::DeviceAdapterTagCuda,
249  vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const;
250 #endif
251 }
252 }
253 
254 #endif
255 #endif
256 #endif
257 // VTK-HeaderTest-Exclude: vtkmCellSetExplicit.h
const vtkm::cont::ArrayHandle< vtkm::Id, tovtkm::vtkCellArrayContainerTag > & GetConnectivityArray(vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const
vtkmCellSetExplicitAOS(const std::string &name=std::string())
const vtkm::cont::ArrayHandle< vtkm::UInt8, tovtkm::vtkAOSArrayContainerTag > & GetShapesArray(vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const
const vtkm::cont::ArrayHandle< vtkm::Id, tovtkm::vtkAOSArrayContainerTag > & GetIndexOffsetArray(vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const
vtkm::exec::ConnectivityVTKAOS< Device > PrepareForInput(Device, vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const
vtkmCellSetExplicitAOS(const vtkmCellSetExplicitAOS &src)
vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagCell) const
vtkm::Id GetNumberOfEdges() const override
vtkm::Id GetNumberOfFaces() const override
vtkmCellSetExplicitAOS & operator=(const vtkmCellSetExplicitAOS &src)
vtkm::Id GetNumberOfCells() const override
vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagPoint) const
vtkm::Id GetNumberOfPoints() const override