PACMAN 0.1.0
Portable Algorithms for Coupling, Mapping, and Adaptive iNterpolation
Loading...
Searching...
No Matches
mls/interpolator.hpp
Go to the documentation of this file.
1//
2// This file is subject to the terms and conditions defined in
3// file 'LICENSE', which is part of this source code package.
4//
5
6#pragma once
7
8#include <iostream>
9#include <ArborX_InterpMovingLeastSquares.hpp>
10#include <ArborX_Point.hpp>
11#include <Kokkos_Core.hpp>
12#include <Kokkos_Profiling_ScopedRegion.hpp>
13
14#include "common/concepts.hpp"
15#include "common/transfer.hxx"
16#include "common/types.hpp"
17#include "mls/interpolator.hxx"
18
19namespace PACMAN {
20namespace MLS {
21
24template <KokkosViewRank<2> SourceType, KokkosViewRank<1> TargetType,
25 int_t Dim>
26static inline void FillPoints(const SourceType &sourceView,
28 assert(Dim == sourceView.extent(1));
29 using ExecSpace = typename SourceType::execution_space;
30 const auto K = sourceView.extent(0);
31 Kokkos::parallel_for(
32 "MLS::FillPoints",
33 Kokkos::RangePolicy<ExecSpace>(ExecSpace{}, 0, K),
34 KOKKOS_LAMBDA(const std::size_t k) {
35 ::ArborX::Point<Dim, coordinates_t> point{};
36 for (int_t axis = 0; axis < Dim; ++axis) {
38 }
39 targetView(k) = point;
40 });
41}
42
50PACMAN_MLS_CLASSNAME::MLSInterpolator(Transfer<ExecSpace, Dim> &rTransfer) {
51 const std::string _region_name = "MLSInterpolator::MLSInterpolator";
52 Kokkos::Profiling::ScopedRegion region(_region_name);
53
54 const ExecSpace execspace{};
55 using Point = ::ArborX::Point<Dim, coordinates_t>;
56 using MemSpace = typename ExecSpace::memory_space;
57
58 const int_t nTgt =
59 static_cast<int_t>(rTransfer.targetPoints.extent(0));
60 // Convert the 2-D target coordinate array into an ArborX::Point view.
61 auto tgtPoints = Kokkos::View<Point *, MemSpace>(
62 Kokkos::view_alloc(execspace, Kokkos::WithoutInitializing,
63 "MLSInterpolator::tgtPoints"),
64 nTgt);
65 FillPoints<decltype(rTransfer.targetPoints), decltype(tgtPoints), Dim>(
66 rTransfer.targetPoints, tgtPoints);
67 Kokkos::fence();
68
69 // Alias the output to the transfer's target-values view.
70 this->out = rTransfer.targetValues;
71
72 // Build Moving Least Squares coefficients and interpolate.
73 ::ArborX::Interpolation::MovingLeastSquares<MemSpace> MLS(
74 execspace, rTransfer.sourcePoints, tgtPoints);
75 MLS.interpolate(execspace, rTransfer.sourceValues, this->out);
76 Kokkos::fence();
77}
78
79} // namespace MLS
80} // namespace PACMAN
static void FillPoints(const SourceType &sourceView, TargetType &targetView)
Convert a 2-D [N × Dim] coordinate view into a 1-D view of ArborX::Point<Dim, coordinates_t>.
int32_t int_t
Definition types.hpp:18