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 
23 #include "vtkmTags.h"
24 
25 #include <vtkm/CellShape.h>
26 #include <vtkm/TopologyElementTag.h>
27 #include <vtkm/cont/ArrayHandle.h>
28 #include <vtkm/cont/CellSet.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 #include "vtkmConnectivityExec.h"
35 
36 namespace vtkm {
37 namespace cont {
38 
39 class VTKACCELERATORSVTKM_EXPORT vtkmCellSetExplicitAOS : public CellSet
40 {
41 public:
43  : CellSet(name), Shapes(), Connectivity(), IndexOffsets(),
44  ReverseConnectivityBuilt(false),RConn(), RNumIndices(), RIndexOffsets(),
45  NumberOfPoints(0)
46  {
47  }
48 
50  {
51  }
52 
54  {
55  this->CellSet::operator=(src);
56  this->Shapes = src.Shapes;
57  this->Connectivity = src.Connectivity;
58  this->IndexOffsets = src.IndexOffsets;
59  this->ReverseConnectivityBuilt = src.ReverseConnectivityBuilt;
60  this->RConn = src.RConn;
61  this->RNumIndices = src.RNumIndices;
62  this->RIndexOffsets = src.RIndexOffsets;
63  this->NumberOfPoints = src.NumberOfPoints;
64  return *this;
65  }
66 
67  vtkm::Id GetNumberOfCells() const
68  {
69  return this->Shapes.GetNumberOfValues();
70  }
71 
72  vtkm::Id GetNumberOfPoints() const
73  {
74  return this->NumberOfPoints;
75  }
76 
77  virtual vtkm::Id GetNumberOfFaces() const { return -1; }
78 
79  virtual vtkm::Id GetNumberOfEdges() const { return -1; }
80 
81 
82  vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagCell) const
83  {
84  return this->GetNumberOfCells();
85  }
86 
87  vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagPoint) const
88  {
89  return this->GetNumberOfPoints();
90  }
91 
92  vtkm::IdComponent GetNumberOfPointsInCell(vtkm::Id index) const;
93 
94  vtkm::Id GetCellShape(vtkm::Id index) const;
95 
98  void Fill(
99  vtkm::Id numberOfPoints,
100  const vtkm::cont::ArrayHandle<vtkm::UInt8,
102  const vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkCellArrayContainerTag>&
103  connectivity,
104  const vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkAOSArrayContainerTag>&
105  offsets);
106 
107  template <typename DeviceAdapter, typename FromTopology, typename ToTopology>
109 
110  template <typename DeviceAdapter>
111  struct ExecutionTypes<DeviceAdapter, vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell>
112  {
114  };
115 
116  template <typename DeviceAdapter>
117  struct ExecutionTypes<DeviceAdapter, vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint>
118  {
120  };
121 
122  template <typename Device>
124  PrepareForInput(Device, vtkm::TopologyElementTagPoint,
125  vtkm::TopologyElementTagCell) const;
126 
127  template <typename Device>
129  PrepareForInput(Device, vtkm::TopologyElementTagCell,
130  vtkm::TopologyElementTagPoint) const;
131 
132  const vtkm::cont::ArrayHandle<vtkm::UInt8, tovtkm::vtkAOSArrayContainerTag>&
133  GetShapesArray(vtkm::TopologyElementTagPoint,
134  vtkm::TopologyElementTagCell) const
135  {
136  return this->Shapes;
137  }
138 
139  const vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkCellArrayContainerTag>&
140  GetConnectivityArray(vtkm::TopologyElementTagPoint,
141  vtkm::TopologyElementTagCell) const
142  {
143  return this->Connectivity;
144  }
145 
146  const vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkAOSArrayContainerTag>&
147  GetIndexOffsetArray(vtkm::TopologyElementTagPoint,
148  vtkm::TopologyElementTagCell) const
149  {
150  return this->IndexOffsets;
151  }
152 
153  virtual void PrintSummary(std::ostream& out) const;
154 
155 private:
156  vtkm::cont::ArrayHandle<vtkm::UInt8, tovtkm::vtkAOSArrayContainerTag> Shapes;
157  vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkCellArrayContainerTag>
158  Connectivity;
159  vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkAOSArrayContainerTag>
160  IndexOffsets;
161 
162  //Reverse connectivity (cell -> point)
163  //Todo: Need a better way to represent that PrepareForInput is a
164  // non-const operation, but that is going to take some real
165  // code refactoring in vtk-m
166  mutable bool ReverseConnectivityBuilt;
167  mutable vtkm::cont::ArrayHandle<vtkm::Id> RConn;
168  mutable vtkm::cont::ArrayHandle<vtkm::IdComponent> RNumIndices;
169  mutable vtkm::cont::ArrayHandle<vtkm::Id> RIndexOffsets;
170  mutable vtkm::Id NumberOfPoints;
171 
172 };
173 
174 // template methods we want to compile only once
175 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
177  vtkmCellSetExplicitAOS::PrepareForInput(vtkm::cont::DeviceAdapterTagSerial,
178  vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const;
179 
180 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
182  vtkmCellSetExplicitAOS::PrepareForInput(vtkm::cont::DeviceAdapterTagSerial,
183  vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const;
184 
185 #ifdef VTKM_ENABLE_TBB
186 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
188  vtkmCellSetExplicitAOS::PrepareForInput(vtkm::cont::DeviceAdapterTagTBB,
189  vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const;
190 
191 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
193  vtkmCellSetExplicitAOS::PrepareForInput(vtkm::cont::DeviceAdapterTagTBB,
194  vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const;
195 #endif
196 
197 #if defined(VTKM_ENABLE_CUDA) && defined(VTKM_CUDA)
198 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
200  vtkmCellSetExplicitAOS::PrepareForInput(vtkm::cont::DeviceAdapterTagCuda,
201  vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const;
202 
203 extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
205  vtkmCellSetExplicitAOS::PrepareForInput(vtkm::cont::DeviceAdapterTagCuda,
206  vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const;
207 #endif
208 }
209 }
210 
211 #endif
212 // VTK-HeaderTest-Exclude: vtkmCellSetExplicit.h
vtkmCellSetExplicitAOS(const std::string &name=std::string())
const vtkm::cont::ArrayHandle< vtkm::Id, tovtkm::vtkCellArrayContainerTag > & GetConnectivityArray(vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const
const vtkm::cont::ArrayHandle< vtkm::UInt8, tovtkm::vtkAOSArrayContainerTag > & GetShapesArray(vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const
virtual vtkm::Id GetNumberOfFaces() const
vtkm::exec::ConnectivityVTKAOS< Device > PrepareForInput(Device, vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const
vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagCell) const
const vtkm::cont::ArrayHandle< vtkm::Id, tovtkm::vtkAOSArrayContainerTag > & GetIndexOffsetArray(vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const
virtual vtkm::Id GetNumberOfEdges() const
vtkmCellSetExplicitAOS & operator=(const vtkmCellSetExplicitAOS &src)
vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagPoint) const