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  {
78  this->CellSet::operator=(src);
79  this->NumberOfCells = src.NumberOfCells;
80  this->NumberOfPoints = src.NumberOfPoints;
81  this->CellTypeAsId = src.CellTypeAsId;
82  this->ReverseConnectivityBuilt = src.ReverseConnectivityBuilt;
83  this->Connectivity = src.Connectivity;
84  this->RConn = src.RConn;
85  this->RNumIndices = src.RNumIndices;
86  this->RIndexOffsets = src.RIndexOffsets;
87  return *this;
88  }
89 
90  vtkm::Id GetNumberOfCells() const
91  {
92  return this->NumberOfCells;
93  }
94 
95  vtkm::Id GetNumberOfPoints() const
96  {
97  return this->NumberOfPoints;
98  }
99 
100  virtual vtkm::Id GetNumberOfFaces() const { return -1; }
101 
102  virtual vtkm::Id GetNumberOfEdges() const { return -1; }
103 
104  vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagCell) const
105  {
106  return this->GetNumberOfCells();
107  }
108 
109  vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagPoint) const
110  {
111  return this->GetNumberOfPoints();
112  }
113 
114  // This is the way you can fill the memory from another system without copying
115  void Fill(
116  vtkm::Id numberOfPoints,
117  const vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkCellArrayContainerTag>&
118  connectivity);
119 
120  template <typename DeviceAdapter, typename FromTopology, typename ToTopology>
122 
123  template <typename DeviceAdapter>
124  struct ExecutionTypes<DeviceAdapter, vtkm::TopologyElementTagPoint,
125  vtkm::TopologyElementTagCell>
126  {
128  };
129 
130  template <typename DeviceAdapter>
131  struct ExecutionTypes<DeviceAdapter, vtkm::TopologyElementTagCell,
132  vtkm::TopologyElementTagPoint>
133  {
135  };
136 
137  template <typename Device>
139  PrepareForInput(Device, vtkm::TopologyElementTagPoint,
140  vtkm::TopologyElementTagCell) const;
141 
142  template <typename Device>
144  PrepareForInput(Device, vtkm::TopologyElementTagCell,
145  vtkm::TopologyElementTagPoint) const;
146 
147 
148  const vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkCellArrayContainerTag>&
149  GetConnectivityArray(vtkm::TopologyElementTagPoint,
150  vtkm::TopologyElementTagCell) const
151  {
152  return this->Connectivity;
153  }
154 
155  virtual void PrintSummary(std::ostream& out) const;
156 
157 private:
158  template <typename CellShapeTag>
159  void DetermineNumberOfPoints(CellShapeTag, vtkm::CellTraitsTagSizeFixed,
160  vtkm::IdComponent& numberOfPoints) const
161  {
162  numberOfPoints = vtkm::CellTraits<CellShapeTag>::NUM_POINTS;
163  }
164 
165  template <typename CellShapeTag>
166  void DetermineNumberOfPoints(CellShapeTag, vtkm::CellTraitsTagSizeVariable,
167  vtkm::IdComponent& numberOfPoints) const
168  { // variable length cells can't be used with this class
169  numberOfPoints = -1;
170  }
171 
172  vtkm::IdComponent DetermineNumberOfPoints() const;
173 
174  vtkm::Id NumberOfCells;
175  mutable vtkm::Id NumberOfPoints;
176  vtkm::Id CellTypeAsId;
177  vtkm::cont::ArrayHandle<vtkm::Id, ConnectivityStorageTag> Connectivity;
178 
179  mutable bool ReverseConnectivityBuilt;
180  mutable vtkm::cont::ArrayHandle<vtkm::Id> RConn;
181  mutable vtkm::cont::ArrayHandle<vtkm::IdComponent> RNumIndices;
182  mutable vtkm::cont::ArrayHandle<vtkm::Id> RIndexOffsets;
183 };
184 
185 // template methods we want to compile only once
186 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
188  vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagSerial,
189  vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const;
190 
191 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
193  vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagSerial,
194  vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const;
195 
196 #ifdef VTKM_ENABLE_TBB
197 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
199  vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagTBB,
200  vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const;
201 
202 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
204  vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagTBB,
205  vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const;
206 #endif
207 
208 #if defined(VTKM_ENABLE_CUDA) && defined(VTKM_CUDA)
209 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
211  vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagCuda,
212  vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const;
213 
214 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
216  vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagCuda,
217  vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const;
218 #endif
219 }
220 } // namespace vtkm::cont
221 
222 #endif
223 #endif
224 #endif // vtkmlib_vtkmCellSetSingleType_h
225 // 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)