vtkmCellSetSingleType.h 8.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
//============================================================================
//  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 2015 Sandia Corporation.
//  Copyright 2015 UT-Battelle, LLC.
//  Copyright 2015 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 vtkmCellSetSingleType_h
#define vtkmCellSetSingleType_h
22
#ifndef __VTK_WRAP__
23
#ifndef VTK_WRAPPING_CXX
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

#include "vtkmTags.h"

#include <vtkm/CellShape.h>
#include <vtkm/CellTraits.h>
#include <vtkm/TopologyElementTag.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/CellSet.h>

#include <vtkm/VecFromPortal.h>

#include <vtkm/cont/serial/DeviceAdapterSerial.h>
#include <vtkm/cont/cuda/DeviceAdapterCuda.h>
#include <vtkm/cont/tbb/DeviceAdapterTBB.h>

#include "vtkmConnectivityExec.h"

namespace vtkm {
namespace cont {

44
class VTKACCELERATORSVTKM_EXPORT vtkmCellSetSingleType : public CellSet
45 46 47 48 49
{
  typedef tovtkm::vtkCellArrayContainerTag ConnectivityStorageTag;

public:
  vtkmCellSetSingleType()
50 51 52 53 54 55 56 57 58
    : CellSet((std::string()))
    , NumberOfCells(0)
    , NumberOfPoints(0)
    , CellTypeAsId(CellShapeTagEmpty::Id)
    , Connectivity()
    , ReverseConnectivityBuilt(false)
    , RConn()
    , RNumIndices()
    , RIndexOffsets()
59 60 61 62
  {
  }

  template <typename CellShapeTag>
Sujin Philip's avatar
Sujin Philip committed
63
  vtkmCellSetSingleType(CellShapeTag, const std::string& name)
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    : CellSet(name)
    , NumberOfCells(0)
    , NumberOfPoints(0)
    , CellTypeAsId(CellShapeTag::Id)
    , Connectivity()
    , ReverseConnectivityBuilt(false)
    , RConn()
    , RNumIndices()
    , RIndexOffsets()
  {
  }

  vtkmCellSetSingleType(const vtkmCellSetSingleType& src)
    : CellSet(src)
    , NumberOfCells(src.NumberOfCells)
    , NumberOfPoints(src.NumberOfPoints)
    , CellTypeAsId(src.CellTypeAsId)
    , Connectivity(src.Connectivity)
    , ReverseConnectivityBuilt(src.ReverseConnectivityBuilt)
    , RConn(src.RConn)
    , RNumIndices(src.RNumIndices)
    , RIndexOffsets(src.RIndexOffsets)
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
  {
  }

  vtkmCellSetSingleType& operator=(const vtkmCellSetSingleType& src)
  {
    this->CellSet::operator=(src);
    this->NumberOfCells = src.NumberOfCells;
    this->NumberOfPoints = src.NumberOfPoints;
    this->CellTypeAsId = src.CellTypeAsId;
    this->ReverseConnectivityBuilt = src.ReverseConnectivityBuilt;
    this->Connectivity = src.Connectivity;
    this->RConn = src.RConn;
    this->RNumIndices = src.RNumIndices;
    this->RIndexOffsets  = src.RIndexOffsets;
    return *this;
  }

103
  vtkm::Id GetNumberOfCells() const override
104 105 106 107
  {
    return this->NumberOfCells;
  }

108
  vtkm::Id GetNumberOfPoints() const override
109 110 111 112
  {
    return this->NumberOfPoints;
  }

113
  vtkm::Id GetNumberOfFaces() const override{ return -1; }
114

115
  vtkm::Id GetNumberOfEdges() const override{ return -1; }
116 117 118 119 120 121 122 123 124 125 126 127 128

  vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagCell) const
  {
    return this->GetNumberOfCells();
  }

  vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagPoint) const
  {
    return this->GetNumberOfPoints();
  }

  // This is the way you can fill the memory from another system without copying
  void Fill(
Sujin Philip's avatar
Sujin Philip committed
129
      vtkm::Id numberOfPoints,
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
      const vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkCellArrayContainerTag>&
          connectivity);

  template <typename DeviceAdapter, typename FromTopology, typename ToTopology>
  struct ExecutionTypes;

  template <typename DeviceAdapter>
  struct ExecutionTypes<DeviceAdapter, vtkm::TopologyElementTagPoint,
                        vtkm::TopologyElementTagCell>
  {
    typedef vtkm::exec::ConnectivityVTKSingleType<DeviceAdapter> ExecObjectType;
  };

