2016-12-14 16:00:07 +00:00
|
|
|
//============================================================================
|
|
|
|
// 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 2014 Sandia Corporation.
|
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
|
|
|
// Copyright 2014 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.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/cont/DynamicCellSet.h>
|
|
|
|
|
|
|
|
#include <vtkm/worklet/DispatcherMapTopology.h>
|
|
|
|
|
2016-12-15 19:14:57 +00:00
|
|
|
#include <vtkm/worklet/Gradient.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2016-12-14 16:00:07 +00:00
|
|
|
|
2016-12-15 19:14:57 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename DerivedPolicy, typename Device, typename T, typename S>
|
2016-12-14 16:00:07 +00:00
|
|
|
struct PointGrad
|
|
|
|
{
|
2017-05-26 17:53:28 +00:00
|
|
|
PointGrad(const vtkm::cont::CoordinateSystem& coords,
|
|
|
|
const vtkm::cont::ArrayHandle<T, S>& field,
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>* result)
|
|
|
|
: Points(&coords)
|
|
|
|
, InField(&field)
|
|
|
|
, Result(result)
|
2016-12-14 16:00:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename CellSetType>
|
|
|
|
void operator()(const CellSetType& cellset) const
|
2016-12-14 16:00:07 +00:00
|
|
|
{
|
2016-12-23 20:11:56 +00:00
|
|
|
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::PointGradient, Device> dispatcher;
|
2016-12-14 16:00:07 +00:00
|
|
|
dispatcher.Invoke(cellset, //topology to iterate on a per point basis
|
|
|
|
cellset, //whole cellset in
|
2017-05-26 17:53:28 +00:00
|
|
|
vtkm::filter::ApplyPolicy(*this->Points, this->Policy),
|
|
|
|
*this->InField,
|
2016-12-14 16:00:07 +00:00
|
|
|
*this->Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
vtkm::filter::PolicyBase<DerivedPolicy> Policy;
|
|
|
|
const vtkm::cont::CoordinateSystem* const Points;
|
2017-05-18 14:29:41 +00:00
|
|
|
const vtkm::cont::ArrayHandle<T, S>* const InField;
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>* Result;
|
2017-01-10 18:10:38 +00:00
|
|
|
|
|
|
|
private:
|
2017-05-18 14:29:41 +00:00
|
|
|
void operator=(const PointGrad<DerivedPolicy, Device, T, S>&) = delete;
|
2016-12-14 16:00:07 +00:00
|
|
|
};
|
|
|
|
|
2016-12-15 19:14:57 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename HandleType>
|
2017-05-26 17:53:28 +00:00
|
|
|
inline void add_field(vtkm::filter::ResultField& result,
|
|
|
|
const HandleType& handle,
|
2017-05-18 14:29:41 +00:00
|
|
|
const std::string name)
|
2016-12-15 19:14:57 +00:00
|
|
|
{
|
|
|
|
const vtkm::cont::Field::AssociationEnum assoc = result.GetField().GetAssociation();
|
2017-05-18 14:29:41 +00:00
|
|
|
if ((assoc == vtkm::cont::Field::ASSOC_WHOLE_MESH) || (assoc == vtkm::cont::Field::ASSOC_POINTS))
|
2016-12-15 19:14:57 +00:00
|
|
|
{
|
|
|
|
vtkm::cont::Field field(name, assoc, handle);
|
|
|
|
result.GetDataSet().AddField(field);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::Field field(name, assoc, result.GetField().GetAssocCellSet(), handle);
|
2016-12-15 19:14:57 +00:00
|
|
|
result.GetDataSet().AddField(field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T, typename S, typename DeviceAdapter>
|
|
|
|
inline void add_extra_vec_fields(
|
|
|
|
const vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Vec<T, 3>, 3>, S>& inField,
|
2017-05-26 17:53:28 +00:00
|
|
|
const vtkm::filter::Gradient* const filter,
|
|
|
|
vtkm::filter::ResultField& result,
|
2017-05-18 14:29:41 +00:00
|
|
|
const DeviceAdapter&)
|
2016-12-15 19:14:57 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
if (filter->GetComputeDivergence())
|
2016-12-23 14:12:37 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::ArrayHandle<T> divergence;
|
|
|
|
vtkm::worklet::DispatcherMapField<vtkm::worklet::Divergence, DeviceAdapter> dispatcher;
|
2016-12-23 14:12:37 +00:00
|
|
|
dispatcher.Invoke(inField, divergence);
|
|
|
|
|
|
|
|
add_field(result, divergence, filter->GetDivergenceName());
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
if (filter->GetComputeVorticity())
|
2016-12-15 19:14:57 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>> vorticity;
|
|
|
|
vtkm::worklet::DispatcherMapField<vtkm::worklet::Vorticity, DeviceAdapter> dispatcher;
|
2016-12-15 19:14:57 +00:00
|
|
|
dispatcher.Invoke(inField, vorticity);
|
2016-12-14 16:00:07 +00:00
|
|
|
|
2016-12-15 19:14:57 +00:00
|
|
|
add_field(result, vorticity, filter->GetVorticityName());
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
if (filter->GetComputeQCriterion())
|
2016-12-15 19:14:57 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::ArrayHandle<T> qc;
|
|
|
|
vtkm::worklet::DispatcherMapField<vtkm::worklet::QCriterion, DeviceAdapter> dispatcher;
|
2016-12-15 19:14:57 +00:00
|
|
|
dispatcher.Invoke(inField, qc);
|
|
|
|
|
|
|
|
add_field(result, qc, filter->GetQCriterionName());
|
|
|
|
}
|
2016-12-14 16:00:07 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T, typename S, typename DeviceAdapter>
|
|
|
|
inline void add_extra_vec_fields(const vtkm::cont::ArrayHandle<T, S>&,
|
2017-05-26 17:53:28 +00:00
|
|
|
const vtkm::filter::Gradient* const,
|
|
|
|
vtkm::filter::ResultField&,
|
2017-05-18 14:29:41 +00:00
|
|
|
const DeviceAdapter&)
|
2016-12-15 19:14:57 +00:00
|
|
|
{
|
|
|
|
//not a vector array handle so add nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace filter
|
|
|
|
{
|
2016-12-14 16:00:07 +00:00
|
|
|
|
2016-12-15 19:14:57 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
Gradient::Gradient()
|
|
|
|
: ComputePointGradient(false)
|
|
|
|
, ComputeVorticity(false)
|
|
|
|
, ComputeQCriterion(false)
|
|
|
|
, DivergenceName("Divergence")
|
|
|
|
, VorticityName("Vorticity")
|
|
|
|
, QCriterionName("QCriterion")
|
|
|
|
{
|
|
|
|
}
|
2016-12-15 19:14:57 +00:00
|
|
|
|
2016-12-14 16:00:07 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
|
|
|
|
inline vtkm::filter::ResultField Gradient::DoExecute(
|
2017-05-26 17:53:28 +00:00
|
|
|
const vtkm::cont::DataSet& input,
|
|
|
|
const vtkm::cont::ArrayHandle<T, StorageType>& inField,
|
2017-05-18 14:29:41 +00:00
|
|
|
const vtkm::filter::FieldMetadata& fieldMetadata,
|
2017-05-26 17:53:28 +00:00
|
|
|
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
|
|
|
|
const DeviceAdapter& adapter)
|
2016-12-14 16:00:07 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
if (!fieldMetadata.IsPointField())
|
2016-12-14 16:00:07 +00:00
|
|
|
{
|
|
|
|
//we currently only support point fields, as we need to write the
|
|
|
|
//worklet to efficiently map a cell field to the points of a cell
|
|
|
|
//without doing a memory explosion
|
|
|
|
return vtkm::filter::ResultField();
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
const vtkm::cont::DynamicCellSet& cells = input.GetCellSet(this->GetActiveCellSetIndex());
|
2016-12-14 16:00:07 +00:00
|
|
|
const vtkm::cont::CoordinateSystem& coords =
|
2017-05-18 14:29:41 +00:00
|
|
|
input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex());
|
2016-12-14 16:00:07 +00:00
|
|
|
|
|
|
|
vtkm::cont::Field::AssociationEnum fieldAssociation;
|
|
|
|
std::string outputName = this->GetOutputFieldName();
|
|
|
|
if (outputName.empty())
|
|
|
|
{
|
|
|
|
outputName = "Gradients";
|
|
|
|
}
|
|
|
|
|
|
|
|
//todo: we need to ask the policy what storage type we should be using
|
|
|
|
//If the input is implicit, we should know what to fall back to
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>> outArray;
|
|
|
|
if (this->ComputePointGradient)
|
2016-12-14 16:00:07 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
PointGrad<DerivedPolicy, DeviceAdapter, T, StorageType> func(coords, inField, &outArray);
|
|
|
|
vtkm::cont::CastAndCall(vtkm::filter::ApplyPolicy(cells, policy), func);
|
2016-12-14 16:00:07 +00:00
|
|
|
fieldAssociation = vtkm::cont::Field::ASSOC_POINTS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellGradient, DeviceAdapter> dispatcher;
|
|
|
|
dispatcher.Invoke(vtkm::filter::ApplyPolicy(cells, policy),
|
2017-05-26 17:53:28 +00:00
|
|
|
vtkm::filter::ApplyPolicy(coords, policy),
|
|
|
|
inField,
|
|
|
|
outArray);
|
2016-12-14 16:00:07 +00:00
|
|
|
fieldAssociation = vtkm::cont::Field::ASSOC_CELL_SET;
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::filter::ResultField result(input, outArray, outputName, fieldAssociation, cells.GetName());
|
2016-12-14 16:00:07 +00:00
|
|
|
|
2016-12-15 19:14:57 +00:00
|
|
|
//Add the vorticity and qcriterion fields if they are enabled to the result
|
|
|
|
add_extra_vec_fields(outArray, this, result, adapter);
|
|
|
|
|
|
|
|
return result;
|
2016-12-14 16:00:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::filter
|