VTK-m  2.0
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 
13 #include <vtkm/cont/vtkm_cont_export.h>
14 
16 #include <vtkm/cont/CellSet.h>
17 #include <vtkm/cont/ErrorBadType.h>
20 
21 namespace vtkm
22 {
23 namespace cont
24 {
25 
26 template <vtkm::IdComponent DIMENSION>
27 class VTKM_ALWAYS_EXPORT CellSetStructured final : public CellSet
28 {
29 private:
31  using InternalsType = vtkm::internal::ConnectivityStructuredInternals<DIMENSION>;
32 
33 public:
34  static const vtkm::IdComponent Dimension = DIMENSION;
35 
36  using SchedulingRangeType = typename InternalsType::SchedulingRangeType;
37 
38  vtkm::Id GetNumberOfCells() const override { return this->Structure.GetNumberOfCells(); }
39 
40  vtkm::Id GetNumberOfPoints() const override { return this->Structure.GetNumberOfPoints(); }
41 
42  vtkm::Id GetNumberOfFaces() const override { return -1; }
43 
44  vtkm::Id GetNumberOfEdges() const override { return -1; }
45 
46  // Since the entire topology is defined by by three integers, nothing to do here.
47  void ReleaseResourcesExecution() override {}
48 
50  {
51  this->Structure.SetPointDimensions(dimensions);
52  }
53 
55  {
56  this->Structure.SetGlobalPointDimensions(dimensions);
57  }
58 
60  {
61  this->Structure.SetGlobalPointIndexStart(start);
62  }
63 
64  SchedulingRangeType GetPointDimensions() const { return this->Structure.GetPointDimensions(); }
65 
67  {
68  return this->Structure.GetGlobalPointDimensions();
69  }
70 
71  SchedulingRangeType GetCellDimensions() const { return this->Structure.GetCellDimensions(); }
72 
74  {
75  return this->Structure.GetGlobalCellDimensions();
76  }
77 
79  {
80  return this->Structure.GetGlobalPointIndexStart();
81  }
82 
84  {
85  return this->Structure.GetNumberOfPointsInCell();
86  }
87 
88  vtkm::UInt8 GetCellShape(vtkm::Id vtkmNotUsed(cellIndex) = 0) const override
89  {
90  return static_cast<vtkm::UInt8>(this->Structure.GetCellShape());
91  }
92 
93  void GetCellPointIds(vtkm::Id id, vtkm::Id* ptids) const override
94  {
95  auto asVec = this->Structure.GetPointsOfCell(id);
96  for (vtkm::IdComponent i = 0; i < InternalsType::NUM_POINTS_IN_CELL; ++i)
97  {
98  ptids[i] = asVec[i];
99  }
100  }
101 
102  std::shared_ptr<CellSet> NewInstance() const override
103  {
104  return std::make_shared<CellSetStructured>();
105  }
106 
107  void DeepCopy(const CellSet* src) override
108  {
109  const auto* other = dynamic_cast<const CellSetStructured*>(src);
110  if (!other)
111  {
112  throw vtkm::cont::ErrorBadType("CellSetStructured::DeepCopy types don't match");
113  }
114 
115  this->Structure = other->Structure;
116  }
117 
118  template <typename TopologyElement>
120  {
121  VTKM_IS_TOPOLOGY_ELEMENT_TAG(TopologyElement);
122  return this->Structure.GetSchedulingRange(TopologyElement());
123  }
124 
125  template <typename VisitTopology, typename IncidentTopology>
126  using ExecConnectivityType =
128 
129  template <typename VisitTopology, typename IncidentTopology>
131  VisitTopology,
132  IncidentTopology,
133  vtkm::cont::Token&) const
134  {
136  }
137 
138  void PrintSummary(std::ostream& out) const override
139  {
140  out << " StructuredCellSet:\n";
141  this->Structure.PrintSummary(out);
142  }
143 
144  // Cannot use the default implementation of the destructor because the CUDA compiler
145  // will attempt to create it for device, and then it will fail when it tries to call
146  // the destructor of the superclass.
147  ~CellSetStructured() override {}
148 
149  CellSetStructured() = default;
150 
152  : CellSet()
153  , Structure(src.Structure)
154  {
155  }
156 
158  {
159  this->Structure = src.Structure;
160  return *this;
161  }
162 
164  : CellSet()
165  , Structure(std::move(src.Structure))
166  {
167  }
168 
170  {
171  this->Structure = std::move(src.Structure);
172  return *this;
173  }
174 
175 private:
177 };
178 
179 #ifndef vtkm_cont_CellSetStructured_cxx
180 extern template class VTKM_CONT_TEMPLATE_EXPORT CellSetStructured<1>;
181 extern template class VTKM_CONT_TEMPLATE_EXPORT CellSetStructured<2>;
182 extern template class VTKM_CONT_TEMPLATE_EXPORT CellSetStructured<3>;
183 #endif
184 }
185 } // namespace vtkm::cont
186 
187 //=============================================================================
188 // Specializations of serialization related classes
190 namespace vtkm
191 {
192 namespace cont
193 {
194 
195 template <vtkm::IdComponent DIMENSION>
196 struct SerializableTypeString<vtkm::cont::CellSetStructured<DIMENSION>>
197 {
198  static VTKM_CONT const std::string& Get()
199  {
200  static std::string name = "CS_Structured<" + std::to_string(DIMENSION) + ">";
201  return name;
202  }
203 };
204 }
205 } // vtkm::cont
206 
207 namespace mangled_diy_namespace
208 {
209 
210 template <vtkm::IdComponent DIMENSION>
211 struct Serialization<vtkm::cont::CellSetStructured<DIMENSION>>
212 {
213 private:
215 
216 public:
217  static VTKM_CONT void save(BinaryBuffer& bb, const Type& cs)
218  {
219  vtkmdiy::save(bb, cs.GetPointDimensions());
220  vtkmdiy::save(bb, cs.GetGlobalPointDimensions());
221  vtkmdiy::save(bb, cs.GetGlobalPointIndexStart());
222  }
223 
224  static VTKM_CONT void load(BinaryBuffer& bb, Type& cs)
225  {
226  typename Type::SchedulingRangeType dims, gdims, start;
227  vtkmdiy::load(bb, dims);
228  vtkmdiy::load(bb, gdims);
229  vtkmdiy::load(bb, start);
230 
231  cs = Type{};
232  cs.SetPointDimensions(dims);
233  cs.SetGlobalPointDimensions(gdims);
234  cs.SetGlobalPointIndexStart(start);
235  }
236 };
237 
238 } // diy
240 
241 #endif //vtk_m_cont_CellSetStructured_h
vtkm::cont::CellSetStructured::GetNumberOfPointsInCell
vtkm::IdComponent GetNumberOfPointsInCell(vtkm::Id vtkmNotUsed(cellIndex)=0) const override
Definition: CellSetStructured.h:83
vtkm::cont::CellSetStructured::PrintSummary
void PrintSummary(std::ostream &out) const override
Definition: CellSetStructured.h:138
ConnectivityStructured.h
vtkm::cont::CellSetStructured::CellSetStructured
CellSetStructured(const CellSetStructured &src)
Definition: CellSetStructured.h:151
vtkm::cont::CellSetStructured::GetNumberOfCells
vtkm::Id GetNumberOfCells() const override
Definition: CellSetStructured.h:38
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
ConnectivityStructuredInternals.h
vtkm::cont::CellSetStructured::Structure
InternalsType Structure
Definition: CellSetStructured.h:176
vtkm::Get
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT auto Get(const vtkm::Tuple< Ts... > &tuple) -> decltype(tuple.template Get< Index >())
Retrieve the object from a vtkm::Tuple at the given index.
Definition: Tuple.h:83
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::cont::CellSetStructured
Definition: CastAndCall.h:32
vtkm::cont::CellSetStructured::GetNumberOfFaces
vtkm::Id GetNumberOfFaces() const override
Definition: CellSetStructured.h:42
vtkm::cont::CellSetStructured::NewInstance
std::shared_ptr< CellSet > NewInstance() const override
Definition: CellSetStructured.h:102
vtkm::cont::CellSetStructured::CellSetStructured
CellSetStructured(CellSetStructured &&src) noexcept
Definition: CellSetStructured.h:163
VTKM_IS_TOPOLOGY_ELEMENT_TAG
#define VTKM_IS_TOPOLOGY_ELEMENT_TAG(type)
Definition: TopologyElementTag.h:92
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:107
mangled_diy_namespace
Definition: Particle.h:331
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::exec::arg::load
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC T load(const U &u, vtkm::Id v)
Definition: FetchTagArrayDirectIn.h:36
vtkm::cont::CellSetStructured::operator=
CellSetStructured & operator=(const CellSetStructured &src)
Definition: CellSetStructured.h:157
vtkm::cont::CellSetStructured::GetNumberOfEdges
vtkm::Id GetNumberOfEdges() const override
Definition: CellSetStructured.h:44
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
Definition: CellSetStructured.h:40
vtkm::cont::CellSetStructured::GetCellShape
vtkm::UInt8 GetCellShape(vtkm::Id vtkmNotUsed(cellIndex)=0) const override
Definition: CellSetStructured.h:88
vtkm::cont::CellSetStructured< 3 >::InternalsType
vtkm::internal::ConnectivityStructuredInternals< DIMENSION > InternalsType
Definition: CellSetStructured.h:31
vtkm::cont::CellSetStructured::GetSchedulingRange
SchedulingRangeType GetSchedulingRange(TopologyElement) const
Definition: CellSetStructured.h:119
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
CellSet.h
vtkm::cont::CellSet
Definition: CellSet.h:24
vtkm::cont::CellSetStructured< 3 >::SchedulingRangeType
typename InternalsType::SchedulingRangeType SchedulingRangeType
Definition: CellSetStructured.h:36
vtkm::UInt8
uint8_t UInt8
Definition: Types.h:157
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:93
vtkm::exec::ConnectivityStructured
Definition: ConnectivityStructured.h:24
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
vtkm::cont::CellSetStructured::GetPointDimensions
SchedulingRangeType GetPointDimensions() const
Definition: CellSetStructured.h:64
vtkm::cont::CellSetStructured::SetPointDimensions
void SetPointDimensions(SchedulingRangeType dimensions)
Definition: CellSetStructured.h:49
vtkm::cont::CellSetStructured::GetGlobalCellDimensions
SchedulingRangeType GetGlobalCellDimensions() const
Definition: CellSetStructured.h:73
vtkm::cont::CellSetStructured::GetCellDimensions
SchedulingRangeType GetCellDimensions() const
Definition: CellSetStructured.h:71
vtkm::cont::CellSetStructured::SetGlobalPointDimensions
void SetGlobalPointDimensions(SchedulingRangeType dimensions)
Definition: CellSetStructured.h:54
vtkm::cont::CellSetStructured::ReleaseResourcesExecution
void ReleaseResourcesExecution() override
Definition: CellSetStructured.h:47
vtkm::cont::CellSetStructured::PrepareForInput
ExecConnectivityType< VisitTopology, IncidentTopology > PrepareForInput(vtkm::cont::DeviceAdapterId, VisitTopology, IncidentTopology, vtkm::cont::Token &) const
Definition: CellSetStructured.h:130
vtkm::cont::CellSetStructured::operator=
CellSetStructured & operator=(CellSetStructured &&src) noexcept
Definition: CellSetStructured.h:169
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:92
ErrorBadType.h
vtkm::cont::CellSetStructured::SetGlobalPointIndexStart
void SetGlobalPointIndexStart(SchedulingRangeType start)
Definition: CellSetStructured.h:59
vtkm::cont::CellSetStructured::GetGlobalPointIndexStart
SchedulingRangeType GetGlobalPointIndexStart() const
Definition: CellSetStructured.h:78
vtkm::cont::CellSetStructured::GetGlobalPointDimensions
SchedulingRangeType GetGlobalPointDimensions() const
Definition: CellSetStructured.h:66
vtkm::cont::CellSetStructured::~CellSetStructured
~CellSetStructured() override
Definition: CellSetStructured.h:147
TopologyElementTag.h