VTK-m  2.2
CellSetStructured.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 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_cont_CellSetStructured_h
11 #define vtk_m_cont_CellSetStructured_h
12 
14 
16 #include <vtkm/cont/CellSet.h>
17 #include <vtkm/cont/ErrorBadType.h>
20 
21 namespace vtkm
22 {
23 namespace cont
24 {
25 
32 template <vtkm::IdComponent DIMENSION>
33 class VTKM_ALWAYS_EXPORT CellSetStructured final : public CellSet
34 {
35 private:
37  using InternalsType = vtkm::internal::ConnectivityStructuredInternals<DIMENSION>;
38 
39 public:
40  static const vtkm::IdComponent Dimension = DIMENSION;
41 
42  using SchedulingRangeType = typename InternalsType::SchedulingRangeType;
43 
45  vtkm::Id GetNumberOfCells() const override { return this->Structure.GetNumberOfCells(); }
46 
48  vtkm::Id GetNumberOfPoints() const override { return this->Structure.GetNumberOfPoints(); }
49 
50  vtkm::Id GetNumberOfFaces() const override { return -1; }
51 
52  vtkm::Id GetNumberOfEdges() const override { return -1; }
53 
54  // Since the entire topology is defined by by three integers, nothing to do here.
55  void ReleaseResourcesExecution() override {}
56 
59  {
60  this->Structure.SetPointDimensions(dimensions);
61  }
62 
64  {
65  this->Structure.SetGlobalPointDimensions(dimensions);
66  }
67 
69  {
70  this->Structure.SetGlobalPointIndexStart(start);
71  }
72 
74  SchedulingRangeType GetPointDimensions() const { return this->Structure.GetPointDimensions(); }
75 
77  {
78  return this->Structure.GetGlobalPointDimensions();
79  }
80 
83  SchedulingRangeType GetCellDimensions() const { return this->Structure.GetCellDimensions(); }
84 
86  {
87  return this->Structure.GetGlobalCellDimensions();
88  }
89 
91  {
92  return this->Structure.GetGlobalPointIndexStart();
93  }
94 
96  {
97  return this->Structure.GetNumberOfPointsInCell();
98  }
99 
100  vtkm::UInt8 GetCellShape(vtkm::Id vtkmNotUsed(cellIndex) = 0) const override
101  {
102  return static_cast<vtkm::UInt8>(this->Structure.GetCellShape());
103  }
104 
105  void GetCellPointIds(vtkm::Id id, vtkm::Id* ptids) const override
106  {
107  auto asVec = this->Structure.GetPointsOfCell(id);
108  for (vtkm::IdComponent i = 0; i < InternalsType::NUM_POINTS_IN_CELL; ++i)
109  {
110  ptids[i] = asVec[i];
111  }
112  }
113 
114  std::shared_ptr<CellSet> NewInstance() const override
115  {
116  return std::make_shared<CellSetStructured>();
117  }
118 
119  void DeepCopy(const CellSet* src) override
120  {
121  const auto* other = dynamic_cast<const CellSetStructured*>(src);
122  if (!other)
123  {
124  throw vtkm::cont::ErrorBadType("CellSetStructured::DeepCopy types don't match");
125  }
126 
127  this->Structure = other->Structure;
128  }
129 
130  template <typename TopologyElement>
132  {
133  VTKM_IS_TOPOLOGY_ELEMENT_TAG(TopologyElement);
134  return this->Structure.GetSchedulingRange(TopologyElement());
135  }
136 
137  template <typename VisitTopology, typename IncidentTopology>
138  using ExecConnectivityType =
140 
155  template <typename VisitTopology, typename IncidentTopology>
158  VisitTopology visitTopology,
159  IncidentTopology incidentTopology,
160  vtkm::cont::Token& token) const
161  {
162  (void)device;
163  (void)visitTopology;
164  (void)incidentTopology;
165  (void)token;
167  }
168 
169  void PrintSummary(std::ostream& out) const override
170  {
171  out << " StructuredCellSet:\n";
172  this->Structure.PrintSummary(out);
173  }
174 
175  // Cannot use the default implementation of the destructor because the CUDA compiler
176  // will attempt to create it for device, and then it will fail when it tries to call
177  // the destructor of the superclass.
178  ~CellSetStructured() override {}
179 
180  CellSetStructured() = default;
181 
183  : CellSet()
184  , Structure(src.Structure)
185  {
186  }
187 
189  {
190  this->Structure = src.Structure;
191  return *this;
192  }
193 
195  : CellSet()
196  , Structure(std::move(src.Structure))
197  {
198  }
199 
201  {
202  this->Structure = std::move(src.Structure);
203  return *this;
204  }
205 
206 private:
208 };
209 
210 #ifndef vtkm_cont_CellSetStructured_cxx
211 extern template class VTKM_CONT_TEMPLATE_EXPORT CellSetStructured<1>;
212 extern template class VTKM_CONT_TEMPLATE_EXPORT CellSetStructured<2>;
213 extern template class VTKM_CONT_TEMPLATE_EXPORT CellSetStructured<3>;
214 #endif
215 }
216 } // namespace vtkm::cont
217 
218 //=============================================================================
219 // Specializations of serialization related classes
221 namespace vtkm
222 {
223 namespace cont
224 {
225 
226 template <vtkm::IdComponent DIMENSION>
227 struct SerializableTypeString<vtkm::cont::CellSetStructured<DIMENSION>>
228 {
229  static VTKM_CONT const std::string& Get()
230  {
231  static std::string name = "CS_Structured<" + std::to_string(DIMENSION) + ">";
232  return name;
233  }
234 };
235 }
236 } // vtkm::cont
237 
238 namespace mangled_diy_namespace
239 {
240 
241 template <vtkm::IdComponent DIMENSION>
242 struct Serialization<vtkm::cont::CellSetStructured<DIMENSION>>
243 {
244 private:
246 
247 public:
248  static VTKM_CONT void save(BinaryBuffer& bb, const Type& cs)
249  {
250  vtkmdiy::save(bb, cs.GetPointDimensions());
251  vtkmdiy::save(bb, cs.GetGlobalPointDimensions());
252  vtkmdiy::save(bb, cs.GetGlobalPointIndexStart());
253  }
254 
255  static VTKM_CONT void load(BinaryBuffer& bb, Type& cs)
256  {
257  typename Type::SchedulingRangeType dims, gdims, start;
258  vtkmdiy::load(bb, dims);
259  vtkmdiy::load(bb, gdims);
260  vtkmdiy::load(bb, start);
261 
262  cs = Type{};
263  cs.SetPointDimensions(dims);
264  cs.SetGlobalPointDimensions(gdims);
265  cs.SetGlobalPointIndexStart(start);
266  }
267 };
268 
269 } // diy
271 
272 #endif //vtk_m_cont_CellSetStructured_h
vtkm::cont::CellSetStructured::PrintSummary
void PrintSummary(std::ostream &out) const override
Definition: CellSetStructured.h:169
ConnectivityStructured.h
vtkm::cont::CellSetStructured::CellSetStructured
CellSetStructured(const CellSetStructured &src)
Definition: CellSetStructured.h:182
vtkm::cont::CellSetStructured::GetNumberOfCells
vtkm::Id GetNumberOfCells() const override
Get the number of cells in the topology.
Definition: CellSetStructured.h:45
vtkm::exec::arg::load
T load(const U &u, vtkm::Id v)
Definition: FetchTagArrayDirectIn.h:36
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
ConnectivityStructuredInternals.h
vtkm::Get
auto Get(const vtkm::Tuple< Ts... > &tuple)
Retrieve the object from a vtkm::Tuple at the given index.
Definition: Tuple.h:81
vtkm::cont::CellSetStructured::Structure
InternalsType Structure
Definition: CellSetStructured.h:207
vtkm::IdComponent
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
vtkm::cont::CellSetStructured
Defines a 1-, 2-, or 3-dimensional structured grid of points.
Definition: CastAndCall.h:32
vtkm::cont::CellSetStructured::GetNumberOfFaces
vtkm::Id GetNumberOfFaces() const override
Definition: CellSetStructured.h:50
vtkm::cont::CellSetStructured::NewInstance
std::shared_ptr< CellSet > NewInstance() const override
Definition: CellSetStructured.h:114
vtkm::cont::CellSetStructured::CellSetStructured
CellSetStructured(CellSetStructured &&src) noexcept
Definition: CellSetStructured.h:194
VTKM_IS_TOPOLOGY_ELEMENT_TAG
#define VTKM_IS_TOPOLOGY_ELEMENT_TAG(type)
Definition: TopologyElementTag.h:92
vtkm::cont::CellSetStructured::GetCellShape
vtkm::UInt8 GetCellShape(vtkm::Id=0) const override
Definition: CellSetStructured.h:100
vtkm::cont::ErrorBadType
This class is thrown when VTK-m encounters data of a type that is incompatible with the current opera...
Definition: ErrorBadType.h:25
vtkm::cont::CellSetStructured::DeepCopy
void DeepCopy(const CellSet *src) override
Definition: CellSetStructured.h:119
mangled_diy_namespace
Definition: Particle.h:351
vtkm::cont::CellSetStructured::operator=
CellSetStructured & operator=(const CellSetStructured &src)
Definition: CellSetStructured.h:188
vtkm::cont::CellSetStructured::GetNumberOfEdges
vtkm::Id GetNumberOfEdges() const override
Definition: CellSetStructured.h:52
vtkm::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
vtkm::cont::CellSetStructured::GetNumberOfPoints
vtkm::Id GetNumberOfPoints() const override
Get the number of points in the topology.
Definition: CellSetStructured.h:48
vtkm::cont::CellSetStructured::InternalsType
vtkm::internal::ConnectivityStructuredInternals< DIMENSION > InternalsType
Definition: CellSetStructured.h:37
vtkm::cont::CellSetStructured::GetSchedulingRange
SchedulingRangeType GetSchedulingRange(TopologyElement) const
Definition: CellSetStructured.h:131
vtkm_cont_export.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
CellSet.h
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::cont::CellSet
Defines the topological structure of the data in a DataSet.
Definition: CellSet.h:28
vtkm::cont::CellSetStructured::PrepareForInput
ExecConnectivityType< VisitTopology, IncidentTopology > PrepareForInput(vtkm::cont::DeviceAdapterId device, VisitTopology visitTopology, IncidentTopology incidentTopology, vtkm::cont::Token &token) const
Prepares the data for a particular device and returns the execution object for it.
Definition: CellSetStructured.h:156
vtkm::cont::CellSetStructured::SchedulingRangeType
typename InternalsType::SchedulingRangeType SchedulingRangeType
Definition: CellSetStructured.h:42
vtkm::UInt8
uint8_t UInt8
Base type to use for 8-bit unsigned integer numbers.
Definition: Types.h:169
vtkmNotUsed
#define vtkmNotUsed(parameter_name)
Simple macro to identify a parameter as unused.
Definition: ExportMacros.h:128
vtkm::cont::CellSetStructured::GetCellPointIds
void GetCellPointIds(vtkm::Id id, vtkm::Id *ptids) const override
Definition: CellSetStructured.h:105
vtkm::exec::ConnectivityStructured
A class holding information about topology connections.
Definition: ConnectivityStructured.h:30
vtkm::cont::DeviceAdapterId
An object used to specify a device.
Definition: DeviceAdapterTag.h:58
vtkm::cont::CellSetStructured::GetPointDimensions
SchedulingRangeType GetPointDimensions() const
Get the dimensions of the points.
Definition: CellSetStructured.h:74
VTKM_CONT_TEMPLATE_EXPORT
#define VTKM_CONT_TEMPLATE_EXPORT
Definition: vtkm_cont_export.h:62
vtkm::cont::CellSetStructured::SetPointDimensions
void SetPointDimensions(SchedulingRangeType dimensions)
Set the dimensions of the structured array of points.
Definition: CellSetStructured.h:58
vtkm::cont::CellSetStructured::GetGlobalCellDimensions
SchedulingRangeType GetGlobalCellDimensions() const
Definition: CellSetStructured.h:85
vtkm::cont::CellSetStructured::GetCellDimensions
SchedulingRangeType GetCellDimensions() const
Get the dimensions of the cells.
Definition: CellSetStructured.h:83
vtkm::cont::CellSetStructured::SetGlobalPointDimensions
void SetGlobalPointDimensions(SchedulingRangeType dimensions)
Definition: CellSetStructured.h:63
vtkm::cont::CellSetStructured::ReleaseResourcesExecution
void ReleaseResourcesExecution() override
Definition: CellSetStructured.h:55
vtkm::cont::CellSetStructured::operator=
CellSetStructured & operator=(CellSetStructured &&src) noexcept
Definition: CellSetStructured.h:200
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:89
ErrorBadType.h
vtkm::cont::CellSetStructured::GetNumberOfPointsInCell
vtkm::IdComponent GetNumberOfPointsInCell(vtkm::Id=0) const override
Definition: CellSetStructured.h:95
vtkm::cont::CellSetStructured::SetGlobalPointIndexStart
void SetGlobalPointIndexStart(SchedulingRangeType start)
Definition: CellSetStructured.h:68
vtkm::cont::CellSetStructured::GetGlobalPointIndexStart
SchedulingRangeType GetGlobalPointIndexStart() const
Definition: CellSetStructured.h:90
vtkm::cont::CellSetStructured::GetGlobalPointDimensions
SchedulingRangeType GetGlobalPointDimensions() const
Definition: CellSetStructured.h:76
vtkm::cont::CellSetStructured::~CellSetStructured
~CellSetStructured() override
Definition: CellSetStructured.h:178
TopologyElementTag.h