//============================================================================ // Copyright (c) Kitware, Inc. // All rights reserved. // See LICENSE.txt for details. // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. // // Copyright 2014 Sandia Corporation. // Copyright 2014 UT-Battelle, LLC. // Copyright 2014 Los Alamos National Security. // // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, // the U.S. Government retains certain rights in this software. // // Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National // Laboratory (LANL), the U.S. Government retains certain rights in // this software. //============================================================================ #ifndef vtk_m_cont_Field_h #define vtk_m_cont_Field_h #include #include #include namespace vtkm { namespace cont { /// A \c Field encapsulates an array on some piece of the mesh, such as /// the points, a cell set, a node logical dimension, or the whole mesh. /// class Field { public: enum Association { ASSOC_WHOLE_MESH, ASSOC_POINTS, ASSOC_CELL_SET, ASSOC_LOGICAL_DIM }; /// constructors for points / whole mesh template VTKM_CONT_EXPORT Field(std::string n, int o, Association a, ArrayHandle &d) : name(n), order(o), association(a) { VTKM_ASSERT_CONT(association == ASSOC_WHOLE_MESH || association == ASSOC_POINTS); SetData(d); } template VTKM_CONT_EXPORT Field(std::string n, int o, Association a, const std::vector &d) : name(n), order(o), association(a) { VTKM_ASSERT_CONT(association == ASSOC_WHOLE_MESH || association == ASSOC_POINTS); CopyData(&d[0], d.size()); } template VTKM_CONT_EXPORT Field(std::string n, int o, Association a, const T *d, vtkm::Id nvals) : name(n), order(o), association(a) { VTKM_ASSERT_CONT(association == ASSOC_WHOLE_MESH || association == ASSOC_POINTS); CopyData(d, nvals); } VTKM_CONT_EXPORT Field(std::string n, int o, Association a) : name(n), order(o), association(a) { VTKM_ASSERT_CONT(association == ASSOC_WHOLE_MESH || association == ASSOC_POINTS); } /// constructors for cell set associations template VTKM_CONT_EXPORT Field(std::string n, int o, Association a, std::string csn, ArrayHandle &d) : name(n), order(o), association(a), assoc_cellset_name(csn) { VTKM_ASSERT_CONT(association == ASSOC_CELL_SET); SetData(d); } template VTKM_CONT_EXPORT Field(std::string n, int o, Association a, std::string csn, const std::vector &d) : name(n), order(o), association(a), assoc_cellset_name(csn) { VTKM_ASSERT_CONT(association == ASSOC_CELL_SET); CopyData(&d[0], d.size()); } template VTKM_CONT_EXPORT Field(std::string n, int o, Association a, std::string csn, const T *d, vtkm::Id nvals) : name(n), order(o), association(a), assoc_cellset_name(csn) { VTKM_ASSERT_CONT(association == ASSOC_CELL_SET); CopyData(d, nvals); } VTKM_CONT_EXPORT Field(std::string n, int o, Association a, std::string csn) : name(n), order(o), association(a), assoc_cellset_name(csn) { VTKM_ASSERT_CONT(association == ASSOC_CELL_SET); } /// constructors for logical dimension associations template VTKM_CONT_EXPORT Field(std::string n, int o, Association a, int l, ArrayHandle &d) : name(n), order(o), association(a), assoc_logical_dim(l) { VTKM_ASSERT_CONT(association == ASSOC_LOGICAL_DIM); SetData(d); } template VTKM_CONT_EXPORT Field(std::string n, int o, Association a, int l, const std::vector &d) : name(n), order(o), association(a), assoc_logical_dim(l) { VTKM_ASSERT_CONT(association == ASSOC_LOGICAL_DIM); CopyData(&d[0], d.size()); } template VTKM_CONT_EXPORT Field(std::string n, int o, Association a, int l, const T *d, vtkm::Id nvals) : name(n), order(o), association(a), assoc_logical_dim(l) { VTKM_ASSERT_CONT(association == ASSOC_LOGICAL_DIM); CopyData(d, nvals); } VTKM_CONT_EXPORT Field(std::string n, int o, Association a, int l) : name(n), order(o), association(a), assoc_logical_dim(l) { VTKM_ASSERT_CONT(association == ASSOC_LOGICAL_DIM); } VTKM_CONT_EXPORT const std::string &GetName() { return name; } VTKM_CONT_EXPORT Association GetAssociation() { return association; } VTKM_CONT_EXPORT int GetOrder() { return order; } VTKM_CONT_EXPORT std::string GetAssocCellSet() { return assoc_cellset_name; } VTKM_CONT_EXPORT int GetAssocLogicalDim() { return assoc_logical_dim; } VTKM_CONT_EXPORT vtkm::cont::DynamicArrayHandle &GetData() { return data; } template VTKM_CONT_EXPORT void SetData(vtkm::cont::ArrayHandle &newdata) { data = newdata; } template VTKM_CONT_EXPORT void CopyData(const T *ptr, vtkm::Id nvals) { //allocate main memory using an array handle vtkm::cont::ArrayHandle tmp; tmp.Allocate(nvals); //copy into the memory owned by the array handle std::copy(ptr, ptr + static_cast(nvals), vtkm::cont::ArrayPortalToIteratorBegin(tmp.GetPortalControl())); //assign to the dynamic array handle data = tmp; } VTKM_CONT_EXPORT virtual void PrintSummary(std::ostream &out) { out<<" "< vals; vals = data.CastToArrayHandle(vtkm::Float32(), VTKM_DEFAULT_STORAGE_TAG()); printSummary_ArrayHandle(vals, out); //out<<" order= "<