VTK-m  2.2
PartitionedDataSet.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_PartitionedDataSet_h
11 #define vtk_m_cont_PartitionedDataSet_h
12 #include <limits>
13 #include <vtkm/StaticAssert.h>
14 
15 #include <vtkm/cont/ArrayHandle.h>
16 #include <vtkm/cont/DataSet.h>
17 #include <vtkm/cont/Field.h>
19 
20 namespace vtkm
21 {
22 namespace cont
23 {
24 
27 {
28  using StorageVec = std::vector<vtkm::cont::DataSet>;
29 
30 public:
31  using iterator = typename StorageVec::iterator;
32  using const_iterator = typename StorageVec::const_iterator;
33  using value_type = typename StorageVec::value_type;
34  using reference = typename StorageVec::reference;
35  using const_reference = typename StorageVec::const_reference;
36 
38  VTKM_CONT
40 
42  VTKM_CONT
43  explicit PartitionedDataSet(const std::vector<vtkm::cont::DataSet>& partitions);
45  VTKM_CONT
46  explicit PartitionedDataSet(vtkm::Id size);
47 
48  VTKM_CONT
49  PartitionedDataSet() = default;
50 
52  VTKM_CONT
53  vtkm::cont::Field GetFieldFromPartition(const std::string& field_name, int partition_index) const;
54 
56  VTKM_CONT
57  vtkm::Id GetNumberOfPartitions() const;
58 
61  VTKM_CONT
62  vtkm::Id GetGlobalNumberOfPartitions() const;
63 
65  VTKM_CONT
66  const vtkm::cont::DataSet& GetPartition(vtkm::Id partId) const;
67 
69  VTKM_CONT const std::vector<vtkm::cont::DataSet>& GetPartitions() const;
70 
72  VTKM_CONT void AppendPartition(const vtkm::cont::DataSet& ds);
73 
77  VTKM_CONT void InsertPartition(vtkm::Id index, const vtkm::cont::DataSet& ds);
78 
81  VTKM_CONT void ReplacePartition(vtkm::Id index, const vtkm::cont::DataSet& ds);
82 
87  VTKM_CONT void AppendPartitions(const std::vector<vtkm::cont::DataSet>& partitions);
88 
90  VTKM_CONT vtkm::IdComponent GetNumberOfFields() const { return this->Fields.GetNumberOfFields(); }
91 
95  VTKM_CONT void AddField(const Field& field) { this->Fields.AddField(field); }
96 
100  VTKM_CONT void AddField(const std::string& name,
101  vtkm::cont::Field::Association association,
102  const vtkm::cont::UnknownArrayHandle& data)
103  {
104  this->AddField({ name, association, data });
105  }
106 
108  template <typename T, typename Storage>
109  VTKM_CONT void AddGlobalField(const std::string& fieldName,
111  {
112  this->AddField(fieldName, vtkm::cont::Field::Association::Global, field);
113  }
114 
115  template <typename T>
116  VTKM_CONT void AddGlobalField(const std::string& fieldName, const std::vector<T>& field)
117  {
118  this->AddField(
120  }
121 
122  template <typename T>
123  VTKM_CONT void AddGlobalField(const std::string& fieldName, const T* field, const vtkm::Id& n)
124  {
125  this->AddField(
127  }
128 
130  template <typename T, typename Storage>
131  VTKM_CONT void AddPartitionsField(const std::string& fieldName,
133  {
134  this->AddField(fieldName, vtkm::cont::Field::Association::Partitions, field);
135  }
136 
137  template <typename T>
138  VTKM_CONT void AddPartitionsField(const std::string& fieldName, const std::vector<T>& field)
139  {
140  this->AddField(
142  }
143 
144  template <typename T>
145  VTKM_CONT void AddPartitionsField(const std::string& fieldName, const T* field, const vtkm::Id& n)
146  {
147  this->AddField(make_Field(
149  }
150 
151  VTKM_CONT
152  const vtkm::cont::Field& GetField(vtkm::Id index) const { return this->Fields.GetField(index); }
153 
154  VTKM_CONT
155  vtkm::cont::Field& GetField(vtkm::Id index) { return this->Fields.GetField(index); }
156 
157  VTKM_CONT
159  const std::string& name,
161  {
162  return this->Fields.GetField(name, assoc);
163  }
164 
168  VTKM_CONT
170  const std::string& name,
172  {
173  return this->Fields.GetField(name, assoc);
174  }
175 
177  VTKM_CONT
178  const vtkm::cont::Field& GetGlobalField(const std::string& name) const
179  {
180  return this->GetField(name, vtkm::cont::Field::Association::Global);
181  }
182 
184  VTKM_CONT
185  const vtkm::cont::Field& GetPartitionsField(const std::string& name) const
186  {
187  return this->GetField(name, vtkm::cont::Field::Association::Partitions);
188  }
189 
190  VTKM_CONT
191  vtkm::cont::Field& GetGlobalField(const std::string& name)
192  {
193  return this->GetField(name, vtkm::cont::Field::Association::Global);
194  }
195 
196  VTKM_CONT
197  vtkm::cont::Field& GetPartitionsField(const std::string& name)
198  {
199  return this->GetField(name, vtkm::cont::Field::Association::Partitions);
200  }
201 
203  VTKM_CONT
204  bool HasField(const std::string& name,
206  {
207  return this->Fields.HasField(name, assoc);
208  }
209 
211  VTKM_CONT bool HasGlobalField(const std::string& name) const
212  {
213  return (this->Fields.GetFieldIndex(name, vtkm::cont::Field::Association::Global) != -1);
214  }
215 
217  VTKM_CONT bool HasPartitionsField(const std::string& name) const
218  {
219  return (this->Fields.GetFieldIndex(name, vtkm::cont::Field::Association::Partitions) != -1);
220  }
221 
223  VTKM_CONT
224  void CopyPartitions(const vtkm::cont::PartitionedDataSet& source);
225 
226  VTKM_CONT
227  void PrintSummary(std::ostream& stream) const;
228 
234  VTKM_CONT
235  iterator begin() noexcept { return this->Partitions.begin(); }
236  VTKM_CONT
237  iterator end() noexcept { return this->Partitions.end(); }
238  VTKM_CONT
239  const_iterator begin() const noexcept { return this->Partitions.begin(); }
240  VTKM_CONT
241  const_iterator end() const noexcept { return this->Partitions.end(); }
242  VTKM_CONT
243  const_iterator cbegin() const noexcept { return this->Partitions.cbegin(); }
244  VTKM_CONT
245  const_iterator cend() const noexcept { return this->Partitions.cend(); }
247 
248 private:
249  std::vector<vtkm::cont::DataSet> Partitions;
250 
251  vtkm::cont::internal::FieldCollection Fields{ vtkm::cont::Field::Association::Partitions,
253 };
254 }
255 } // namespace vtkm::cont
256 
257 #endif
vtkm::cont::PartitionedDataSet::cbegin
const_iterator cbegin() const noexcept
Definition: PartitionedDataSet.h:243
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:300
ArrayHandle.h
vtkm::cont::PartitionedDataSet::GetGlobalField
vtkm::cont::Field & GetGlobalField(const std::string &name)
Definition: PartitionedDataSet.h:191
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
FieldCollection.h
vtkm::cont::PartitionedDataSet::begin
iterator begin() noexcept
Definition: PartitionedDataSet.h:235
vtkm::cont::PartitionedDataSet::GetNumberOfFields
vtkm::IdComponent GetNumberOfFields() const
Methods to Add and Get fields on a PartitionedDataSet.
Definition: PartitionedDataSet.h:90
vtkm::cont::PartitionedDataSet::AddGlobalField
void AddGlobalField(const std::string &fieldName, const std::vector< T > &field)
Definition: PartitionedDataSet.h:116
vtkm::IdComponent
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
vtkm::cont::Field::Association::Global
@ Global
A field that applies to all partitions.
vtkm::cont::Field::Association
Association
Identifies what elements of a data set a field is associated with.
Definition: Field.h:38
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: Field.h:257
vtkm::cont::UnknownArrayHandle
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:430
vtkm::cont::DataSet
Contains and manages the geometric data structures that VTK-m operates on.
Definition: DataSet.h:57
vtkm::cont::PartitionedDataSet::cend
const_iterator cend() const noexcept
Definition: PartitionedDataSet.h:245
vtkm::cont::PartitionedDataSet::AddGlobalField
void AddGlobalField(const std::string &fieldName, const vtkm::cont::ArrayHandle< T, Storage > &field)
Add a field with a global association.
Definition: PartitionedDataSet.h:109
vtkm::cont::PartitionedDataSet::GetGlobalField
const vtkm::cont::Field & GetGlobalField(const std::string &name) const
Get a global field.
Definition: PartitionedDataSet.h:178
vtkm::cont::PartitionedDataSet::GetField
vtkm::cont::Field & GetField(vtkm::Id index)
Definition: PartitionedDataSet.h:155
vtkm::cont::PartitionedDataSet::GetField
const vtkm::cont::Field & GetField(const std::string &name, vtkm::cont::Field::Association assoc=vtkm::cont::Field::Association::Any) const
Definition: PartitionedDataSet.h:158
vtkm::cont::PartitionedDataSet::AddField
void AddField(const Field &field)
Adds a field that is applied to the meta-partition structure.
Definition: PartitionedDataSet.h:95
vtkm::cont::PartitionedDataSet::AddPartitionsField
void AddPartitionsField(const std::string &fieldName, const vtkm::cont::ArrayHandle< T, Storage > &field)
Add a field where each entry is associated with a whole partition.
Definition: PartitionedDataSet.h:131
vtkm::cont::Field
A Field encapsulates an array on some piece of the mesh, such as the points, a cell set,...
Definition: Field.h:31
VTKM_CONT_EXPORT
#define VTKM_CONT_EXPORT
Definition: vtkm_cont_export.h:44
vtkm::cont::PartitionedDataSet::HasGlobalField
bool HasGlobalField(const std::string &name) const
Query whether the partitioned data set has the named global field.
Definition: PartitionedDataSet.h:211
vtkm::cont::Field::Association::Any
@ Any
Any field regardless of the association.
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
Field.h
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::cont::PartitionedDataSet::AddField
void AddField(const std::string &name, vtkm::cont::Field::Association association, const vtkm::cont::UnknownArrayHandle &data)
Adds a field that is applied to the meta-partition structure.
Definition: PartitionedDataSet.h:100
vtkm::CopyFlag::On
@ On
vtkm::cont::PartitionedDataSet::AddPartitionsField
void AddPartitionsField(const std::string &fieldName, const std::vector< T > &field)
Definition: PartitionedDataSet.h:138
vtkm::cont::PartitionedDataSet::HasPartitionsField
bool HasPartitionsField(const std::string &name) const
Query whether the partitioned data set has the named partition field.
Definition: PartitionedDataSet.h:217
vtkm::cont::PartitionedDataSet::GetField
vtkm::cont::Field & GetField(const std::string &name, vtkm::cont::Field::Association assoc=vtkm::cont::Field::Association::Any)
Get a field associated with the partitioned data structure.
Definition: PartitionedDataSet.h:169
vtkm::cont::PartitionedDataSet::GetPartitionsField
vtkm::cont::Field & GetPartitionsField(const std::string &name)
Definition: PartitionedDataSet.h:197
vtkm::cont::PartitionedDataSet::begin
const_iterator begin() const noexcept
Definition: PartitionedDataSet.h:239
vtkm::cont::PartitionedDataSet::HasField
bool HasField(const std::string &name, vtkm::cont::Field::Association assoc=vtkm::cont::Field::Association::Any) const
Query whether the partitioned data set has the named field.
Definition: PartitionedDataSet.h:204
vtkm::cont::PartitionedDataSet::Partitions
std::vector< vtkm::cont::DataSet > Partitions
Definition: PartitionedDataSet.h:249
vtkm::cont::PartitionedDataSet::AddPartitionsField
void AddPartitionsField(const std::string &fieldName, const T *field, const vtkm::Id &n)
Definition: PartitionedDataSet.h:145
StaticAssert.h
vtkm::cont::Field::Association::Partitions
@ Partitions
A field that applies to partitions.
vtkm::cont::PartitionedDataSet::end
iterator end() noexcept
Definition: PartitionedDataSet.h:237
vtkm::cont::PartitionedDataSet::iterator
typename StorageVec::iterator iterator
Definition: PartitionedDataSet.h:31
vtkm::cont::PartitionedDataSet::value_type
typename StorageVec::value_type value_type
Definition: PartitionedDataSet.h:33
vtkm::cont::PartitionedDataSet::end
const_iterator end() const noexcept
Definition: PartitionedDataSet.h:241
vtkm::cont::PartitionedDataSet::const_reference
typename StorageVec::const_reference const_reference
Definition: PartitionedDataSet.h:35
vtkm::cont::PartitionedDataSet::GetPartitionsField
const vtkm::cont::Field & GetPartitionsField(const std::string &name) const
Get a field associated with the partitions.
Definition: PartitionedDataSet.h:185
vtkm::cont::PartitionedDataSet::const_iterator
typename StorageVec::const_iterator const_iterator
Definition: PartitionedDataSet.h:32
DataSet.h
vtkm::cont::PartitionedDataSet::StorageVec
std::vector< vtkm::cont::DataSet > StorageVec
Definition: PartitionedDataSet.h:28
vtkm::cont::PartitionedDataSet::GetField
const vtkm::cont::Field & GetField(vtkm::Id index) const
Definition: PartitionedDataSet.h:152
vtkm::cont::PartitionedDataSet
Comprises a set of vtkm::cont::DataSet objects.
Definition: PartitionedDataSet.h:26
vtkm::cont::PartitionedDataSet::reference
typename StorageVec::reference reference
Definition: PartitionedDataSet.h:34
vtkm::cont::PartitionedDataSet::AddGlobalField
void AddGlobalField(const std::string &fieldName, const T *field, const vtkm::Id &n)
Definition: PartitionedDataSet.h:123