Viskores  1.0
CellSetExplicit.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_cont_CellSetExplicit_h
19 #define viskores_cont_CellSetExplicit_h
20 
21 #include <viskores/CellShape.h>
28 #include <viskores/cont/CellSet.h>
32 
34 
35 namespace viskores
36 {
37 namespace cont
38 {
39 
40 namespace detail
41 {
42 
43 template <typename CellSetType, typename VisitTopology, typename IncidentTopology>
44 struct CellSetExplicitConnectivityChooser
45 {
46  using ConnectivityType = viskores::cont::internal::ConnectivityExplicitInternals<>;
47 };
48 
49 // The connectivity generally used for the visit-points-with-cells connectivity.
50 // This type of connectivity does not have variable shape types, and since it is
51 // never really provided externally we can use the defaults for the other arrays.
52 using DefaultVisitPointsWithCellsConnectivityExplicit =
53  viskores::cont::internal::ConnectivityExplicitInternals<
55 
56 VISKORES_CONT_EXPORT void BuildReverseConnectivity(
57  const viskores::cont::UnknownArrayHandle& connections,
59  viskores::Id numberOfPoints,
60  viskores::cont::detail::DefaultVisitPointsWithCellsConnectivityExplicit& visitPointsWithCells,
62 
63 } // namespace detail
64 
65 #ifndef VISKORES_DEFAULT_SHAPES_STORAGE_TAG
66 #define VISKORES_DEFAULT_SHAPES_STORAGE_TAG VISKORES_DEFAULT_STORAGE_TAG
67 #endif
68 
69 #ifndef VISKORES_DEFAULT_CONNECTIVITY_STORAGE_TAG
70 #define VISKORES_DEFAULT_CONNECTIVITY_STORAGE_TAG VISKORES_DEFAULT_STORAGE_TAG
71 #endif
72 
73 #ifndef VISKORES_DEFAULT_OFFSETS_STORAGE_TAG
74 #define VISKORES_DEFAULT_OFFSETS_STORAGE_TAG VISKORES_DEFAULT_STORAGE_TAG
75 #endif
76 
81 template <typename ShapesStorageTag = VISKORES_DEFAULT_SHAPES_STORAGE_TAG,
82  typename ConnectivityStorageTag = VISKORES_DEFAULT_CONNECTIVITY_STORAGE_TAG,
83  typename OffsetsStorageTag = VISKORES_DEFAULT_OFFSETS_STORAGE_TAG>
84 class VISKORES_ALWAYS_EXPORT CellSetExplicit : public CellSet
85 {
87 
88  template <typename VisitTopology, typename IncidentTopology>
90  {
91  private:
92  using Chooser = typename detail::
93  CellSetExplicitConnectivityChooser<Thisclass, VisitTopology, IncidentTopology>;
94 
95  public:
96  using ConnectivityType = typename Chooser::ConnectivityType;
97  using ShapesArrayType = typename ConnectivityType::ShapesArrayType;
98  using ConnectivityArrayType = typename ConnectivityType::ConnectivityArrayType;
99  using OffsetsArrayType = typename ConnectivityType::OffsetsArrayType;
100 
102 
103  using ExecConnectivityType =
104  viskores::exec::ConnectivityExplicit<typename ShapesArrayType::ReadPortalType,
105  typename ConnectivityArrayType::ReadPortalType,
106  typename OffsetsArrayType::ReadPortalType>;
107  };
108 
109  using ConnTypes =
111  using RConnTypes =
113 
116 
117 public:
119 
120  using ShapesArrayType = typename CellPointIdsType::ShapesArrayType;
121  using ConnectivityArrayType = typename CellPointIdsType::ConnectivityArrayType;
122  using OffsetsArrayType = typename CellPointIdsType::OffsetsArrayType;
124 
127  VISKORES_CONT CellSetExplicit(Thisclass&& src) noexcept;
128 
129  VISKORES_CONT Thisclass& operator=(const Thisclass& src);
130  VISKORES_CONT Thisclass& operator=(Thisclass&& src) noexcept;
131 
132  VISKORES_CONT ~CellSetExplicit() override;
133 
134  VISKORES_CONT viskores::Id GetNumberOfCells() const override;
135  VISKORES_CONT viskores::Id GetNumberOfPoints() const override;
136  VISKORES_CONT viskores::Id GetNumberOfFaces() const override;
137  VISKORES_CONT viskores::Id GetNumberOfEdges() const override;
138  VISKORES_CONT void PrintSummary(std::ostream& out) const override;
139 
140  VISKORES_CONT void ReleaseResourcesExecution() override;
141 
142  VISKORES_CONT std::shared_ptr<CellSet> NewInstance() const override;
143  VISKORES_CONT void DeepCopy(const CellSet* src) override;
144 
147 
148  VISKORES_CONT viskores::IdComponent GetNumberOfPointsInCell(viskores::Id cellid) const override;
149  VISKORES_CONT void GetCellPointIds(viskores::Id id, viskores::Id* ptids) const override;
150 
156  ShapesReadPortal() const;
157 
158  VISKORES_CONT viskores::UInt8 GetCellShape(viskores::Id cellid) const override;
159 
162  template <viskores::IdComponent NumIndices>
163  VISKORES_CONT void GetIndices(viskores::Id index,
165 
167  VISKORES_CONT void GetIndices(viskores::Id index,
169 
174  VISKORES_CONT void PrepareToAddCells(viskores::Id numCells, viskores::Id connectivityMaxLen);
175 
179  template <typename IdVecType>
180  VISKORES_CONT void AddCell(viskores::UInt8 cellType,
181  viskores::IdComponent numVertices,
182  const IdVecType& ids);
183 
185  VISKORES_CONT void CompleteAddingCells(viskores::Id numPoints);
186 
192  void Fill(viskores::Id numPoints,
196 
197  template <typename VisitTopology, typename IncidentTopology>
198  using ExecConnectivityType =
200 
215  template <typename VisitTopology, typename IncidentTopology>
218  VisitTopology visitTopology,
219  IncidentTopology incidentTopology,
220  viskores::cont::Token& token) const;
221 
228  template <typename VisitTopology, typename IncidentTopology>
229  VISKORES_CONT const typename ConnectivityChooser<VisitTopology,
230  IncidentTopology>::ShapesArrayType&
231  GetShapesArray(VisitTopology, IncidentTopology) const;
232 
240  template <typename VisitTopology, typename IncidentTopology>
241  VISKORES_CONT const typename ConnectivityChooser<VisitTopology,
242  IncidentTopology>::ConnectivityArrayType&
243  GetConnectivityArray(VisitTopology, IncidentTopology) const;
244 
252  template <typename VisitTopology, typename IncidentTopology>
253  VISKORES_CONT const typename ConnectivityChooser<VisitTopology,
254  IncidentTopology>::OffsetsArrayType&
255  GetOffsetsArray(VisitTopology, IncidentTopology) const;
256 
257  template <typename VisitTopology, typename IncidentTopology>
259  GetNumIndicesArray(VisitTopology, IncidentTopology) const;
260 
264  template <typename VisitTopology, typename IncidentTopology>
265  VISKORES_CONT bool HasConnectivity(VisitTopology visit, IncidentTopology incident) const
266  {
267  return this->HasConnectivityImpl(visit, incident);
268  }
269 
270  // Can be used to reset a connectivity table, mostly useful for benchmarking.
271  template <typename VisitTopology, typename IncidentTopology>
272  VISKORES_CONT void ResetConnectivity(VisitTopology visit, IncidentTopology incident)
273  {
274  this->ResetConnectivityImpl(visit, incident);
275  }
276 
277 protected:
281  {
282  VISKORES_ASSERT(this->Data->CellPointIds.ElementsValid);
283  // no-op
284  }
285 
289  {
290  detail::BuildReverseConnectivity(this->Data->CellPointIds.Connectivity,
291  this->Data->CellPointIds.Offsets,
292  this->Data->NumberOfPoints,
293  this->Data->PointCellIds,
294  device);
295  }
296 
299  {
300  return this->Data->CellPointIds.ElementsValid;
301  }
302 
305  {
306  return this->Data->PointCellIds.ElementsValid;
307  }
308 
311  {
312  // Reset entire cell set
313  this->Data->CellPointIds = CellPointIdsType{};
314  this->Data->PointCellIds = PointCellIdsType{};
315  this->Data->ConnectivityAdded = -1;
316  this->Data->NumberOfCellsAdded = -1;
317  this->Data->NumberOfPoints = 0;
318  }
319 
322  {
323  this->Data->PointCellIds = PointCellIdsType{};
324  }
325 
326  // Store internals in a shared pointer so shallow copies stay consistent.
327  // See #2268.
328  struct Internals
329  {
332 
333  // These are used in the AddCell and related methods to incrementally add
334  // cells. They need to be protected as subclasses of CellSetExplicit
335  // need to set these values when implementing Fill()
339 
342  : ConnectivityAdded(-1)
343  , NumberOfCellsAdded(-1)
344  , NumberOfPoints(0)
345  {
346  }
347  };
348 
349  std::shared_ptr<Internals> Data;
350 
351 private:
355  {
356  return this->Data->CellPointIds;
357  }
358 
362  {
363  return this->Data->CellPointIds;
364  }
365 
369  {
370  return this->Data->PointCellIds;
371  }
372 
376  {
377  return this->Data->PointCellIds;
378  }
379 };
380 
381 namespace detail
382 {
383 
384 template <typename Storage1, typename Storage2, typename Storage3>
385 struct CellSetExplicitConnectivityChooser<
386  viskores::cont::CellSetExplicit<Storage1, Storage2, Storage3>,
389 {
390  using ConnectivityType =
391  viskores::cont::internal::ConnectivityExplicitInternals<Storage1, Storage2, Storage3>;
392 };
393 
394 template <typename CellSetType>
395 struct CellSetExplicitConnectivityChooser<CellSetType,
396  viskores::TopologyElementTagPoint,
398 {
399  //only specify the shape type as it will be constant as everything
400  //is a vertex. otherwise use the defaults.
401  using ConnectivityType = viskores::cont::detail::DefaultVisitPointsWithCellsConnectivityExplicit;
402 };
403 
404 } // namespace detail
405 
408 #ifndef viskores_cont_CellSetExplicit_cxx
409 extern template class VISKORES_CONT_TEMPLATE_EXPORT CellSetExplicit<>; // default
410 extern template class VISKORES_CONT_TEMPLATE_EXPORT CellSetExplicit<
413  typename viskores::cont::ArrayHandleCounting<viskores::Id>::StorageTag>; // CellSetSingleType base
414 #endif
415 }
417 } // namespace viskores::cont
418 
419 //=============================================================================
420 // Specializations of serialization related classes
422 namespace viskores
423 {
424 namespace cont
425 {
426 
427 template <typename SST, typename CST, typename OST>
428 struct SerializableTypeString<viskores::cont::CellSetExplicit<SST, CST, OST>>
429 {
430  static VISKORES_CONT const std::string& Get()
431  {
432  static std::string name = "CS_Explicit<" +
433  SerializableTypeString<viskores::cont::ArrayHandle<viskores::UInt8, SST>>::Get() + "_ST," +
434  SerializableTypeString<viskores::cont::ArrayHandle<viskores::Id, CST>>::Get() + "_ST," +
435  SerializableTypeString<viskores::cont::ArrayHandle<viskores::Id, OST>>::Get() + "_ST>";
436 
437  return name;
438  }
439 };
440 }
441 } // viskores::cont
442 
443 namespace mangled_diy_namespace
444 {
445 
446 template <typename SST, typename CST, typename OST>
447 struct Serialization<viskores::cont::CellSetExplicit<SST, CST, OST>>
448 {
449 private:
451 
452 public:
453  static VISKORES_CONT void save(BinaryBuffer& bb, const Type& cs)
454  {
455  viskoresdiy::save(bb, cs.GetNumberOfPoints());
456  viskoresdiy::save(
457  bb,
459  viskoresdiy::save(bb,
460  cs.GetConnectivityArray(viskores::TopologyElementTagCell{},
462  viskoresdiy::save(
463  bb,
465  }
466 
467  static VISKORES_CONT void load(BinaryBuffer& bb, Type& cs)
468  {
469  viskores::Id numberOfPoints = 0;
470  viskoresdiy::load(bb, numberOfPoints);
472  viskoresdiy::load(bb, shapes);
474  viskoresdiy::load(bb, connectivity);
476  viskoresdiy::load(bb, offsets);
477 
478  cs = Type{};
479  cs.Fill(numberOfPoints, shapes, connectivity, offsets);
480  }
481 };
482 
483 } // diy
485 
486 #ifndef viskores_cont_CellSetExplicit_hxx
487 #include <viskores/cont/CellSetExplicit.hxx>
488 #endif //viskores_cont_CellSetExplicit_hxx
489 
490 #endif //viskores_cont_CellSetExplicit_h
viskores::exec::arg::load
T load(const U &u, viskores::Id v)
Definition: FetchTagArrayDirectIn.h:44
viskores::cont::CellSetExplicit::HasConnectivity
bool HasConnectivity(VisitTopology visit, IncidentTopology incident) const
Returns whether the CellSetExplicit has information for the given visit and incident topology element...
Definition: CellSetExplicit.h:265
viskores::TopologyElementTagCell
A tag used to identify the cell elements in a topology.
Definition: TopologyElementTag.h:32
viskores::cont::CellSetExplicit::ConnectivityChooser::ConnectivityArrayType
typename ConnectivityType::ConnectivityArrayType ConnectivityArrayType
Definition: CellSetExplicit.h:98
ArrayHandleCast.h
viskores::exec::ConnectivityExplicit
A class holding information about topology connections.
Definition: ConnectivityExplicit.h:37
viskores::cont::CellSetExplicit::ResetConnectivity
void ResetConnectivity(VisitTopology visit, IncidentTopology incident)
Definition: CellSetExplicit.h:272
viskores::cont::CellSetExplicit::CellPointIdsType
typename ConnTypes::ConnectivityType CellPointIdsType
Definition: CellSetExplicit.h:114
viskores::cont::CellSetExplicit::BuildConnectivity
void BuildConnectivity(viskores::cont::DeviceAdapterId device, viskores::TopologyElementTagPoint, viskores::TopologyElementTagCell) const
Definition: CellSetExplicit.h:286
viskores::cont::CellSetExplicit::ConnectivityChooser::ShapesArrayType
typename ConnectivityType::ShapesArrayType ShapesArrayType
Definition: CellSetExplicit.h:97
viskores::cont::ArrayHandle< viskores::Id >
ArrayHandleConstant.h
viskores::cont::CellSetExplicit::SchedulingRangeType
viskores::Id SchedulingRangeType
Definition: CellSetExplicit.h:118
VISKORES_DEFAULT_SHAPES_STORAGE_TAG
#define VISKORES_DEFAULT_SHAPES_STORAGE_TAG
Definition: CellSetExplicit.h:66
viskores::cont::ArrayHandle::ReadPortalType
typename StorageType::ReadPortalType ReadPortalType
The type of portal used when accessing data in a read-only mode.
Definition: ArrayHandle.h:325
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
CellShape.h
viskores::cont::CellSetExplicit::ShapesArrayType
typename CellPointIdsType::ShapesArrayType ShapesArrayType
Definition: CellSetExplicit.h:120
mangled_diy_namespace
Definition: Particle.h:373
viskores::cont::CellSetExplicit::Internals::Internals
Internals()
Definition: CellSetExplicit.h:341
viskores::cont::CellSetExplicit::ConnectivityChooser::OffsetsArrayType
typename ConnectivityType::OffsetsArrayType OffsetsArrayType
Definition: CellSetExplicit.h:99
viskores::cont::ArrayHandleConstant::StorageTag
typename Superclass::StorageTag StorageTag
Definition: ArrayHandleConstant.h:85
viskores::TopologyElementTagPoint
A tag used to identify the point elements in a topology.
Definition: TopologyElementTag.h:42
viskores::cont::CellSetExplicit::ResetConnectivityImpl
void ResetConnectivityImpl(viskores::TopologyElementTagPoint, viskores::TopologyElementTagCell)
Definition: CellSetExplicit.h:320
ConnectivityExplicit.h
viskores::cont::CellSetExplicit::ExecConnectivityType
typename ConnectivityChooser< VisitTopology, IncidentTopology >::ExecConnectivityType ExecConnectivityType
Definition: CellSetExplicit.h:199
viskores::cont::CellSetExplicit::PointCellIdsType
typename RConnTypes::ConnectivityType PointCellIdsType
Definition: CellSetExplicit.h:115
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
UnknownArrayHandle.h
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
VISKORES_DEFAULT_OFFSETS_STORAGE_TAG
#define VISKORES_DEFAULT_OFFSETS_STORAGE_TAG
Definition: CellSetExplicit.h:74
viskores::cont::CellSetExplicit::Internals::PointCellIds
PointCellIdsType PointCellIds
Definition: CellSetExplicit.h:331
viskores::cont::CellSetExplicit::Internals::NumberOfPoints
viskores::Id NumberOfPoints
Definition: CellSetExplicit.h:338
viskores::cont::CellSetExplicit::Data
std::shared_ptr< Internals > Data
Definition: CellSetExplicit.h:349
viskores::cont::ArrayHandleOffsetsToNumComponents
An ArrayHandle that converts an array of offsets to an array of Vec sizes.
Definition: ArrayHandleOffsetsToNumComponents.h:148
viskores::cont::CellSetExplicit
Defines an irregular collection of cells.
Definition: CastAndCall.h:44
viskores::cont::CellSetExplicit::GetConnectivity
const PointCellIdsType & GetConnectivity(viskores::TopologyElementTagPoint, viskores::TopologyElementTagCell) const
Definition: CellSetExplicit.h:367
CellSet.h
viskores::cont::CellSetExplicit::Internals
Definition: CellSetExplicit.h:328
VISKORES_ASSERT
#define VISKORES_ASSERT(condition)
Definition: Assert.h:51
viskores::cont::CellSetExplicit::Internals::ConnectivityAdded
viskores::Id ConnectivityAdded
Definition: CellSetExplicit.h:336
ArrayGetValues.h
viskores::UInt8
uint8_t UInt8
Base type to use for 8-bit unsigned integer numbers.
Definition: Types.h:177
viskores::cont::DeviceAdapterId
An object used to specify a device.
Definition: DeviceAdapterTag.h:66
viskores::cont::CellSetExplicit::Internals::CellPointIds
CellPointIdsType CellPointIds
Definition: CellSetExplicit.h:330
viskores::cont::CellSetExplicit::NumIndicesArrayType
typename ConnTypes::NumIndicesArrayType NumIndicesArrayType
Definition: CellSetExplicit.h:123
viskores::cont::CellSetExplicit::ConnectivityChooser
Definition: CellSetExplicit.h:89
viskores::cont::ArrayHandleCounting::StorageTag
typename Superclass::StorageTag StorageTag
Definition: ArrayHandleCounting.h:147
ConnectivityExplicitInternals.h
viskores::cont::CellSetExplicit::OffsetsArrayType
typename CellPointIdsType::OffsetsArrayType OffsetsArrayType
Definition: CellSetExplicit.h:122
ArrayHandleCounting.h
viskores::cont::CellSetExplicit::ResetConnectivityImpl
void ResetConnectivityImpl(viskores::TopologyElementTagCell, viskores::TopologyElementTagPoint)
Definition: CellSetExplicit.h:309
viskores::Get
auto Get(const viskores::Tuple< Ts... > &tuple)
Retrieve the object from a viskores::Tuple at the given index.
Definition: Tuple.h:89
viskores::cont::CellSetExplicit::Internals::NumberOfCellsAdded
viskores::Id NumberOfCellsAdded
Definition: CellSetExplicit.h:337
viskores::cont::UnknownArrayHandle
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:451
viskores::cont::CellSetExplicit::ConnectivityArrayType
typename CellPointIdsType::ConnectivityArrayType ConnectivityArrayType
Definition: CellSetExplicit.h:121
viskores::cont::CellSetExplicit::GetConnectivity
const CellPointIdsType & GetConnectivity(viskores::TopologyElementTagCell, viskores::TopologyElementTagPoint) const
Definition: CellSetExplicit.h:353
viskores::Vec
A short fixed-length array.
Definition: Types.h:365
viskores::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:43
viskores::cont::CellSetExplicit::HasConnectivityImpl
bool HasConnectivityImpl(viskores::TopologyElementTagCell, viskores::TopologyElementTagPoint) const
Definition: CellSetExplicit.h:297
viskores::cont::CellSet
Defines the topological structure of the data in a DataSet.
Definition: CellSet.h:36
viskores::cont::CellSetExplicit::BuildConnectivity
void BuildConnectivity(viskores::cont::DeviceAdapterId, viskores::TopologyElementTagCell, viskores::TopologyElementTagPoint) const
Definition: CellSetExplicit.h:278
viskores::cont::CellSetExplicit::ConnectivityChooser::ConnectivityType
typename Chooser::ConnectivityType ConnectivityType
Definition: CellSetExplicit.h:96
viskores::cont::CellSetExplicit::HasConnectivityImpl
bool HasConnectivityImpl(viskores::TopologyElementTagPoint, viskores::TopologyElementTagCell) const
Definition: CellSetExplicit.h:303
viskores::cont::CellSetExplicit::GetConnectivity
const CellPointIdsType & GetConnectivity(viskores::TopologyElementTagCell, viskores::TopologyElementTagPoint)
Definition: CellSetExplicit.h:360
viskores::cont::CellSetExplicit::GetConnectivity
const PointCellIdsType & GetConnectivity(viskores::TopologyElementTagPoint, viskores::TopologyElementTagCell)
Definition: CellSetExplicit.h:374
ArrayHandleOffsetsToNumComponents.h
TopologyElementTag.h
viskores::cont::CellSetExplicit::ConnectivityChooser::Chooser
typename detail::CellSetExplicitConnectivityChooser< Thisclass, VisitTopology, IncidentTopology > Chooser
Definition: CellSetExplicit.h:93
viskores_cont_export.h
VISKORES_DEFAULT_CONNECTIVITY_STORAGE_TAG
#define VISKORES_DEFAULT_CONNECTIVITY_STORAGE_TAG
Definition: CellSetExplicit.h:70