Stylistic changes to CellLocators to match VTK-m

This commit is contained in:
Sujin Philip 2019-03-28 08:27:37 -04:00
parent f350517de2
commit ee838b8296
7 changed files with 150 additions and 201 deletions

@ -26,10 +26,8 @@
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/cont/ExecutionObjectBase.h>
#include <vtkm/cont/VirtualObjectHandle.h>
#include <vtkm/exec/CellLocator.h>
#include <vtkm/exec/CellLocatorBoundingIntervalHierarchyExec.h>
namespace vtkm
{
@ -47,7 +45,7 @@ public:
void SetCellSet(const vtkm::cont::DynamicCellSet& cellSet)
{
this->CellSet = cellSet;
this->SetDirty();
this->SetModified();
}
vtkm::cont::CoordinateSystem GetCoordinates() const { return this->Coords; }
@ -55,37 +53,32 @@ public:
void SetCoordinates(const vtkm::cont::CoordinateSystem& coords)
{
this->Coords = coords;
this->SetDirty();
this->SetModified();
}
void Update()
{
if (this->Dirty)
if (this->Modified)
{
this->Build();
this->Dirty = false;
this->Modified = false;
}
}
VTKM_CONT const vtkm::exec::CellLocator* PrepareForExecution(
const vtkm::cont::DeviceAdapterId device) const
{
return this->PrepareForExecutionImpl(device).PrepareForExecution(device);
}
using HandleType = vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator>;
VTKM_CONT virtual const vtkm::exec::CellLocator* PrepareForExecution(
vtkm::cont::DeviceAdapterId device) const = 0;
protected:
void SetDirty() { this->Dirty = true; }
void SetModified() { this->Modified = true; }
bool GetModified() const { return this->Modified; }
//This is going to need a TryExecute
VTKM_CONT virtual void Build() = 0;
VTKM_CONT virtual const HandleType PrepareForExecutionImpl(
const vtkm::cont::DeviceAdapterId device) const = 0;
private:
vtkm::cont::DynamicCellSet CellSet;
vtkm::cont::CoordinateSystem Coords;
bool Dirty = true;
bool Modified = true;
};
} // namespace cont

