mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Merge topic 'worklet_run'
2f62e8c28 minor change based on code review b8c39f4f9 de-template CellSetConnectivity::Run 386c633d6 simplify ThresholdWorklet::Run Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !2846
This commit is contained in:
commit
e42b1d00b4
@ -21,7 +21,7 @@ VTKM_CONT vtkm::cont::DataSet CellSetConnectivity::DoExecute(const vtkm::cont::D
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> component;
|
||||
|
||||
vtkm::worklet::connectivity::CellSetConnectivity().Run(input.GetCellSet(), component);
|
||||
vtkm::worklet::connectivity::CellSetConnectivity::Run(input.GetCellSet(), component);
|
||||
|
||||
return this->CreateResultFieldCell(input, this->GetOutputFieldName(), component);
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ public:
|
||||
vtkm::cont::ArrayHandle<int> conns_h = vtkm::cont::make_ArrayHandle(conns, vtkm::CopyFlag::Off);
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> comps_h;
|
||||
vtkm::worklet::connectivity::GraphConnectivity().Run(counts_h, offsets_h, conns_h, comps_h);
|
||||
vtkm::worklet::connectivity::GraphConnectivity::Run(counts_h, offsets_h, conns_h, comps_h);
|
||||
|
||||
VTKM_TEST_ASSERT(vtkm::cont::Algorithm::Reduce(comps_h, vtkm::Id(0), vtkm::Maximum{}) ==
|
||||
ncomps - 1,
|
||||
|
@ -23,17 +23,17 @@ namespace connectivity
|
||||
class CellSetConnectivity
|
||||
{
|
||||
public:
|
||||
template <typename CellSetType>
|
||||
void Run(const CellSetType& cellSet, vtkm::cont::ArrayHandle<vtkm::Id>& componentArray) const
|
||||
static void Run(const vtkm::cont::UnknownCellSet& cellSet,
|
||||
vtkm::cont::ArrayHandle<vtkm::Id>& componentArray)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> numIndicesArray;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> indexOffsetsArray;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> connectivityArray;
|
||||
|
||||
// create cell to cell connectivity graph (dual graph)
|
||||
CellSetDualGraph().Run(cellSet, numIndicesArray, indexOffsetsArray, connectivityArray);
|
||||
CellSetDualGraph::Run(cellSet, numIndicesArray, indexOffsetsArray, connectivityArray);
|
||||
// find the connected component of the dual graph
|
||||
GraphConnectivity().Run(numIndicesArray, indexOffsetsArray, connectivityArray, componentArray);
|
||||
GraphConnectivity::Run(numIndicesArray, indexOffsetsArray, connectivityArray, componentArray);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -99,19 +99,11 @@ struct CellToCellConnectivity : public vtkm::worklet::WorkletMapField
|
||||
|
||||
class CellSetDualGraph
|
||||
{
|
||||
public:
|
||||
using Algorithm = vtkm::cont::Algorithm;
|
||||
|
||||
struct degree2
|
||||
{
|
||||
VTKM_EXEC
|
||||
bool operator()(vtkm::Id degree) const { return degree >= 2; }
|
||||
};
|
||||
|
||||
template <typename CellSet>
|
||||
void EdgeToCellConnectivity(const CellSet& cellSet,
|
||||
vtkm::cont::ArrayHandle<vtkm::Id>& cellIds,
|
||||
vtkm::cont::ArrayHandle<vtkm::Id2>& cellEdges) const
|
||||
static void EdgeToCellConnectivity(const vtkm::cont::UnknownCellSet& cellSet,
|
||||
vtkm::cont::ArrayHandle<vtkm::Id>& cellIds,
|
||||
vtkm::cont::ArrayHandle<vtkm::Id2>& cellEdges)
|
||||
{
|
||||
// Get number of edges for each cell and use it as scatter count.
|
||||
vtkm::cont::ArrayHandle<vtkm::IdComponent> numEdgesPerCell;
|
||||
@ -124,11 +116,17 @@ public:
|
||||
edgeExtractDisp.Invoke(cellSet, cellIds, cellEdges);
|
||||
}
|
||||
|
||||
template <typename CellSetType>
|
||||
void Run(const CellSetType& cellSet,
|
||||
vtkm::cont::ArrayHandle<vtkm::Id>& numIndicesArray,
|
||||
vtkm::cont::ArrayHandle<vtkm::Id>& indexOffsetArray,
|
||||
vtkm::cont::ArrayHandle<vtkm::Id>& connectivityArray) const
|
||||
public:
|
||||
struct degree2
|
||||
{
|
||||
VTKM_EXEC
|
||||
bool operator()(vtkm::Id degree) const { return degree >= 2; }
|
||||
};
|
||||
|
||||
static void Run(const vtkm::cont::UnknownCellSet& cellSet,
|
||||
vtkm::cont::ArrayHandle<vtkm::Id>& numIndicesArray,
|
||||
vtkm::cont::ArrayHandle<vtkm::Id>& indexOffsetArray,
|
||||
vtkm::cont::ArrayHandle<vtkm::Id>& connectivityArray)
|
||||
{
|
||||
// calculate the uncompressed Edge to Cell connectivity from Point to Cell connectivity
|
||||
// in the CellSet
|
||||
|
@ -69,10 +69,10 @@ class GraphConnectivity
|
||||
{
|
||||
public:
|
||||
template <typename InputArrayType, typename OutputArrayType>
|
||||
void Run(const InputArrayType& numIndicesArray,
|
||||
const InputArrayType& indexOffsetsArray,
|
||||
const InputArrayType& connectivityArray,
|
||||
OutputArrayType& componentsOut) const
|
||||
static void Run(const InputArrayType& numIndicesArray,
|
||||
const InputArrayType& indexOffsetsArray,
|
||||
const InputArrayType& connectivityArray,
|
||||
OutputArrayType& componentsOut)
|
||||
{
|
||||
VTKM_IS_ARRAY_HANDLE(InputArrayType);
|
||||
VTKM_IS_ARRAY_HANDLE(OutputArrayType);
|
||||
|
@ -352,17 +352,12 @@ VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute(const vtkm::cont::DataS
|
||||
|
||||
if (this->GetRemoveAllGhost())
|
||||
{
|
||||
cellOut = worklet.Run(cells.ResetCellSetList<VTKM_DEFAULT_CELL_SET_LIST>(),
|
||||
fieldArray,
|
||||
field.GetAssociation(),
|
||||
RemoveAllGhosts());
|
||||
cellOut = worklet.Run(cells, fieldArray, field.GetAssociation(), RemoveAllGhosts());
|
||||
}
|
||||
else if (this->GetRemoveByType())
|
||||
{
|
||||
cellOut = worklet.Run(cells.ResetCellSetList<VTKM_DEFAULT_CELL_SET_LIST>(),
|
||||
fieldArray,
|
||||
field.GetAssociation(),
|
||||
RemoveGhostByType(this->GetRemoveType()));
|
||||
cellOut = worklet.Run(
|
||||
cells, fieldArray, field.GetAssociation(), RemoveGhostByType(this->GetRemoveType()));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -83,15 +83,8 @@ vtkm::cont::DataSet Threshold::DoExecute(const vtkm::cont::DataSet& input)
|
||||
vtkm::cont::UnknownCellSet cellOut;
|
||||
|
||||
auto resolveArrayType = [&](const auto& concrete) {
|
||||
// Note: there are two overloads of .Run, the first one taking an UncertainCellSet, which is
|
||||
// the desired entry point in the following call. The other is a function template on the input
|
||||
// CellSet. Without the call to .ResetCellSetList to turn an UnknownCellSet to an UncertainCellSet,
|
||||
// the compiler will pick the function template (i.e. wrong overload).
|
||||
cellOut = worklet.Run(cells.ResetCellSetList<VTKM_DEFAULT_CELL_SET_LIST>(),
|
||||
concrete,
|
||||
field.GetAssociation(),
|
||||
predicate,
|
||||
this->GetAllInRange());
|
||||
cellOut =
|
||||
worklet.Run(cells, concrete, field.GetAssociation(), predicate, this->GetAllInRange());
|
||||
};
|
||||
|
||||
field.GetData().CastAndCallForTypes<vtkm::TypeListScalarAll, VTKM_DEFAULT_STORAGE_LIST>(
|
||||
|
@ -30,12 +30,6 @@ namespace worklet
|
||||
class Threshold
|
||||
{
|
||||
public:
|
||||
enum class FieldType
|
||||
{
|
||||
Point,
|
||||
Cell
|
||||
};
|
||||
|
||||
template <typename UnaryPredicate>
|
||||
class ThresholdByPointField : public vtkm::worklet::WorkletVisitCellsWithPoints
|
||||
{
|
||||
@ -84,22 +78,8 @@ public:
|
||||
bool ReturnAllInRange;
|
||||
};
|
||||
|
||||
struct ThresholdCopy : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
using ControlSignature = void(FieldIn, FieldOut, WholeArrayIn);
|
||||
|
||||
template <typename ScalarType, typename WholeFieldIn>
|
||||
VTKM_EXEC void operator()(vtkm::Id& index,
|
||||
ScalarType& output,
|
||||
const WholeFieldIn& inputField) const
|
||||
{
|
||||
output = inputField.Get(index);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename CellSetType, typename ValueType, typename StorageType, typename UnaryPredicate>
|
||||
vtkm::cont::CellSetPermutation<CellSetType> Run(
|
||||
vtkm::cont::CellSetPermutation<CellSetType> RunImpl(
|
||||
const CellSetType& cellSet,
|
||||
const vtkm::cont::ArrayHandle<ValueType, StorageType>& field,
|
||||
const vtkm::cont::Field::Association fieldType,
|
||||
@ -141,53 +121,18 @@ public:
|
||||
return OutputType(this->ValidCellIds, cellSet);
|
||||
}
|
||||
|
||||
template <typename FieldArrayType, typename UnaryPredicate>
|
||||
struct CallWorklet
|
||||
{
|
||||
vtkm::cont::UnknownCellSet& Output;
|
||||
vtkm::worklet::Threshold& Worklet;
|
||||
const FieldArrayType& Field;
|
||||
const vtkm::cont::Field::Association FieldType;
|
||||
const UnaryPredicate& Predicate;
|
||||
const bool ReturnAllInRange;
|
||||
|
||||
CallWorklet(vtkm::cont::UnknownCellSet& output,
|
||||
vtkm::worklet::Threshold& worklet,
|
||||
const FieldArrayType& field,
|
||||
const vtkm::cont::Field::Association fieldType,
|
||||
const UnaryPredicate& predicate,
|
||||
const bool returnAllInRange)
|
||||
: Output(output)
|
||||
, Worklet(worklet)
|
||||
, Field(field)
|
||||
, FieldType(fieldType)
|
||||
, Predicate(predicate)
|
||||
, ReturnAllInRange(returnAllInRange)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename CellSetType>
|
||||
void operator()(const CellSetType& cellSet) const
|
||||
{
|
||||
// Copy output to an explicit grid so that other units can guess what this is.
|
||||
this->Output = vtkm::worklet::CellDeepCopy::Run(this->Worklet.Run(
|
||||
cellSet, this->Field, this->FieldType, this->Predicate, this->ReturnAllInRange));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename CellSetList, typename ValueType, typename StorageType, typename UnaryPredicate>
|
||||
vtkm::cont::UnknownCellSet Run(const vtkm::cont::UncertainCellSet<CellSetList>& cellSet,
|
||||
template <typename ValueType, typename StorageType, typename UnaryPredicate>
|
||||
vtkm::cont::UnknownCellSet Run(const vtkm::cont::UnknownCellSet& cellSet,
|
||||
const vtkm::cont::ArrayHandle<ValueType, StorageType>& field,
|
||||
const vtkm::cont::Field::Association fieldType,
|
||||
const UnaryPredicate& predicate,
|
||||
const bool returnAllInRange = false)
|
||||
{
|
||||
using Worker = CallWorklet<vtkm::cont::ArrayHandle<ValueType, StorageType>, UnaryPredicate>;
|
||||
|
||||
vtkm::cont::UnknownCellSet output;
|
||||
Worker worker(output, *this, field, fieldType, predicate, returnAllInRange);
|
||||
cellSet.CastAndCall(worker);
|
||||
|
||||
CastAndCall(cellSet, [&](auto concrete) {
|
||||
output = vtkm::worklet::CellDeepCopy::Run(
|
||||
this->template RunImpl(concrete, field, fieldType, predicate, returnAllInRange));
|
||||
});
|
||||
return output;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user