2020-10-21 22:24:10 +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.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#ifndef vtk_m_filter_particle_density_cic_hxx
|
|
|
|
#define vtk_m_filter_particle_density_cic_hxx
|
|
|
|
|
2021-03-05 16:43:38 +00:00
|
|
|
#include <vtkm/cont/ArrayCopy.h>
|
2020-10-21 22:24:10 +00:00
|
|
|
#include <vtkm/cont/CellLocatorUniformGrid.h>
|
|
|
|
#include <vtkm/cont/DataSetBuilderUniform.h>
|
|
|
|
#include <vtkm/filter/PolicyBase.h>
|
2021-03-05 15:29:00 +00:00
|
|
|
#include <vtkm/worklet/WorkletMapField.h>
|
2020-10-21 22:24:10 +00:00
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace worklet
|
|
|
|
{
|
2021-03-05 15:29:00 +00:00
|
|
|
class CICWorklet : public vtkm::worklet::WorkletMapField
|
2020-10-21 22:24:10 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-03-05 15:29:00 +00:00
|
|
|
using ControlSignature = void(FieldIn coords,
|
|
|
|
FieldIn field,
|
|
|
|
ExecObject locator,
|
|
|
|
WholeCellSetIn<Cell, Point> cellSet,
|
|
|
|
AtomicArrayInOut density);
|
|
|
|
using ExecutionSignature = void(_1, _2, _3, _4, _5);
|
|
|
|
|
|
|
|
template <typename Point,
|
|
|
|
typename T,
|
|
|
|
typename CellLocatorExecObj,
|
|
|
|
typename CellSet,
|
|
|
|
typename AtomicArray>
|
|
|
|
VTKM_EXEC void operator()(const Point& point,
|
|
|
|
const T value,
|
|
|
|
const CellLocatorExecObj& locator,
|
|
|
|
const CellSet& cellSet,
|
|
|
|
AtomicArray& density) const
|
|
|
|
{
|
|
|
|
vtkm::Id cellId{};
|
|
|
|
vtkm::Vec3f parametric;
|
|
|
|
|
|
|
|
if (locator.FindCell(point, cellId, parametric) == vtkm::ErrorCode::Success)
|
|
|
|
{
|
|
|
|
// iterate through all the points of the cell and deposit with correct weight.
|
|
|
|
auto indices = cellSet.GetIndices(cellId);
|
2021-03-19 18:48:51 +00:00
|
|
|
auto rparametric = vtkm::Vec3f{ 1, 1, 1 } - parametric;
|
2021-03-05 15:29:00 +00:00
|
|
|
|
|
|
|
// deposit the scalar field value in proportion to the volume of the sub-hexahedron
|
|
|
|
// the vertex is in.
|
|
|
|
density.Add(indices[0], value * parametric[0] * parametric[1] * parametric[2]);
|
2021-03-19 18:48:51 +00:00
|
|
|
density.Add(indices[1], value * rparametric[0] * parametric[1] * parametric[2]);
|
|
|
|
density.Add(indices[2], value * rparametric[0] * rparametric[1] * parametric[2]);
|
|
|
|
density.Add(indices[3], value * parametric[0] * rparametric[1] * parametric[2]);
|
2021-03-05 15:29:00 +00:00
|
|
|
|
2021-03-19 18:48:51 +00:00
|
|
|
density.Add(indices[4], value * parametric[0] * parametric[1] * rparametric[2]);
|
|
|
|
density.Add(indices[5], value * rparametric[0] * parametric[1] * rparametric[2]);
|
|
|
|
density.Add(indices[6], value * rparametric[0] * rparametric[1] * rparametric[2]);
|
|
|
|
density.Add(indices[7], value * parametric[0] * rparametric[1] * rparametric[2]);
|
2021-03-05 15:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We simply ignore that particular particle when it is not in the mesh.
|
|
|
|
}
|
2020-10-21 22:24:10 +00:00
|
|
|
};
|
|
|
|
} // worklet
|
|
|
|
} // vtkm
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace filter
|
|
|
|
{
|
|
|
|
inline VTKM_CONT ParticleDensityCloudInCell::ParticleDensityCloudInCell(const vtkm::Id3& dimension,
|
|
|
|
const vtkm::Vec3f& origin,
|
|
|
|
const vtkm::Vec3f& spacing)
|
2021-03-18 22:44:23 +00:00
|
|
|
: Superclass(dimension, origin, spacing)
|
2020-10-21 22:24:10 +00:00
|
|
|
{
|
|
|
|
}
|
2021-03-05 15:29:00 +00:00
|
|
|
|
2021-03-18 22:44:23 +00:00
|
|
|
inline VTKM_CONT ParticleDensityCloudInCell::ParticleDensityCloudInCell(const Id3& dimension,
|
|
|
|
const vtkm::Bounds& bounds)
|
|
|
|
: Superclass(dimension, bounds)
|
|
|
|
{
|
|
|
|
}
|
2021-03-05 15:29:00 +00:00
|
|
|
|
2020-10-21 22:24:10 +00:00
|
|
|
template <typename T, typename StorageType, typename Policy>
|
2021-03-05 15:29:00 +00:00
|
|
|
inline VTKM_CONT vtkm::cont::DataSet ParticleDensityCloudInCell::DoExecute(
|
|
|
|
const cont::DataSet& dataSet,
|
2020-10-21 22:24:10 +00:00
|
|
|
const cont::ArrayHandle<T, StorageType>& field,
|
2021-03-05 15:29:00 +00:00
|
|
|
const vtkm::filter::FieldMetadata&,
|
|
|
|
PolicyBase<Policy>)
|
2020-10-21 22:24:10 +00:00
|
|
|
{
|
|
|
|
// Unlike ParticleDensityNGP, particle deposit mass on the grid points, thus it is natural to
|
|
|
|
// return the density as PointField;
|
2021-03-05 15:29:00 +00:00
|
|
|
auto uniform = vtkm::cont::DataSetBuilderUniform::Create(
|
|
|
|
this->Dimension + vtkm::Id3{ 1, 1, 1 }, this->Origin, this->Spacing);
|
2020-10-21 22:24:10 +00:00
|
|
|
|
|
|
|
vtkm::cont::CellLocatorUniformGrid locator;
|
|
|
|
locator.SetCellSet(uniform.GetCellSet());
|
|
|
|
locator.SetCoordinates(uniform.GetCoordinateSystem());
|
|
|
|
locator.Update();
|
|
|
|
|
2021-03-23 15:31:55 +00:00
|
|
|
auto coords = dataSet.GetCoordinateSystem().GetDataAsMultiplexer();
|
2021-03-05 15:29:00 +00:00
|
|
|
|
|
|
|
vtkm::cont::ArrayHandle<T> density;
|
|
|
|
vtkm::cont::ArrayCopy(vtkm::cont::ArrayHandleConstant<T>(0, uniform.GetNumberOfPoints()),
|
2020-10-21 22:24:10 +00:00
|
|
|
density);
|
|
|
|
|
2021-04-23 15:48:29 +00:00
|
|
|
this->Invoke(vtkm::worklet::CICWorklet{},
|
|
|
|
coords,
|
|
|
|
field,
|
|
|
|
locator,
|
2022-01-04 23:42:55 +00:00
|
|
|
uniform.GetCellSet().template AsCellSet<vtkm::cont::CellSetStructured<3>>(),
|
2021-04-23 15:48:29 +00:00
|
|
|
density);
|
2020-10-21 22:24:10 +00:00
|
|
|
|
2021-03-18 22:44:23 +00:00
|
|
|
if (DivideByVolume)
|
|
|
|
{
|
|
|
|
auto volume = this->Spacing[0] * this->Spacing[1] * this->Spacing[2];
|
|
|
|
this->Invoke(DivideByVolumeWorklet{ volume }, density);
|
|
|
|
}
|
|
|
|
|
2020-10-21 22:24:10 +00:00
|
|
|
uniform.AddField(vtkm::cont::make_FieldPoint("density", density));
|
|
|
|
|
|
|
|
return uniform;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // vtk_m_filter_particle_density_cic_hxx
|