2016-11-10 16:32:46 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2016-11-10 16:32:46 +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_Gradient_h
|
|
|
|
#define vtk_m_worklet_Gradient_h
|
|
|
|
|
2017-05-31 18:48:38 +00:00
|
|
|
#include <vtkm/worklet/DispatcherMapTopology.h>
|
2017-07-11 12:33:56 +00:00
|
|
|
#include <vtkm/worklet/DispatcherPointNeighborhood.h>
|
2016-11-10 16:32:46 +00:00
|
|
|
|
2017-05-31 19:03:03 +00:00
|
|
|
#include <vtkm/worklet/gradient/CellGradient.h>
|
|
|
|
#include <vtkm/worklet/gradient/Divergence.h>
|
|
|
|
#include <vtkm/worklet/gradient/GradientOutput.h>
|
|
|
|
#include <vtkm/worklet/gradient/PointGradient.h>
|
|
|
|
#include <vtkm/worklet/gradient/QCriterion.h>
|
2017-07-11 12:33:56 +00:00
|
|
|
#include <vtkm/worklet/gradient/StructuredPointGradient.h>
|
2017-06-29 20:35:58 +00:00
|
|
|
#include <vtkm/worklet/gradient/Transpose.h>
|
2017-05-31 19:03:03 +00:00
|
|
|
#include <vtkm/worklet/gradient/Vorticity.h>
|
2016-12-01 19:20:47 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace worklet
|
|
|
|
{
|
2016-12-23 14:12:37 +00:00
|
|
|
|
2017-05-31 18:48:38 +00:00
|
|
|
template <typename T>
|
2017-05-31 19:03:03 +00:00
|
|
|
struct GradientOutputFields;
|
2016-12-01 19:20:47 +00:00
|
|
|
|
2017-05-31 19:03:03 +00:00
|
|
|
namespace gradient
|
2016-12-01 19:20:47 +00:00
|
|
|
{
|
2016-11-10 16:32:46 +00:00
|
|
|
|
2017-05-31 18:48:38 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2018-08-30 15:53:18 +00:00
|
|
|
template <typename CoordinateSystem, typename T, typename S>
|
2017-05-31 18:48:38 +00:00
|
|
|
struct DeducedPointGrad
|
|
|
|
{
|
|
|
|
DeducedPointGrad(const CoordinateSystem& coords,
|
|
|
|
const vtkm::cont::ArrayHandle<T, S>& field,
|
2017-05-31 19:03:03 +00:00
|
|
|
GradientOutputFields<T>* result)
|
2017-05-31 18:48:38 +00:00
|
|
|
: Points(&coords)
|
|
|
|
, Field(&field)
|
|
|
|
, Result(result)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename CellSetType>
|
|
|
|
void operator()(const CellSetType& cellset) const
|
|
|
|
{
|
2020-03-19 12:32:43 +00:00
|
|
|
vtkm::worklet::DispatcherMapTopology<PointGradient> dispatcher;
|
2017-05-31 18:48:38 +00:00
|
|
|
dispatcher.Invoke(cellset, //topology to iterate on a per point basis
|
|
|
|
cellset, //whole cellset in
|
|
|
|
*this->Points,
|
|
|
|
*this->Field,
|
|
|
|
*this->Result);
|
|
|
|
}
|
|
|
|
|
2017-07-11 12:33:56 +00:00
|
|
|
void operator()(const vtkm::cont::CellSetStructured<3>& cellset) const
|
|
|
|
{
|
2020-03-19 12:32:43 +00:00
|
|
|
vtkm::worklet::DispatcherPointNeighborhood<StructuredPointGradient> dispatcher;
|
2017-07-11 12:33:56 +00:00
|
|
|
dispatcher.Invoke(cellset, //topology to iterate on a per point basis
|
|
|
|
*this->Points,
|
|
|
|
*this->Field,
|
|
|
|
*this->Result);
|
|
|
|
}
|
|
|
|
|
2017-09-04 16:05:46 +00:00
|
|
|
template <typename PermIterType>
|
|
|
|
void operator()(const vtkm::cont::CellSetPermutation<vtkm::cont::CellSetStructured<3>,
|
|
|
|
PermIterType>& cellset) const
|
|
|
|
{
|
2020-03-19 12:32:43 +00:00
|
|
|
vtkm::worklet::DispatcherPointNeighborhood<StructuredPointGradient> dispatcher;
|
2017-09-04 16:05:46 +00:00
|
|
|
dispatcher.Invoke(cellset, //topology to iterate on a per point basis
|
|
|
|
*this->Points,
|
|
|
|
*this->Field,
|
|
|
|
*this->Result);
|
|
|
|
}
|
|
|
|
|
2017-07-11 12:33:56 +00:00
|
|
|
void operator()(const vtkm::cont::CellSetStructured<2>& cellset) const
|
|
|
|
{
|
2020-03-19 12:32:43 +00:00
|
|
|
vtkm::worklet::DispatcherPointNeighborhood<StructuredPointGradient> dispatcher;
|
2017-07-11 12:33:56 +00:00
|
|
|
dispatcher.Invoke(cellset, //topology to iterate on a per point basis
|
|
|
|
*this->Points,
|
|
|
|
*this->Field,
|
|
|
|
*this->Result);
|
|
|
|
}
|
|
|
|
|
2017-09-04 16:05:46 +00:00
|
|
|
template <typename PermIterType>
|
|
|
|
void operator()(const vtkm::cont::CellSetPermutation<vtkm::cont::CellSetStructured<2>,
|
|
|
|
PermIterType>& cellset) const
|
|
|
|
{
|
2020-03-19 12:32:43 +00:00
|
|
|
vtkm::worklet::DispatcherPointNeighborhood<StructuredPointGradient> dispatcher;
|
2017-09-04 16:05:46 +00:00
|
|
|
dispatcher.Invoke(cellset, //topology to iterate on a per point basis
|
|
|
|
*this->Points,
|
|
|
|
*this->Field,
|
|
|
|
*this->Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-31 18:48:38 +00:00
|
|
|
const CoordinateSystem* const Points;
|
|
|
|
const vtkm::cont::ArrayHandle<T, S>* const Field;
|
2017-05-31 19:03:03 +00:00
|
|
|
GradientOutputFields<T>* Result;
|
2017-05-31 18:48:38 +00:00
|
|
|
|
|
|
|
private:
|
2018-08-30 15:53:18 +00:00
|
|
|
void operator=(const DeducedPointGrad<CoordinateSystem, T, S>&) = delete;
|
2017-05-31 18:48:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} //namespace gradient
|
|
|
|
|
2017-05-31 19:03:03 +00:00
|
|
|
template <typename T>
|
2018-05-10 23:53:39 +00:00
|
|
|
struct GradientOutputFields : public vtkm::cont::ExecutionObjectBase
|
2017-05-31 19:03:03 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
using ValueType = T;
|
2019-09-09 19:01:03 +00:00
|
|
|
using BaseTType = typename vtkm::VecTraits<T>::BaseComponentType;
|
2017-05-31 19:03:03 +00:00
|
|
|
|
|
|
|
template <typename DeviceAdapter>
|
|
|
|
struct ExecutionTypes
|
|
|
|
{
|
2018-05-15 22:47:22 +00:00
|
|
|
using Portal = vtkm::exec::GradientOutput<T>;
|
2017-05-31 19:03:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GradientOutputFields()
|
|
|
|
: Gradient()
|
|
|
|
, Divergence()
|
|
|
|
, Vorticity()
|
|
|
|
, QCriterion()
|
|
|
|
, StoreGradient(true)
|
|
|
|
, ComputeDivergence(false)
|
|
|
|
, ComputeVorticity(false)
|
|
|
|
, ComputeQCriterion(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GradientOutputFields(bool store, bool divergence, bool vorticity, bool qc)
|
|
|
|
: Gradient()
|
|
|
|
, Divergence()
|
|
|
|
, Vorticity()
|
|
|
|
, QCriterion()
|
|
|
|
, StoreGradient(store)
|
|
|
|
, ComputeDivergence(divergence)
|
|
|
|
, ComputeVorticity(vorticity)
|
|
|
|
, ComputeQCriterion(qc)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Add divergence field to the output data.
|
|
|
|
/// The input array must have 3 components in order to compute this.
|
|
|
|
/// The default is off.
|
|
|
|
void SetComputeDivergence(bool enable) { ComputeDivergence = enable; }
|
|
|
|
bool GetComputeDivergence() const { return ComputeDivergence; }
|
|
|
|
|
|
|
|
/// Add voriticity/curl field to the output data.
|
|
|
|
/// The input array must have 3 components in order to compute this.
|
|
|
|
/// The default is off.
|
|
|
|
void SetComputeVorticity(bool enable) { ComputeVorticity = enable; }
|
|
|
|
bool GetComputeVorticity() const { return ComputeVorticity; }
|
|
|
|
|
|
|
|
/// Add Q-criterion field to the output data.
|
|
|
|
/// The input array must have 3 components in order to compute this.
|
|
|
|
/// The default is off.
|
|
|
|
void SetComputeQCriterion(bool enable) { ComputeQCriterion = enable; }
|
|
|
|
bool GetComputeQCriterion() const { return ComputeQCriterion; }
|
|
|
|
|
|
|
|
/// Add gradient field to the output data.
|
|
|
|
/// The input array must have 3 components in order to disable this.
|
|
|
|
/// The default is on.
|
|
|
|
void SetComputeGradient(bool enable) { StoreGradient = enable; }
|
|
|
|
bool GetComputeGradient() const { return StoreGradient; }
|
|
|
|
|
|
|
|
//todo fix this for scalar
|
2018-05-15 22:47:22 +00:00
|
|
|
vtkm::exec::GradientOutput<T> PrepareForOutput(vtkm::Id size)
|
2017-05-31 19:03:03 +00:00
|
|
|
{
|
2018-05-15 22:47:22 +00:00
|
|
|
vtkm::exec::GradientOutput<T> portal(this->StoreGradient,
|
|
|
|
this->ComputeDivergence,
|
|
|
|
this->ComputeVorticity,
|
|
|
|
this->ComputeQCriterion,
|
|
|
|
this->Gradient,
|
|
|
|
this->Divergence,
|
|
|
|
this->Vorticity,
|
|
|
|
this->QCriterion,
|
|
|
|
size);
|
2017-05-31 19:03:03 +00:00
|
|
|
return portal;
|
|
|
|
}
|
|
|
|
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>> Gradient;
|
|
|
|
vtkm::cont::ArrayHandle<BaseTType> Divergence;
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec<BaseTType, 3>> Vorticity;
|
|
|
|
vtkm::cont::ArrayHandle<BaseTType> QCriterion;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool StoreGradient;
|
|
|
|
bool ComputeDivergence;
|
|
|
|
bool ComputeVorticity;
|
|
|
|
bool ComputeQCriterion;
|
|
|
|
};
|
2017-05-31 18:48:38 +00:00
|
|
|
class PointGradient
|
|
|
|
{
|
|
|
|
public:
|
2018-08-30 15:53:18 +00:00
|
|
|
template <typename CellSetType, typename CoordinateSystem, typename T, typename S>
|
2017-05-31 18:48:38 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>> Run(const CellSetType& cells,
|
|
|
|
const CoordinateSystem& coords,
|
2018-08-30 15:53:18 +00:00
|
|
|
const vtkm::cont::ArrayHandle<T, S>& field)
|
2017-05-31 19:03:03 +00:00
|
|
|
{
|
|
|
|
vtkm::worklet::GradientOutputFields<T> extraOutput(true, false, false, false);
|
2018-08-30 15:53:18 +00:00
|
|
|
return this->Run(cells, coords, field, extraOutput);
|
2017-05-31 19:03:03 +00:00
|
|
|
}
|
|
|
|
|
2018-08-30 15:53:18 +00:00
|
|
|
template <typename CellSetType, typename CoordinateSystem, typename T, typename S>
|
2017-05-31 19:03:03 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>> Run(const CellSetType& cells,
|
|
|
|
const CoordinateSystem& coords,
|
|
|
|
const vtkm::cont::ArrayHandle<T, S>& field,
|
2018-08-30 15:53:18 +00:00
|
|
|
GradientOutputFields<T>& extraOutput)
|
2017-05-31 18:48:38 +00:00
|
|
|
{
|
|
|
|
//we are using cast and call here as we pass the cells twice to the invoke
|
|
|
|
//and want the type resolved once before hand instead of twice
|
|
|
|
//by the dispatcher ( that will cost more in time and binary size )
|
2018-08-30 15:53:18 +00:00
|
|
|
gradient::DeducedPointGrad<CoordinateSystem, T, S> func(coords, field, &extraOutput);
|
2017-05-31 18:48:38 +00:00
|
|
|
vtkm::cont::CastAndCall(cells, func);
|
2017-05-31 19:03:03 +00:00
|
|
|
return extraOutput.Gradient;
|
2017-05-31 18:48:38 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class CellGradient
|
|
|
|
{
|
|
|
|
public:
|
2018-08-30 15:53:18 +00:00
|
|
|
template <typename CellSetType, typename CoordinateSystem, typename T, typename S>
|
2017-05-31 18:48:38 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>> Run(const CellSetType& cells,
|
|
|
|
const CoordinateSystem& coords,
|
2018-08-30 15:53:18 +00:00
|
|
|
const vtkm::cont::ArrayHandle<T, S>& field)
|
2017-05-31 18:48:38 +00:00
|
|
|
{
|
2017-05-31 19:03:03 +00:00
|
|
|
vtkm::worklet::GradientOutputFields<T> extra(true, false, false, false);
|
2018-08-30 15:53:18 +00:00
|
|
|
return this->Run(cells, coords, field, extra);
|
2016-12-23 14:12:37 +00:00
|
|
|
}
|
|
|
|
|
2018-08-30 15:53:18 +00:00
|
|
|
template <typename CellSetType, typename CoordinateSystem, typename T, typename S>
|
2017-05-31 19:03:03 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>> Run(const CellSetType& cells,
|
|
|
|
const CoordinateSystem& coords,
|
|
|
|
const vtkm::cont::ArrayHandle<T, S>& field,
|
2018-08-30 15:53:18 +00:00
|
|
|
GradientOutputFields<T>& extraOutput)
|
2016-12-23 14:12:37 +00:00
|
|
|
{
|
2020-03-19 12:32:43 +00:00
|
|
|
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::gradient::CellGradient> dispatcher;
|
2017-05-31 19:03:03 +00:00
|
|
|
dispatcher.Invoke(cells, coords, field, extraOutput);
|
|
|
|
return extraOutput.Gradient;
|
2016-12-23 14:12:37 +00:00
|
|
|
}
|
|
|
|
};
|
2016-11-10 16:32:46 +00:00
|
|
|
}
|
|
|
|
} // namespace vtkm::worklet
|
2016-10-19 22:42:58 +00:00
|
|
|
#endif
|