VTK
vtkmCellSetSingleType.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 vtkmCellSetSingleType_h
21 #define vtkmCellSetSingleType_h
22 #ifndef __VTK_WRAP__
23 #ifndef VTK_WRAPPING_CXX
24 
25 #include "vtkmTags.h"
26 
27 #include <vtkm/CellShape.h>
28 #include <vtkm/CellTraits.h>
29 #include <vtkm/TopologyElementTag.h>
30 #include <vtkm/cont/ArrayHandle.h>
31 #include <vtkm/cont/CellSet.h>
32 
33 #include <vtkm/VecFromPortal.h>
34 
35 #include <vtkm/cont/serial/DeviceAdapterSerial.h>
36 #include <vtkm/cont/cuda/DeviceAdapterCuda.h>
37 #include <vtkm/cont/tbb/DeviceAdapterTBB.h>
38 
39 #include "vtkmConnectivityExec.h"
40 
41 namespace vtkm {
42 namespace cont {
43 
44 class VTKACCELERATORSVTKM_EXPORT vtkmCellSetSingleType : public CellSet
45 {
47 
48 public:
50  : CellSet((std::string()))
51  , NumberOfCells(0)
52  , NumberOfPoints(0)
53  , CellTypeAsId(CellShapeTagEmpty::Id)
54  , Connectivity()
55  , ReverseConnectivityBuilt(false)
56  , RConn()
57  , RNumIndices()
58  , RIndexOffsets()
59  {
60  }
61 
62  template <typename CellShapeTag>
63  vtkmCellSetSingleType(CellShapeTag, const std::string& name)
64  : CellSet(name)
65  , NumberOfCells(0)
66  , NumberOfPoints(0)
67  , CellTypeAsId(CellShapeTag::Id)
68  , Connectivity()
69  , ReverseConnectivityBuilt(false)
70  , RConn()
71  , RNumIndices()
72  , RIndexOffsets()
73  {
74  }
75 
77  : CellSet(src)
78  , NumberOfCells(src.NumberOfCells)
79  , NumberOfPoints(src.NumberOfPoints)
80  , CellTypeAsId(src.CellTypeAsId)
81  , Connectivity(src.Connectivity)
82  , ReverseConnectivityBuilt(src.ReverseConnectivityBuilt)
83  , RConn(src.RConn)
84  , RNumIndices(src.RNumIndices)
85  , RIndexOffsets(src.RIndexOffsets)
86  {
87  }
88 
90  {
91  this->CellSet::operator=(src);
92  this->NumberOfCells = src.NumberOfCells;
93  this->NumberOfPoints = src.NumberOfPoints;
94  this->CellTypeAsId = src.CellTypeAsId;
95  this->ReverseConnectivityBuilt = src.ReverseConnectivityBuilt;
96  this->Connectivity = src.Connectivity;
97  this->RConn = src.RConn;
98  this->RNumIndices = src.RNumIndices;
99  this->RIndexOffsets = src.RIndexOffsets;
100  return *this;
101  }
102 
103  vtkm::Id GetNumberOfCells() const override
104  {
105  return this->NumberOfCells;
106  }
107 
108  vtkm::Id GetNumberOfPoints() const override
109  {
110  return this->NumberOfPoints;
111  }
112 
113  vtkm::Id GetNumberOfFaces() const override{ return -1; }
114 
115  vtkm::Id GetNumberOfEdges() const override{ return -1; }
116 
117  vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagCell) const
118  {
119  return this->GetNumberOfCells();
120  }
121 
122  vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagPoint) const
123  {
124  return this->GetNumberOfPoints();
125  }
126 
127  // This is the way you can fill the memory from another system without copying
128  void Fill(
129  vtkm::Id numberOfPoints,
130  const vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkCellArrayContainerTag>&
131  connectivity);
132 
133  template <typename DeviceAdapter, typename FromTopology, typename ToTopology>
135 
136  template <typename DeviceAdapter>
137  struct ExecutionTypes<DeviceAdapter, vtkm::TopologyElementTagPoint,
138  vtkm::TopologyElementTagCell>
139  {
141  };
142 
143  template <typename DeviceAdapter>
144  struct ExecutionTypes<DeviceAdapter, vtkm::TopologyElementTagCell,
145  vtkm::TopologyElementTagPoint>
146  {
148  };
149 
150  template <typename Device>
152  PrepareForInput(Device, vtkm::TopologyElementTagPoint,
153  vtkm::TopologyElementTagCell) const;
154 
155  template <typename Device>
157  PrepareForInput(Device, vtkm::TopologyElementTagCell,
158  vtkm::TopologyElementTagPoint) const;
159 
160 
161  const vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkCellArrayContainerTag>&
162  GetConnectivityArray(vtkm::TopologyElementTagPoint,
163  vtkm::TopologyElementTagCell) const
164  {
165  return this->Connectivity;
166  }
167 
168  void PrintSummary(std::ostream& out) const override;
169 
171  {
172  this->Connectivity.ReleaseResourcesExecution();
173  this->RConn.ReleaseResourcesExecution();
174  this->RNumIndices.ReleaseResourcesExecution();
175  this->RIndexOffsets.ReleaseResourcesExecution();
176  }
177 
178 private:
179  template <typename CellShapeTag>
180  void DetermineNumberOfPoints(CellShapeTag, vtkm::CellTraitsTagSizeFixed,
181  vtkm::IdComponent& numberOfPoints) const
182  {
183  numberOfPoints = vtkm::CellTraits<CellShapeTag>::NUM_POINTS;
184  }
185 
186  template <typename CellShapeTag>
187  void DetermineNumberOfPoints(CellShapeTag, vtkm::CellTraitsTagSizeVariable,
188  vtkm::IdComponent& numberOfPoints) const
189  { // variable length cells can't be used with this class
190  numberOfPoints = -1;
191  }
192 
193  vtkm::IdComponent DetermineNumberOfPoints() const;
194 
195  vtkm::Id NumberOfCells;
196  mutable vtkm::Id NumberOfPoints;
197  vtkm::Id CellTypeAsId;
198  vtkm::cont::ArrayHandle<vtkm::Id, ConnectivityStorageTag> Connectivity;
199 
200  mutable bool ReverseConnectivityBuilt;
201  mutable vtkm::cont::ArrayHandle<vtkm::Id> RConn;
202  mutable vtkm::cont::ArrayHandle<vtkm::IdComponent> RNumIndices;
203  mutable vtkm::cont::ArrayHandle<vtkm::Id> RIndexOffsets;
204 };
205 
206 // template methods we want to compile only once
207 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
209  vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagSerial,
210  vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const;
211 
212 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
214  vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagSerial,
215  vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const;
216 
217 #ifdef VTKM_ENABLE_TBB
218 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
220  vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagTBB,
221  vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const;
222 
223 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
225  vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagTBB,
226  vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const;
227 #endif
228 
229 #ifdef VTKM_ENABLE_OPENMP
230 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
232  vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagOpenMP,
233  vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const;
234 
235 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
237  vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagTBB,
238  vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const;
239 #endif
240 
241 #if defined(VTKM_ENABLE_CUDA) && defined(VTKM_CUDA)
242 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
244  vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagCuda,
245  vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const;
246 
247 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
249  vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagCuda,
250  vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const;
251 #endif
252 }
253 } // namespace vtkm::cont
254 
255 #endif
256 #endif
257 #endif // vtkmlib_vtkmCellSetSingleType_h
258 // VTK-HeaderTest-Exclude: vtkmCellSetSingleType.h
vtkm::exec::ConnectivityVTKSingleType< Device > PrepareForInput(Device, vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const
vtkmCellSetSingleType(CellShapeTag, const std::string &name)
vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagPoint) const
vtkm::Id GetNumberOfPoints() const override
vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagCell) const
vtkm::Id GetNumberOfFaces() const override
vtkm::Id GetNumberOfEdges() const override
vtkm::Id GetNumberOfCells() const override
vtkmCellSetSingleType & operator=(const vtkmCellSetSingleType &src)
vtkmCellSetSingleType(const vtkmCellSetSingleType &src)
const vtkm::cont::ArrayHandle< vtkm::Id, tovtkm::vtkCellArrayContainerTag > & GetConnectivityArray(vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const