@ -45,7 +45,6 @@ namespace cont
using IdArrayHandle = vtkm::cont::ArrayHandle<vtkm::Id>;
using IdPermutationArrayHandle = vtkm::cont::ArrayHandlePermutation<IdArrayHandle, IdArrayHandle>;
using BoundsArrayHandle = vtkm::cont::ArrayHandle<vtkm::Bounds>;
using CoordsArrayHandle = vtkm::cont::ArrayHandle<vtkm::FloatDefault>;
using CoordsPermutationArrayHandle =
vtkm::cont::ArrayHandlePermutation<IdArrayHandle, CoordsArrayHandle>;
@ -58,8 +57,6 @@ using SplitPermutationArrayHandle =
vtkm::cont::ArrayHandlePermutation<IdArrayHandle, SplitArrayHandle>;
using SplitPropertiesArrayHandle =
vtkm::cont::ArrayHandle<vtkm::worklet::spatialstructure::SplitProperties>;
using HandleType = vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator>;
namespace
{
@ -458,83 +455,44 @@ void CellLocatorBoundingIntervalHierarchy::Build()
//std::cout << "Total time: " << totalTimer.GetElapsedTime() << "\n";
}
class CellLocatorBoundingIntervalHierarchy::PrepareForExecutionFunctor
struct CellLocatorBoundingIntervalHierarchy::MakeExecObject
{
public:
template <typename DeviceAdapter>
VTKM_CONT bool operator()(DeviceAdapter,
const vtkm::cont::CellLocatorBoundingIntervalHierarchy& bih,
HandleType& bihExec) const
using NodeArrayHandle =
vtkm::cont::ArrayHandle<vtkm::exec::CellLocatorBoundingIntervalHierarchyNode>;
template <typename CellSetType, typename DeviceAdapter>
void operator()(const CellSetType& cellset,
const vtkm::cont::CellLocatorBoundingIntervalHierarchy& bih,
DeviceAdapter device) const
{
vtkm::cont::DynamicCellSet cellSet = bih.GetCellSet();
if (cellSet.IsType<vtkm::cont::CellSetExplicit<>>())
{
using CellSetType = vtkm::cont::CellSetExplicit<>;
using ExecutionType =
vtkm::exec::CellLocatorBoundingIntervalHierarchyExec<DeviceAdapter, CellSetType>;
ExecutionType* execObject = new ExecutionType(bih.Nodes,
bih.ProcessedCellIds,
bih.GetCellSet().Cast<CellSetType>(),
bih.GetCoordinates().GetData(),
DeviceAdapter());
bihExec.Reset(execObject);
}
else if (cellSet.IsType<vtkm::cont::CellSetStructured<2>>())
{
using CellSetType = vtkm::cont::CellSetStructured<2>;
using ExecutionType =
vtkm::exec::CellLocatorBoundingIntervalHierarchyExec<DeviceAdapter, CellSetType>;
ExecutionType* execObject = new ExecutionType(bih.Nodes,
bih.ProcessedCellIds,
bih.GetCellSet().Cast<CellSetType>(),
bih.GetCoordinates().GetData(),
DeviceAdapter());
bihExec.Reset(execObject);
}
else if (cellSet.IsType<vtkm::cont::CellSetStructured<3>>())
{
using CellSetType = vtkm::cont::CellSetStructured<3>;
using ExecutionType =
vtkm::exec::CellLocatorBoundingIntervalHierarchyExec<DeviceAdapter, CellSetType>;
ExecutionType* execObject = new ExecutionType(bih.Nodes,
bih.ProcessedCellIds,
bih.GetCellSet().Cast<CellSetType>(),
bih.GetCoordinates().GetData(),
DeviceAdapter());
bihExec.Reset(execObject);
}
else if (cellSet.IsType<vtkm::cont::CellSetSingleType<>>())
{
using CellSetType = vtkm::cont::CellSetSingleType<>;
using ExecutionType =
vtkm::exec::CellLocatorBoundingIntervalHierarchyExec<DeviceAdapter, CellSetType>;
ExecutionType* execObject = new ExecutionType(bih.Nodes,
bih.ProcessedCellIds,
bih.GetCellSet().Cast<CellSetType>(),
bih.GetCoordinates().GetData(),
DeviceAdapter());
bihExec.Reset(execObject);
}
else
{
throw vtkm::cont::ErrorBadType("Could not determine type to write out.");
}
using ExecObjectType =
vtkm::exec::CellLocatorBoundingIntervalHierarchyExec<DeviceAdapter, CellSetType>;
auto execObject = new ExecObjectType(
bih.Nodes, bih.ProcessedCellIds, cellset, bih.GetCoordinates().GetData(), device);
bih.ExecutionObjectHandle.Reset(execObject);
}
};
struct CellLocatorBoundingIntervalHierarchy::PrepareForExecutionFunctor
{
template <typename DeviceAdapter>
VTKM_CONT bool operator()(DeviceAdapter device,
const vtkm::cont::CellLocatorBoundingIntervalHierarchy& bih) const
{
bih.GetCellSet().CastAndCall(MakeExecObject{}, bih, device);
return true;
}
};
VTKM_CONT
const HandleType CellLocatorBoundingIntervalHierarchy::PrepareForExecutionImpl(
const vtkm::cont::DeviceAdapterId deviceId) const
const vtkm::exec::CellLocator* CellLocatorBoundingIntervalHierarchy::PrepareForExecution(
vtkm::cont::DeviceAdapterId device) const
{
const bool success =
vtkm::cont::TryExecuteOnDevice(deviceId, PrepareForExecutionFunctor(), *this, this->ExecHandle);
if (!success)
if (!vtkm::cont::TryExecuteOnDevice(device, PrepareForExecutionFunctor(), *this))
{
throwFailedRuntimeDeviceTransfer("BoundingIntervalHierarchy", deviceId);
throwFailedRuntimeDeviceTransfer("BoundingIntervalHierarchy", device);
}
return this->ExecHandle;
return this->ExecutionObjectHandle.PrepareForExecution(device);
}
} //namespace cont

