Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving least squares interpolation #946

Merged
merged 32 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0207ebb
Moving least squares coefficients computation
mrlag31 Sep 26, 2023
7b9e389
Moving least squares
mrlag31 Sep 26, 2023
c4b7190
Example
mrlag31 Sep 26, 2023
139ef2c
Better CMake integration and small fixes
mrlag31 Sep 26, 2023
8b499ac
SYCL and windows fix
mrlag31 Oct 4, 2023
1478078
Testing views name
mrlag31 Oct 16, 2023
a5c6e31
Testing views name
mrlag31 Oct 17, 2023
fbaf7f3
Better example
mrlag31 Oct 17, 2023
1fc3915
Profiling regions
mrlag31 Oct 18, 2023
3943b47
Renaming, better defaults and use of KOKKOS_CLASS_LAMBDA
mrlag31 Oct 19, 2023
ced621e
Dumping of data from the example
mrlag31 Oct 23, 2023
01271f6
`KOKKOS_ASSERT` and auto file closing
mrlag31 Oct 24, 2023
4e8c483
Regular meshes and basis changes
mrlag31 Oct 24, 2023
03afffc
Adding neighbors to example and changing defaults
mrlag31 Oct 26, 2023
c0bd551
New callback api fix
mrlag31 Nov 9, 2023
07ba1e0
Readability and moving coefficients creation space
mrlag31 Nov 21, 2023
a743130
Naming typo and better cl args
mrlag31 Nov 22, 2023
d2653ba
Update some tests (avoid repeated evaluation of 0s)
mrlag31 Nov 27, 2023
b07d0f0
nvcc 11.0.3 / empty example
mrlag31 Nov 28, 2023
e2854ab
Example rework
mrlag31 Nov 30, 2023
afc0072
Interface update
mrlag31 Dec 18, 2023
a2e5a74
`std::optional` nvcc fix
mrlag31 Dec 19, 2023
d13afe5
Using Kokkos scoped regions
mrlag31 Dec 20, 2023
ef2bebb
Reworked example
mrlag31 Dec 20, 2023
da7c6ee
MLS Interface rework
mrlag31 Dec 20, 2023
b945686
Renaming test
mrlag31 Dec 20, 2023
728458a
Polynomial degree alias
mrlag31 Dec 20, 2023
b1aca0c
Usage of new BVH API
mrlag31 Dec 20, 2023
ff7e6c7
Moving spaces inside main
mrlag31 Dec 20, 2023
46ae5fd
Removing hard-coded values in example
mrlag31 Dec 20, 2023
37161b9
Comment update and better naming
mrlag31 Dec 21, 2023
6529ca0
Get source size through AccessTraits interface
mrlag31 Dec 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,15 @@ target_include_directories(ArborX INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/details>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/geometry>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/kokkos_ext>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/interpolation>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/interpolation/details>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include/ArborX>
$<INSTALL_INTERFACE:include/ArborX/details>
$<INSTALL_INTERFACE:include/ArborX/geometry>
$<INSTALL_INTERFACE:include/ArborX/kokkos_ext>
$<INSTALL_INTERFACE:include/ArborX/interpolation>
$<INSTALL_INTERFACE:include/ArborX/interpolation/details>
)

