preCICE v3.1.1
Loading...
Searching...
No Matches
GinkgoRBFKernels.cpp
Go to the documentation of this file.
2#include "math/math.hpp"
3
4#include <functional>
5#include <ginkgo/ginkgo.hpp>
6#include <stdio.h>
7
8#include <ginkgo/kernels/kernel_launch.hpp>
9
11
12using namespace gko::kernels::GKO_DEVICE_NAMESPACE;
13
16
17template <typename ValueType, typename EvalFunctionType>
19 const std::size_t n1, const std::size_t n2, const std::size_t dataDimensionality, const std::array<bool, 3> activeAxis, ValueType *mtx, ValueType *supportPoints,
20 ValueType *targetPoints, EvalFunctionType f, const RadialBasisParameters rbf_params, const std::size_t inputRowLength, const std::size_t outputRowLength, const bool addPolynomial, const unsigned int extraDims = 0)
21{
22 run_kernel(
23 exec,
24 GKO_KERNEL(auto i, auto j, auto N, auto dataDimensionality, auto activeAxis, auto mtx, auto supportPoints, auto targetPoints, auto f, auto rbf_params, auto inputRowLength, auto outputRowLength, auto addPolynomial, auto extraDims) {
25 const unsigned int rowLength = N + extraDims;
26 double dist = 0;
27
28 // Make each entry zero if polynomial is on since not every entry will be adjusted below
29 if (addPolynomial) {
30 mtx[i * rowLength + j] = 0;
31 }
32
33#if defined(__NVCC__) || defined(__HIPCC__)
34
35 double y;
36 for (size_t k = 0; k < dataDimensionality; ++k) {
37 y = supportPoints[k * inputRowLength + j] - targetPoints[k * outputRowLength + i];
38 dist = fma(y, y, dist);
39 }
40
41 dist = sqrt(dist);
42
43#else
44 const unsigned int supportPointOffset = dataDimensionality * j; // Point of current column
45 const unsigned int targetPointOffset = dataDimensionality * i; // Point of current row
46 // Loop over each dimension and calculate euclidean distance
47 for (size_t k = 0; k < dataDimensionality; ++k) {
48 dist += pow_int<2>(supportPoints[supportPointOffset + k] - targetPoints[targetPointOffset + k]) * static_cast<int>(activeAxis.at(k));
49 }
50
51 dist = std::sqrt(dist);
52#endif
53
54 mtx[i * rowLength + j] = f(dist, rbf_params);
55 },
56 gko::dim<2>{n1, n2}, n2, dataDimensionality, activeAxis, mtx, supportPoints, targetPoints, f, rbf_params, inputRowLength, outputRowLength, addPolynomial, extraDims);
57}
58
59// Here, we need to instantiate all possible variants for each basis function
60
62 double *, double *, double *, precice::mapping::ThinPlateSplines, const RadialBasisParameters,
63 const std::size_t, const std::size_t, const bool, const unsigned int);
64
66 double *, double *, double *, precice::mapping::Multiquadrics, const RadialBasisParameters,
67 const std::size_t, const std::size_t, const bool, const unsigned int);
68
70 double *, double *, double *, precice::mapping::InverseMultiquadrics, const RadialBasisParameters,
71 const std::size_t, const std::size_t, const bool, const unsigned int);
72
74 double *, double *, double *, precice::mapping::VolumeSplines, const RadialBasisParameters,
75 const std::size_t, const std::size_t, const bool, const unsigned int);
76
78 double *, double *, double *, precice::mapping::Gaussian, const RadialBasisParameters,
79 const std::size_t, const std::size_t, const bool, const unsigned int);
80
82 double *, double *, double *, precice::mapping::CompactThinPlateSplinesC2, const RadialBasisParameters,
83 const std::size_t, const std::size_t, const bool, const unsigned int);
84
86 double *, double *, double *, precice::mapping::CompactPolynomialC0, const RadialBasisParameters,
87 const std::size_t, const std::size_t, const bool, const unsigned int);
88
90 double *, double *, double *, precice::mapping::CompactPolynomialC2, const RadialBasisParameters,
91 const std::size_t, const std::size_t, const bool, const unsigned int);
92
94 double *, double *, double *, precice::mapping::CompactPolynomialC4, const RadialBasisParameters,
95 const std::size_t, const std::size_t, const bool, const unsigned int);
96
98 double *, double *, double *, precice::mapping::CompactPolynomialC6, const RadialBasisParameters,
99 const std::size_t, const std::size_t, const bool, const unsigned int);
100
102 double *, double *, double *, precice::mapping::CompactPolynomialC8, const RadialBasisParameters,
103 const std::size_t, const std::size_t, const bool, const unsigned int);
104
105template <typename ValueType>
107 const std::size_t n1, const std::size_t n2, ValueType *mtx, ValueType *x, const std::size_t supportPointsRowLength, const unsigned int dims = 4)
108{
109 run_kernel(
110 exec,
111 GKO_KERNEL(auto i, auto j, auto N1, auto N2, auto mtx, auto x, auto supportPointsRowLength, auto dims) {
112#if defined(__NVCC__) || defined(__HIPCC__)
113 if (j < dims - 1) {
114 mtx[i * dims + j] = x[j * supportPointsRowLength + i];
115 } else {
116 mtx[i * dims + j] = 1;
117 }
118#else
119 const unsigned int supportPointOffset = (dims - 1) * i;
120 if (j < dims - 1) {
121 mtx[i * dims + j] = x[supportPointOffset + j];
122 } else {
123 mtx[i * dims + j] = 1;
124 }
125#endif
126 },
127 gko::dim<2>{n1, n2}, n1, n2, mtx, x, supportPointsRowLength, dims);
128}
129
130template void fill_polynomial_matrix<double>(std::shared_ptr<const DefaultExecutor>, const std::size_t, const std::size_t, double *, double *, const std::size_t, const unsigned int);
131
132} // namespace GKO_DEVICE_NAMESPACE
T at(T... args)
Wendland radial basis function with compact support.
Wendland radial basis function with compact support.
Wendland radial basis function with compact support.
Wendland radial basis function with compact support.
Wendland radial basis function with compact support.
Radial basis function with compact support.
Radial basis function with global and compact support.
Radial basis function with global support.
Radial basis function with global support.
Radial basis function with global support.
Radial basis function with global support.
template void create_rbf_system_matrix< double, precice::mapping::Gaussian >(std::shared_ptr< const DefaultExecutor >, const std::size_t, const std::size_t, const std::size_t, const std::array< bool, 3 >, double *, double *, double *, precice::mapping::Gaussian, const RadialBasisParameters, const std::size_t, const std::size_t, const bool, const unsigned int)
template void create_rbf_system_matrix< double, precice::mapping::ThinPlateSplines >(std::shared_ptr< const DefaultExecutor >, const std::size_t, const std::size_t, const std::size_t, const std::array< bool, 3 >, double *, double *, double *, precice::mapping::ThinPlateSplines, const RadialBasisParameters, const std::size_t, const std::size_t, const bool, const unsigned int)
template void create_rbf_system_matrix< double, precice::mapping::VolumeSplines >(std::shared_ptr< const DefaultExecutor >, const std::size_t, const std::size_t, const std::size_t, const std::array< bool, 3 >, double *, double *, double *, precice::mapping::VolumeSplines, const RadialBasisParameters, const std::size_t, const std::size_t, const bool, const unsigned int)
template void create_rbf_system_matrix< double, precice::mapping::CompactPolynomialC2 >(std::shared_ptr< const DefaultExecutor >, const std::size_t, const std::size_t, const std::size_t, const std::array< bool, 3 >, double *, double *, double *, precice::mapping::CompactPolynomialC2, const RadialBasisParameters, const std::size_t, const std::size_t, const bool, const unsigned int)
template void create_rbf_system_matrix< double, precice::mapping::InverseMultiquadrics >(std::shared_ptr< const DefaultExecutor >, const std::size_t, const std::size_t, const std::size_t, const std::array< bool, 3 >, double *, double *, double *, precice::mapping::InverseMultiquadrics, const RadialBasisParameters, const std::size_t, const std::size_t, const bool, const unsigned int)
void fill_polynomial_matrix(std::shared_ptr< const DefaultExecutor > exec, const std::size_t n1, const std::size_t n2, ValueType *mtx, ValueType *x, const std::size_t supportPointsRowLength, const unsigned int dims=4)
void create_rbf_system_matrix(std::shared_ptr< const DefaultExecutor > exec, const std::size_t n1, const std::size_t n2, const std::size_t dataDimensionality, const std::array< bool, 3 > activeAxis, ValueType *mtx, ValueType *supportPoints, ValueType *targetPoints, EvalFunctionType f, const RadialBasisParameters rbf_params, const std::size_t inputRowLength, const std::size_t outputRowLength, const bool addPolynomial, const unsigned int extraDims=0)
template void create_rbf_system_matrix< double, precice::mapping::CompactThinPlateSplinesC2 >(std::shared_ptr< const DefaultExecutor >, const std::size_t, const std::size_t, const std::size_t, const std::array< bool, 3 >, double *, double *, double *, precice::mapping::CompactThinPlateSplinesC2, const RadialBasisParameters, const std::size_t, const std::size_t, const bool, const unsigned int)
template void create_rbf_system_matrix< double, precice::mapping::CompactPolynomialC8 >(std::shared_ptr< const DefaultExecutor >, const std::size_t, const std::size_t, const std::size_t, const std::array< bool, 3 >, double *, double *, double *, precice::mapping::CompactPolynomialC8, const RadialBasisParameters, const std::size_t, const std::size_t, const bool, const unsigned int)
template void fill_polynomial_matrix< double >(std::shared_ptr< const DefaultExecutor >, const std::size_t, const std::size_t, double *, double *, const std::size_t, const unsigned int)
template void create_rbf_system_matrix< double, precice::mapping::CompactPolynomialC6 >(std::shared_ptr< const DefaultExecutor >, const std::size_t, const std::size_t, const std::size_t, const std::array< bool, 3 >, double *, double *, double *, precice::mapping::CompactPolynomialC6, const RadialBasisParameters, const std::size_t, const std::size_t, const bool, const unsigned int)
template void create_rbf_system_matrix< double, precice::mapping::CompactPolynomialC0 >(std::shared_ptr< const DefaultExecutor >, const std::size_t, const std::size_t, const std::size_t, const std::array< bool, 3 >, double *, double *, double *, precice::mapping::CompactPolynomialC0, const RadialBasisParameters, const std::size_t, const std::size_t, const bool, const unsigned int)
template void create_rbf_system_matrix< double, precice::mapping::Multiquadrics >(std::shared_ptr< const DefaultExecutor >, const std::size_t, const std::size_t, const std::size_t, const std::array< bool, 3 >, double *, double *, double *, precice::mapping::Multiquadrics, const RadialBasisParameters, const std::size_t, const std::size_t, const bool, const unsigned int)
template void create_rbf_system_matrix< double, precice::mapping::CompactPolynomialC4 >(std::shared_ptr< const DefaultExecutor >, const std::size_t, const std::size_t, const std::size_t, const std::array< bool, 3 >, double *, double *, double *, precice::mapping::CompactPolynomialC4, const RadialBasisParameters, const std::size_t, const std::size_t, const bool, const unsigned int)
constexpr T pow_int(const T x)
Computes the power of a given number by an integral exponent given at compile time,...
Definition math.hpp:23
T sqrt(T... args)
Wrapper struct that is used to transfer RBF-specific parameters to the GPU.