@ -27,6 +27,7 @@
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleTransform.h>
#include <vtkm/cont/CellLocator.h>
#include <vtkm/cont/VirtualObjectHandle.h>
#include <vtkm/worklet/spatialstructure/BoundingIntervalHierarchy.h>
@ -37,19 +38,6 @@ namespace cont
class VTKM_CONT_EXPORT CellLocatorBoundingIntervalHierarchy : public vtkm::cont::CellLocator
{
private:
using IdArrayHandle = vtkm::cont::ArrayHandle<vtkm::Id>;
using CoordsArrayHandle = vtkm::cont::ArrayHandle<vtkm::FloatDefault>;
using RangeArrayHandle = vtkm::cont::ArrayHandle<vtkm::Range>;
using RangePermutationArrayHandle =
vtkm::cont::ArrayHandlePermutation<IdArrayHandle, RangeArrayHandle>;
using SplitPropertiesArrayHandle =
vtkm::cont::ArrayHandle<vtkm::worklet::spatialstructure::SplitProperties>;
using HandleType = vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator>;
class BuildFunctor;
class PrepareForExecutionFunctor;
public:
VTKM_CONT
CellLocatorBoundingIntervalHierarchy(vtkm::IdComponent numPlanes = 4,
@ -66,37 +54,41 @@ public:
VTKM_CONT
void SetNumberOfSplittingPlanes(vtkm::IdComponent numPlanes)
{
NumPlanes = numPlanes;
SetDirty();
this->NumPlanes = numPlanes;
this->SetModified();
}
VTKM_CONT
vtkm::IdComponent GetNumberOfSplittingPlanes() { return NumPlanes; }
vtkm::IdComponent GetNumberOfSplittingPlanes() { return this->NumPlanes; }
VTKM_CONT
void SetMaxLeafSize(vtkm::IdComponent maxLeafSize)
{
MaxLeafSize = maxLeafSize;
SetDirty();
this->MaxLeafSize = maxLeafSize;
this->SetModified();
}
VTKM_CONT
vtkm::Id GetMaxLeafSize() { return MaxLeafSize; }
vtkm::Id GetMaxLeafSize() { return this->MaxLeafSize; }
VTKM_CONT
const vtkm::exec::CellLocator* PrepareForExecution(
vtkm::cont::DeviceAdapterId device) const override;
protected:
VTKM_CONT
void Build() override;
VTKM_CONT
virtual const HandleType PrepareForExecutionImpl(
const vtkm::cont::DeviceAdapterId device) const override;
private:
vtkm::IdComponent NumPlanes;
vtkm::IdComponent MaxLeafSize;
vtkm::cont::ArrayHandle<vtkm::exec::CellLocatorBoundingIntervalHierarchyNode> Nodes;
IdArrayHandle ProcessedCellIds;
mutable HandleType ExecHandle;
vtkm::cont::ArrayHandle<vtkm::Id> ProcessedCellIds;
mutable vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator> ExecutionObjectHandle;
struct MakeExecObject;
struct PrepareForExecutionFunctor;
};
} // namespace cont

