2015-02-10 17:36:10 +00:00
|
|
|
//============================================================================
|
|
|
|
// 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.
|
2015-06-03 19:06:43 +00:00
|
|
|
// Copyright 2014 Los Alamos National Security.
|
2015-02-10 17:36:10 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//============================================================================
|
2015-05-29 13:51:11 +00:00
|
|
|
#ifndef vtk_m_cont_Field_h
|
|
|
|
#define vtk_m_cont_Field_h
|
2015-02-10 17:36:10 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
|
|
|
#include <vtkm/cont/DynamicArrayHandle.h>
|
2015-05-29 13:44:57 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/internal/ArrayPortalFromIterators.h>
|
2015-02-10 17:36:10 +00:00
|
|
|
|
|
|
|
namespace vtkm {
|
|
|
|
namespace cont {
|
|
|
|
|
|
|
|
/// A \c Field encapsulates an array on some piece of the mesh, such as
|
2015-05-11 20:15:58 +00:00
|
|
|
/// the points, a cell set, a node logical dimension, or the whole mesh.
|
2015-02-10 17:36:10 +00:00
|
|
|
///
|
|
|
|
class Field
|
|
|
|
{
|
|
|
|
public:
|
2015-05-11 20:15:58 +00:00
|
|
|
|
|
|
|
enum Association
|
|
|
|
{
|
|
|
|
ASSOC_WHOLE_MESH,
|
|
|
|
ASSOC_POINTS,
|
|
|
|
ASSOC_CELL_SET,
|
|
|
|
ASSOC_LOGICAL_DIM
|
|
|
|
};
|
|
|
|
|
2015-05-19 20:49:17 +00:00
|
|
|
/// constructors for points / whole mesh
|
2015-07-13 19:50:07 +00:00
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
Field(std::string name, int order, Association association,
|
|
|
|
vtkm::cont::DynamicArrayHandle &data)
|
2015-07-13 21:14:57 +00:00
|
|
|
: Name(name), Order(order), AssocTag(association), AssocCellsetName(),
|
|
|
|
AssocLogicalDim(-1), Data(data)
|
2015-07-13 19:50:07 +00:00
|
|
|
{
|
|
|
|
VTKM_ASSERT_CONT(this->AssocTag == ASSOC_WHOLE_MESH ||
|
|
|
|
this->AssocTag == ASSOC_POINTS);
|
|
|
|
}
|
|
|
|
|
2015-05-11 20:15:58 +00:00
|
|
|
template <typename T>
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-07-13 19:17:03 +00:00
|
|
|
Field(std::string name, int order, Association association, ArrayHandle<T> &data)
|
2015-07-13 21:14:57 +00:00
|
|
|
: Name(name), Order(order), AssocTag(association), AssocCellsetName(),
|
|
|
|
AssocLogicalDim(-1)
|
2015-05-11 20:15:58 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
VTKM_ASSERT_CONT(this->AssocTag == ASSOC_WHOLE_MESH ||
|
|
|
|
this->AssocTag == ASSOC_POINTS);
|
|
|
|
this->SetData(data);
|
2015-05-11 20:15:58 +00:00
|
|
|
}
|
2015-06-04 13:06:47 +00:00
|
|
|
|
2015-05-19 20:49:17 +00:00
|
|
|
template <typename T>
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-07-13 19:17:03 +00:00
|
|
|
Field(std::string name, int order, Association association,
|
|
|
|
const std::vector<T> &data)
|
2015-07-13 21:14:57 +00:00
|
|
|
: Name(name), Order(order), AssocTag(association), AssocCellsetName(),
|
|
|
|
AssocLogicalDim(-1)
|
2015-05-19 20:49:17 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
VTKM_ASSERT_CONT(this->AssocTag == ASSOC_WHOLE_MESH ||
|
|
|
|
this->AssocTag == ASSOC_POINTS);
|
|
|
|
this->CopyData(&data[0], data.size());
|
2015-05-19 20:49:17 +00:00
|
|
|
}
|
2015-06-04 13:06:47 +00:00
|
|
|
|
2015-05-19 20:49:17 +00:00
|
|
|
template <typename T>
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-07-13 19:17:03 +00:00
|
|
|
Field(std::string name, int order, Association association, const T *data,
|
|
|
|
vtkm::Id nvals)
|
2015-07-13 21:14:57 +00:00
|
|
|
: Name(name), Order(order), AssocTag(association), AssocCellsetName(),
|
|
|
|
AssocLogicalDim(-1)
|
2015-05-19 20:49:17 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
VTKM_ASSERT_CONT(this->AssocTag == ASSOC_WHOLE_MESH ||
|
|
|
|
this->AssocTag == ASSOC_POINTS);
|
|
|
|
this->CopyData(data, nvals);
|
2015-05-19 20:49:17 +00:00
|
|
|
}
|
2015-06-04 13:06:47 +00:00
|
|
|
|
2015-06-08 20:14:49 +00:00
|
|
|
template<typename T>
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-07-13 19:17:03 +00:00
|
|
|
Field(std::string name, int order, Association association, T)
|
2015-07-13 21:14:57 +00:00
|
|
|
: Name(name), Order(order), AssocTag(association), AssocCellsetName(),
|
|
|
|
AssocLogicalDim(-1), Data(vtkm::cont::ArrayHandle<T>())
|
2015-05-19 20:49:17 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
VTKM_ASSERT_CONT(this->AssocTag == ASSOC_WHOLE_MESH ||
|
|
|
|
this->AssocTag == ASSOC_POINTS);
|
2015-05-19 20:49:17 +00:00
|
|
|
}
|
2015-05-11 20:15:58 +00:00
|
|
|
|
2015-05-19 20:49:17 +00:00
|
|
|
/// constructors for cell set associations
|
2015-07-13 19:50:07 +00:00
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
Field(std::string name, int order, Association association,
|
|
|
|
const std::string& cellSetName, vtkm::cont::DynamicArrayHandle &data)
|
|
|
|
: Name(name), Order(order), AssocTag(association), AssocCellsetName(cellSetName),
|
2015-07-13 21:14:57 +00:00
|
|
|
AssocLogicalDim(-1), Data(data)
|
2015-07-13 19:50:07 +00:00
|
|
|
{
|
|
|
|
VTKM_ASSERT_CONT(this->AssocTag == ASSOC_CELL_SET);
|
|
|
|
}
|
|
|
|
|
2015-05-11 20:15:58 +00:00
|
|
|
template <typename T>
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-07-13 19:17:03 +00:00
|
|
|
Field(std::string name, int order, Association association,
|
|
|
|
const std::string& cellSetName, ArrayHandle<T> &data)
|
2015-07-13 21:14:57 +00:00
|
|
|
: Name(name), Order(order), AssocTag(association), AssocCellsetName(cellSetName),
|
|
|
|
AssocLogicalDim(-1)
|
2015-05-11 20:15:58 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
VTKM_ASSERT_CONT(this->AssocTag == ASSOC_CELL_SET);
|
|
|
|
this->SetData(data);
|
2015-05-11 20:15:58 +00:00
|
|
|
}
|
2015-06-04 13:06:47 +00:00
|
|
|
|
2015-05-19 20:49:17 +00:00
|
|
|
template <typename T>
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-07-13 19:17:03 +00:00
|
|
|
Field(std::string name, int order, Association association,
|
|
|
|
const std::string& cellSetName, const std::vector<T> &data)
|
2015-07-13 21:14:57 +00:00
|
|
|
: Name(name), Order(order), AssocTag(association), AssocCellsetName(cellSetName),
|
|
|
|
AssocLogicalDim(-1)
|
2015-05-19 20:49:17 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
VTKM_ASSERT_CONT(this->AssocTag == ASSOC_CELL_SET);
|
|
|
|
this->CopyData(&data[0], data.size());
|
2015-05-19 20:49:17 +00:00
|
|
|
}
|
2015-06-04 13:06:47 +00:00
|
|
|
|
2015-05-19 20:49:17 +00:00
|
|
|
template <typename T>
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-07-13 19:17:03 +00:00
|
|
|
Field(std::string name, int order, Association association,
|
|
|
|
const std::string& cellSetName, const T *data, vtkm::Id nvals)
|
2015-07-13 21:14:57 +00:00
|
|
|
: Name(name), Order(order), AssocTag(association), AssocCellsetName(cellSetName),
|
|
|
|
AssocLogicalDim(-1)
|
2015-05-19 20:49:17 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
VTKM_ASSERT_CONT(this->AssocTag == ASSOC_CELL_SET);
|
|
|
|
this->CopyData(data, nvals);
|
2015-05-19 20:49:17 +00:00
|
|
|
}
|
2015-06-04 13:06:47 +00:00
|
|
|
|
2015-06-08 20:14:49 +00:00
|
|
|
template<typename T>
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-07-13 19:17:03 +00:00
|
|
|
Field(std::string name, int order, Association association,
|
|
|
|
const std::string& cellSetName, T)
|
|
|
|
: Name(name), Order(order), AssocTag(association), AssocCellsetName(cellSetName),
|
2015-07-13 21:14:57 +00:00
|
|
|
AssocLogicalDim(-1), Data(vtkm::cont::ArrayHandle<T>())
|
2015-05-19 20:49:17 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
VTKM_ASSERT_CONT(this->AssocTag == ASSOC_CELL_SET);
|
2015-05-19 20:49:17 +00:00
|
|
|
}
|
2015-05-11 20:15:58 +00:00
|
|
|
|
2015-05-19 20:49:17 +00:00
|
|
|
/// constructors for logical dimension associations
|
2015-07-13 19:50:07 +00:00
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
Field(std::string name, int order, Association association, int logicalDim,
|
|
|
|
vtkm::cont::DynamicArrayHandle &data)
|
2015-07-13 21:14:57 +00:00
|
|
|
: Name(name), Order(order), AssocTag(association), AssocCellsetName(),
|
|
|
|
AssocLogicalDim(logicalDim), Data(data)
|
2015-07-13 19:50:07 +00:00
|
|
|
{
|
|
|
|
VTKM_ASSERT_CONT(this->AssocTag == ASSOC_LOGICAL_DIM);
|
|
|
|
}
|
|
|
|
|
2015-05-11 20:15:58 +00:00
|
|
|
template <typename T>
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-07-13 19:17:03 +00:00
|
|
|
Field(std::string name, int order, Association association, int logicalDim,
|
|
|
|
ArrayHandle<T> &data)
|
2015-07-13 21:14:57 +00:00
|
|
|
: Name(name), Order(order), AssocTag(association), AssocCellsetName(),
|
|
|
|
AssocLogicalDim(logicalDim)
|
2015-05-11 20:15:58 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
VTKM_ASSERT_CONT(this->AssocTag == ASSOC_LOGICAL_DIM);
|
|
|
|
this->SetData(data);
|
2015-05-11 20:15:58 +00:00
|
|
|
}
|
2015-06-04 13:06:47 +00:00
|
|
|
|
2015-05-19 20:49:17 +00:00
|
|
|
template <typename T>
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-07-13 19:17:03 +00:00
|
|
|
Field(std::string name, int order, Association association, int logicalDim,
|
|
|
|
const std::vector<T> &data)
|
2015-07-13 21:14:57 +00:00
|
|
|
: Name(name), Order(order), AssocTag(association), AssocCellsetName(),
|
|
|
|
AssocLogicalDim(logicalDim)
|
2015-05-19 20:49:17 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
VTKM_ASSERT_CONT(this->AssocTag == ASSOC_LOGICAL_DIM);
|
|
|
|
this->CopyData(&data[0], data.size());
|
2015-05-19 20:49:17 +00:00
|
|
|
}
|
2015-06-04 13:06:47 +00:00
|
|
|
|
2015-05-19 20:49:17 +00:00
|
|
|
template <typename T>
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-07-13 19:17:03 +00:00
|
|
|
Field(std::string name, int order, Association association, int logicalDim,
|
|
|
|
const T *data, vtkm::Id nvals)
|
2015-07-13 21:14:57 +00:00
|
|
|
: Name(name), Order(order), AssocTag(association), AssocCellsetName(),
|
|
|
|
AssocLogicalDim(logicalDim)
|
2015-05-19 20:49:17 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
VTKM_ASSERT_CONT(this->AssocTag == ASSOC_LOGICAL_DIM);
|
|
|
|
this->CopyData(data, nvals);
|
2015-05-19 20:49:17 +00:00
|
|
|
}
|
2015-06-04 13:06:47 +00:00
|
|
|
|
2015-06-08 20:14:49 +00:00
|
|
|
template<typename T>
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-07-13 19:17:03 +00:00
|
|
|
Field(std::string name, int order, Association association, int logicalDim, T)
|
2015-07-13 21:14:57 +00:00
|
|
|
: Name(name), Order(order), AssocTag(association), AssocCellsetName(),
|
|
|
|
AssocLogicalDim(logicalDim), Data(vtkm::cont::ArrayHandle<T>())
|
2015-05-19 20:49:17 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
VTKM_ASSERT_CONT(this->AssocTag == ASSOC_LOGICAL_DIM);
|
2015-05-19 20:49:17 +00:00
|
|
|
}
|
2015-05-11 20:15:58 +00:00
|
|
|
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-07-13 20:20:39 +00:00
|
|
|
const std::string &GetName() const
|
2015-05-19 20:21:15 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
return this->Name;
|
2015-05-19 20:21:15 +00:00
|
|
|
}
|
|
|
|
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-07-13 20:20:39 +00:00
|
|
|
Association GetAssociation() const
|
2015-05-11 20:15:58 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
return this->AssocTag;
|
2015-05-11 20:15:58 +00:00
|
|
|
}
|
|
|
|
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-07-13 20:20:39 +00:00
|
|
|
int GetOrder() const
|
2015-05-11 20:15:58 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
return this->Order;
|
2015-05-11 20:15:58 +00:00
|
|
|
}
|
|
|
|
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-07-13 20:20:39 +00:00
|
|
|
std::string GetAssocCellSet() const
|
2015-05-11 20:15:58 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
return this->AssocCellsetName;
|
2015-05-11 20:15:58 +00:00
|
|
|
}
|
|
|
|
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-07-13 20:20:39 +00:00
|
|
|
int GetAssocLogicalDim() const
|
2015-05-11 20:15:58 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
return this->AssocLogicalDim;
|
2015-05-11 20:15:58 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 20:20:39 +00:00
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
const vtkm::cont::DynamicArrayHandle &GetData() const
|
|
|
|
{
|
|
|
|
return this->Data;
|
|
|
|
}
|
|
|
|
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-04-15 16:33:27 +00:00
|
|
|
vtkm::cont::DynamicArrayHandle &GetData()
|
2015-02-10 17:36:10 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
return this->Data;
|
2015-02-10 17:36:10 +00:00
|
|
|
}
|
|
|
|
|
2015-05-11 20:15:58 +00:00
|
|
|
template <typename T>
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-05-11 20:15:58 +00:00
|
|
|
void SetData(vtkm::cont::ArrayHandle<T> &newdata)
|
2015-02-10 17:36:10 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
this->Data = newdata;
|
2015-02-10 17:36:10 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 20:21:15 +00:00
|
|
|
template <typename T>
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-05-29 13:44:57 +00:00
|
|
|
void CopyData(const T *ptr, vtkm::Id nvals)
|
2015-02-10 17:36:10 +00:00
|
|
|
{
|
2015-05-29 13:44:57 +00:00
|
|
|
//allocate main memory using an array handle
|
|
|
|
vtkm::cont::ArrayHandle<T> tmp;
|
|
|
|
tmp.Allocate(nvals);
|
|
|
|
|
|
|
|
//copy into the memory owned by the array handle
|
|
|
|
std::copy(ptr,
|
|
|
|
ptr + static_cast<std::size_t>(nvals),
|
|
|
|
vtkm::cont::ArrayPortalToIteratorBegin(tmp.GetPortalControl()));
|
|
|
|
|
|
|
|
//assign to the dynamic array handle
|
2015-07-13 19:17:03 +00:00
|
|
|
this->Data = tmp;
|
2015-02-10 17:36:10 +00:00
|
|
|
}
|
2015-05-20 19:26:10 +00:00
|
|
|
|
2015-05-29 16:48:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-07-13 20:20:39 +00:00
|
|
|
virtual void PrintSummary(std::ostream &out) const
|
2015-05-20 19:26:10 +00:00
|
|
|
{
|
2015-07-13 19:17:03 +00:00
|
|
|
out<<" "<<this->Name;
|
2015-05-20 19:26:10 +00:00
|
|
|
out<<" assoc= ";
|
2015-07-13 19:17:03 +00:00
|
|
|
switch (this->GetAssociation())
|
2015-05-20 19:26:10 +00:00
|
|
|
{
|
|
|
|
case ASSOC_WHOLE_MESH: out<<"Mesh "; break;
|
|
|
|
case ASSOC_POINTS: out<<"Points "; break;
|
|
|
|
case ASSOC_CELL_SET: out<<"Cells "; break;
|
|
|
|
case ASSOC_LOGICAL_DIM: out<<"LogicalDim "; break;
|
|
|
|
}
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Float32> vals;
|
2015-07-13 19:17:03 +00:00
|
|
|
vals = this->Data.CastToArrayHandle(vtkm::Float32(), VTKM_DEFAULT_STORAGE_TAG());
|
2015-05-20 19:26:10 +00:00
|
|
|
printSummary_ArrayHandle(vals, out);
|
2015-07-13 19:17:03 +00:00
|
|
|
//out<<" Order= "<<Order;
|
2015-05-20 19:26:10 +00:00
|
|
|
out<<"\n";
|
|
|
|
}
|
2015-05-29 13:44:57 +00:00
|
|
|
|
2015-02-10 17:36:10 +00:00
|
|
|
private:
|
2015-07-13 19:17:03 +00:00
|
|
|
std::string Name; ///< Name of field
|
2015-05-19 20:21:15 +00:00
|
|
|
|
2015-07-13 19:17:03 +00:00
|
|
|
int Order; ///< 0=(piecewise) constant, 1=linear, 2=quadratic
|
|
|
|
Association AssocTag;
|
|
|
|
std::string AssocCellsetName; ///< only populate if assoc is cells
|
|
|
|
int AssocLogicalDim; ///< only populate if assoc is logical dim
|
2015-05-11 20:15:58 +00:00
|
|
|
|
2015-07-13 19:17:03 +00:00
|
|
|
vtkm::cont::DynamicArrayHandle Data;
|
2015-02-10 17:36:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace cont
|
|
|
|
} // namespace vtkm
|
|
|
|
|
2015-05-29 13:51:11 +00:00
|
|
|
#endif //vtk_m_cont_Field_h
|