  template <typename DeviceAdapter>
  struct ExecutionTypes<DeviceAdapter, vtkm::TopologyElementTagCell,
                        vtkm::TopologyElementTagPoint>
  {
    typedef vtkm::exec::ReverseConnectivityVTK<DeviceAdapter> ExecObjectType;
  };

  template <typename Device>
  typename vtkm::exec::ConnectivityVTKSingleType<Device>
      PrepareForInput(Device, vtkm::TopologyElementTagPoint,
                      vtkm::TopologyElementTagCell) const;

  template <typename Device>
  typename vtkm::exec::ReverseConnectivityVTK<Device>
      PrepareForInput(Device, vtkm::TopologyElementTagCell,
                      vtkm::TopologyElementTagPoint) const;


  const vtkm::cont::ArrayHandle<vtkm::Id, tovtkm::vtkCellArrayContainerTag>&
      GetConnectivityArray(vtkm::TopologyElementTagPoint,
                           vtkm::TopologyElementTagCell) const
  {
    return this->Connectivity;
  }

168 169 170 171 172 173 174 175 176
  void PrintSummary(std::ostream& out) const override;

  void ReleaseResourcesExecution() override
  {
    this->Connectivity.ReleaseResourcesExecution();
    this->RConn.ReleaseResourcesExecution();
    this->RNumIndices.ReleaseResourcesExecution();
    this->RIndexOffsets.ReleaseResourcesExecution();
  }
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204

private:
  template <typename CellShapeTag>
  void DetermineNumberOfPoints(CellShapeTag, vtkm::CellTraitsTagSizeFixed,
                               vtkm::IdComponent& numberOfPoints) const
  {
    numberOfPoints = vtkm::CellTraits<CellShapeTag>::NUM_POINTS;
  }

  template <typename CellShapeTag>
  void DetermineNumberOfPoints(CellShapeTag, vtkm::CellTraitsTagSizeVariable,
                               vtkm::IdComponent& numberOfPoints) const
  { // variable length cells can't be used with this class
    numberOfPoints = -1;
  }

  vtkm::IdComponent DetermineNumberOfPoints() const;

  vtkm::Id NumberOfCells;
  mutable vtkm::Id NumberOfPoints;
  vtkm::Id CellTypeAsId;
  vtkm::cont::ArrayHandle<vtkm::Id, ConnectivityStorageTag> Connectivity;

  mutable bool ReverseConnectivityBuilt;
  mutable vtkm::cont::ArrayHandle<vtkm::Id> RConn;
  mutable vtkm::cont::ArrayHandle<vtkm::IdComponent> RNumIndices;
  mutable vtkm::cont::ArrayHandle<vtkm::Id> RIndexOffsets;
};
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222

// template methods we want to compile only once
extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
  vtkm::exec::ConnectivityVTKSingleType<vtkm::cont::DeviceAdapterTagSerial>
    vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagSerial,
      vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const;

extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
  vtkm::exec::ReverseConnectivityVTK<vtkm::cont::DeviceAdapterTagSerial>
    vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagSerial,
      vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const;

#ifdef VTKM_ENABLE_TBB
extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
  vtkm::exec::ConnectivityVTKSingleType<vtkm::cont::DeviceAdapterTagTBB>
    vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagTBB,
      vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const;

223 224 225 226 227 228 229 230 231 232 233 234
extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
  vtkm::exec::ReverseConnectivityVTK<vtkm::cont::DeviceAdapterTagTBB>
    vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagTBB,
      vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const;
#endif

#ifdef VTKM_ENABLE_OPENMP
extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
  vtkm::exec::ConnectivityVTKSingleType<vtkm::cont::DeviceAdapterTagOpenMP>
    vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagOpenMP,
      vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const;

235 236 237 238 239 240
extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
  vtkm::exec::ReverseConnectivityVTK<vtkm::cont::DeviceAdapterTagTBB>
    vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagTBB,
      vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const;
#endif

241
#if defined(VTKM_ENABLE_CUDA) && defined(VTKM_CUDA)
242 243 244 245 246 247 248 249 250 251
extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
  vtkm::exec::ConnectivityVTKSingleType<vtkm::cont::DeviceAdapterTagCuda>
    vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagCuda,
      vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const;

extern template VTKACCELERATORSVTKM_TEMPLATE_EXPORT
  vtkm::exec::ReverseConnectivityVTK<vtkm::cont::DeviceAdapterTagCuda>
    vtkmCellSetSingleType::PrepareForInput(vtkm::cont::DeviceAdapterTagCuda,
      vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const;
#endif
252 253 254
}
} // namespace vtkm::cont

255
#endif
256
#endif
257 258
#endif // vtkmlib_vtkmCellSetSingleType_h
// VTK-HeaderTest-Exclude: vtkmCellSetSingleType.h