PACMAN 0.1.0
Portable Algorithms for Coupling, Mapping, and Adaptive iNterpolation
Loading...
Searching...
No Matches
rbf_interface.cpp
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#include "interface.hpp"
7
8#include <ArborX_Point.hpp>
9#include <Kokkos_Core.hpp>
10#include <Kokkos_Profiling_ScopedRegion.hpp>
11#include <stdexcept>
12#include <string>
13
14#include "common/concepts.hpp"
15#include "common/transfer.hxx"
16// Extern-template declarations in interpolator.hxx suppress re-instantiation
17// in this TU. ETI is provided by rbf_interface_eti_*.cpp.
18#include "rbf_pum/interpolator.hxx"
20
21// ---------------------------------------------------------------------------
22// Internal helpers (anonymous namespace)
23// ---------------------------------------------------------------------------
24
25namespace {
26
27using namespace PACMAN;
28
32
34 switch (rbfFunction) {
36 return RbfPum::WendlandC0{};
38 return RbfPum::WendlandC2{};
40 return RbfPum::WendlandC4{};
42 return RbfPum::WendlandC6{};
44 return RbfPum::WendlandC8{};
45 default:
46 throw std::invalid_argument("Unsupported RBF function selector: " +
47 std::to_string(rbfFunction));
48 }
49}
50
51template <typename ExecSpace, typename RbfFuncType, PACMAN::int_t Dim>
59 pSourcePoints, pSourceValues, nullptr, nullptr,
60 nullptr, pTargetPoints);
61
62 PACMAN::RbfPum::RbfPumInterpolator<ExecSpace, Dim, RbfFuncType> interpolator(
63 transfer);
64
66 result.targetValues.resize(nTargetPoints);
67
69 Kokkos::View<PACMAN::fp_t *,
70 Kokkos::DefaultHostExecutionSpace::memory_space,
71 Kokkos::MemoryTraits<Kokkos::Unmanaged>>(
72 result.targetValues.data(), nTargetPoints);
73 Kokkos::deep_copy(unmanaged_host_tv, transfer.targetValues);
74 return result;
75}
76
77template <PACMAN::int_t Dim>
79DispatchRbf(unsigned char execSpace, unsigned char rbfFunction,
83 return std::visit(
84 [&](auto execSpaceObj, auto rbfFunctionObj) {
85 return RunRbfInterpolate<decltype(execSpaceObj),
86 decltype(rbfFunctionObj), Dim>(
89 },
91}
92
93} // anonymous namespace
94
95// ---------------------------------------------------------------------------
96// Public API implementation
97// ---------------------------------------------------------------------------
98
99namespace PACMAN {
100
103 unsigned char rbfFunction, coordinates_t *sourcePoints,
104 int_t nSourcePoints, fp_t *sourceValues,
106 const std::string _region_name = "PACMAN::rbf_interpolate";
107 const Kokkos::Profiling::ScopedRegion region(_region_name);
108
109 if (sourcePoints == nullptr && nSourcePoints > 0)
110 throw std::invalid_argument("sourcePoints is null but nSourcePoints > 0");
111 if (targetPoints == nullptr && nTargetPoints > 0)
112 throw std::invalid_argument("targetPoints is null but nTargetPoints > 0");
113 if (sourceValues == nullptr && nSourcePoints > 0)
114 throw std::invalid_argument("sourceValues is null but nSourcePoints > 0");
115
116 switch (spaceDimension) {
117 case 1:
119 sourceValues, targetPoints, nTargetPoints);
120 case 2:
122 sourceValues, targetPoints, nTargetPoints);
123 case 3:
125 sourceValues, targetPoints, nTargetPoints);
126 default:
127 throw std::runtime_error(
128 "The dimension of the points can only be: 1, 2 or 3.\n");
129 }
130}
131
132} // namespace PACMAN
A functor which computes a RBF function: WendlandC0 Each RBF function must have a host device method ...
A functor which computes a RBF function: WendlandC2 Each RBF function must have a host device method ...
A functor which computes a RBF function: WendlandC4 Each RBF function must have a host device method ...
A functor which computes a RBF function: WendlandC6 Each RBF function must have a host device method ...
A functor which computes a RBF function: WendlandC8 Each RBF function must have a host device method ...
double fp_t
Definition types.hpp:15
double coordinates_t
Definition types.hpp:16
RbfInterpolateResult rbf_interpolate(int_t spaceDimension, unsigned char execSpace, unsigned char rbfFunction, coordinates_t *sourcePoints, int_t nSourcePoints, fp_t *sourceValues, coordinates_t *targetPoints, int_t nTargetPoints)
C++ interface for RBF-PUM interpolation.
static AvailableExecSpaces MakeExecSpace(const unsigned char s)
Converts an execution-space selector byte to a variant type.
int32_t int_t
Definition types.hpp:18
static constexpr unsigned char WENDLANDC6
Definition interface.hpp:29
static constexpr unsigned char WENDLANDC8
Definition interface.hpp:30
static constexpr unsigned char WENDLANDC2
Definition interface.hpp:27
static constexpr unsigned char WENDLANDC0
Definition interface.hpp:26
static constexpr unsigned char WENDLANDC4
Definition interface.hpp:28
Result of an RBF-PUM interpolation call.