VTK-m  2.2
Field.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_Field_h
11 #define vtk_m_cont_Field_h
12 
14 
15 #include <vtkm/Range.h>
16 #include <vtkm/Types.h>
17 
18 #include <vtkm/cont/ArrayHandle.h>
19 #include <vtkm/cont/CastAndCall.h>
21 
22 namespace vtkm
23 {
24 namespace cont
25 {
26 
27 
32 {
33 public:
38  enum struct Association
39  {
40  // Documentation is below (for better layout in generated documents).
41  Any,
42  WholeDataSet,
43  Points,
44  Cells,
45  Partitions,
46  Global,
47  };
48 
54 
60 
69 
77 
85 
91 
92  VTKM_CONT
93  Field() = default;
94 
96  VTKM_CONT
97  Field(std::string name, Association association, const vtkm::cont::UnknownArrayHandle& data);
98 
100  template <typename T, typename Storage>
101  VTKM_CONT Field(std::string name,
102  Association association,
104  : Field(name, association, vtkm::cont::UnknownArrayHandle{ data })
105  {
106  }
107 
108  Field(const vtkm::cont::Field& src);
109  Field(vtkm::cont::Field&& src) noexcept;
110 
111  VTKM_CONT virtual ~Field();
112 
113  VTKM_CONT Field& operator=(const vtkm::cont::Field& src);
114  VTKM_CONT Field& operator=(vtkm::cont::Field&& src) noexcept;
115 
117  VTKM_CONT bool IsCellField() const { return this->FieldAssociation == Association::Cells; }
119  VTKM_CONT bool IsPointField() const { return this->FieldAssociation == Association::Points; }
122  {
123  return this->FieldAssociation == Association::WholeDataSet;
124  }
127  {
128  return this->FieldAssociation == Association::Partitions;
129  }
133  VTKM_CONT bool IsGlobalField() const { return this->FieldAssociation == Association::Global; }
134 
137  VTKM_CONT bool IsSupportedType() const;
138 
140  VTKM_CONT vtkm::Id GetNumberOfValues() const { return this->Data.GetNumberOfValues(); }
141 
143  VTKM_CONT const std::string& GetName() const { return this->Name; }
145  VTKM_CONT Association GetAssociation() const { return this->FieldAssociation; }
147  const vtkm::cont::UnknownArrayHandle& GetData() const;
150 
159  VTKM_CONT const vtkm::cont::ArrayHandle<vtkm::Range>& GetRange() const;
160 
166  VTKM_CONT void GetRange(vtkm::Range* range) const;
167 
182  VTKM_CONT vtkm::cont::UnknownArrayHandle GetDataAsDefaultFloat() const;
183 
199  VTKM_CONT vtkm::cont::UnknownArrayHandle GetDataWithExpectedTypes() const;
200 
216  VTKM_CONT void ConvertToExpected();
217 
218  VTKM_CONT void SetData(const vtkm::cont::UnknownArrayHandle& newdata);
219 
220  template <typename T, typename StorageTag>
222  {
223  this->SetData(vtkm::cont::UnknownArrayHandle(newdata));
224  }
225 
227  VTKM_CONT
228  virtual void PrintSummary(std::ostream& out, bool full = false) const;
229 
231  VTKM_CONT
233  {
234  this->Data.ReleaseResourcesExecution();
235  this->Range.ReleaseResourcesExecution();
236  }
237 
238 private:
239  std::string Name;
240 
241  Association FieldAssociation = Association::Any;
244  mutable bool ModifiedFlag = true;
245 };
246 
247 template <typename Functor, typename... Args>
248 void CastAndCall(const vtkm::cont::Field& field, Functor&& f, Args&&... args)
249 {
250  vtkm::cont::CastAndCall(field.GetData(), std::forward<Functor>(f), std::forward<Args>(args)...);
251 }
252 
253 
255 template <typename T>
257 vtkm::cont::Field make_Field(std::string name,
258  Field::Association association,
259  const T* data,
260  vtkm::Id size,
261  vtkm::CopyFlag copy)
262 {
263  return vtkm::cont::Field(name, association, vtkm::cont::make_ArrayHandle(data, size, copy));
264 }
265 
266 template <typename T>
267 vtkm::cont::Field make_Field(std::string name,
268  Field::Association association,
269  const std::vector<T>& data,
270  vtkm::CopyFlag copy)
271 {
272  return vtkm::cont::Field(name, association, vtkm::cont::make_ArrayHandle(data, copy));
273 }
274 
275 template <typename T>
277  Field::Association association,
278  std::vector<T>&& data)
279 {
280  return vtkm::cont::Field(name, association, vtkm::cont::make_ArrayHandleMove(std::move(data)));
281 }
282 
283 template <typename T>
284 vtkm::cont::Field make_Field(std::string name,
285  Field::Association association,
286  std::vector<T>&& data,
288 {
289  return make_FieldMove(name, association, std::move(data));
290 }
291 
292 template <typename T>
293 vtkm::cont::Field make_Field(std::string name,
294  Field::Association association,
295  std::initializer_list<T>&& data)
296 {
297  return make_FieldMove(name, association, vtkm::cont::make_ArrayHandle(std::move(data)));
298 }
299 
301 
303 template <typename T, typename S>
305 {
307 }
308 
310 inline vtkm::cont::Field make_FieldPoint(std::string name,
311  const vtkm::cont::UnknownArrayHandle& data)
312 {
314 }
315 
317 template <typename T, typename S>
319 {
321 }
322 
323 
325 inline vtkm::cont::Field make_FieldCell(std::string name,
326  const vtkm::cont::UnknownArrayHandle& data)
327 {
329 }
330 
331 } // namespace cont
332 } // namespace vtkm
333 
334 
335 namespace vtkm
336 {
337 namespace cont
338 {
339 namespace internal
340 {
341 template <>
342 struct DynamicTransformTraits<vtkm::cont::Field>
343 {
344  using DynamicTag = vtkm::cont::internal::DynamicTransformTagCastAndCall;
345 };
346 } // namespace internal
347 } // namespace cont
348 } // namespace vtkm
349 
350 //=============================================================================
351 // Specializations of serialization related classes
353 
354 namespace mangled_diy_namespace
355 {
356 
357 template <>
358 struct VTKM_CONT_EXPORT Serialization<vtkm::cont::Field>
359 {
360  static VTKM_CONT void save(BinaryBuffer& bb, const vtkm::cont::Field& field);
361  static VTKM_CONT void load(BinaryBuffer& bb, vtkm::cont::Field& field);
362 };
363 
364 } // diy
366 
367 #endif //vtk_m_cont_Field_h
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:300
ArrayHandle.h
vtkm::exec::arg::load
T load(const U &u, vtkm::Id v)
Definition: FetchTagArrayDirectIn.h:36
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::cont::Field::IsCellField
bool IsCellField() const
Return true if this field is associated with cells.
Definition: Field.h:117
Types.h
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::Field::Range
vtkm::cont::ArrayHandle< vtkm::Range > Range
Definition: Field.h:243
vtkm::cont::make_ArrayHandleMove
vtkm::cont::ArrayHandleBasic< T > make_ArrayHandleMove(T *&array, vtkm::Id numberOfValues, vtkm::cont::internal::BufferInfo::Deleter deleter=internal::SimpleArrayDeleter< T >, vtkm::cont::internal::BufferInfo::Reallocater reallocater=internal::SimpleArrayReallocater< T >)
A convenience function to move a user-allocated array into an ArrayHandle.
Definition: ArrayHandleBasic.h:294
vtkm::cont::Field::Name
std::string Name
name of field
Definition: Field.h:239
vtkm::cont::CastAndCall
void CastAndCall(const DynamicObject &dynamicObject, Functor &&f, Args &&... args)
A Generic interface to CastAndCall.
Definition: CastAndCall.h:47
vtkm::cont::Field::IsPartitionsField
bool IsPartitionsField() const
Return true if this field is associated with partitions in a partitioned data set.
Definition: Field.h:126
mangled_diy_namespace
Definition: Particle.h:351
vtkm::cont::Field::GetData
const vtkm::cont::UnknownArrayHandle & GetData() const
Get the array of the data for the field.
vtkm::cont::Field::Field
Field(std::string name, Association association, const vtkm::cont::ArrayHandle< T, Storage > &data)
Create a field with the given name, association, and data.
Definition: Field.h:101
vtkm::cont::Field::Data
vtkm::cont::UnknownArrayHandle Data
Definition: Field.h:242
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: Field.h:318
UnknownArrayHandle.h
CastAndCall.h
vtkm::cont::Field::ReleaseResourcesExecution
virtual void ReleaseResourcesExecution()
Remove the data from the device memory (but preserve the data on the host).
Definition: Field.h:232
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
Range.h
vtkm_cont_export.h
vtkm::cont::Field::Association::Points
@ Points
A field that applies to points.
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::cont::Field::IsGlobalField
bool IsGlobalField() const
Return true if this field is global.
Definition: Field.h:133
vtkmNotUsed
#define vtkmNotUsed(parameter_name)
Simple macro to identify a parameter as unused.
Definition: ExportMacros.h:128
vtkm::cont::Field::GetName
const std::string & GetName() const
Return the name of the field.
Definition: Field.h:143
vtkm::cont::Field::IsWholeDataSetField
bool IsWholeDataSetField() const
Return true if this field is associated with the whole data set.
Definition: Field.h:121
vtkm::cont::Field::IsPointField
bool IsPointField() const
Return true if this field is associated with points.
Definition: Field.h:119
vtkm::cont::Field::SetData
void SetData(const vtkm::cont::ArrayHandle< T, StorageTag > &newdata)
Definition: Field.h:221
vtkm::cont::Field::Association::Cells
@ Cells
A field that applies to cells.
vtkm::CopyFlag
CopyFlag
Identifier used to specify whether a function should deep copy data.
Definition: Flags.h:17
vtkm::cont::make_ArrayHandle
vtkm::cont::ArrayHandleBasic< T > make_ArrayHandle(const T *array, vtkm::Id numberOfValues, vtkm::CopyFlag copy)
A convenience function for creating an ArrayHandle from a standard C array.
Definition: ArrayHandleBasic.h:270
vtkm::cont::make_FieldMove
vtkm::cont::Field make_FieldMove(std::string name, Field::Association association, std::vector< T > &&data)
Definition: Field.h:276
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: Field.h:304
vtkm::cont::Field::GetAssociation
Association GetAssociation() const
Return the association of the field.
Definition: Field.h:145
vtkm::cont::Field::GetNumberOfValues
vtkm::Id GetNumberOfValues() const
Return the number of values in the field array.
Definition: Field.h:140
vtkm::Range
Represent a continuous scalar range of values.
Definition: Range.h:31