vtk-m/vtkm/filter/GhostCellClassify.hxx

158 lines
5.1 KiB
C++
Raw Normal View History

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.
//============================================================================
#ifndef vtk_m_filter_GhostCellClassify_hxx
#define vtk_m_filter_GhostCellClassify_hxx
2019-02-07 20:26:20 +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>
#include <vtkm/worklet/WorkletPointNeighborhood.h>
2019-02-07 20:26:20 +00:00
namespace
{
2019-12-05 21:38:41 +00:00
struct TypeUInt8 : vtkm::List<vtkm::UInt8>
2019-02-07 20:26:20 +00:00
{
};
class SetStructuredGhostCells1D : public vtkm::worklet::WorkletPointNeighborhood
2019-02-07 20:26:20 +00:00
{
public:
SetStructuredGhostCells1D(vtkm::IdComponent numLayers = 1)
: NumLayers(numLayers)
2019-02-07 20:26:20 +00:00
{
}
using ControlSignature = void(CellSetIn, FieldOut);
using ExecutionSignature = void(Boundary, _2);
2019-02-07 20:26:20 +00:00
VTKM_EXEC void operator()(const vtkm::exec::BoundaryState& boundary, vtkm::UInt8& value) const
2019-02-07 20:26:20 +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:
vtkm::IdComponent NumLayers;
2019-02-07 20:26:20 +00:00
};
class SetStructuredGhostCells2D : public vtkm::worklet::WorkletPointNeighborhood
2019-02-07 20:26:20 +00:00
{
public:
SetStructuredGhostCells2D(vtkm::IdComponent numLayers = 1)
: NumLayers(numLayers)
2019-02-07 20:26:20 +00:00
{
}
using ControlSignature = void(CellSetIn, FieldOut);
using ExecutionSignature = void(Boundary, _2);
2019-02-07 20:26:20 +00:00
VTKM_EXEC void operator()(const vtkm::exec::BoundaryState& boundary, vtkm::UInt8& value) const
2019-02-07 20:26:20 +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:
vtkm::IdComponent NumLayers;
2019-02-07 20:26:20 +00:00
};
class SetStructuredGhostCells3D : public vtkm::worklet::WorkletPointNeighborhood
2019-02-07 20:26:20 +00:00
{
public:
SetStructuredGhostCells3D(vtkm::IdComponent numLayers = 1)
: NumLayers(numLayers)
2019-02-07 20:26:20 +00:00
{
}
using ControlSignature = void(CellSetIn, FieldOut);
using ExecutionSignature = void(Boundary, _2);
2019-02-07 20:26:20 +00:00
VTKM_EXEC void operator()(const vtkm::exec::BoundaryState& boundary, vtkm::UInt8& value) const
2019-02-07 20:26:20 +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:
vtkm::IdComponent NumLayers;
2019-02-07 20:26:20 +00:00
};
};
namespace vtkm
{
namespace filter
{
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
{
const vtkm::cont::DynamicCellSet& cellset = input.GetCellSet();
2019-02-07 20:26:20 +00:00
vtkm::cont::ArrayHandle<vtkm::UInt8> ghosts;
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>>();
//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>>();
//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>>();
//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-03-25 13:08:16 +00:00
throw vtkm::cont::ErrorFilterExecution("Unsupported cellset type for GhostCellClassify.");
}
2019-02-07 20:26:20 +00:00
return CreateResultFieldCell(input, ghosts, "vtkmGhostCells");
2019-02-07 20:26:20 +00:00
}
}
}
#endif