VTK-m  2.1
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 
81  SchedulingRangeType GetCellDimensions() const { return this->Structure.GetCellDimensions(); }
82 
84  {
85  return this->Structure.GetGlobalCellDimensions();
86  }
87 
89  {
90  return this->Structure.GetGlobalPointIndexStart();
91  }
92 
94  {
95  return this->Structure.GetNumberOfPointsInCell();
96  }
97 
98  vtkm::UInt8 GetCellShape(vtkm::Id vtkmNotUsed(cellIndex) = 0) const override
99  {
100  return static_cast<vtkm::UInt8>(this->Structure.GetCellShape());
101  }
102 
103  void GetCellPointIds(vtkm::Id id, vtkm::Id* ptids) const override
104  {
105  auto asVec = this->Structure.GetPointsOfCell(id);
106  for (vtkm::IdComponent i = 0; i < InternalsType::NUM_POINTS_IN_CELL; ++i)
107  {
108  ptids[i] = asVec[i];
109  }
110  }
111 
112  std::shared_ptr<CellSet> NewInstance() const override
113  {
114  return std::make_shared<CellSetStructured>();
115  }
116 
117  void DeepCopy(const CellSet* src) override
118  {
119  const auto* other = dynamic_cast<const CellSetStructured*>(src);
120  if (!other)
121  {
122  throw vtkm::cont::ErrorBadType("CellSetStructured::DeepCopy types don't match");
123  }
124 
125  this->Structure = other->Structure;
126  }
127 
128  template <typename TopologyElement>
130  {
131  VTKM_IS_TOPOLOGY_ELEMENT_TAG(TopologyElement);
132  return this->Structure.GetSchedulingRange(TopologyElement());
133  }
134 
135  template <typename VisitTopology, typename IncidentTopology>
136  using ExecConnectivityType =
138 
139  template <typename VisitTopology, typename IncidentTopology>
141  VisitTopology,
142  IncidentTopology,
143  vtkm::cont::Token&) const
144  {
146  }
147 
148  void PrintSummary(std::ostream& out) const override
149  {
150  out << " StructuredCellSet:\n";
151  this->Structure.PrintSummary(out);
152  }
153 
154  // Cannot use the default implementation of the destructor because the CUDA compiler
155  // will attempt to create it for device, and then it will fail when it tries to call
156  // the destructor of the superclass.
157  ~CellSetStructured() override {}
158 
159  CellSetStructured() = default;
160 
162  : CellSet()
163  , Structure(src.Structure)
164  {
165  }
166 
168  {
169  this->Structure = src.Structure;
170  return *this;
171  }
172 
174  : CellSet()
175  , Structure(std::move(src.Structure))
176  {
177  }
178 
180  {
181  this->Structure = std::move(src.Structure);
182  return *this;
183  }
184 
185 private:
187 };
188 
189 #ifndef vtkm_cont_CellSetStructured_cxx
190 extern template class VTKM_CONT_TEMPLATE_EXPORT CellSetStructured<1>;
191 extern template class VTKM_CONT_TEMPLATE_EXPORT CellSetStructured<2>;
192 extern template class VTKM_CONT_TEMPLATE_EXPORT CellSetStructured<3>;
193 #endif
194 }
195 } // namespace vtkm::cont
196 
197 //=============================================================================
198 // Specializations of serialization related classes
200 namespace vtkm
201 {
202 namespace cont
203 {
204 
205 template <vtkm::IdComponent DIMENSION>
206 struct SerializableTypeString<vtkm::cont::CellSetStructured<DIMENSION>>
207 {
208  static VTKM_CONT const std::string& Get()
209  {
210  static std::string name = "CS_Structured<" + std::to_string(DIMENSION) + ">";
211  return name;
212  }
213 };
214 }
215 } // vtkm::cont
216 
217 namespace mangled_diy_namespace
218 {
219 
220 template <vtkm::IdComponent DIMENSION>
221 struct Serialization<vtkm::cont::CellSetStructured<DIMENSION>>
222 {
223 private:
225 
226 public:
227  static VTKM_CONT void save(BinaryBuffer& bb, const Type& cs)
228  {
229  vtkmdiy::save(bb, cs.GetPointDimensions());
230  vtkmdiy::save(bb, cs.GetGlobalPointDimensions());
231  vtkmdiy::save(bb, cs.GetGlobalPointIndexStart());
232  }
233 
234  static VTKM_CONT void load(BinaryBuffer& bb, Type& cs)
235  {
236  typename Type::SchedulingRangeType dims, gdims, start;
237  vtkmdiy::load(bb, dims);
238  vtkmdiy::load(bb, gdims);
239  vtkmdiy::load(bb, start);
240 
241  cs = Type{};
242  cs.SetPointDimensions(dims);
243  cs.SetGlobalPointDimensions(gdims);
244  cs.SetGlobalPointIndexStart(start);
245  }
246 };
247 
248 } // diy
250 
251 #endif //vtk_m_cont_CellSetStructured_h
vtkm::cont::CellSetStructured::PrintSummary
void PrintSummary(std::ostream &out) const override
Definition: CellSetStructured.h:148
ConnectivityStructured.h
vtkm::cont::CellSetStructured::CellSetStructured
CellSetStructured(const CellSetStructured &src)
Definition: CellSetStructured.h:161
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:186
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:112
vtkm::cont::CellSetStructured::CellSetStructured
CellSetStructured(CellSetStructured &&src) noexcept
Definition: CellSetStructured.h:173
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:98
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:117
mangled_diy_namespace
Definition: Particle.h:351
vtkm::cont::CellSetStructured::operator=
CellSetStructured & operator=(const CellSetStructured &src)
Definition: CellSetStructured.h:167
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:129
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::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:103
vtkm::exec::ConnectivityStructured
Definition: ConnectivityStructured.h:25
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:83
vtkm::cont::CellSetStructured::GetCellDimensions
SchedulingRangeType GetCellDimensions() const
Definition: CellSetStructured.h:81
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::PrepareForInput
ExecConnectivityType< VisitTopology, IncidentTopology > PrepareForInput(vtkm::cont::DeviceAdapterId, VisitTopology, IncidentTopology, vtkm::cont::Token &) const
Definition: CellSetStructured.h:140
vtkm::cont::CellSetStructured::operator=
CellSetStructured & operator=(CellSetStructured &&src) noexcept
Definition: CellSetStructured.h:179
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:93
vtkm::cont::CellSetStructured::SetGlobalPointIndexStart
void SetGlobalPointIndexStart(SchedulingRangeType start)
Definition: CellSetStructured.h:68
vtkm::cont::CellSetStructured::GetGlobalPointIndexStart
SchedulingRangeType GetGlobalPointIndexStart() const
Definition: CellSetStructured.h:88
vtkm::cont::CellSetStructured::GetGlobalPointDimensions
SchedulingRangeType GetGlobalPointDimensions() const
Definition: CellSetStructured.h:76
vtkm::cont::CellSetStructured::~CellSetStructured
~CellSetStructured() override
Definition: CellSetStructured.h:157
TopologyElementTag.h