2017-07-12 02:22:28 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2017-07-12 02:22:28 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#ifndef vtk_m_worklet_ParticleAdvection_h
|
|
|
|
#define vtk_m_worklet_ParticleAdvection_h
|
|
|
|
|
|
|
|
#include <vtkm/Types.h>
|
2017-09-25 22:54:46 +00:00
|
|
|
#include <vtkm/cont/ArrayCopy.h>
|
2017-07-12 02:22:28 +00:00
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
2019-12-04 16:52:08 +00:00
|
|
|
#include <vtkm/cont/Invoker.h>
|
2017-07-12 02:22:28 +00:00
|
|
|
#include <vtkm/worklet/particleadvection/ParticleAdvectionWorklets.h>
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace worklet
|
|
|
|
{
|
|
|
|
|
2019-12-04 16:52:08 +00:00
|
|
|
namespace detail
|
2017-07-20 11:36:57 +00:00
|
|
|
{
|
2019-12-04 16:52:08 +00:00
|
|
|
class CopyToParticle : public vtkm::worklet::WorkletMapField
|
|
|
|
{
|
|
|
|
public:
|
2019-12-11 20:32:40 +00:00
|
|
|
using ControlSignature =
|
|
|
|
void(FieldIn pt, FieldIn id, FieldIn time, FieldIn step, FieldOut particle);
|
|
|
|
using ExecutionSignature = void(_1, _2, _3, _4, _5);
|
2019-12-04 16:52:08 +00:00
|
|
|
using InputDomain = _1;
|
|
|
|
|
2021-11-22 20:10:08 +00:00
|
|
|
template <typename ParticleType>
|
2019-12-04 16:52:08 +00:00
|
|
|
VTKM_EXEC void operator()(const vtkm::Vec3f& pt,
|
2019-12-11 20:32:40 +00:00
|
|
|
const vtkm::Id& id,
|
2019-12-04 16:52:08 +00:00
|
|
|
const vtkm::FloatDefault& time,
|
|
|
|
const vtkm::Id& step,
|
2021-11-22 20:10:08 +00:00
|
|
|
ParticleType& particle) const
|
2017-07-20 11:36:57 +00:00
|
|
|
{
|
2019-12-04 16:52:08 +00:00
|
|
|
particle.Pos = pt;
|
2019-12-11 20:32:40 +00:00
|
|
|
particle.ID = id;
|
2019-12-04 16:52:08 +00:00
|
|
|
particle.Time = time;
|
|
|
|
particle.NumSteps = step;
|
|
|
|
particle.Status.SetOk();
|
2017-07-20 11:36:57 +00:00
|
|
|
}
|
2019-12-04 16:52:08 +00:00
|
|
|
};
|
2017-07-20 11:36:57 +00:00
|
|
|
|
2019-12-04 16:52:08 +00:00
|
|
|
} //detail
|
|
|
|
|
2020-07-21 01:15:46 +00:00
|
|
|
template <typename ParticleType>
|
2019-12-04 16:52:08 +00:00
|
|
|
struct ParticleAdvectionResult
|
|
|
|
{
|
|
|
|
ParticleAdvectionResult()
|
|
|
|
: Particles()
|
2017-07-20 11:36:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-07-21 01:15:46 +00:00
|
|
|
ParticleAdvectionResult(const vtkm::cont::ArrayHandle<ParticleType>& p)
|
2019-12-04 16:52:08 +00:00
|
|
|
: Particles(p)
|
2018-03-23 07:49:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-07-21 01:15:46 +00:00
|
|
|
vtkm::cont::ArrayHandle<ParticleType> Particles;
|
2017-07-20 11:36:57 +00:00
|
|
|
};
|
|
|
|
|
2017-07-12 02:22:28 +00:00
|
|
|
class ParticleAdvection
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ParticleAdvection() {}
|
|
|
|
|
2020-07-21 01:15:46 +00:00
|
|
|
template <typename IntegratorType, typename ParticleType, typename ParticleStorage>
|
|
|
|
ParticleAdvectionResult<ParticleType> Run(
|
|
|
|
const IntegratorType& it,
|
|
|
|
vtkm::cont::ArrayHandle<ParticleType, ParticleStorage>& particles,
|
|
|
|
vtkm::Id MaxSteps)
|
2019-09-17 20:24:44 +00:00
|
|
|
{
|
2020-07-21 01:15:46 +00:00
|
|
|
vtkm::worklet::particleadvection::ParticleAdvectionWorklet<IntegratorType, ParticleType>
|
|
|
|
worklet;
|
2019-09-17 20:24:44 +00:00
|
|
|
|
2019-10-01 17:33:12 +00:00
|
|
|
worklet.Run(it, particles, MaxSteps);
|
2020-07-21 01:15:46 +00:00
|
|
|
return ParticleAdvectionResult<ParticleType>(particles);
|
2019-09-17 20:24:44 +00:00
|
|
|
}
|
2019-12-11 20:32:40 +00:00
|
|
|
|
2020-07-21 01:15:46 +00:00
|
|
|
template <typename IntegratorType, typename ParticleType, typename PointStorage>
|
|
|
|
ParticleAdvectionResult<ParticleType> Run(
|
|
|
|
const IntegratorType& it,
|
|
|
|
const vtkm::cont::ArrayHandle<vtkm::Vec3f, PointStorage>& points,
|
|
|
|
vtkm::Id MaxSteps)
|
2019-12-11 20:32:40 +00:00
|
|
|
{
|
2020-07-21 01:15:46 +00:00
|
|
|
vtkm::worklet::particleadvection::ParticleAdvectionWorklet<IntegratorType, ParticleType>
|
|
|
|
worklet;
|
2019-12-11 20:32:40 +00:00
|
|
|
|
2020-07-21 01:15:46 +00:00
|
|
|
vtkm::cont::ArrayHandle<ParticleType> particles;
|
2019-12-11 20:32:40 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> step, ids;
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::FloatDefault> time;
|
|
|
|
vtkm::cont::Invoker invoke;
|
|
|
|
|
|
|
|
vtkm::Id numPts = points.GetNumberOfValues();
|
|
|
|
vtkm::cont::ArrayHandleConstant<vtkm::Id> s(0, numPts);
|
|
|
|
vtkm::cont::ArrayHandleConstant<vtkm::FloatDefault> t(0, numPts);
|
|
|
|
vtkm::cont::ArrayHandleCounting<vtkm::Id> id(0, 1, numPts);
|
|
|
|
|
|
|
|
//Copy input to vtkm::Particle
|
|
|
|
vtkm::cont::ArrayCopy(s, step);
|
|
|
|
vtkm::cont::ArrayCopy(t, time);
|
|
|
|
vtkm::cont::ArrayCopy(id, ids);
|
|
|
|
invoke(detail::CopyToParticle{}, points, ids, time, step, particles);
|
|
|
|
|
|
|
|
worklet.Run(it, particles, MaxSteps);
|
2020-07-21 01:15:46 +00:00
|
|
|
return ParticleAdvectionResult<ParticleType>(particles);
|
2019-12-11 20:32:40 +00:00
|
|
|
}
|
2017-07-12 02:22:28 +00:00
|
|
|
};
|
|
|
|
|
2020-07-21 01:15:46 +00:00
|
|
|
template <typename ParticleType>
|
2017-07-21 18:37:20 +00:00
|
|
|
struct StreamlineResult
|
|
|
|
{
|
|
|
|
StreamlineResult()
|
2019-12-05 20:46:41 +00:00
|
|
|
: Particles()
|
|
|
|
, Positions()
|
|
|
|
, PolyLines()
|
2017-07-21 18:37:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-07-21 01:15:46 +00:00
|
|
|
StreamlineResult(const vtkm::cont::ArrayHandle<ParticleType>& part,
|
2019-12-05 20:46:41 +00:00
|
|
|
const vtkm::cont::ArrayHandle<vtkm::Vec3f>& pos,
|
|
|
|
const vtkm::cont::CellSetExplicit<>& lines)
|
|
|
|
: Particles(part)
|
|
|
|
, Positions(pos)
|
|
|
|
, PolyLines(lines)
|
2018-04-19 04:01:08 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-07-21 01:15:46 +00:00
|
|
|
vtkm::cont::ArrayHandle<ParticleType> Particles;
|
2019-12-05 20:46:41 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec3f> Positions;
|
|
|
|
vtkm::cont::CellSetExplicit<> PolyLines;
|
2017-07-21 18:37:20 +00:00
|
|
|
};
|
|
|
|
|
2017-07-12 02:22:28 +00:00
|
|
|
class Streamline
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Streamline() {}
|
|
|
|
|
2020-07-21 01:15:46 +00:00
|
|
|
template <typename IntegratorType, typename ParticleType, typename ParticleStorage>
|
|
|
|
StreamlineResult<ParticleType> Run(
|
|
|
|
const IntegratorType& it,
|
|
|
|
vtkm::cont::ArrayHandle<ParticleType, ParticleStorage>& particles,
|
|
|
|
vtkm::Id MaxSteps)
|
2018-04-19 04:01:08 +00:00
|
|
|
{
|
2020-07-21 01:15:46 +00:00
|
|
|
vtkm::worklet::particleadvection::StreamlineWorklet<IntegratorType, ParticleType> worklet;
|
2018-04-19 04:01:08 +00:00
|
|
|
|
2019-09-05 20:57:37 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec3f> positions;
|
2018-04-19 04:01:08 +00:00
|
|
|
vtkm::cont::CellSetExplicit<> polyLines;
|
|
|
|
|
2019-12-04 16:52:08 +00:00
|
|
|
worklet.Run(it, particles, MaxSteps, positions, polyLines);
|
2019-10-10 13:46:29 +00:00
|
|
|
|
2020-07-21 01:15:46 +00:00
|
|
|
return StreamlineResult<ParticleType>(particles, positions, polyLines);
|
2019-10-10 13:46:29 +00:00
|
|
|
}
|
2017-07-12 02:22:28 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // vtk_m_worklet_ParticleAdvection_h
|