Viskores  1.0
Field.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_Field_h
19 #define viskores_cont_Field_h
20 
22 
23 #include <viskores/Range.h>
24 #include <viskores/Types.h>
25 
29 
30 namespace viskores
31 {
32 namespace cont
33 {
34 
35 
39 class VISKORES_CONT_EXPORT Field
40 {
41 public:
46  enum struct Association
47  {
48  // Documentation is below (for better layout in generated documents).
49  Any,
50  WholeDataSet,
51  Points,
52  Cells,
53  Partitions,
54  Global,
55  };
56 
62 
68 
77 
85 
93 
99 
101  Field() = default;
102 
105  Field(std::string name, Association association, const viskores::cont::UnknownArrayHandle& data);
106 
108  template <typename T, typename Storage>
109  VISKORES_CONT Field(std::string name,
110  Association association,
112  : Field(name, association, viskores::cont::UnknownArrayHandle{ data })
113  {
114  }
115 
116  Field(const viskores::cont::Field& src);
117  Field(viskores::cont::Field&& src) noexcept;
118 
119  VISKORES_CONT virtual ~Field();
120 
121  VISKORES_CONT Field& operator=(const viskores::cont::Field& src);
122  VISKORES_CONT Field& operator=(viskores::cont::Field&& src) noexcept;
123 
125  VISKORES_CONT bool IsCellField() const { return this->FieldAssociation == Association::Cells; }
127  VISKORES_CONT bool IsPointField() const { return this->FieldAssociation == Association::Points; }
130  {
131  return this->FieldAssociation == Association::WholeDataSet;
132  }
135  {
136  return this->FieldAssociation == Association::Partitions;
137  }
141  VISKORES_CONT bool IsGlobalField() const { return this->FieldAssociation == Association::Global; }
142 
145  VISKORES_CONT bool IsSupportedType() const;
146 
148  VISKORES_CONT viskores::Id GetNumberOfValues() const { return this->Data.GetNumberOfValues(); }
149 
151  VISKORES_CONT const std::string& GetName() const { return this->Name; }
153  VISKORES_CONT Association GetAssociation() const { return this->FieldAssociation; }
155  const viskores::cont::UnknownArrayHandle& GetData() const;
158 
168 
174  VISKORES_CONT void GetRange(viskores::Range* range) const;
175 
190  VISKORES_CONT viskores::cont::UnknownArrayHandle GetDataAsDefaultFloat() const;
191 
207  VISKORES_CONT viskores::cont::UnknownArrayHandle GetDataWithExpectedTypes() const;
208 
224  VISKORES_CONT void ConvertToExpected();
225 
226  VISKORES_CONT void SetData(const viskores::cont::UnknownArrayHandle& newdata);
227 
228  template <typename T, typename StorageTag>
230  {
231  this->SetData(viskores::cont::UnknownArrayHandle(newdata));
232  }
233 
236  virtual void PrintSummary(std::ostream& out, bool full = false) const;
237 
241  {
242  this->Data.ReleaseResourcesExecution();
243  this->Range.ReleaseResourcesExecution();
244  }
245 
246 private:
247  std::string Name;
248 
249  Association FieldAssociation = Association::Any;
252  mutable bool ModifiedFlag = true;
253 };
254 
255 template <typename Functor, typename... Args>
256 void CastAndCall(const viskores::cont::Field& field, Functor&& f, Args&&... args)
257 {
259  field.GetData(), std::forward<Functor>(f), std::forward<Args>(args)...);
260 }
261 
262 
264 template <typename T>
267  Field::Association association,
268  const T* data,
269  viskores::Id size,
270  viskores::CopyFlag copy)
271 {
272  return viskores::cont::Field(
273  name, association, viskores::cont::make_ArrayHandle(data, size, copy));
274 }
275 
276 template <typename T>
278  Field::Association association,
279  const std::vector<T>& data,
280  viskores::CopyFlag copy)
281 {
282  return viskores::cont::Field(name, association, viskores::cont::make_ArrayHandle(data, copy));
283 }
284 
285 template <typename T>
287  Field::Association association,
288  std::vector<T>&& data)
289 {
290  return viskores::cont::Field(
291  name, association, viskores::cont::make_ArrayHandleMove(std::move(data)));
292 }
293 
294 template <typename T>
296  Field::Association association,
297  std::vector<T>&& data,
299 {
300  return make_FieldMove(name, association, std::move(data));
301 }
302 
303 template <typename T>
305  Field::Association association,
306  std::initializer_list<T>&& data)
307 {
308  return make_FieldMove(name, association, viskores::cont::make_ArrayHandle(std::move(data)));
309 }
310 
312 
314 template <typename T, typename S>
317 {
319 }
320 
322 inline viskores::cont::Field make_FieldPoint(std::string name,
324 {
326 }
327 
329 template <typename T, typename S>
332 {
334 }
335 
336 
338 inline viskores::cont::Field make_FieldCell(std::string name,
340 {
342 }
343 
344 } // namespace cont
345 } // namespace viskores
346 
347 
348 namespace viskores
349 {
350 namespace cont
351 {
352 namespace internal
353 {
354 template <>
355 struct DynamicTransformTraits<viskores::cont::Field>
356 {
357  using DynamicTag = viskores::cont::internal::DynamicTransformTagCastAndCall;
358 };
359 } // namespace internal
360 } // namespace cont
361 } // namespace viskores
362 
363 //=============================================================================
364 // Specializations of serialization related classes
366 
367 namespace mangled_diy_namespace
368 {
369 
370 template <>
371 struct VISKORES_CONT_EXPORT Serialization<viskores::cont::Field>
372 {
373  static VISKORES_CONT void save(BinaryBuffer& bb, const viskores::cont::Field& field);
374  static VISKORES_CONT void load(BinaryBuffer& bb, viskores::cont::Field& field);
375 };
376 
377 } // diy
379 
380 #endif //viskores_cont_Field_h
viskores::exec::arg::load
T load(const U &u, viskores::Id v)
Definition: FetchTagArrayDirectIn.h:44
viskores::cont::Field::GetAssociation
Association GetAssociation() const
Return the association of the field.
Definition: Field.h:153
ArrayHandle.h
viskores::cont::make_FieldMove
viskores::cont::Field make_FieldMove(std::string name, Field::Association association, std::vector< T > &&data)
Definition: Field.h:286
viskores::cont::Field::Data
viskores::cont::UnknownArrayHandle Data
Definition: Field.h:250
viskores::cont::Field::IsPartitionsField
bool IsPartitionsField() const
Return true if this field is associated with partitions in a partitioned data set.
Definition: Field.h:134
viskores::cont::Field::IsGlobalField
bool IsGlobalField() const
Return true if this field is global.
Definition: Field.h:141
viskores::cont::make_FieldCell
viskores::cont::Field make_FieldCell(std::string name, const viskores::cont::ArrayHandle< T, S > &data)
Convenience function to build cell fields from viskores::cont::ArrayHandle.
Definition: Field.h:330
Types.h
viskores::cont::Field::Association
Association
Identifies what elements of a data set a field is associated with.
Definition: Field.h:46
viskores::cont::CastAndCall
void CastAndCall(const DynamicObject &dynamicObject, Functor &&f, Args &&... args)
A Generic interface to CastAndCall.
Definition: CastAndCall.h:55
viskores::cont::Field::Field
Field(std::string name, Association association, const viskores::cont::ArrayHandle< T, Storage > &data)
Create a field with the given name, association, and data.
Definition: Field.h:109
viskoresNotUsed
#define viskoresNotUsed(parameter_name)
Simple macro to identify a parameter as unused.
Definition: ExportMacros.h:136
viskores::cont::Field::GetData
const viskores::cont::UnknownArrayHandle & GetData() const
Get the array of the data for the field.
viskores::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:313
viskores::cont::make_ArrayHandleMove
viskores::cont::ArrayHandleBasic< T > make_ArrayHandleMove(T *&array, viskores::Id numberOfValues, viskores::cont::internal::BufferInfo::Deleter deleter=internal::SimpleArrayDeleter< T >, viskores::cont::internal::BufferInfo::Reallocater reallocater=internal::SimpleArrayReallocater< T >)
A convenience function to move a user-allocated array into an ArrayHandle.
Definition: ArrayHandleBasic.h:310
viskores::cont::Field::Association::Cells
@ Cells
A field that applies to cells.
mangled_diy_namespace
Definition: Particle.h:373
viskores::cont::Field::IsPointField
bool IsPointField() const
Return true if this field is associated with points.
Definition: Field.h:127
viskores::cont::make_FieldPoint
viskores::cont::Field make_FieldPoint(std::string name, const viskores::cont::ArrayHandle< T, S > &data)
Convenience function to build point fields from viskores::cont::ArrayHandle.
Definition: Field.h:315
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
UnknownArrayHandle.h
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::cont::Field::SetData
void SetData(const viskores::cont::ArrayHandle< T, StorageTag > &newdata)
Definition: Field.h:229
CastAndCall.h
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::cont::Field::ReleaseResourcesExecution
virtual void ReleaseResourcesExecution()
Remove the data from the device memory (but preserve the data on the host).
Definition: Field.h:240
viskores::cont::Field::Range
viskores::cont::ArrayHandle< viskores::Range > Range
Definition: Field.h:251
Range.h
viskores::cont::Field::GetName
const std::string & GetName() const
Return the name of the field.
Definition: Field.h:151
viskores::Range
Represent a continuous scalar range of values.
Definition: Range.h:39
viskores::cont::Field::GetNumberOfValues
viskores::Id GetNumberOfValues() const
Return the number of values in the field array.
Definition: Field.h:148
viskores::cont::Field::Name
std::string Name
name of field
Definition: Field.h:247
viskores::cont::UnknownArrayHandle
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:451
viskores::CopyFlag
CopyFlag
Identifier used to specify whether a function should deep copy data.
Definition: Flags.h:25
viskores::cont::Field::IsCellField
bool IsCellField() const
Return true if this field is associated with cells.
Definition: Field.h:125
viskores::cont::Field::Association::Points
@ Points
A field that applies to points.
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
viskores::cont::make_ArrayHandle
viskores::cont::ArrayHandleBasic< T > make_ArrayHandle(const T *array, viskores::Id numberOfValues, viskores::CopyFlag copy)
A convenience function for creating an ArrayHandle from a standard C array.
Definition: ArrayHandleBasic.h:285
viskores::cont::Field::IsWholeDataSetField
bool IsWholeDataSetField() const
Return true if this field is associated with the whole data set.
Definition: Field.h:129
viskores_cont_export.h