install(TARGETS ArborX
Expand Down
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ if(Boost_FOUND)
add_subdirectory(viz)
add_subdirectory(raytracing)
add_subdirectory(brute_force)
add_subdirectory(moving_least_squares)
endif()
3 changes: 3 additions & 0 deletions examples/moving_least_squares/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_executable(ArborX_Example_MovingLeastSquares.exe moving_least_squares.cpp)
target_link_libraries(ArborX_Example_MovingLeastSquares.exe ArborX::ArborX)
add_test(NAME ArborX_Example_MovingLeastSquares COMMAND ArborX_Example_MovingLeastSquares.exe)
104 changes: 104 additions & 0 deletions examples/moving_least_squares/moving_least_squares.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/****************************************************************************
* Copyright (c) 2023 by the ArborX authors *
* All rights reserved. *
* *
* This file is part of the ArborX library. ArborX is *
* distributed under a BSD 3-clause license. For the licensing terms see *
* the LICENSE file in the top-level directory. *
* *
* SPDX-License-Identifier: BSD-3-Clause *
****************************************************************************/

#include <ArborX.hpp>
#include <ArborX_InterpMovingLeastSquares.hpp>

#include <Kokkos_Core.hpp>

#include <iostream>

using Point = ArborX::ExperimentalHyperGeometry::Point<2, double>;

KOKKOS_FUNCTION double functionToApproximate(Point const &p)
{
return Kokkos::cos(p[0] + p[1] / 4);
}

int main(int argc, char *argv[])
{
Kokkos::ScopeGuard guard(argc, argv);

using ExecutionSpace = Kokkos::DefaultExecutionSpace;
using MemorySpace = typename ExecutionSpace::memory_space;
ExecutionSpace space{};

// Source space is a 3x3 grid
// Target space is a single point
mrlag31 marked this conversation as resolved.
Show resolved Hide resolved
//
// ^
// |
// S S S
// |
// | T
// S S T S
// |
// | T
// -S-----S-----S->
// |

// Set up points
Kokkos::View<Point *, MemorySpace> src_points("Example::src_points", 9);
Kokkos::View<Point *, MemorySpace> tgt_points("Example::tgt_points", 3);
mrlag31 marked this conversation as resolved.
Show resolved Hide resolved
Kokkos::parallel_for(
"Example::make_points", Kokkos::RangePolicy<ExecutionSpace>(space, 0, 1),
KOKKOS_LAMBDA(int const) {
src_points(0) = {0., 0.};
src_points(1) = {1., 0.};
src_points(2) = {2., 0.};
src_points(3) = {0., 1.};
src_points(4) = {1., 1.};
src_points(5) = {2., 1.};
src_points(6) = {0., 2.};
src_points(7) = {1., 2.};
src_points(8) = {2., 2.};
tgt_points(0) = {4. / 6., 4. / 3.};
tgt_points(1) = {9. / 6., 3. / 3.};
tgt_points(2) = {2. / 6., 1. / 3.};
});

// Set up values
Kokkos::View<double *, MemorySpace> src_values("Example::src_values", 9);
Kokkos::View<double *, MemorySpace> app_values("Example::app_values", 3);
Kokkos::View<double *, MemorySpace> tgt_values("Example::tgt_values", 3);
Kokkos::parallel_for(
mrlag31 marked this conversation as resolved.
Show resolved Hide resolved
"Example::make_values", Kokkos::RangePolicy<ExecutionSpace>(space, 0, 9),
KOKKOS_LAMBDA(int const i) {
src_values(i) = functionToApproximate(src_points(i));
if (i < 3)
tgt_values(i) = functionToApproximate(tgt_points(i));
});

// Build the moving least squares coefficients
ArborX::Interpolation::MovingLeastSquares<MemorySpace> mls(space, src_points,
tgt_points);

// Interpolate
mls.interpolate(space, src_values, app_values);

// Show results
auto app_values_host =
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, app_values);
auto tgt_values_host =
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, tgt_values);
auto diff = [=](int const i) {
return Kokkos::abs(app_values_host(i) - tgt_values_host(i));
};

std::cout << "Approximated values: " << app_values_host(0) << ' '
<< app_values_host(1) << ' ' << app_values_host(2) << '\n';
std::cout << "Real values : " << tgt_values_host(0) << ' '
<< tgt_values_host(1) << ' ' << tgt_values_host(2) << '\n';
std::cout << "Differences : " << diff(0) << ' ' << diff(1) << ' '
<< diff(2) << '\n';

return 0;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment (nothing to be done here): There is an option in clang-format-16 for adding a newline at the end of the file, see https://releases.llvm.org/16.0.0/tools/clang/docs/ClangFormatStyleOptions.html#insertnewlineateof.

2 changes: 1 addition & 1 deletion src/geometry/ArborX_GeometryTraits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct is_triangle : std::is_same<typename tag<Geometry>::type, TriangleTag>
{};

template <typename Geometry>
void check_valid_geometry_traits(Geometry const &)
KOKKOS_FUNCTION constexpr void check_valid_geometry_traits(Geometry const &)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this? As far as I can tell it is not needed in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The polynomial basis is computed on the device and needs to ensure that the argument given is a point. KOKKOS_FUNCTION is necessary to compile, constexpr could be removed

masterleinad marked this conversation as resolved.
Show resolved Hide resolved
{
static_assert(
!Kokkos::is_detected<DimensionNotSpecializedArchetypeAlias, Geometry>{},
Expand Down
Loading