Field.cxx 4.7 KB
Newer Older
1 2 3 4 5 6 7 8
//============================================================================
//  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.
//
9
//  Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
10 11 12
//  Copyright 2015 UT-Battelle, LLC.
//  Copyright 2015 Los Alamos National Security.
//
13
//  Under the terms of Contract DE-NA0003525 with NTESS,
14 15 16 17 18 19
//  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.
//============================================================================
20

21
#include "Field.h"
22

23 24 25 26
namespace vtkm
{
namespace cont
{
27

28 29
/// constructors for points / whole mesh
VTKM_CONT
30
Field::Field(std::string name, Association association, const vtkm::cont::VariantArrayHandle& data)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
  : Name(name)
  , FieldAssociation(association)
  , AssocCellSetName()
  , AssocLogicalDim(-1)
  , Data(data)
  , Range()
  , ModifiedFlag(true)
{
  VTKM_ASSERT(this->FieldAssociation == Association::WHOLE_MESH ||
              this->FieldAssociation == Association::POINTS);
}

/// constructors for cell set associations
VTKM_CONT
Field::Field(std::string name,
             Association association,
             const std::string& cellSetName,
48
             const vtkm::cont::VariantArrayHandle& data)
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
  : Name(name)
  , FieldAssociation(association)
  , AssocCellSetName(cellSetName)
  , AssocLogicalDim(-1)
  , Data(data)
  , Range()
  , ModifiedFlag(true)
{
  VTKM_ASSERT(this->FieldAssociation == Association::CELL_SET);
}

/// constructors for logical dimension associations
VTKM_CONT
Field::Field(std::string name,
             Association association,
             vtkm::IdComponent logicalDim,
65
             const vtkm::cont::VariantArrayHandle& data)
66 67 68 69 70 71 72 73 74 75 76
  : Name(name)
  , FieldAssociation(association)
  , AssocCellSetName()
  , AssocLogicalDim(logicalDim)
  , Data(data)
  , Range()
  , ModifiedFlag(true)
{
  VTKM_ASSERT(this->FieldAssociation == Association::LOGICAL_DIM);
}

77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
VTKM_CONT
Field::Field(const vtkm::cont::Field& src)
  : Name(src.Name)
  , FieldAssociation(src.FieldAssociation)
  , AssocCellSetName(src.AssocCellSetName)
  , AssocLogicalDim(src.AssocLogicalDim)
  , Data(src.Data)
  , Range(src.Range)
  , ModifiedFlag(src.ModifiedFlag)
{
}

VTKM_CONT
Field::Field(vtkm::cont::Field&& src) noexcept : Name(std::move(src.Name)),
                                                 FieldAssociation(std::move(src.FieldAssociation)),
                                                 AssocCellSetName(std::move(src.AssocCellSetName)),
                                                 AssocLogicalDim(std::move(src.AssocLogicalDim)),
                                                 Data(std::move(src.Data)),
                                                 Range(std::move(src.Range)),
                                                 ModifiedFlag(std::move(src.ModifiedFlag))
{
}

VTKM_CONT
Field& Field::operator=(const vtkm::cont::Field& src)
{
  this->Name = src.Name;
  this->FieldAssociation = src.FieldAssociation;
  this->AssocCellSetName = src.AssocCellSetName;
  this->AssocLogicalDim = src.AssocLogicalDim;
  this->Data = src.Data;
  this->Range = src.Range;
  this->ModifiedFlag = src.ModifiedFlag;
  return *this;
}

VTKM_CONT
Field& Field::operator=(vtkm::cont::Field&& src) noexcept
{
  this->Name = std::move(src.Name);
  this->FieldAssociation = std::move(src.FieldAssociation);
  this->AssocCellSetName = std::move(src.AssocCellSetName);
  this->AssocLogicalDim = std::move(src.AssocLogicalDim);
  this->Data = std::move(src.Data);
  this->Range = std::move(src.Range);
  this->ModifiedFlag = std::move(src.ModifiedFlag);
  return *this;
}

126

127
VTKM_CONT
128
void Field::PrintSummary(std::ostream& out) const
129
{
130 131
  out << "   " << this->Name;
  out << " assoc= ";
132 133
  switch (this->GetAssociation())
  {
134
    case Association::ANY:
135 136
      out << "Any ";
      break;
137
    case Association::WHOLE_MESH:
138 139
      out << "Mesh ";
      break;
140
    case Association::POINTS:
141 142
      out << "Points ";
      break;
143
    case Association::CELL_SET:
144 145
      out << "Cells ";
      break;
146
    case Association::LOGICAL_DIM:
147 148
      out << "LogicalDim ";
      break;
149 150
  }
  this->Data.PrintSummary(out);
151 152
}

153 154 155 156 157
VTKM_CONT
Field::~Field()
{
}

158 159

VTKM_CONT
160
const vtkm::cont::VariantArrayHandle& Field::GetData() const
161
{
162
  return this->Data;
163
}
164

165
VTKM_CONT
166
vtkm::cont::VariantArrayHandle& Field::GetData()
167
{
168 169 170
  this->ModifiedFlag = true;
  return this->Data;
}
171 172
}
} // namespace vtkm::cont