Streamline.hxx 4.61 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.
//
Dave Pugmire's avatar
Dave Pugmire committed
9 10 11
//  Copyright 2017 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
//  Copyright 2017 UT-Battelle, LLC.
//  Copyright 2017 Los Alamos National Security.
12
//
Dave Pugmire's avatar
Dave Pugmire committed
13
//  Under the terms of Contract DE-NA0003525 with NTESS,
14 15 16 17 18 19 20 21
//  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.
//============================================================================

#include <vtkm/cont/ArrayHandleIndex.h>
22
#include <vtkm/cont/ErrorFilterExecution.h>
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
#include <vtkm/worklet/particleadvection/GridEvaluators.h>
#include <vtkm/worklet/particleadvection/Integrators.h>
#include <vtkm/worklet/particleadvection/Particles.h>

namespace vtkm
{
namespace filter
{

namespace
{

template <typename CellSetList>
bool IsCellSupported(const vtkm::cont::DynamicCellSetBase<CellSetList>& cellset)
{
  //We only support 3D structured for now.
  if (cellset.template IsType<vtkm::cont::CellSetStructured<3>>())
    return true;
  return false;
}
} // anonymous namespace

//-----------------------------------------------------------------------------
inline VTKM_CONT Streamline::Streamline()
  : vtkm::filter::FilterDataSetWithField<Streamline>()
  , Worklet()
{
}

//-----------------------------------------------------------------------------
inline VTKM_CONT void Streamline::SetSeeds(
  vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::FloatDefault, 3>>& seeds)
{
  this->Seeds = seeds;
}

//-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
61
inline VTKM_CONT vtkm::cont::DataSet Streamline::DoExecute(
62 63 64 65 66 67 68 69
  const vtkm::cont::DataSet& input,
  const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, StorageType>& field,
  const vtkm::filter::FieldMetadata& fieldMeta,
  const vtkm::filter::PolicyBase<DerivedPolicy>&,
  const DeviceAdapter& device)
{
  //Check for some basics.
  if (this->Seeds.GetNumberOfValues() == 0)
70 71 72
  {
    throw vtkm::cont::ErrorFilterExecution("No seeds provided.");
  }
73 74 75 76 77 78

  const vtkm::cont::DynamicCellSet& cells = input.GetCellSet(this->GetActiveCellSetIndex());
  const vtkm::cont::CoordinateSystem& coords =
    input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex());

  if (!IsCellSupported(cells))
79 80 81
  {
    throw vtkm::cont::ErrorFilterExecution("Cell type not supported.");
  }
82 83

  if (!fieldMeta.IsPointField())
84 85 86
  {
    throw vtkm::cont::ErrorFilterExecution("Point field expected.");
  }
87 88

  //todo: add check for rectilinear.
89
  using FieldHandle = vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, StorageType>;
90 91
  using FieldPortalConstType =
    typename FieldHandle::template ExecutionTypes<DeviceAdapter>::PortalConst;
92 93
  using RGEvalType = vtkm::worklet::particleadvection::
    UniformGridEvaluate<FieldPortalConstType, T, DeviceAdapter, StorageType>;
94
  using RK4RGType = vtkm::worklet::particleadvection::RK4Integrator<RGEvalType, T>;
95 96 97

  //RGEvalType eval(input.GetCoordinateSystem(), input.GetCellSet(0), field);
  RGEvalType eval(coords, cells, field);
98
  RK4RGType rk4(eval, static_cast<T>(this->StepSize));
99 100 101

  vtkm::worklet::Streamline streamline;
  vtkm::worklet::StreamlineResult<T> res;
102 103 104 105

  vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>> seedArray;
  vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>::Copy(this->Seeds, seedArray);
  res = Worklet.Run(rk4, seedArray, this->NumberOfSteps, device);
106

Dave Pugmire's avatar
Dave Pugmire committed
107 108 109 110 111
  vtkm::cont::DataSet outData;
  vtkm::cont::CoordinateSystem outputCoords("coordinates", res.positions);
  outData.AddCellSet(res.polyLines);
  outData.AddCoordinateSystem(outputCoords);

112
  return outData;
113 114 115 116
}

//-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
117
inline VTKM_CONT bool Streamline::DoMapField(vtkm::cont::DataSet&,
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
118 119 120 121
                                             const vtkm::cont::ArrayHandle<T, StorageType>&,
                                             const vtkm::filter::FieldMetadata&,
                                             const vtkm::filter::PolicyBase<DerivedPolicy>&,
                                             const DeviceAdapter&)
122
{
123
  return false;
124 125 126
}
}
} // namespace vtkm::filter