2019-02-07 20:26:20 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2019-02-07 20:26:20 +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-03-21 21:00:09 +00:00
|
|
|
#include <vtkm/CellClassification.h>
|
2019-02-07 20:26:20 +00:00
|
|
|
#include <vtkm/RangeId.h>
|
|
|
|
#include <vtkm/RangeId2.h>
|
|
|
|
#include <vtkm/RangeId3.h>
|
|
|
|
#include <vtkm/Types.h>
|
|
|
|
#include <vtkm/cont/ArrayCopy.h>
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
2019-03-29 18:45:10 +00:00
|
|
|
|
2019-09-10 19:00:53 +00:00
|
|
|
#include <vtkm/worklet/WorkletPointNeighborhood.h>
|
2019-02-07 20:26:20 +00:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
struct TypeUInt8 : vtkm::ListTagBase<vtkm::UInt8>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2019-09-10 19:00:53 +00:00
|
|
|
class SetStructuredGhostCells1D : public vtkm::worklet::WorkletPointNeighborhood
|
2019-02-07 20:26:20 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-09-10 19:00:53 +00:00
|
|
|
SetStructuredGhostCells1D(vtkm::IdComponent numLayers = 1)
|
|
|
|
: NumLayers(numLayers)
|
2019-02-07 20:26:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-09-10 19:00:53 +00:00
|
|
|
using ControlSignature = void(CellSetIn, FieldOut);
|
|
|
|
using ExecutionSignature = void(Boundary, _2);
|
2019-02-07 20:26:20 +00:00
|
|
|
|
2019-09-10 19:00:53 +00:00
|
|
|
VTKM_EXEC void operator()(const vtkm::exec::BoundaryState& boundary, vtkm::UInt8& value) const
|
2019-02-07 20:26:20 +00:00
|
|
|
{
|
2019-09-10 19:00:53 +00:00
|
|
|
const bool notOnBoundary = boundary.IsRadiusInXBoundary(this->NumLayers);
|
|
|
|
value = (notOnBoundary) ? vtkm::CellClassification::NORMAL : vtkm::CellClassification::GHOST;
|
2019-02-07 20:26:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-09-10 19:00:53 +00:00
|
|
|
vtkm::IdComponent NumLayers;
|
2019-02-07 20:26:20 +00:00
|
|
|
};
|
|
|
|
|
2019-09-10 19:00:53 +00:00
|
|
|
class SetStructuredGhostCells2D : public vtkm::worklet::WorkletPointNeighborhood
|
2019-02-07 20:26:20 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-09-10 19:00:53 +00:00
|
|
|
SetStructuredGhostCells2D(vtkm::IdComponent numLayers = 1)
|
|
|
|
: NumLayers(numLayers)
|
2019-02-07 20:26:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-09-10 19:00:53 +00:00
|
|
|
using ControlSignature = void(CellSetIn, FieldOut);
|
|
|
|
using ExecutionSignature = void(Boundary, _2);
|
2019-02-07 20:26:20 +00:00
|
|
|
|
2019-09-10 19:00:53 +00:00
|
|
|
VTKM_EXEC void operator()(const vtkm::exec::BoundaryState& boundary, vtkm::UInt8& value) const
|
2019-02-07 20:26:20 +00:00
|
|
|
{
|
2019-09-10 19:00:53 +00:00
|
|
|
const bool notOnBoundary = boundary.IsRadiusInXBoundary(this->NumLayers) &&
|
|
|
|
boundary.IsRadiusInYBoundary(this->NumLayers);
|
|
|
|
value = (notOnBoundary) ? vtkm::CellClassification::NORMAL : vtkm::CellClassification::GHOST;
|
2019-02-07 20:26:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-09-10 19:00:53 +00:00
|
|
|
vtkm::IdComponent NumLayers;
|
2019-02-07 20:26:20 +00:00
|
|
|
};
|
|
|
|
|
2019-09-10 19:00:53 +00:00
|
|
|
class SetStructuredGhostCells3D : public vtkm::worklet::WorkletPointNeighborhood
|
2019-02-07 20:26:20 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-09-10 19:00:53 +00:00
|
|
|
SetStructuredGhostCells3D(vtkm::IdComponent numLayers = 1)
|
|
|
|
: NumLayers(numLayers)
|
2019-02-07 20:26:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-09-10 19:00:53 +00:00
|
|
|
using ControlSignature = void(CellSetIn, FieldOut);
|
|
|
|
using ExecutionSignature = void(Boundary, _2);
|
2019-02-07 20:26:20 +00:00
|
|
|
|
2019-09-10 19:00:53 +00:00
|
|
|
VTKM_EXEC void operator()(const vtkm::exec::BoundaryState& boundary, vtkm::UInt8& value) const
|
2019-02-07 20:26:20 +00:00
|
|
|
{
|
2019-09-10 19:00:53 +00:00
|
|
|
const bool notOnBoundary = boundary.IsRadiusInBoundary(this->NumLayers);
|
|
|
|
value = (notOnBoundary) ? vtkm::CellClassification::NORMAL : vtkm::CellClassification::GHOST;
|
2019-02-07 20:26:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-09-10 19:00:53 +00:00
|
|
|
vtkm::IdComponent NumLayers;
|
2019-02-07 20:26:20 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace filter
|
|
|
|
{
|
|
|
|
|
2019-03-25 13:08:16 +00:00
|
|
|
inline VTKM_CONT GhostCellClassify::GhostCellClassify()
|
2019-02-07 20:26:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Policy>
|
2019-03-25 13:08:16 +00:00
|
|
|
inline VTKM_CONT vtkm::cont::DataSet GhostCellClassify::DoExecute(const vtkm::cont::DataSet& input,
|
|
|
|
vtkm::filter::PolicyBase<Policy>)
|
2019-02-07 20:26:20 +00:00
|
|
|
{
|
2019-08-13 17:08:54 +00:00
|
|
|
const vtkm::cont::DynamicCellSet& cellset = input.GetCellSet();
|
2019-02-07 20:26:20 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::UInt8> ghosts;
|
2019-09-10 19:00:53 +00:00
|
|
|
const vtkm::Id numCells = cellset.GetNumberOfCells();
|
2019-02-07 20:26:20 +00:00
|
|
|
|
|
|
|
//Structured cases are easy...
|
|
|
|
if (cellset.template IsType<vtkm::cont::CellSetStructured<1>>())
|
|
|
|
{
|
|
|
|
if (numCells <= 2)
|
2019-03-25 13:08:16 +00:00
|
|
|
throw vtkm::cont::ErrorFilterExecution("insufficient number of cells for GhostCellClassify.");
|
2019-02-07 20:26:20 +00:00
|
|
|
|
|
|
|
vtkm::cont::CellSetStructured<1> cellset1d = cellset.Cast<vtkm::cont::CellSetStructured<1>>();
|
2019-09-10 19:00:53 +00:00
|
|
|
|
|
|
|
//We use the dual of the cellset since we are using the PointNeighborhood worklet
|
|
|
|
vtkm::cont::CellSetStructured<3> dual;
|
|
|
|
const auto dim = cellset1d.GetCellDimensions();
|
|
|
|
dual.SetPointDimensions(vtkm::Id3{ dim, 1, 1 });
|
|
|
|
this->Invoke(SetStructuredGhostCells1D{}, dual, ghosts);
|
2019-02-07 20:26:20 +00:00
|
|
|
}
|
|
|
|
else if (cellset.template IsType<vtkm::cont::CellSetStructured<2>>())
|
|
|
|
{
|
|
|
|
if (numCells <= 4)
|
2019-03-25 13:08:16 +00:00
|
|
|
throw vtkm::cont::ErrorFilterExecution("insufficient number of cells for GhostCellClassify.");
|
2019-02-07 20:26:20 +00:00
|
|
|
|
|
|
|
vtkm::cont::CellSetStructured<2> cellset2d = cellset.Cast<vtkm::cont::CellSetStructured<2>>();
|
2019-09-10 19:00:53 +00:00
|
|
|
|
|
|
|
//We use the dual of the cellset since we are using the PointNeighborhood worklet
|
|
|
|
vtkm::cont::CellSetStructured<3> dual;
|
|
|
|
const auto dims = cellset2d.GetCellDimensions();
|
|
|
|
dual.SetPointDimensions(vtkm::Id3{ dims[0], dims[1], 1 });
|
|
|
|
this->Invoke(SetStructuredGhostCells2D{}, dual, ghosts);
|
2019-02-07 20:26:20 +00:00
|
|
|
}
|
|
|
|
else if (cellset.template IsType<vtkm::cont::CellSetStructured<3>>())
|
|
|
|
{
|
|
|
|
if (numCells <= 8)
|
2019-03-25 13:08:16 +00:00
|
|
|
throw vtkm::cont::ErrorFilterExecution("insufficient number of cells for GhostCellClassify.");
|
2019-02-07 20:26:20 +00:00
|
|
|
|
|
|
|
vtkm::cont::CellSetStructured<3> cellset3d = cellset.Cast<vtkm::cont::CellSetStructured<3>>();
|
2019-09-10 19:00:53 +00:00
|
|
|
|
|
|
|
//We use the dual of the cellset since we are using the PointNeighborhood worklet
|
|
|
|
vtkm::cont::CellSetStructured<3> dual;
|
|
|
|
dual.SetPointDimensions(cellset3d.GetCellDimensions());
|
|
|
|
this->Invoke(SetStructuredGhostCells3D{}, dual, ghosts);
|
2019-02-07 20:26:20 +00:00
|
|
|
}
|
|
|
|
else
|
2019-08-07 16:54:47 +00:00
|
|
|
{
|
2019-03-25 13:08:16 +00:00
|
|
|
throw vtkm::cont::ErrorFilterExecution("Unsupported cellset type for GhostCellClassify.");
|
2019-08-07 16:54:47 +00:00
|
|
|
}
|
2019-02-07 20:26:20 +00:00
|
|
|
|
2019-08-13 17:08:54 +00:00
|
|
|
return CreateResultFieldCell(input, ghosts, "vtkmGhostCells");
|
2019-02-07 20:26:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|