Commit 7ef956a9 authored by Li-Ta Lo's avatar Li-Ta Lo
Browse files

Merge branch 'master' into connected_component

parents a9ed1ecf 3de1717b
......@@ -14,4 +14,4 @@ data/* filter=lfs diff=lfs merge=lfs -text
*.rst whitespace=tab-in-indent conflict-marker-size=79
*.txt whitespace=tab-in-indent
diy/** -format.clang-format -whitespace
vtkm/thirdparty/diy/vtkmdiy/** -format.clang-format -whitespace
......@@ -39,9 +39,7 @@ set(FILES_TO_CHECK
set(EXCEPTIONS
LICENSE.txt
README.txt
diy/include/diy
diy/LEGAL.txt
diy/LICENSE.txt
vtkm/thirdparty/diy/vtkmdiy
)
if (NOT VTKm_SOURCE_DIR)
......
......@@ -39,11 +39,21 @@ set(FILES_TO_CHECK
set(EXCEPTIONS
)
set(DIRECTORY_EXCEPTIONS
${VTKm_SOURCE_DIR}/vtkm/thirdparty/diy/vtkmdiy
)
if (NOT VTKm_SOURCE_DIR)
message(SEND_ERROR "VTKm_SOURCE_DIR not defined.")
endif (NOT VTKm_SOURCE_DIR)
function(check_directory directory parent_CMakeLists_contents)
foreach(exception IN LISTS DIRECTORY_EXCEPTIONS)
if(directory MATCHES "^${exception}$")
return()
endif()
endforeach(exception)
message("Checking directory ${directory}...")
get_filename_component(directory_name "${directory}" NAME)
......
......@@ -221,11 +221,6 @@ find_package(Pyexpander)
#-----------------------------------------------------------------------------
# Add subdirectories
if(VTKm_ENABLE_MPI)
# This `if` is temporary and will be removed once `diy` supports building
# without MPI.
add_subdirectory(diy)
endif()
add_subdirectory(vtkm)
#-----------------------------------------------------------------------------
......
......@@ -104,14 +104,11 @@ int main(int argc, char* argv[])
output.AddCellSet(outputCellSet);
auto inCoords = input.GetCoordinateSystem(0).GetData();
timer.Reset();
vtkm::cont::DynamicArrayHandle coords;
{
FieldMapper<DeviceAdapter> coordMapper(coords, clip, false);
input.GetCoordinateSystem(0).GetData().CastAndCall(coordMapper);
}
auto outCoords = clip.ProcessCellField(inCoords, DeviceAdapter());
vtkm::Float64 processCoordinatesTime = timer.GetElapsedTime();
output.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", coords));
output.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", outCoords));
timer.Reset();
for (vtkm::Id i = 0; i < input.GetNumberOfFields(); ++i)
......
......@@ -23,6 +23,7 @@
#endif
#include <vtkm/Math.h>
#include <vtkm/cont/ArrayCopy.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/worklet/DispatcherMapField.h>
......@@ -68,30 +69,6 @@ Quaternion qrot;
int lastx, lasty;
int mouse_state = 1;
//
// Functor to retrieve vertex locations from the CoordinateSystem
// Actually need a static cast to ArrayHandle from DynamicArrayHandleCoordinateSystem
// but haven't been able to figure out what that is
//
struct GetVertexArray
{
template <typename ArrayHandleType>
VTKM_CONT void operator()(ArrayHandleType array) const
{
this->GetVertexPortal(array.GetPortalConstControl());
}
private:
template <typename PortalType>
VTKM_CONT void GetVertexPortal(const PortalType& portal) const
{
for (vtkm::Id index = 0; index < portal.GetNumberOfValues(); index++)
{
vertexArray.GetPortalControl().Set(index, portal.Get(index));
}
}
};
//
// Initialize the OpenGL state
//
......@@ -145,16 +122,10 @@ void displayCall()
// Get the cell set, coordinate system and coordinate data
vtkm::cont::CellSetExplicit<> cellSet;
outDataSet.GetCellSet(0).CopyTo(cellSet);
const vtkm::cont::DynamicArrayHandleCoordinateSystem& coordArray =
outDataSet.GetCoordinateSystem().GetData();
auto coordArray = outDataSet.GetCoordinateSystem().GetData();
vtkm::Id numberOfCells = cellSet.GetNumberOfCells();
vtkm::Id numberOfPoints = coordArray.GetNumberOfValues();
// Need the actual vertex points from a static cast of the dynamic array but can't get it right
// So use cast and call on a functor that stores that dynamic array into static array we created
vertexArray.Allocate(numberOfPoints);
vtkm::cont::CastAndCall(coordArray, GetVertexArray());
vtkm::cont::ArrayCopy(coordArray, vertexArray);
// Each cell is a polyline
glColor3f(1.0f, 0.0f, 0.0f);
......
......@@ -52,9 +52,6 @@ namespace
// Takes input uniform grid and outputs unstructured grid of tets
static vtkm::cont::DataSet outDataSet;
// Point location of vertices from a CastAndCall but needs a static cast eventually
static vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float64, 3>> vertexArray;
// OpenGL display variables
Quaternion qrot;
int lastx, lasty;
......@@ -123,30 +120,6 @@ vtkm::cont::DataSet MakeTetrahedralizeExplicitDataSet()
return builder.Create();
}
//
// Functor to retrieve vertex locations from the CoordinateSystem
// Actually need a static cast to ArrayHandle from DynamicArrayHandleCoordinateSystem
// but haven't been able to figure out what that is
//
struct GetVertexArray
{
template <typename ArrayHandleType>
VTKM_CONT void operator()(ArrayHandleType array) const
{
this->GetVertexPortal(array.GetPortalConstControl());
}
private:
template <typename PortalType>
VTKM_CONT void GetVertexPortal(const PortalType& portal) const
{
for (vtkm::Id index = 0; index < portal.GetNumberOfValues(); index++)
{
vertexArray.GetPortalControl().Set(index, portal.Get(index));
}
}
};
//
// Initialize the OpenGL state
//
......@@ -201,10 +174,7 @@ void displayCall()
outDataSet.GetCellSet(0).CopyTo(cellSet);
vtkm::Id numberOfCells = cellSet.GetNumberOfCells();
// Need the actual vertex points from a static cast of the dynamic array but can't get it right
// So use cast and call on a functor that stores that dynamic array into static array we created
vertexArray.Allocate(cellSet.GetNumberOfPoints());
vtkm::cont::CastAndCall(outDataSet.GetCoordinateSystem(), GetVertexArray());
auto vertexArray = outDataSet.GetCoordinateSystem().GetData();
// Draw the five tetrahedra belonging to each hexadron
vtkm::Float32 color[5][3] = { { 1.0f, 0.0f, 0.0f },
......@@ -223,10 +193,10 @@ void displayCall()
cellSet.GetIndices(tetra, tetIndices);
// Get the vertex points for this tetrahedron
vtkm::Vec<vtkm::Float64, 3> pt0 = vertexArray.GetPortalConstControl().Get(tetIndices[0]);
vtkm::Vec<vtkm::Float64, 3> pt1 = vertexArray.GetPortalConstControl().Get(tetIndices[1]);
vtkm::Vec<vtkm::Float64, 3> pt2 = vertexArray.GetPortalConstControl().Get(tetIndices[2]);
vtkm::Vec<vtkm::Float64, 3> pt3 = vertexArray.GetPortalConstControl().Get(tetIndices[3]);
auto pt0 = vertexArray.GetPortalConstControl().Get(tetIndices[0]);
auto pt1 = vertexArray.GetPortalConstControl().Get(tetIndices[1]);
auto pt2 = vertexArray.GetPortalConstControl().Get(tetIndices[2]);
auto pt3 = vertexArray.GetPortalConstControl().Get(tetIndices[3]);
// Draw the tetrahedron filled with alternating colors
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
......@@ -323,7 +293,6 @@ int main(int argc, char* argv[])
glutMainLoop();
outDataSet.Clear();
vertexArray.ReleaseResources();
return 0;
}
......
......@@ -52,9 +52,6 @@ static vtkm::Id cellsToDisplay = 64;
// Takes input uniform grid and outputs unstructured grid of tets
static vtkm::cont::DataSet tetDataSet;
// Point location of vertices from a CastAndCall but needs a static cast eventually
static vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float64, 3>> vertexArray;
// OpenGL display variables
static Quaternion qrot;
static int lastx, lasty;
......@@ -87,30 +84,6 @@ vtkm::cont::DataSet MakeTetrahedralizeTestDataSet(vtkm::Id3 dim)
return dataSet;
}
//
// Functor to retrieve vertex locations from the CoordinateSystem
// Actually need a static cast to ArrayHandle from DynamicArrayHandleCoordinateSystem
// but haven't been able to figure out what that is
//
struct GetVertexArray
{
template <typename ArrayHandleType>
VTKM_CONT void operator()(ArrayHandleType array) const
{
this->GetVertexPortal(array.GetPortalConstControl());
}
private:
template <typename PortalType>
VTKM_CONT void GetVertexPortal(const PortalType& portal) const
{
for (vtkm::Id index = 0; index < portal.GetNumberOfValues(); index++)
{
vertexArray.GetPortalControl().Set(index, portal.Get(index));
}
}
};
//
// Initialize the OpenGL state
//
......@@ -165,10 +138,7 @@ void displayCall()
vtkm::cont::CellSetSingleType<> cellSet;
tetDataSet.GetCellSet(0).CopyTo(cellSet);
// Need the actual vertex points from a static cast of the dynamic array but can't get it right
// So use cast and call on a functor that stores that dynamic array into static array we created
vertexArray.Allocate(cellSet.GetNumberOfPoints());
vtkm::cont::CastAndCall(tetDataSet.GetCoordinateSystem(), GetVertexArray());
auto vertexArray = tetDataSet.GetCoordinateSystem().GetData();
// Draw the five tetrahedra belonging to each hexadron
vtkm::Id tetra = 0;
......@@ -190,10 +160,10 @@ void displayCall()
cellSet.GetIndices(tetra, tetIndices);
// Get the vertex points for this tetrahedron
vtkm::Vec<vtkm::Float64, 3> pt0 = vertexArray.GetPortalConstControl().Get(tetIndices[0]);
vtkm::Vec<vtkm::Float64, 3> pt1 = vertexArray.GetPortalConstControl().Get(tetIndices[1]);
vtkm::Vec<vtkm::Float64, 3> pt2 = vertexArray.GetPortalConstControl().Get(tetIndices[2]);
vtkm::Vec<vtkm::Float64, 3> pt3 = vertexArray.GetPortalConstControl().Get(tetIndices[3]);
auto pt0 = vertexArray.GetPortalConstControl().Get(tetIndices[0]);
auto pt1 = vertexArray.GetPortalConstControl().Get(tetIndices[1]);
auto pt2 = vertexArray.GetPortalConstControl().Get(tetIndices[2]);
auto pt3 = vertexArray.GetPortalConstControl().Get(tetIndices[3]);
// Draw the tetrahedron filled with alternating colors
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
......@@ -305,7 +275,6 @@ int main(int argc, char* argv[])
glutMainLoop();
tetDataSet.Clear();
vertexArray.ReleaseResources();
return 0;
}
......
......@@ -50,9 +50,6 @@ namespace
static vtkm::cont::DataSet outDataSet;
static vtkm::Id numberOfInPoints;
// Point location of vertices from a CastAndCall but needs a static cast eventually
static vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float64, 3>> vertexArray;
} // anonymous namespace
//
......@@ -125,30 +122,6 @@ vtkm::cont::DataSet MakeTriangulateExplicitDataSet()
return builder.Create();
}
//
// Functor to retrieve vertex locations from the CoordinateSystem
// Actually need a static cast to ArrayHandle from DynamicArrayHandleCoordinateSystem
// but haven't been able to figure out what that is
//
struct GetVertexArray
{
template <typename ArrayHandleType>
VTKM_CONT void operator()(ArrayHandleType array) const
{
this->GetVertexPortal(array.GetPortalConstControl());
}
private:
template <typename PortalType>
VTKM_CONT void GetVertexPortal(const PortalType& portal) const
{
for (vtkm::Id index = 0; index < portal.GetNumberOfValues(); index++)
{
vertexArray.GetPortalControl().Set(index, portal.Get(index));
}
}
};
//
// Initialize the OpenGL state
//
......@@ -173,10 +146,7 @@ void displayCall()
outDataSet.GetCellSet(0).CopyTo(cellSet);
vtkm::Id numberOfCells = cellSet.GetNumberOfCells();
// Need the actual vertex points from a static cast of the dynamic array but can't get it right
// So use cast and call on a functor that stores that dynamic array into static array we created
vertexArray.Allocate(numberOfInPoints);
vtkm::cont::CastAndCall(outDataSet.GetCoordinateSystem(), GetVertexArray());
auto vertexArray = outDataSet.GetCoordinateSystem().GetData();
// Draw the two triangles belonging to each quad
vtkm::Float32 color[4][3] = {
......@@ -239,7 +209,6 @@ int main(int argc, char* argv[])
glutMainLoop();
outDataSet.Clear();
vertexArray.ReleaseResources();
return 0;
}
......
......@@ -50,9 +50,6 @@ static vtkm::Id cellsToDisplay = 16;
// Takes input uniform grid and outputs unstructured grid of triangles
static vtkm::cont::DataSet triDataSet;
// Point location of vertices from a CastAndCall but needs a static cast eventually
static vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float64, 3>> vertexArray;
//
// Construct an input data set with uniform grid of indicated dimensions, origin and spacing
//
......@@ -78,30 +75,6 @@ vtkm::cont::DataSet MakeTriangulateTestDataSet(vtkm::Id2 dim)
return dataSet;
}
//
// Functor to retrieve vertex locations from the CoordinateSystem
// Actually need a static cast to ArrayHandle from DynamicArrayHandleCoordinateSystem
// but haven't been able to figure out what that is
//
struct GetVertexArray
{
template <typename ArrayHandleType>
VTKM_CONT void operator()(ArrayHandleType array) const
{
this->GetVertexPortal(array.GetPortalConstControl());
}
private:
template <typename PortalType>
VTKM_CONT void GetVertexPortal(const PortalType& portal) const
{
for (vtkm::Id index = 0; index < portal.GetNumberOfValues(); index++)
{
vertexArray.GetPortalControl().Set(index, portal.Get(index));
}
}
};
//
// Initialize the OpenGL state
//
......@@ -125,10 +98,7 @@ void displayCall()
vtkm::cont::CellSetSingleType<> cellSet;
triDataSet.GetCellSet(0).CopyTo(cellSet);
// Need the actual vertex points from a static cast of the dynamic array but can't get it right
// So use cast and call on a functor that stores that dynamic array into static array we created
vertexArray.Allocate(cellSet.GetNumberOfPoints());
vtkm::cont::CastAndCall(triDataSet.GetCoordinateSystem(), GetVertexArray());
auto vertexArray = triDataSet.GetCoordinateSystem().GetData();
// Draw the two triangles belonging to each quad
vtkm::Id triangle = 0;
......@@ -207,7 +177,6 @@ int main(int argc, char* argv[])
glutMainLoop();
triDataSet.Clear();
vertexArray.ReleaseResources();
return 0;
}
......
......@@ -67,6 +67,11 @@ vtkm_declare_headers(${headers})
#-----------------------------------------------------------------------------
#first add all the components vtkm that are shared between control and exec
if(VTKm_ENABLE_MPI)
# This `if` is temporary and will be removed once `diy` supports building
# without MPI.
add_subdirectory(thirdparty/diy)
endif()
add_subdirectory(testing)
add_subdirectory(internal)
......
......@@ -48,6 +48,7 @@
#define VTKM_CUDA_MATH_FUNCTION_32(func) func##f
#define VTKM_CUDA_MATH_FUNCTION_64(func) func
// clang-format off
namespace vtkm
{
......@@ -88,41 +89,22 @@ static inline VTKM_EXEC_CONT vtkm::Float64 Pi_4()
namespace detail
{
template <typename T>
struct FloatingPointReturnCondition
: std::enable_if<
std::is_same<typename vtkm::VecTraits<T>::ComponentType, vtkm::Float32>::value ||
std::is_same<typename vtkm::VecTraits<T>::ComponentType, const vtkm::Float32>::value>
{
};
template <typename T, typename = void>
struct FloatingPointReturnType
{
using Type = vtkm::Float64;
};
template <typename T>
struct FloatingPointReturnType<T, typename FloatingPointReturnCondition<T>::type>
{
using Type = vtkm::Float32;
using ctype = typename vtkm::VecTraits<T>::ComponentType;
using representable_as_float_type = std::integral_constant<bool,
((sizeof(ctype) < sizeof(float)) || std::is_same<ctype, vtkm::Float32>::value)>;
using Type = typename std::conditional<representable_as_float_type::value,
vtkm::Float32,
vtkm::Float64>::type;
};
} // namespace detail
/// Compute the sine of \p x.
///
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Sin(T x)
{
#ifdef VTKM_CUDA
return VTKM_CUDA_MATH_FUNCTION_64(sin)(static_cast<vtkm::Float64>(x));
#else
return std::sin(static_cast<vtkm::Float64>(x));
#endif
}
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type Sin(vtkm::Float32 x)
inline VTKM_EXEC_CONT vtkm::Float32 Sin(vtkm::Float32 x)
{
#ifdef VTKM_CUDA
return VTKM_CUDA_MATH_FUNCTION_32(sin)(x);
......@@ -130,8 +112,8 @@ inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type Sin(v
return std::sin(x);
#endif
}
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type Sin(vtkm::Float64 x)
inline VTKM_EXEC_CONT vtkm::Float64 Sin(vtkm::Float64 x)
{
#ifdef VTKM_CUDA
return VTKM_CUDA_MATH_FUNCTION_64(sin)(x);
......@@ -139,6 +121,12 @@ inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type Sin(v
return std::sin(x);
#endif
}
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Sin(const T& x)
{
using RT = typename detail::FloatingPointReturnType<T>::Type;
return vtkm::Sin(static_cast<RT>(x));
}
template <typename T, vtkm::IdComponent N>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> Sin(
const vtkm::Vec<T, N>& x)
......@@ -174,17 +162,8 @@ static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<
/// Compute the cosine of \p x.
///
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Cos(T x)
{
#ifdef VTKM_CUDA
return VTKM_CUDA_MATH_FUNCTION_64(cos)(static_cast<vtkm::Float64>(x));
#else
return std::cos(static_cast<vtkm::Float64>(x));
#endif
}
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type Cos(vtkm::Float32 x)
inline VTKM_EXEC_CONT vtkm::Float32 Cos(vtkm::Float32 x)
{
#ifdef VTKM_CUDA
return VTKM_CUDA_MATH_FUNCTION_32(cos)(x);
......@@ -192,8 +171,8 @@ inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type Cos(v
return std::cos(x);
#endif
}
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type Cos(vtkm::Float64 x)
inline VTKM_EXEC_CONT vtkm::Float64 Cos(vtkm::Float64 x)
{
#ifdef VTKM_CUDA
return VTKM_CUDA_MATH_FUNCTION_64(cos)(x);
......@@ -201,6 +180,12 @@ inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type Cos(v
return std::cos(x);
#endif
}
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Cos(const T& x)
{
using RT = typename detail::FloatingPointReturnType<T>::Type;
return vtkm::Cos(static_cast<RT>(x));
}
template <typename T, vtkm::IdComponent N>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> Cos(
const vtkm::Vec<T, N>& x)
......@@ -236,17 +221,8 @@ static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<
/// Compute the tangent of \p x.
///
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Tan(T x)
{
#ifdef VTKM_CUDA
return VTKM_CUDA_MATH_FUNCTION_64(tan)(static_cast<vtkm::Float64>(x));
#else
return std::tan(static_cast<vtkm::Float64>(x));
#endif
}
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type Tan(vtkm::Float32 x)
inline VTKM_EXEC_CONT vtkm::Float32 Tan(vtkm::Float32 x)
{
#ifdef VTKM_CUDA
return VTKM_CUDA_MATH_FUNCTION_32(tan)(x);
......@@ -254,8 +230,8 @@ inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float32>::Type Tan(v
return std::tan(x);
#endif
}
template <>
inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type Tan(vtkm::Float64 x)
inline VTKM_EXEC_CONT vtkm::Float64 Tan(vtkm::Float64 x)
{
#ifdef VTKM_CUDA
return VTKM_CUDA_MATH_FUNCTION_64(tan)(x);
......@@ -263,6 +239,12 @@ inline VTKM_EXEC_CONT detail::FloatingPointReturnType<vtkm::Float64>::Type Tan(v
return std::tan(x);
#endif
}
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type Tan(const T& x)
{
using RT = typename detail::FloatingPointReturnType<T>::Type;
return vtkm::Tan(static_cast<RT>(x));
}
template <typename T, vtkm::IdComponent N>
static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<T>::Type, N> Tan(
const vtkm::Vec<T, N>& x)
......@@ -298,17 +280,8 @@ static inline VTKM_EXEC_CONT vtkm::Vec<typename detail::FloatingPointReturnType<
/// Compute the arc sine of \p x.
///
template <typename T>
static inline VTKM_EXEC_CONT typename detail::FloatingPointReturnType<T>::Type ASin(T x)