2016-12-14 16:00:07 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2016-12-14 16:00:07 +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.
|
|
|
|
//============================================================================
|
|
|
|
|
2019-10-07 19:39:02 +00:00
|
|
|
#ifndef vtk_m_filter_Gradient_hxx
|
|
|
|
#define vtk_m_filter_Gradient_hxx
|
|
|
|
|
2016-12-14 16:00:07 +00:00
|
|
|
#include <vtkm/cont/DynamicCellSet.h>
|
2018-04-02 21:58:21 +00:00
|
|
|
#include <vtkm/cont/ErrorFilterExecution.h>
|
2019-08-08 15:00:04 +00:00
|
|
|
|
2016-12-15 19:14:57 +00:00
|
|
|
#include <vtkm/worklet/Gradient.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2017-06-29 20:35:58 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2018-08-30 15:53:18 +00:00
|
|
|
template <typename T, typename S>
|
|
|
|
inline void transpose_3x3(vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Vec<T, 3>, 3>, S>& field)
|
2017-06-29 20:35:58 +00:00
|
|
|
{
|
|
|
|
vtkm::worklet::gradient::Transpose3x3<T> transpose;
|
2018-08-30 15:53:18 +00:00
|
|
|
transpose.Run(field);
|
2017-06-29 20:35:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2018-08-30 15:53:18 +00:00
|
|
|
template <typename T, typename S>
|
|
|
|
inline void transpose_3x3(vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, S>&)
|
2017-06-29 20:35:58 +00:00
|
|
|
{ //This is not a 3x3 matrix so no transpose needed
|
|
|
|
}
|
|
|
|
|
2016-12-15 19:14:57 +00:00
|
|
|
} //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
|
|
|
//-----------------------------------------------------------------------------
|
2018-08-30 15:53:18 +00:00
|
|
|
template <typename T, typename StorageType, typename DerivedPolicy>
|
2018-04-02 21:58:21 +00:00
|
|
|
inline vtkm::cont::DataSet 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,
|
2020-03-12 20:19:12 +00:00
|
|
|
vtkm::filter::PolicyBase<DerivedPolicy> policy)
|
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
|
|
|
{
|
2018-04-02 21:58:21 +00:00
|
|
|
throw vtkm::cont::ErrorFilterExecution("Point field expected.");
|
2016-12-14 16:00:07 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 23:04:54 +00:00
|
|
|
constexpr bool isVector = std::is_same<typename vtkm::VecTraits<T>::HasMultipleComponents,
|
|
|
|
vtkm::VecTraitsTagMultipleComponents>::value;
|
|
|
|
|
|
|
|
if (GetComputeQCriterion() && !isVector)
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorFilterExecution("scalar gradients can't generate qcriterion");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetComputeVorticity() && !isVector)
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorFilterExecution("scalar gradients can't generate vorticity");
|
|
|
|
}
|
|
|
|
|
2019-08-13 17:08:54 +00:00
|
|
|
const vtkm::cont::DynamicCellSet& cells = input.GetCellSet();
|
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
|
|
|
|
|
|
|
std::string outputName = this->GetOutputFieldName();
|
|
|
|
if (outputName.empty())
|
|
|
|
{
|
2017-05-31 19:03:03 +00:00
|
|
|
outputName = this->GradientsName;
|
2016-12-14 16:00:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//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-31 19:03:03 +00:00
|
|
|
vtkm::worklet::GradientOutputFields<T> gradientfields(this->GetComputeGradient(),
|
|
|
|
this->GetComputeDivergence(),
|
|
|
|
this->GetComputeVorticity(),
|
|
|
|
this->GetComputeQCriterion());
|
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-31 18:48:38 +00:00
|
|
|
vtkm::worklet::PointGradient gradient;
|
2019-09-09 22:08:11 +00:00
|
|
|
outArray = gradient.Run(
|
2020-05-15 23:47:30 +00:00
|
|
|
vtkm::filter::ApplyPolicyCellSet(cells, policy, *this), coords, inField, gradientfields);
|
2016-12-14 16:00:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-31 18:48:38 +00:00
|
|
|
vtkm::worklet::CellGradient gradient;
|
2019-09-09 22:08:11 +00:00
|
|
|
outArray = gradient.Run(
|
2020-05-15 23:47:30 +00:00
|
|
|
vtkm::filter::ApplyPolicyCellSet(cells, policy, *this), coords, inField, gradientfields);
|
2016-12-14 16:00:07 +00:00
|
|
|
}
|
2017-06-29 20:35:58 +00:00
|
|
|
if (!this->RowOrdering)
|
|
|
|
{
|
2018-08-30 15:53:18 +00:00
|
|
|
transpose_3x3(outArray);
|
2017-06-29 20:35:58 +00:00
|
|
|
}
|
|
|
|
|
2018-05-18 20:10:15 +00:00
|
|
|
vtkm::cont::Field::Association fieldAssociation(this->ComputePointGradient
|
|
|
|
? vtkm::cont::Field::Association::POINTS
|
|
|
|
: vtkm::cont::Field::Association::CELL_SET);
|
2019-08-12 19:46:55 +00:00
|
|
|
vtkm::cont::DataSet result;
|
|
|
|
result.CopyStructure(input);
|
2019-08-13 17:08:54 +00:00
|
|
|
result.AddField(vtkm::cont::Field{ outputName, fieldAssociation, outArray });
|
2016-12-14 16:00:07 +00:00
|
|
|
|
2017-05-31 19:03:03 +00:00
|
|
|
if (this->GetComputeDivergence() && isVector)
|
|
|
|
{
|
2019-08-13 17:08:54 +00:00
|
|
|
result.AddField(
|
|
|
|
vtkm::cont::Field{ this->GetDivergenceName(), fieldAssociation, gradientfields.Divergence });
|
2017-05-31 19:03:03 +00:00
|
|
|
}
|
|
|
|
if (this->GetComputeVorticity() && isVector)
|
|
|
|
{
|
2019-08-13 17:08:54 +00:00
|
|
|
result.AddField(
|
|
|
|
vtkm::cont::Field{ this->GetVorticityName(), fieldAssociation, gradientfields.Vorticity });
|
2017-05-31 19:03:03 +00:00
|
|
|
}
|
|
|
|
if (this->GetComputeQCriterion() && isVector)
|
|
|
|
{
|
2019-08-13 17:08:54 +00:00
|
|
|
result.AddField(
|
|
|
|
vtkm::cont::Field{ this->GetQCriterionName(), fieldAssociation, gradientfields.QCriterion });
|
2017-05-31 19:03:03 +00:00
|
|
|
}
|
2016-12-15 19:14:57 +00:00
|
|
|
return result;
|
2016-12-14 16:00:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::filter
|
2019-10-07 19:39:02 +00:00
|
|
|
|
|
|
|
#endif
|