@ -18,16 +18,27 @@
// this software.
//============================================================================
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleCartesianProduct.h>
#include <vtkm/cont/CellLocatorRectilinearGrid.h>
#include <vtkm/cont/TryExecute.h>
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/exec/CellLocatorRectilinearGrid.h>
vtkm::cont::CellLocatorRectilinearGrid::CellLocatorRectilinearGrid() = default;
namespace vtkm
{
namespace cont
{
vtkm::cont::CellLocatorRectilinearGrid::~CellLocatorRectilinearGrid() = default;
CellLocatorRectilinearGrid::CellLocatorRectilinearGrid() = default;
void vtkm::cont::CellLocatorRectilinearGrid::Build()
CellLocatorRectilinearGrid::~CellLocatorRectilinearGrid() = default;
using StructuredType = vtkm::cont::CellSetStructured<3>;
using AxisHandle = vtkm::cont::ArrayHandle<vtkm::FloatDefault>;
using RectilinearType = vtkm::cont::ArrayHandleCartesianProduct<AxisHandle, AxisHandle, AxisHandle>;
void CellLocatorRectilinearGrid::Build()
{
vtkm::cont::CoordinateSystem coords = this->GetCoordinates();
vtkm::cont::DynamicCellSet cellSet = this->GetCellSet();
@ -44,34 +55,31 @@ void vtkm::cont::CellLocatorRectilinearGrid::Build()
this->RowSize = celldims[0];
}
struct vtkm::cont::CellLocatorRectilinearGrid::PrepareForExecutionFunctor
struct CellLocatorRectilinearGrid::PrepareForExecutionFunctor
{
template <typename DeviceAdapter>
VTKM_CONT bool operator()(DeviceAdapter,
const vtkm::cont::CellLocatorRectilinearGrid& contLocator,
HandleType& execLocator) const
VTKM_CONT bool operator()(DeviceAdapter, const CellLocatorRectilinearGrid& contLocator) const
{
using ExecutionType = vtkm::exec::CellLocatorRectilinearGrid<DeviceAdapter>;
ExecutionType* execObject =
new ExecutionType(contLocator.PlaneSize,
contLocator.RowSize,
contLocator.GetCellSet().template Cast<StructuredType>(),
contLocator.GetCoordinates().GetData().template Cast<RectilinearType>(),
DeviceAdapter());
execLocator.Reset(execObject);
auto* execObject = new vtkm::exec::CellLocatorRectilinearGrid<DeviceAdapter>(
contLocator.PlaneSize,
contLocator.RowSize,
contLocator.GetCellSet().template Cast<StructuredType>(),
contLocator.GetCoordinates().GetData().template Cast<RectilinearType>(),
DeviceAdapter());
contLocator.ExecutionObjectHandle.Reset(execObject);
return true;
}
};
const vtkm::cont::CellLocator::HandleType
vtkm::cont::CellLocatorRectilinearGrid::PrepareForExecutionImpl(
const vtkm::cont::DeviceAdapterId deviceId) const
const vtkm::exec::CellLocator* CellLocatorRectilinearGrid::PrepareForExecution(
vtkm::cont::DeviceAdapterId device) const
{
const bool success =
vtkm::cont::TryExecuteOnDevice(deviceId, PrepareForExecutionFunctor(), *this, this->ExecHandle);
if (!success)
if (!vtkm::cont::TryExecuteOnDevice(device, PrepareForExecutionFunctor(), *this))
{
throwFailedRuntimeDeviceTransfer("CellLocatorRectilinearGrid", deviceId);
throwFailedRuntimeDeviceTransfer("CellLocatorRectilinearGrid", device);
}
return this->ExecHandle;
return this->ExecutionObjectHandle.PrepareForExecution(device);
}
}
} // vtkm::cont

