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
29using AvailableRbfFunctions =
32
33static AvailableRbfFunctions MakeRbfFunction(unsigned char rbfFunction) {
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 // LCOV_EXCL_START
47 throw std::invalid_argument("Unsupported RBF function selector: " +
48 std::to_string(rbfFunction));
49 // LCOV_EXCL_STOP
50 }
51}
52
53template <typename ExecSpace, typename RbfFuncType, PACMAN::int_t Dim>
54void
55RunRbfInterpolate(PACMAN::coordinates_t *pSourcePoints,
56 PACMAN::int_t nSourcePoints, PACMAN::fp_t *pSourceValues,
57 PACMAN::coordinates_t *pTargetPoints,
58 PACMAN::int_t nTargetPoints,
59 PACMAN::int_t nComponents,
60 PACMAN::fp_t *pTargetValues) {
61 PACMAN::Transfer<ExecSpace, Dim> transfer(PACMAN::TransferMethods::RBF_PUM);
62 PACMAN::SetupTransferClass(transfer, nSourcePoints, 0, 0, nTargetPoints,
63 nComponents,
64 pSourcePoints, pSourceValues, nullptr, nullptr,
65 nullptr, pTargetPoints);
66
67 PACMAN::RbfPum::RbfPumInterpolator<ExecSpace, Dim, RbfFuncType> interpolator(
68 transfer);
69
70 PACMAN::CopyToRowMajorHost(transfer.targetValues, pTargetValues);
71}
72
73template <PACMAN::int_t Dim>
74requires PACMAN::IsValidDim<Dim> void
75DispatchRbf(unsigned char execSpace, unsigned char rbfFunction,
76 PACMAN::coordinates_t *pSourcePoints, PACMAN::int_t nSourcePoints,
77 PACMAN::fp_t *pSourceValues, PACMAN::coordinates_t *pTargetPoints,
78 PACMAN::int_t nTargetPoints, PACMAN::int_t nComponents,
79 PACMAN::fp_t *pTargetValues) {
80 std::visit(
81 [&](auto execSpaceObj, auto rbfFunctionObj) {
82 RunRbfInterpolate<decltype(execSpaceObj), decltype(rbfFunctionObj), Dim>(
83 pSourcePoints, nSourcePoints, pSourceValues, pTargetPoints,
84 nTargetPoints, nComponents, pTargetValues);
85 },
86 PACMAN::MakeExecSpace(execSpace), MakeRbfFunction(rbfFunction));
87}
88
89} // anonymous namespace
90
91// ---------------------------------------------------------------------------
92// Public API implementation
93// ---------------------------------------------------------------------------
94
95namespace PACMAN {
96
97void
98rbf_interpolate(int_t spaceDimension, unsigned char execSpace,
99 unsigned char rbfFunction, coordinates_t *sourcePoints,
100 int_t nSourcePoints, fp_t *sourceValues,
101 coordinates_t *targetPoints, int_t nTargetPoints,
102 fp_t *targetValues, int_t nComponents) {
103 const std::string _region_name = "PACMAN::rbf_interpolate";
104 const Kokkos::Profiling::ScopedRegion region(_region_name);
105
106 // LCOV_EXCL_START
107 if (sourcePoints == nullptr && nSourcePoints > 0)
108 throw std::invalid_argument("sourcePoints is null but nSourcePoints > 0");
109 if (targetPoints == nullptr && nTargetPoints > 0)
110 throw std::invalid_argument("targetPoints is null but nTargetPoints > 0");
111 if (sourceValues == nullptr && nSourcePoints > 0)
112 throw std::invalid_argument("sourceValues is null but nSourcePoints > 0");
113 if (targetValues == nullptr && nTargetPoints > 0)
114 throw std::invalid_argument("targetValues is null but nTargetPoints > 0");
115 if (nComponents < 1)
116 throw std::invalid_argument("nComponents must be greater than zero");
117 // LCOV_EXCL_STOP
118
119 switch (spaceDimension) {
120 case 1:
121 return DispatchRbf<1>(execSpace, rbfFunction, sourcePoints, nSourcePoints,
122 sourceValues, targetPoints, nTargetPoints,
123 nComponents, targetValues);
124 case 2:
125 return DispatchRbf<2>(execSpace, rbfFunction, sourcePoints, nSourcePoints,
126 sourceValues, targetPoints, nTargetPoints,
127 nComponents, targetValues);
128 case 3:
129 return DispatchRbf<3>(execSpace, rbfFunction, sourcePoints, nSourcePoints,
130 sourceValues, targetPoints, nTargetPoints,
131 nComponents, targetValues);
132 // LCOV_EXCL_START
133 default:
134 throw std::runtime_error(
135 "The dimension of the points can only be: 1, 2 or 3.\n");
136 // LCOV_EXCL_STOP
137 }
138}
139
140} // 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
void 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, fp_t *targetValues, int_t nComponents=1)
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:27
static constexpr unsigned char WENDLANDC8
Definition interface.hpp:28
static constexpr unsigned char WENDLANDC2
Definition interface.hpp:25
static constexpr unsigned char WENDLANDC0
Definition interface.hpp:24
static constexpr unsigned char WENDLANDC4
Definition interface.hpp:26