Viskores  1.0
CellSetStructured.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_CellSetStructured_h
19 #define viskores_cont_CellSetStructured_h
20 
22 
24 #include <viskores/cont/CellSet.h>
28 
29 namespace viskores
30 {
31 namespace cont
32 {
33 
40 template <viskores::IdComponent DIMENSION>
41 class VISKORES_ALWAYS_EXPORT CellSetStructured final : public CellSet
42 {
43 private:
45  using InternalsType = viskores::internal::ConnectivityStructuredInternals<DIMENSION>;
46 
47 public:
48  static const viskores::IdComponent Dimension = DIMENSION;
49 
50  using SchedulingRangeType = typename InternalsType::SchedulingRangeType;
51 
53  viskores::Id GetNumberOfCells() const override { return this->Structure.GetNumberOfCells(); }
54 
56  viskores::Id GetNumberOfPoints() const override { return this->Structure.GetNumberOfPoints(); }
57 
58  viskores::Id GetNumberOfFaces() const override { return -1; }
59 
60  viskores::Id GetNumberOfEdges() const override { return -1; }
61 
62  // Since the entire topology is defined by by three integers, nothing to do here.
63  void ReleaseResourcesExecution() override {}
64 
67  {
68  this->Structure.SetPointDimensions(dimensions);
69  }
70 
72  {
73  this->Structure.SetGlobalPointDimensions(dimensions);
74  }
75 
77  {
78  this->Structure.SetGlobalPointIndexStart(start);
79  }
80 
82  SchedulingRangeType GetPointDimensions() const { return this->Structure.GetPointDimensions(); }
83 
85  {
86  return this->Structure.GetGlobalPointDimensions();
87  }
88 
91  SchedulingRangeType GetCellDimensions() const { return this->Structure.GetCellDimensions(); }
92 
94  {
95  return this->Structure.GetGlobalCellDimensions();
96  }
97 
99  {
100  return this->Structure.GetGlobalPointIndexStart();
101  }
102 
104  viskores::Id viskoresNotUsed(cellIndex) = 0) const override
105  {
106  return this->Structure.GetNumberOfPointsInCell();
107  }
108 
110  {
111  return static_cast<viskores::UInt8>(this->Structure.GetCellShape());
112  }
113 
114  void GetCellPointIds(viskores::Id id, viskores::Id* ptids) const override
115  {
116  auto asVec = this->Structure.GetPointsOfCell(id);
117  for (viskores::IdComponent i = 0; i < InternalsType::NUM_POINTS_IN_CELL; ++i)
118  {
119  ptids[i] = asVec[i];
120  }
121  }
122 
123  std::shared_ptr<CellSet> NewInstance() const override
124  {
125  return std::make_shared<CellSetStructured>();
126  }
127 
128  void DeepCopy(const CellSet* src) override
129  {
130  const auto* other = dynamic_cast<const CellSetStructured*>(src);
131  if (!other)
132  {
133  throw viskores::cont::ErrorBadType("CellSetStructured::DeepCopy types don't match");
134  }
135 
136  this->Structure = other->Structure;
137  }
138 
139  template <typename TopologyElement>
141  {
142  VISKORES_IS_TOPOLOGY_ELEMENT_TAG(TopologyElement);
143  return this->Structure.GetSchedulingRange(TopologyElement());
144  }
145 
146  template <typename VisitTopology, typename IncidentTopology>
147  using ExecConnectivityType =
149 
164  template <typename VisitTopology, typename IncidentTopology>
167  VisitTopology visitTopology,
168  IncidentTopology incidentTopology,
169  viskores::cont::Token& token) const
170  {
171  (void)device;
172  (void)visitTopology;
173  (void)incidentTopology;
174  (void)token;
176  }
177 
178  void PrintSummary(std::ostream& out) const override
179  {
180  out << " StructuredCellSet:\n";
181  this->Structure.PrintSummary(out);
182  }
183 
184  // Cannot use the default implementation of the destructor because the CUDA compiler
185  // will attempt to create it for device, and then it will fail when it tries to call
186  // the destructor of the superclass.
187  ~CellSetStructured() override {}
188 
189  CellSetStructured() = default;
190 
192  : CellSet()
193  , Structure(src.Structure)
194  {
195  }
196 
198  {
199  this->Structure = src.Structure;
200  return *this;
201  }
202 
204  : CellSet()
205  , Structure(std::move(src.Structure))
206  {
207  }
208 
210  {
211  this->Structure = std::move(src.Structure);
212  return *this;
213  }
214 
215 private:
217 };
218 
219 #ifndef viskores_cont_CellSetStructured_cxx
220 extern template class VISKORES_CONT_TEMPLATE_EXPORT CellSetStructured<1>;
221 extern template class VISKORES_CONT_TEMPLATE_EXPORT CellSetStructured<2>;
222 extern template class VISKORES_CONT_TEMPLATE_EXPORT CellSetStructured<3>;
223 #endif
224 }
225 } // namespace viskores::cont
226 
227 //=============================================================================
228 // Specializations of serialization related classes
230 namespace viskores
231 {
232 namespace cont
233 {
234 
235 template <viskores::IdComponent DIMENSION>
236 struct SerializableTypeString<viskores::cont::CellSetStructured<DIMENSION>>
237 {
238  static VISKORES_CONT const std::string& Get()
239  {
240  static std::string name = "CS_Structured<" + std::to_string(DIMENSION) + ">";
241  return name;
242  }
243 };
244 }
245 } // viskores::cont
246 
247 namespace mangled_diy_namespace
248 {
249 
250 template <viskores::IdComponent DIMENSION>
251 struct Serialization<viskores::cont::CellSetStructured<DIMENSION>>
252 {
253 private:
255 
256 public:
257  static VISKORES_CONT void save(BinaryBuffer& bb, const Type& cs)
258  {
259  viskoresdiy::save(bb, cs.GetPointDimensions());
260  viskoresdiy::save(bb, cs.GetGlobalPointDimensions());
261  viskoresdiy::save(bb, cs.GetGlobalPointIndexStart());
262  }
263 
264  static VISKORES_CONT void load(BinaryBuffer& bb, Type& cs)
265  {
266  typename Type::SchedulingRangeType dims, gdims, start;
267  viskoresdiy::load(bb, dims);
268  viskoresdiy::load(bb, gdims);
269  viskoresdiy::load(bb, start);
270 
271  cs = Type{};
272  cs.SetPointDimensions(dims);
273  cs.SetGlobalPointDimensions(gdims);
274  cs.SetGlobalPointIndexStart(start);
275  }
276 };
277 
278 } // diy
280 
281 #endif //viskores_cont_CellSetStructured_h
viskores::exec::arg::load
T load(const U &u, viskores::Id v)
Definition: FetchTagArrayDirectIn.h:44
viskores::cont::CellSetStructured::GetNumberOfEdges
viskores::Id GetNumberOfEdges() const override
Definition: CellSetStructured.h:60
viskores::cont::CellSetStructured::InternalsType
viskores::internal::ConnectivityStructuredInternals< DIMENSION > InternalsType
Definition: CellSetStructured.h:45
ConnectivityStructured.h
viskores::cont::CellSetStructured::SchedulingRangeType
typename InternalsType::SchedulingRangeType SchedulingRangeType
Definition: CellSetStructured.h:50
viskores::cont::CellSetStructured::GetCellDimensions
SchedulingRangeType GetCellDimensions() const
Get the dimensions of the cells.
Definition: CellSetStructured.h:91
viskores::cont::CellSetStructured::operator=
CellSetStructured & operator=(CellSetStructured &&src) noexcept
Definition: CellSetStructured.h:209
ConnectivityStructuredInternals.h
viskores::cont::CellSetStructured::ReleaseResourcesExecution
void ReleaseResourcesExecution() override
Definition: CellSetStructured.h:63
viskores::cont::CellSetStructured::DeepCopy
void DeepCopy(const CellSet *src) override
Definition: CellSetStructured.h:128
viskores::cont::ErrorBadType
This class is thrown when Viskores encounters data of a type that is incompatible with the current op...
Definition: ErrorBadType.h:33
viskores::cont::CellSetStructured::CellSetStructured
CellSetStructured(const CellSetStructured &src)
Definition: CellSetStructured.h:191
viskores::cont::CellSetStructured::GetCellPointIds
void GetCellPointIds(viskores::Id id, viskores::Id *ptids) const override
Definition: CellSetStructured.h:114
viskores::cont::CellSetStructured::operator=
CellSetStructured & operator=(const CellSetStructured &src)
Definition: CellSetStructured.h:197
viskoresNotUsed
#define viskoresNotUsed(parameter_name)
Simple macro to identify a parameter as unused.
Definition: ExportMacros.h:136
VISKORES_IS_TOPOLOGY_ELEMENT_TAG
#define VISKORES_IS_TOPOLOGY_ELEMENT_TAG(type)
Definition: TopologyElementTag.h:100
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
viskores::cont::CellSetStructured::PrepareForInput
ExecConnectivityType< VisitTopology, IncidentTopology > PrepareForInput(viskores::cont::DeviceAdapterId device, VisitTopology visitTopology, IncidentTopology incidentTopology, viskores::cont::Token &token) const
Prepares the data for a particular device and returns the execution object for it.
Definition: CellSetStructured.h:165
mangled_diy_namespace
Definition: Particle.h:373
viskores::cont::CellSetStructured::GetSchedulingRange
SchedulingRangeType GetSchedulingRange(TopologyElement) const
Definition: CellSetStructured.h:140
viskores::cont::CellSetStructured::GetPointDimensions
SchedulingRangeType GetPointDimensions() const
Get the dimensions of the points.
Definition: CellSetStructured.h:82
viskores::cont::CellSetStructured::PrintSummary
void PrintSummary(std::ostream &out) const override
Definition: CellSetStructured.h:178
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
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::cont::CellSetStructured::CellSetStructured
CellSetStructured(CellSetStructured &&src) noexcept
Definition: CellSetStructured.h:203
viskores::cont::CellSetStructured::GetNumberOfPointsInCell
viskores::IdComponent GetNumberOfPointsInCell(viskores::Id=0) const override
Definition: CellSetStructured.h:103
viskores::cont::CellSetStructured::NewInstance
std::shared_ptr< CellSet > NewInstance() const override
Definition: CellSetStructured.h:123
viskores::cont::CellSetStructured::GetGlobalPointDimensions
SchedulingRangeType GetGlobalPointDimensions() const
Definition: CellSetStructured.h:84
viskores::cont::CellSetStructured::GetGlobalCellDimensions
SchedulingRangeType GetGlobalCellDimensions() const
Definition: CellSetStructured.h:93
viskores::cont::CellSetStructured::GetNumberOfFaces
viskores::Id GetNumberOfFaces() const override
Definition: CellSetStructured.h:58
viskores::cont::CellSetStructured::GetCellShape
viskores::UInt8 GetCellShape(viskores::Id=0) const override
Definition: CellSetStructured.h:109
viskores::cont::CellSetStructured::GetNumberOfPoints
viskores::Id GetNumberOfPoints() const override
Get the number of points in the topology.
Definition: CellSetStructured.h:56
CellSet.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::CellSetStructured
Defines a 1-, 2-, or 3-dimensional structured grid of points.
Definition: CastAndCall.h:40
viskores::cont::CellSetStructured::GetNumberOfCells
viskores::Id GetNumberOfCells() const override
Get the number of cells in the topology.
Definition: CellSetStructured.h:53
viskores::cont::CellSetStructured::GetGlobalPointIndexStart
SchedulingRangeType GetGlobalPointIndexStart() const
Definition: CellSetStructured.h:98
viskores::cont::CellSetStructured::SetGlobalPointDimensions
void SetGlobalPointDimensions(SchedulingRangeType dimensions)
Definition: CellSetStructured.h:71
viskores::cont::CellSetStructured::~CellSetStructured
~CellSetStructured() override
Definition: CellSetStructured.h:187
viskores::Get
auto Get(const viskores::Tuple< Ts... > &tuple)
Retrieve the object from a viskores::Tuple at the given index.
Definition: Tuple.h:89
ErrorBadType.h
viskores::cont::CellSetStructured::SetPointDimensions
void SetPointDimensions(SchedulingRangeType dimensions)
Set the dimensions of the structured array of points.
Definition: CellSetStructured.h:66
viskores::cont::CellSetStructured::SetGlobalPointIndexStart
void SetGlobalPointIndexStart(SchedulingRangeType start)
Definition: CellSetStructured.h:76
viskores::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:43
viskores::exec::ConnectivityStructured
A class holding information about topology connections.
Definition: ConnectivityStructured.h:38
viskores::cont::CellSet
Defines the topological structure of the data in a DataSet.
Definition: CellSet.h:36
TopologyElementTag.h
viskores_cont_export.h
viskores::cont::CellSetStructured::Structure
InternalsType Structure
Definition: CellSetStructured.h:216