@ -17,47 +17,41 @@
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtkm_cont_celllocatorrectilineargrid_h
#define vtkm_cont_celllocatorrectilineargrid_h
#ifndef vtkm_cont_CellLocatorRectilinearGrid_h
#define vtkm_cont_CellLocatorRectilinearGrid_h
#include <vtkm/cont/CellLocator.h>
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/cont/VirtualObjectHandle.h>
namespace vtkm
{
namespace cont
{
class VTKM_CONT_EXPORT CellLocatorRectilinearGrid : public vtkm::cont::CellLocator
{
public:
using StructuredType = vtkm::cont::CellSetStructured<3>;
using AxisHandle = vtkm::cont::ArrayHandle<vtkm::FloatDefault>;
using RectilinearType =
vtkm::cont::ArrayHandleCartesianProduct<AxisHandle, AxisHandle, AxisHandle>;
VTKM_CONT CellLocatorRectilinearGrid();
VTKM_CONT ~CellLocatorRectilinearGrid() override;
VTKM_CONT void Build() override;
VTKM_CONT const vtkm::exec::CellLocator* PrepareForExecution(
vtkm::cont::DeviceAdapterId device) const override;
VTKM_CONT
const HandleType PrepareForExecutionImpl(
const vtkm::cont::DeviceAdapterId deviceId) const override;
protected:
VTKM_CONT void Build() override;
private:
vtkm::Bounds Bounds;
vtkm::Id PlaneSize;
vtkm::Id RowSize;
mutable HandleType ExecHandle;
mutable vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator> ExecutionObjectHandle;
struct PrepareForExecutionFunctor;
};
} //namespace cont
} //namespace vtkm
#endif //vtkm_cont_celllocatorrectilineargrid_h
#endif //vtkm_cont_CellLocatorRectilinearGrid_h

@ -19,15 +19,24 @@
//============================================================================
#include <vtkm/cont/Algorithm.h>
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
#include <vtkm/cont/CellLocatorUniformGrid.h>
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/exec/CellLocatorUniformGrid.h>
vtkm::cont::CellLocatorUniformGrid::CellLocatorUniformGrid() = default;
namespace vtkm
{
namespace cont
{
CellLocatorUniformGrid::CellLocatorUniformGrid() = default;
vtkm::cont::CellLocatorUniformGrid::~CellLocatorUniformGrid() = default;
CellLocatorUniformGrid::~CellLocatorUniformGrid() = default;
void vtkm::cont::CellLocatorUniformGrid::Build()
using UniformType = vtkm::cont::ArrayHandleUniformPointCoordinates;
using StructuredType = vtkm::cont::CellSetStructured<3>;
void CellLocatorUniformGrid::Build()
{
vtkm::cont::CoordinateSystem coords = this->GetCoordinates();
vtkm::cont::DynamicCellSet cellSet = this->GetCellSet();
@ -37,46 +46,44 @@ void vtkm::cont::CellLocatorUniformGrid::Build()
if (!cellSet.IsSameType(StructuredType()))
throw vtkm::cont::ErrorBadType("Cell set is not 3D structured type");
Bounds = coords.GetBounds();
CellDims = cellSet.Cast<StructuredType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
this->Bounds = coords.GetBounds();
this->CellDims =
cellSet.Cast<StructuredType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
RangeTransform[0] = static_cast<vtkm::FloatDefault>(CellDims[0]) /
static_cast<vtkm::FloatDefault>(Bounds.X.Length());
RangeTransform[1] = static_cast<vtkm::FloatDefault>(CellDims[1]) /
static_cast<vtkm::FloatDefault>(Bounds.Y.Length());
RangeTransform[2] = static_cast<vtkm::FloatDefault>(CellDims[2]) /
static_cast<vtkm::FloatDefault>(Bounds.Z.Length());
this->RangeTransform[0] = static_cast<vtkm::FloatDefault>(this->CellDims[0]) /
static_cast<vtkm::FloatDefault>(this->Bounds.X.Length());
this->RangeTransform[1] = static_cast<vtkm::FloatDefault>(this->CellDims[1]) /
static_cast<vtkm::FloatDefault>(this->Bounds.Y.Length());
this->RangeTransform[2] = static_cast<vtkm::FloatDefault>(this->CellDims[2]) /
static_cast<vtkm::FloatDefault>(this->Bounds.Z.Length());
}
struct vtkm::cont::CellLocatorUniformGrid::PrepareForExecutionFunctor
struct CellLocatorUniformGrid::PrepareForExecutionFunctor
{
template <typename DeviceAdapter>
VTKM_CONT bool operator()(DeviceAdapter,
const vtkm::cont::CellLocatorUniformGrid& contLocator,
HandleType& execLocator) const
VTKM_CONT bool operator()(DeviceAdapter, const CellLocatorUniformGrid& contLocator) const
{
using ExecutionType = vtkm::exec::CellLocatorUniformGrid<DeviceAdapter>;
ExecutionType* execObject =
new ExecutionType(contLocator.Bounds,
contLocator.RangeTransform,
contLocator.CellDims,
contLocator.GetCellSet().template Cast<StructuredType>(),
contLocator.GetCoordinates().GetData(),
DeviceAdapter());
execLocator.Reset(execObject);
auto* execObject = new vtkm::exec::CellLocatorUniformGrid<DeviceAdapter>(
contLocator.Bounds,
contLocator.RangeTransform,
contLocator.CellDims,
contLocator.GetCellSet().template Cast<StructuredType>(),
contLocator.GetCoordinates().GetData(),
DeviceAdapter());
contLocator.ExecutionObjectHandle.Reset(execObject);
return true;
}
};
const vtkm::cont::CellLocator::HandleType
vtkm::cont::CellLocatorUniformGrid::PrepareForExecutionImpl(
const vtkm::cont::DeviceAdapterId deviceId) const
const vtkm::exec::CellLocator* CellLocatorUniformGrid::PrepareForExecution(
vtkm::cont::DeviceAdapterId device) const
{
const bool success =
vtkm::cont::TryExecuteOnDevice(deviceId, PrepareForExecutionFunctor(), *this, this->ExecHandle);
if (!success)
if (!vtkm::cont::TryExecuteOnDevice(device, PrepareForExecutionFunctor(), *this))
{
throwFailedRuntimeDeviceTransfer("CellLocatorUniformGrid", deviceId);
throwFailedRuntimeDeviceTransfer("CellLocatorUniformGrid", device);
}
return this->ExecHandle;
return this->ExecutionObjectHandle.PrepareForExecution(device);
}
}
} // vtkm::cont

