VTK-m  2.0
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 
25 class VTKM_CONT_EXPORT PartitionedDataSet
26 {
27  using StorageVec = std::vector<vtkm::cont::DataSet>;
28 
29 public:
30  using iterator = typename StorageVec::iterator;
31  using const_iterator = typename StorageVec::const_iterator;
32  using value_type = typename StorageVec::value_type;
33  using reference = typename StorageVec::reference;
34  using const_reference = typename StorageVec::const_reference;
35 
37  VTKM_CONT
39 
41  VTKM_CONT
42  explicit PartitionedDataSet(const std::vector<vtkm::cont::DataSet>& partitions);
44  VTKM_CONT
45  explicit PartitionedDataSet(vtkm::Id size);
46 
47  VTKM_CONT
48  PartitionedDataSet() = default;
49 
51  VTKM_CONT
52  vtkm::cont::Field GetFieldFromPartition(const std::string& field_name, int partition_index) const;
53 
55  VTKM_CONT
56  vtkm::Id GetNumberOfPartitions() const;
57 
60  VTKM_CONT
61  vtkm::Id GetGlobalNumberOfPartitions() const;
62 
64  VTKM_CONT
65  const vtkm::cont::DataSet& GetPartition(vtkm::Id partId) const;
66 
68  VTKM_CONT
69  const std::vector<vtkm::cont::DataSet>& GetPartitions() const;
70 
72  VTKM_CONT
73  void AppendPartition(const vtkm::cont::DataSet& ds);
74 
76  VTKM_CONT
77  void InsertPartition(vtkm::Id index, const vtkm::cont::DataSet& ds);
78 
81  VTKM_CONT
82  void ReplacePartition(vtkm::Id index, const vtkm::cont::DataSet& ds);
83 
85  VTKM_CONT
86  void AppendPartitions(const std::vector<vtkm::cont::DataSet>& partitions);
87 
90  VTKM_CONT
91  vtkm::IdComponent GetNumberOfFields() const { return this->Fields.GetNumberOfFields(); }
92 
93  //Fields on partitions.
94  VTKM_CONT void AddField(const Field& field) { this->Fields.AddField(field); }
95 
96  template <typename T, typename Storage>
97  VTKM_CONT void AddGlobalField(const std::string& fieldName,
99  {
100  this->AddField(vtkm::cont::Field(fieldName, vtkm::cont::Field::Association::Global, field));
101  }
102 
103  template <typename T>
104  VTKM_CONT void AddGlobalField(const std::string& fieldName, const std::vector<T>& field)
105  {
106  this->AddField(
108  }
109 
110  template <typename T>
111  VTKM_CONT void AddGlobalField(const std::string& fieldName, const T* field, const vtkm::Id& n)
112  {
113  this->AddField(
115  }
116 
117  template <typename T, typename Storage>
118  VTKM_CONT void AddPartitionsField(const std::string& fieldName,
120  {
121  this->AddField(vtkm::cont::Field(fieldName, vtkm::cont::Field::Association::Partitions, field));
122  }
123 
124  template <typename T>
125  VTKM_CONT void AddPartitionsField(const std::string& fieldName, const std::vector<T>& field)
126  {
127  this->AddField(
129  }
130 
131  template <typename T>
132  VTKM_CONT void AddPartitionsField(const std::string& fieldName, const T* field, const vtkm::Id& n)
133  {
134  this->AddField(make_Field(
136  }
137 
138  VTKM_CONT
139  const vtkm::cont::Field& GetField(vtkm::Id index) const { return this->Fields.GetField(index); }
140 
141  VTKM_CONT
142  vtkm::cont::Field& GetField(vtkm::Id index) { return this->Fields.GetField(index); }
143 
144  VTKM_CONT
146  const std::string& name,
148  {
149  return this->Fields.GetField(name, assoc);
150  }
151 
152  VTKM_CONT
154  const std::string& name,
156  {
157  return this->Fields.GetField(name, assoc);
158  }
159 
160  VTKM_CONT
161  const vtkm::cont::Field& GetGlobalField(const std::string& name) const
162  {
163  return this->GetField(name, vtkm::cont::Field::Association::Global);
164  }
165 
166  VTKM_CONT
167  const vtkm::cont::Field& GetPartitionsField(const std::string& name) const
168  {
169  return this->GetField(name, vtkm::cont::Field::Association::Partitions);
170  }
171 
172  VTKM_CONT
173  vtkm::cont::Field& GetGlobalField(const std::string& name)
174  {
175  return this->GetField(name, vtkm::cont::Field::Association::Global);
176  }
177 
178  VTKM_CONT
179  vtkm::cont::Field& GetPartitionsField(const std::string& name)
180  {
181  return this->GetField(name, vtkm::cont::Field::Association::Partitions);
182  }
183 
184  VTKM_CONT
185  bool HasField(const std::string& name,
187  {
188  return this->Fields.HasField(name, assoc);
189  }
190 
191  VTKM_CONT
192  bool HasGlobalField(const std::string& name) const
193  {
194  return (this->Fields.GetFieldIndex(name, vtkm::cont::Field::Association::Global) != -1);
195  }
196 
197  VTKM_CONT
198  bool HasPartitionsField(const std::string& name) const
199  {
200  return (this->Fields.GetFieldIndex(name, vtkm::cont::Field::Association::Partitions) != -1);
201  }
203 
205  VTKM_CONT
206  void CopyPartitions(const vtkm::cont::PartitionedDataSet& source);
207 
208  VTKM_CONT
209  void PrintSummary(std::ostream& stream) const;
210 
213  VTKM_CONT
214  iterator begin() noexcept { return this->Partitions.begin(); }
215  VTKM_CONT
216  iterator end() noexcept { return this->Partitions.end(); }
217  VTKM_CONT
218  const_iterator begin() const noexcept { return this->Partitions.begin(); }
219  VTKM_CONT
220  const_iterator end() const noexcept { return this->Partitions.end(); }
221  VTKM_CONT
222  const_iterator cbegin() const noexcept { return this->Partitions.cbegin(); }
223  VTKM_CONT
224  const_iterator cend() const noexcept { return this->Partitions.cend(); }
226 
227 private:
228  std::vector<vtkm::cont::DataSet> Partitions;
229 
230  vtkm::cont::internal::FieldCollection Fields{ vtkm::cont::Field::Association::Partitions,
232 };
233 }
234 } // namespace vtkm::cont
235 
236 #endif
vtkm::cont::PartitionedDataSet::AddPartitionsField
VTKM_CONT void AddPartitionsField(const std::string &fieldName, const std::vector< T > &field)
Definition: PartitionedDataSet.h:125
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:283
ArrayHandle.h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::cont::PartitionedDataSet::GetPartitionsField
const VTKM_CONT vtkm::cont::Field & GetPartitionsField(const std::string &name) const
Definition: PartitionedDataSet.h:167
FieldCollection.h
vtkm::cont::PartitionedDataSet::GetField
const VTKM_CONT vtkm::cont::Field & GetField(vtkm::Id index) const
Definition: PartitionedDataSet.h:139
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::cont::Field::Association::Global
@ Global
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::PartitionedDataSet::HasGlobalField
VTKM_CONT bool HasGlobalField(const std::string &name) const
Definition: PartitionedDataSet.h:192
vtkm::cont::DataSet
Definition: DataSet.h:34
vtkm::cont::PartitionedDataSet::GetField
VTKM_CONT vtkm::cont::Field & GetField(const std::string &name, vtkm::cont::Field::Association assoc=vtkm::cont::Field::Association::Any)
Definition: PartitionedDataSet.h:153
vtkm::cont::PartitionedDataSet::end
VTKM_CONT iterator end() noexcept
Definition: PartitionedDataSet.h:216
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::cont::PartitionedDataSet::AddGlobalField
VTKM_CONT void AddGlobalField(const std::string &fieldName, const T *field, const vtkm::Id &n)
Definition: PartitionedDataSet.h:111
vtkm::cont::PartitionedDataSet::cbegin
VTKM_CONT const_iterator cbegin() const noexcept
Definition: PartitionedDataSet.h:222
vtkm::cont::PartitionedDataSet::GetField
VTKM_CONT vtkm::cont::Field & GetField(vtkm::Id index)
Definition: PartitionedDataSet.h:142
vtkm::cont::PartitionedDataSet::begin
VTKM_CONT iterator begin() noexcept
Definition: PartitionedDataSet.h:214
vtkm::cont::PartitionedDataSet::end
VTKM_CONT const_iterator end() const noexcept
Definition: PartitionedDataSet.h:220
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::PartitionedDataSet::GetField
const VTKM_CONT vtkm::cont::Field & GetField(const std::string &name, vtkm::cont::Field::Association assoc=vtkm::cont::Field::Association::Any) const
Definition: PartitionedDataSet.h:145
vtkm::cont::PartitionedDataSet::AddPartitionsField
VTKM_CONT void AddPartitionsField(const std::string &fieldName, const T *field, const vtkm::Id &n)
Definition: PartitionedDataSet.h:132
vtkm::cont::PartitionedDataSet::GetPartitionsField
VTKM_CONT vtkm::cont::Field & GetPartitionsField(const std::string &name)
Definition: PartitionedDataSet.h:179
vtkm::cont::Field::Association::Any
@ Any
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::PartitionedDataSet::HasPartitionsField
VTKM_CONT bool HasPartitionsField(const std::string &name) const
Definition: PartitionedDataSet.h:198
vtkm::cont::PartitionedDataSet::AddField
VTKM_CONT void AddField(const Field &field)
Definition: PartitionedDataSet.h:94
vtkm::cont::PartitionedDataSet::AddPartitionsField
VTKM_CONT void AddPartitionsField(const std::string &fieldName, const vtkm::cont::ArrayHandle< T, Storage > &field)
Definition: PartitionedDataSet.h:118
vtkm::CopyFlag::On
@ On
vtkm::cont::PartitionedDataSet::HasField
VTKM_CONT bool HasField(const std::string &name, vtkm::cont::Field::Association assoc=vtkm::cont::Field::Association::Any) const
Definition: PartitionedDataSet.h:185
vtkm::cont::PartitionedDataSet::AddGlobalField
VTKM_CONT void AddGlobalField(const std::string &fieldName, const vtkm::cont::ArrayHandle< T, Storage > &field)
Definition: PartitionedDataSet.h:97
vtkm::cont::PartitionedDataSet::Partitions
std::vector< vtkm::cont::DataSet > Partitions
Definition: PartitionedDataSet.h:228
StaticAssert.h
Field.h
vtkm::cont::Field::Association::Partitions
@ Partitions
vtkm::cont::PartitionedDataSet::begin
VTKM_CONT const_iterator begin() const noexcept
Definition: PartitionedDataSet.h:218
vtkm::cont::PartitionedDataSet::GetGlobalField
const VTKM_CONT vtkm::cont::Field & GetGlobalField(const std::string &name) const
Definition: PartitionedDataSet.h:161
vtkm::cont::PartitionedDataSet::iterator
typename StorageVec::iterator iterator
Definition: PartitionedDataSet.h:30
vtkm::cont::PartitionedDataSet::cend
VTKM_CONT const_iterator cend() const noexcept
Definition: PartitionedDataSet.h:224
vtkm::cont::PartitionedDataSet::value_type
typename StorageVec::value_type value_type
Definition: PartitionedDataSet.h:32
vtkm::cont::PartitionedDataSet::const_reference
typename StorageVec::const_reference const_reference
Definition: PartitionedDataSet.h:34
vtkm::cont::PartitionedDataSet::AddGlobalField
VTKM_CONT void AddGlobalField(const std::string &fieldName, const std::vector< T > &field)
Definition: PartitionedDataSet.h:104
vtkm::cont::PartitionedDataSet::GetGlobalField
VTKM_CONT vtkm::cont::Field & GetGlobalField(const std::string &name)
Definition: PartitionedDataSet.h:173
vtkm::cont::PartitionedDataSet::GetNumberOfFields
VTKM_CONT vtkm::IdComponent GetNumberOfFields() const
Definition: PartitionedDataSet.h:91
vtkm::cont::PartitionedDataSet::const_iterator
typename StorageVec::const_iterator const_iterator
Definition: PartitionedDataSet.h:31
DataSet.h
vtkm::cont::PartitionedDataSet::StorageVec
std::vector< vtkm::cont::DataSet > StorageVec
Definition: PartitionedDataSet.h:27
vtkm::cont::PartitionedDataSet
Definition: PartitionedDataSet.h:25
vtkm::cont::PartitionedDataSet::reference
typename StorageVec::reference reference
Definition: PartitionedDataSet.h:33