Viskores  1.0
PartitionedDataSet.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_PartitionedDataSet_h
19 #define viskores_cont_PartitionedDataSet_h
20 #include <limits>
21 #include <viskores/StaticAssert.h>
22 
24 #include <viskores/cont/DataSet.h>
25 #include <viskores/cont/Field.h>
27 
28 namespace viskores
29 {
30 namespace cont
31 {
32 
34 class VISKORES_CONT_EXPORT PartitionedDataSet
35 {
36  using StorageVec = std::vector<viskores::cont::DataSet>;
37 
38 public:
39  using iterator = typename StorageVec::iterator;
40  using const_iterator = typename StorageVec::const_iterator;
41  using value_type = typename StorageVec::value_type;
42  using reference = typename StorageVec::reference;
43  using const_reference = typename StorageVec::const_reference;
44 
48 
51  explicit PartitionedDataSet(const std::vector<viskores::cont::DataSet>& partitions);
54  explicit PartitionedDataSet(viskores::Id size);
55 
57  PartitionedDataSet() = default;
58 
61  viskores::cont::Field GetFieldFromPartition(const std::string& field_name,
62  int partition_index) const;
63 
66  viskores::Id GetNumberOfPartitions() const;
67 
71  viskores::Id GetGlobalNumberOfPartitions() const;
72 
75  const viskores::cont::DataSet& GetPartition(viskores::Id partId) const;
76 
78  VISKORES_CONT const std::vector<viskores::cont::DataSet>& GetPartitions() const;
79 
81  VISKORES_CONT void AppendPartition(const viskores::cont::DataSet& ds);
82 
86  VISKORES_CONT void InsertPartition(viskores::Id index, const viskores::cont::DataSet& ds);
87 
90  VISKORES_CONT void ReplacePartition(viskores::Id index, const viskores::cont::DataSet& ds);
91 
96  VISKORES_CONT void AppendPartitions(const std::vector<viskores::cont::DataSet>& partitions);
97 
100  {
101  return this->Fields.GetNumberOfFields();
102  }
103 
107  VISKORES_CONT void AddField(const Field& field) { this->Fields.AddField(field); }
108 
112  VISKORES_CONT void AddField(const std::string& name,
115  {
116  this->AddField({ name, association, data });
117  }
118 
120  template <typename T, typename Storage>
121  VISKORES_CONT void AddGlobalField(const std::string& fieldName,
123  {
124  this->AddField(fieldName, viskores::cont::Field::Association::Global, field);
125  }
126 
127  template <typename T>
128  VISKORES_CONT void AddGlobalField(const std::string& fieldName, const std::vector<T>& field)
129  {
130  this->AddField(make_Field(
132  }
133 
134  template <typename T>
135  VISKORES_CONT void AddGlobalField(const std::string& fieldName,
136  const T* field,
137  const viskores::Id& n)
138  {
139  this->AddField(make_Field(
141  }
142 
144  template <typename T, typename Storage>
145  VISKORES_CONT void AddPartitionsField(const std::string& fieldName,
147  {
148  this->AddField(fieldName, viskores::cont::Field::Association::Partitions, field);
149  }
150 
151  template <typename T>
152  VISKORES_CONT void AddPartitionsField(const std::string& fieldName, const std::vector<T>& field)
153  {
154  this->AddField(make_Field(
156  }
157 
158  template <typename T>
159  VISKORES_CONT void AddPartitionsField(const std::string& fieldName,
160  const T* field,
161  const viskores::Id& n)
162  {
163  this->AddField(make_Field(
165  }
166 
169  {
170  return this->Fields.GetField(index);
171  }
172 
174  viskores::cont::Field& GetField(viskores::Id index) { return this->Fields.GetField(index); }
175 
178  const std::string& name,
180  {
181  return this->Fields.GetField(name, assoc);
182  }
183 
189  const std::string& name,
191  {
192  return this->Fields.GetField(name, assoc);
193  }
194 
197  const viskores::cont::Field& GetGlobalField(const std::string& name) const
198  {
199  return this->GetField(name, viskores::cont::Field::Association::Global);
200  }
201 
204  const viskores::cont::Field& GetPartitionsField(const std::string& name) const
205  {
206  return this->GetField(name, viskores::cont::Field::Association::Partitions);
207  }
208 
210  viskores::cont::Field& GetGlobalField(const std::string& name)
211  {
212  return this->GetField(name, viskores::cont::Field::Association::Global);
213  }
214 
216  viskores::cont::Field& GetPartitionsField(const std::string& name)
217  {
218  return this->GetField(name, viskores::cont::Field::Association::Partitions);
219  }
220 
223  bool HasField(
224  const std::string& name,
226  {
227  return this->Fields.HasField(name, assoc);
228  }
229 
231  VISKORES_CONT bool HasGlobalField(const std::string& name) const
232  {
233  return (this->Fields.GetFieldIndex(name, viskores::cont::Field::Association::Global) != -1);
234  }
235 
237  VISKORES_CONT bool HasPartitionsField(const std::string& name) const
238  {
239  return (this->Fields.GetFieldIndex(name, viskores::cont::Field::Association::Partitions) != -1);
240  }
241 
244  void CopyPartitions(const viskores::cont::PartitionedDataSet& source);
245 
247  void PrintSummary(std::ostream& stream) const;
248 
255  iterator begin() noexcept { return this->Partitions.begin(); }
257  iterator end() noexcept { return this->Partitions.end(); }
259  const_iterator begin() const noexcept { return this->Partitions.begin(); }
261  const_iterator end() const noexcept { return this->Partitions.end(); }
263  const_iterator cbegin() const noexcept { return this->Partitions.cbegin(); }
265  const_iterator cend() const noexcept { return this->Partitions.cend(); }
267 
268 private:
269  std::vector<viskores::cont::DataSet> Partitions;
270 
271  viskores::cont::internal::FieldCollection Fields{ viskores::cont::Field::Association::Partitions,
273 };
274 }
275 } // namespace viskores::cont
276 
277 #endif
viskores::cont::PartitionedDataSet::cbegin
const_iterator cbegin() const noexcept
Definition: PartitionedDataSet.h:263
ArrayHandle.h
viskores::cont::PartitionedDataSet::AddPartitionsField
void AddPartitionsField(const std::string &fieldName, const T *field, const viskores::Id &n)
Definition: PartitionedDataSet.h:159
viskores::cont::DataSet
Contains and manages the geometric data structures that Viskores operates on.
Definition: DataSet.h:66
viskores::cont::PartitionedDataSet::end
const_iterator end() const noexcept
Definition: PartitionedDataSet.h:261
viskores::cont::PartitionedDataSet::end
iterator end() noexcept
Definition: PartitionedDataSet.h:257
viskores::cont::Field::Association
Association
Identifies what elements of a data set a field is associated with.
Definition: Field.h:46
FieldCollection.h
viskores::cont::PartitionedDataSet::AddGlobalField
void AddGlobalField(const std::string &fieldName, const viskores::cont::ArrayHandle< T, Storage > &field)
Add a field with a global association.
Definition: PartitionedDataSet.h:121
viskores::cont::Field::Association::Any
@ Any
Any field regardless of the association.
viskores::cont::PartitionedDataSet::GetField
const viskores::cont::Field & GetField(const std::string &name, viskores::cont::Field::Association assoc=viskores::cont::Field::Association::Any) const
Definition: PartitionedDataSet.h:177
viskores::cont::PartitionedDataSet::AddGlobalField
void AddGlobalField(const std::string &fieldName, const T *field, const viskores::Id &n)
Definition: PartitionedDataSet.h:135
viskores::cont::PartitionedDataSet::GetGlobalField
const viskores::cont::Field & GetGlobalField(const std::string &name) const
Get a global field.
Definition: PartitionedDataSet.h:197
viskores::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:313
viskores::cont::PartitionedDataSet::const_iterator
typename StorageVec::const_iterator const_iterator
Definition: PartitionedDataSet.h:40
viskores::cont::Field::Association::Global
@ Global
A field that applies to all partitions.
viskores::cont::PartitionedDataSet::Partitions
std::vector< viskores::cont::DataSet > Partitions
Definition: PartitionedDataSet.h:269
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
viskores::cont::PartitionedDataSet::HasGlobalField
bool HasGlobalField(const std::string &name) const
Query whether the partitioned data set has the named global field.
Definition: PartitionedDataSet.h:231
viskores::cont::PartitionedDataSet::GetField
const viskores::cont::Field & GetField(viskores::Id index) const
Definition: PartitionedDataSet.h:168
viskores::cont::PartitionedDataSet::GetPartitionsField
viskores::cont::Field & GetPartitionsField(const std::string &name)
Definition: PartitionedDataSet.h:216
viskores::cont::Field::Association::Partitions
@ Partitions
A field that applies to partitions.
viskores::cont::PartitionedDataSet::AddPartitionsField
void AddPartitionsField(const std::string &fieldName, const viskores::cont::ArrayHandle< T, Storage > &field)
Add a field where each entry is associated with a whole partition.
Definition: PartitionedDataSet.h:145
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::cont::PartitionedDataSet::GetField
viskores::cont::Field & GetField(viskores::Id index)
Definition: PartitionedDataSet.h:174
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::cont::make_Field
viskores::cont::Field make_Field(std::string name, Field::Association association, const T *data, viskores::Id size, viskores::CopyFlag copy)
Convenience functions to build fields from C style arrays and std::vector.
Definition: Field.h:266
viskores::CopyFlag::On
@ On
viskores::cont::PartitionedDataSet::begin
const_iterator begin() const noexcept
Definition: PartitionedDataSet.h:259
Field.h
viskores::cont::PartitionedDataSet
Comprises a set of viskores::cont::DataSet objects.
Definition: PartitionedDataSet.h:34
viskores::cont::PartitionedDataSet::GetField
viskores::cont::Field & GetField(const std::string &name, viskores::cont::Field::Association assoc=viskores::cont::Field::Association::Any)
Get a field associated with the partitioned data structure.
Definition: PartitionedDataSet.h:188
viskores::cont::PartitionedDataSet::AddField
void AddField(const std::string &name, viskores::cont::Field::Association association, const viskores::cont::UnknownArrayHandle &data)
Adds a field that is applied to the meta-partition structure.
Definition: PartitionedDataSet.h:112
viskores::cont::PartitionedDataSet::GetGlobalField
viskores::cont::Field & GetGlobalField(const std::string &name)
Definition: PartitionedDataSet.h:210
viskores::cont::PartitionedDataSet::begin
iterator begin() noexcept
Definition: PartitionedDataSet.h:255
viskores::cont::PartitionedDataSet::HasPartitionsField
bool HasPartitionsField(const std::string &name) const
Query whether the partitioned data set has the named partition field.
Definition: PartitionedDataSet.h:237
viskores::cont::PartitionedDataSet::GetNumberOfFields
viskores::IdComponent GetNumberOfFields() const
Methods to Add and Get fields on a PartitionedDataSet.
Definition: PartitionedDataSet.h:99
viskores::cont::PartitionedDataSet::AddPartitionsField
void AddPartitionsField(const std::string &fieldName, const std::vector< T > &field)
Definition: PartitionedDataSet.h:152
viskores::cont::PartitionedDataSet::StorageVec
std::vector< viskores::cont::DataSet > StorageVec
Definition: PartitionedDataSet.h:36
StaticAssert.h
viskores::cont::PartitionedDataSet::const_reference
typename StorageVec::const_reference const_reference
Definition: PartitionedDataSet.h:43
viskores::cont::PartitionedDataSet::cend
const_iterator cend() const noexcept
Definition: PartitionedDataSet.h:265
viskores::cont::PartitionedDataSet::AddField
void AddField(const Field &field)
Adds a field that is applied to the meta-partition structure.
Definition: PartitionedDataSet.h:107
viskores::cont::PartitionedDataSet::value_type
typename StorageVec::value_type value_type
Definition: PartitionedDataSet.h:41
viskores::cont::PartitionedDataSet::reference
typename StorageVec::reference reference
Definition: PartitionedDataSet.h:42
viskores::cont::UnknownArrayHandle
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:451
viskores::cont::PartitionedDataSet::HasField
bool HasField(const std::string &name, viskores::cont::Field::Association assoc=viskores::cont::Field::Association::Any) const
Query whether the partitioned data set has the named field.
Definition: PartitionedDataSet.h:223
viskores::cont::PartitionedDataSet::iterator
typename StorageVec::iterator iterator
Definition: PartitionedDataSet.h:39
viskores::cont::PartitionedDataSet::AddGlobalField
void AddGlobalField(const std::string &fieldName, const std::vector< T > &field)
Definition: PartitionedDataSet.h:128
viskores::cont::Field
A Field encapsulates an array on some piece of the mesh, such as the points, a cell set,...
Definition: Field.h:39
DataSet.h
viskores::cont::PartitionedDataSet::GetPartitionsField
const viskores::cont::Field & GetPartitionsField(const std::string &name) const
Get a field associated with the partitions.
Definition: PartitionedDataSet.h:204