@ -17,15 +17,14 @@
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtkm_cont_celllocatoruniformgrid_h
#define vtkm_cont_celllocatoruniformgrid_h
#ifndef vtkm_cont_CellLocatorUniformGrid_h
#define vtkm_cont_CellLocatorUniformGrid_h
#include <vtkm/cont/CellLocator.h>
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/cont/VirtualObjectHandle.h>
namespace vtkm
{
namespace cont
{
@ -36,24 +35,22 @@ public:
VTKM_CONT ~CellLocatorUniformGrid() override;
VTKM_CONT const vtkm::exec::CellLocator* PrepareForExecution(
vtkm::cont::DeviceAdapterId device) const override;
protected:
VTKM_CONT void Build() override;
VTKM_CONT
const HandleType PrepareForExecutionImpl(
const vtkm::cont::DeviceAdapterId deviceId) const override;
private:
using UniformType = vtkm::cont::ArrayHandleUniformPointCoordinates;
using StructuredType = vtkm::cont::CellSetStructured<3>;
struct PrepareForExecutionFunctor;
vtkm::Bounds Bounds;
vtkm::Vec<vtkm::FloatDefault, 3> RangeTransform;
vtkm::Vec<vtkm::Id, 3> CellDims;
mutable HandleType ExecHandle;
mutable vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator> ExecutionObjectHandle;
struct PrepareForExecutionFunctor;
};
}
}
} // vtkm::cont
#endif //vtkm_cont_celllocatoruniformgrid_h
#endif //vtkm_cont_CellLocatorUniformGrid_h