VTK-m  2.0
DataSet.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_DataSet_h
11 #define vtk_m_cont_DataSet_h
12 
13 #include <vtkm/cont/vtkm_cont_export.h>
14 
15 #include <vtkm/cont/ArrayHandle.h>
18 #include <vtkm/cont/Field.h>
22 
23 namespace vtkm
24 {
25 namespace cont
26 {
27 
28 VTKM_CONT_EXPORT VTKM_CONT std::string& GlobalGhostCellFieldName() noexcept;
29 
30 VTKM_CONT_EXPORT VTKM_CONT const std::string& GetGlobalGhostCellFieldName() noexcept;
31 
32 VTKM_CONT_EXPORT VTKM_CONT void SetGlobalGhostCellFieldName(const std::string& name) noexcept;
33 
34 class VTKM_CONT_EXPORT DataSet
35 {
36 public:
37  DataSet() = default;
38 
39  DataSet(vtkm::cont::DataSet&&) = default;
40 
41  DataSet(const vtkm::cont::DataSet&) = default;
42 
43  vtkm::cont::DataSet& operator=(vtkm::cont::DataSet&&) = default;
44 
45  vtkm::cont::DataSet& operator=(const vtkm::cont::DataSet&) = default;
46 
47  VTKM_CONT void Clear();
48 
50  VTKM_CONT vtkm::Id GetNumberOfCells() const;
51 
56  VTKM_CONT vtkm::Id GetNumberOfPoints() const;
57 
64  VTKM_CONT void AddField(const Field& field);
65 
74  VTKM_CONT
75  const vtkm::cont::Field& GetField(vtkm::Id index) const { return this->Fields.GetField(index); }
76 
77  VTKM_CONT
78  vtkm::cont::Field& GetField(vtkm::Id index) { return this->Fields.GetField(index); }
80 
81  VTKM_CONT
82  bool HasField(const std::string& name,
84  {
85  return this->Fields.HasField(name, assoc);
86  }
87 
88  VTKM_CONT
89  bool HasCellField(const std::string& name) const
90  {
91  return (this->Fields.GetFieldIndex(name, vtkm::cont::Field::Association::Cells) != -1);
92  }
93 
94  VTKM_CONT
95  bool HasGhostCellField() const;
96 
97  VTKM_CONT
98  const std::string& GetGhostCellFieldName() const;
99 
100  VTKM_CONT
101  bool HasPointField(const std::string& name) const
102  {
103  return (this->Fields.GetFieldIndex(name, vtkm::cont::Field::Association::Points) != -1);
104  }
105 
106 
115  VTKM_CONT
117  const std::string& name,
119  {
120  return this->Fields.GetFieldIndex(name, assoc);
121  }
122 
128  VTKM_CONT
130  const std::string& name,
132  {
133  return this->Fields.GetField(name, assoc);
134  }
135 
136 
137  VTKM_CONT
139  const std::string& name,
141  {
142  return this->Fields.GetField(name, assoc);
143  }
145 
151  VTKM_CONT
152  const vtkm::cont::Field& GetCellField(const std::string& name) const
153  {
154  return this->GetField(name, vtkm::cont::Field::Association::Cells);
155  }
156 
157  VTKM_CONT
158  vtkm::cont::Field& GetCellField(const std::string& name)
159  {
160  return this->GetField(name, vtkm::cont::Field::Association::Cells);
161  }
163 
169  VTKM_CONT
170  const vtkm::cont::Field& GetGhostCellField() const;
172 
178  VTKM_CONT
179  const vtkm::cont::Field& GetPointField(const std::string& name) const
180  {
181  return this->GetField(name, vtkm::cont::Field::Association::Points);
182  }
183 
184  VTKM_CONT
185  vtkm::cont::Field& GetPointField(const std::string& name)
186  {
187  return this->GetField(name, vtkm::cont::Field::Association::Points);
188  }
190 
198  VTKM_CONT
199  void AddPointField(const std::string& fieldName, const vtkm::cont::UnknownArrayHandle& field)
200  {
201  this->AddField(make_FieldPoint(fieldName, field));
202  }
203 
204  template <typename T, typename Storage>
205  VTKM_CONT void AddPointField(const std::string& fieldName,
207  {
208  this->AddField(make_FieldPoint(fieldName, field));
209  }
210 
211  template <typename T>
212  VTKM_CONT void AddPointField(const std::string& fieldName, const std::vector<T>& field)
213  {
214  this->AddField(
216  }
217 
218  template <typename T>
219  VTKM_CONT void AddPointField(const std::string& fieldName, const T* field, const vtkm::Id& n)
220  {
221  this->AddField(
223  }
225 
233  VTKM_CONT
234  void AddCellField(const std::string& fieldName, const vtkm::cont::UnknownArrayHandle& field)
235  {
236  this->AddField(make_FieldCell(fieldName, field));
237  }
238 
239  template <typename T, typename Storage>
240  VTKM_CONT void AddCellField(const std::string& fieldName,
242  {
243  this->AddField(make_FieldCell(fieldName, field));
244  }
245 
246  template <typename T>
247  VTKM_CONT void AddCellField(const std::string& fieldName, const std::vector<T>& field)
248  {
249  this->AddField(
251  }
252 
253  template <typename T>
254  VTKM_CONT void AddCellField(const std::string& fieldName, const T* field, const vtkm::Id& n)
255  {
256  this->AddField(
258  }
260 
264  VTKM_CONT void SetGhostCellFieldName(const std::string& name);
265 
269  VTKM_CONT void SetGhostCellField(const std::string& name);
270 
281  VTKM_CONT void SetGhostCellField(const vtkm::cont::Field& field);
282  VTKM_CONT void SetGhostCellField(const std::string& fieldName,
283  const vtkm::cont::UnknownArrayHandle& field);
285 
295  VTKM_CONT void SetGhostCellField(const vtkm::cont::UnknownArrayHandle& field);
296 
297  VTKM_DEPRECATED(2.0, "Use SetGhostCellField.")
298  VTKM_CONT
299  void AddGhostCellField(const std::string& fieldName, const vtkm::cont::UnknownArrayHandle& field)
300  {
301  this->SetGhostCellField(fieldName, field);
302  }
303 
304  VTKM_DEPRECATED(2.0, "Use SetGhostCellField.")
305  VTKM_CONT
306  void AddGhostCellField(const vtkm::cont::UnknownArrayHandle& field)
307  {
308  this->SetGhostCellField(field);
309  }
310 
311  VTKM_DEPRECATED(2.0, "Use SetGhostCellField.")
312  VTKM_CONT
313  void AddGhostCellField(const vtkm::cont::Field& field) { this->SetGhostCellField(field); }
314 
315 
321  VTKM_CONT
322  vtkm::IdComponent AddCoordinateSystem(const vtkm::cont::CoordinateSystem& cs);
323 
330  VTKM_CONT vtkm::IdComponent AddCoordinateSystem(const std::string& pointFieldName);
331 
332  VTKM_CONT
333  bool HasCoordinateSystem(const std::string& name) const
334  {
335  return this->GetCoordinateSystemIndex(name) >= 0;
336  }
337 
338  VTKM_CONT
339  vtkm::cont::CoordinateSystem GetCoordinateSystem(vtkm::Id index = 0) const;
340 
344  VTKM_CONT
345  vtkm::IdComponent GetCoordinateSystemIndex(const std::string& name) const;
346 
347  VTKM_CONT const std::string& GetCoordinateSystemName(vtkm::Id index = 0) const;
348 
351  VTKM_CONT
352  vtkm::cont::CoordinateSystem GetCoordinateSystem(const std::string& name) const;
353 
354  template <typename CellSetType>
355  VTKM_CONT void SetCellSet(const CellSetType& cellSet)
356  {
358  this->SetCellSetImpl(cellSet);
359  }
360 
361  VTKM_CONT
362  const vtkm::cont::UnknownCellSet& GetCellSet() const { return this->CellSet; }
363 
364  VTKM_CONT
366 
367  VTKM_CONT
368  vtkm::IdComponent GetNumberOfFields() const { return this->Fields.GetNumberOfFields(); }
369 
370  VTKM_CONT
372  {
373  return static_cast<vtkm::IdComponent>(this->CoordSystemNames.size());
374  }
375 
379  VTKM_CONT
380  void CopyStructure(const vtkm::cont::DataSet& source);
381 
395  VTKM_CONT void ConvertToExpected();
396 
397  VTKM_CONT
398  void PrintSummary(std::ostream& out) const;
399 
400 private:
401  std::vector<std::string> CoordSystemNames;
402  vtkm::cont::internal::FieldCollection Fields{ vtkm::cont::Field::Association::WholeDataSet,
405 
407  std::shared_ptr<std::string> GhostCellName;
408 
409  VTKM_CONT void SetCellSetImpl(const vtkm::cont::UnknownCellSet& cellSet);
410 };
411 
412 } // namespace cont
413 } // namespace vtkm
414 
415 //=============================================================================
416 // Specializations of serialization related classes
418 namespace vtkm
419 {
420 namespace cont
421 {
422 
423 template <typename FieldTypeList = VTKM_DEFAULT_TYPE_LIST,
424  typename CellSetTypesList = VTKM_DEFAULT_CELL_SET_LIST>
425 struct SerializableDataSet
426 {
427  SerializableDataSet() = default;
428 
429  explicit SerializableDataSet(const vtkm::cont::DataSet& dataset)
430  : DataSet(dataset)
431  {
432  }
433 
434  vtkm::cont::DataSet DataSet;
435 };
436 }
437 } // vtkm::cont
438 
439 namespace mangled_diy_namespace
440 {
441 
442 template <typename FieldTypeList, typename CellSetTypesList>
443 struct Serialization<vtkm::cont::SerializableDataSet<FieldTypeList, CellSetTypesList>>
444 {
445 private:
446  using Type = vtkm::cont::SerializableDataSet<FieldTypeList, CellSetTypesList>;
447 
448 public:
449  static VTKM_CONT void save(BinaryBuffer& bb, const Type& serializable)
450  {
451  const auto& dataset = serializable.DataSet;
452 
453  vtkmdiy::save(bb, dataset.GetCellSet().ResetCellSetList(CellSetTypesList{}));
454 
455  vtkm::IdComponent numberOfFields = dataset.GetNumberOfFields();
456  vtkmdiy::save(bb, numberOfFields);
457  for (vtkm::IdComponent i = 0; i < numberOfFields; ++i)
458  {
459  vtkmdiy::save(bb, dataset.GetField(i));
460  }
461 
462  vtkm::IdComponent numberOfCoordinateSystems = dataset.GetNumberOfCoordinateSystems();
463  vtkmdiy::save(bb, numberOfCoordinateSystems);
464  for (vtkm::IdComponent i = 0; i < numberOfCoordinateSystems; ++i)
465  {
466  vtkmdiy::save(bb, dataset.GetCoordinateSystemName(i));
467  }
468  }
469 
470  static VTKM_CONT void load(BinaryBuffer& bb, Type& serializable)
471  {
472  auto& dataset = serializable.DataSet;
473  dataset = {}; // clear
474 
476  vtkmdiy::load(bb, cells);
477  dataset.SetCellSet(cells);
478 
479  vtkm::IdComponent numberOfFields = 0;
480  vtkmdiy::load(bb, numberOfFields);
481  for (vtkm::IdComponent i = 0; i < numberOfFields; ++i)
482  {
483  vtkm::cont::Field field;
484  vtkmdiy::load(bb, field);
485  dataset.AddField(field);
486  }
487 
488  vtkm::IdComponent numberOfCoordinateSystems = 0;
489  vtkmdiy::load(bb, numberOfCoordinateSystems);
490  for (vtkm::IdComponent i = 0; i < numberOfCoordinateSystems; ++i)
491  {
492  std::string coordName;
493  vtkmdiy::load(bb, coordName);
494  dataset.AddCoordinateSystem(coordName);
495  }
496  }
497 };
498 
499 } // diy
501 
502 #endif //vtk_m_cont_DataSet_h
vtkm::cont::GetGlobalGhostCellFieldName
VTKM_CONT_EXPORT const VTKM_CONT std::string & GetGlobalGhostCellFieldName() noexcept
vtkm::cont::DataSet::GetCellSet
VTKM_CONT vtkm::cont::UnknownCellSet & GetCellSet()
Definition: DataSet.h:365
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:283
ArrayHandle.h
vtkm::cont::DataSet::HasPointField
VTKM_CONT bool HasPointField(const std::string &name) const
Definition: DataSet.h:101
vtkm::cont::DataSet::AddCellField
VTKM_CONT void AddCellField(const std::string &fieldName, const std::vector< T > &field)
Adds a cell field of a given name to the DataSet.
Definition: DataSet.h:247
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::cont::DataSet::AddPointField
VTKM_CONT void AddPointField(const std::string &fieldName, const vtkm::cont::ArrayHandle< T, Storage > &field)
Adds a point field of a given name to the DataSet.
Definition: DataSet.h:205
FieldCollection.h
vtkm::cont::SetGlobalGhostCellFieldName
VTKM_CONT_EXPORT VTKM_CONT void SetGlobalGhostCellFieldName(const std::string &name) noexcept
VTKM_IS_KNOWN_OR_UNKNOWN_CELL_SET
#define VTKM_IS_KNOWN_OR_UNKNOWN_CELL_SET(T)
Definition: UnknownCellSet.h:313
UnknownCellSet.h
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::cont::DataSet::GetFieldIndex
VTKM_CONT vtkm::Id GetFieldIndex(const std::string &name, vtkm::cont::Field::Association assoc=vtkm::cont::Field::Association::Any) const
Returns the field that matches the provided name and association.
Definition: DataSet.h:116
vtkm::cont::Field::Association
Association
Definition: cont/Field.h:34
vtkm::cont::make_Field
vtkm::cont::Field make_Field(std::string name, Field::Association association, const T *data, vtkm::Id size, vtkm::CopyFlag copy)
Convenience functions to build fields from C style arrays and std::vector.
Definition: cont/Field.h:180
vtkm::cont::UnknownArrayHandle
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:406
vtkm::cont::UncertainCellSet
A CellSet of an uncertain type.
Definition: UncertainCellSet.h:38
vtkm::cont::DataSet
Definition: DataSet.h:34
vtkm::cont::Field::Association::WholeDataSet
@ WholeDataSet
vtkm::cont::UnknownCellSet
A CellSet of an unknown type.
Definition: UnknownCellSet.h:48
vtkm::cont::DataSet::AddCellField
VTKM_CONT void AddCellField(const std::string &fieldName, const vtkm::cont::UnknownArrayHandle &field)
Adds a cell field of a given name to the DataSet.
Definition: DataSet.h:234
CoordinateSystem.h
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::CoordinateSystem
Definition: CoordinateSystem.h:25
vtkm::cont::make_FieldCell
vtkm::cont::Field make_FieldCell(std::string name, const vtkm::cont::ArrayHandle< T, S > &data)
Convenience function to build cell fields from vtkm::cont::ArrayHandle.
Definition: cont/Field.h:241
vtkm::cont::DataSet::AddPointField
VTKM_CONT void AddPointField(const std::string &fieldName, const T *field, const vtkm::Id &n)
Adds a point field of a given name to the DataSet.
Definition: DataSet.h:219
vtkm::cont::DataSet::HasCellField
VTKM_CONT bool HasCellField(const std::string &name) const
Definition: DataSet.h:89
UnknownArrayHandle.h
vtkm::cont::DataSet::CellSet
vtkm::cont::UnknownCellSet CellSet
Definition: DataSet.h:406
vtkm::cont::Field
A Field encapsulates an array on some piece of the mesh, such as the points, a cell set,...
Definition: cont/Field.h:31
vtkm::cont::DataSet::GetNumberOfCoordinateSystems
VTKM_CONT vtkm::IdComponent GetNumberOfCoordinateSystems() const
Definition: DataSet.h:371
vtkm::cont::Field::Association::Any
@ Any
vtkm::cont::Field::Association::Points
@ Points
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::DataSet::AddCellField
VTKM_CONT void AddCellField(const std::string &fieldName, const T *field, const vtkm::Id &n)
Adds a cell field of a given name to the DataSet.
Definition: DataSet.h:254
vtkm::cont::GlobalGhostCellFieldName
VTKM_CONT_EXPORT VTKM_CONT std::string & GlobalGhostCellFieldName() noexcept
vtkm::cont::DataSet::GetPointField
const VTKM_CONT vtkm::cont::Field & GetPointField(const std::string &name) const
Returns the first point field that matches the provided name.
Definition: DataSet.h:179
vtkm::cont::CellSet
Definition: CellSet.h:24
vtkm::CopyFlag::On
@ On
vtkm::cont::DataSet::HasCoordinateSystem
VTKM_CONT bool HasCoordinateSystem(const std::string &name) const
Definition: DataSet.h:333
vtkm::cont::DataSet::AddPointField
VTKM_CONT void AddPointField(const std::string &fieldName, const std::vector< T > &field)
Adds a point field of a given name to the DataSet.
Definition: DataSet.h:212
vtkm::cont::DataSet::GetField
VTKM_CONT vtkm::cont::Field & GetField(vtkm::Id index)
Retrieves a field by index.
Definition: DataSet.h:78
vtkm::cont::Field::Association::Cells
@ Cells
ErrorBadValue.h
Field.h
vtkm::cont::DataSet::GhostCellName
std::shared_ptr< std::string > GhostCellName
Definition: DataSet.h:407
vtkm::cont::DataSet::GetField
const VTKM_CONT vtkm::cont::Field & GetField(vtkm::Id index) const
Retrieves a field by index.
Definition: DataSet.h:75
vtkm::cont::DataSet::GetCellField
VTKM_CONT vtkm::cont::Field & GetCellField(const std::string &name)
Returns the first cell field that matches the provided name.
Definition: DataSet.h:158
vtkm::cont::DataSet::SetCellSet
VTKM_CONT void SetCellSet(const CellSetType &cellSet)
Definition: DataSet.h:355
vtkm::cont::DataSet::GetNumberOfFields
VTKM_CONT vtkm::IdComponent GetNumberOfFields() const
Definition: DataSet.h:368
vtkm::cont::DataSet::AddCellField
VTKM_CONT void AddCellField(const std::string &fieldName, const vtkm::cont::ArrayHandle< T, Storage > &field)
Adds a cell field of a given name to the DataSet.
Definition: DataSet.h:240
vtkm::cont::DataSet::GetField
const VTKM_CONT vtkm::cont::Field & GetField(const std::string &name, vtkm::cont::Field::Association assoc=vtkm::cont::Field::Association::Any) const
Returns the field that matches the provided name and association.
Definition: DataSet.h:129
vtkm::cont::DataSet::HasField
VTKM_CONT bool HasField(const std::string &name, vtkm::cont::Field::Association assoc=vtkm::cont::Field::Association::Any) const
Definition: DataSet.h:82
vtkm::cont::DataSet::CoordSystemNames
std::vector< std::string > CoordSystemNames
Definition: DataSet.h:401
vtkm::cont::DataSet::GetField
VTKM_CONT vtkm::cont::Field & GetField(const std::string &name, vtkm::cont::Field::Association assoc=vtkm::cont::Field::Association::Any)
Returns the field that matches the provided name and association.
Definition: DataSet.h:138
VTKM_DEPRECATED
#define VTKM_DEPRECATED(...)
Definition: Deprecated.h:145
vtkm::cont::DataSet::GetCellSet
const VTKM_CONT vtkm::cont::UnknownCellSet & GetCellSet() const
Definition: DataSet.h:362
vtkm::cont::DataSet::GetPointField
VTKM_CONT vtkm::cont::Field & GetPointField(const std::string &name)
Returns the first point field that matches the provided name.
Definition: DataSet.h:185
vtkm::cont::make_FieldPoint
vtkm::cont::Field make_FieldPoint(std::string name, const vtkm::cont::ArrayHandle< T, S > &data)
Convenience function to build point fields from vtkm::cont::ArrayHandle.
Definition: cont/Field.h:227
vtkm::cont::DataSet::GetCellField
const VTKM_CONT vtkm::cont::Field & GetCellField(const std::string &name) const
Returns the first cell field that matches the provided name.
Definition: DataSet.h:152
vtkm::cont::DataSet::AddPointField
VTKM_CONT void AddPointField(const std::string &fieldName, const vtkm::cont::UnknownArrayHandle &field)
Adds a point field of a given name to the DataSet.
Definition: DataSet.h:199