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