Documentation a537f1bdf2
Loading...
Searching...
No Matches
CRadialBasisFunction.hpp
Go to the documentation of this file.
1/*!
2 * \file CRadialBasisFunction.hpp
3 * \brief Radial basis function interpolation.
4 * \author Joel Ho, P. Gomes
5 * \version 8.5.0 "Harrier"
6 *
7 * SU2 Project Website: https://su2code.github.io
8 *
9 * The SU2 Project is maintained by the SU2 Foundation
10 * (http://su2foundation.org)
11 *
12 * Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)
13 *
14 * SU2 is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * SU2 is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with SU2. If not, see <http://www.gnu.org/licenses/>.
26 */
27#pragma once
28
29#include "CInterpolator.hpp"
30#include "../option_structure.hpp"
31#include "../containers/C2DContainer.hpp"
32
33/*!
34 * \brief Radial basis function interpolation.
35 * \ingroup Interfaces
36 */
37class CRadialBasisFunction final : public CInterpolator {
38 static_assert(su2passivematrix::IsRowMajor, "This class relies on row major storage throughout.");
39
40 private:
41 unsigned long MinDonors = 0, AvgDonors = 0, MaxDonors = 0;
42 passivedouble Density = 0.0, AvgCorrection = 0.0, MaxCorrection = 0.0;
43
44 public:
45 /*!
46 * \brief Constructor of the class.
47 * \param[in] geometry - Geometrical definition of the problem.
48 * \param[in] config - Definition of the particular problem.
49 * \param[in] iZone - index of the donor zone.
50 * \param[in] jZone - index of the target zone.
51 */
52 CRadialBasisFunction(CGeometry**** geometry_container, const CConfig* const* config, unsigned int iZone,
53 unsigned int jZone);
54
55 /*!
56 * \brief Set up transfer matrix defining relation between two meshes
57 * \param[in] config - Definition of the particular problem.
58 */
59 void SetTransferCoeff(CGeometry**** geometry, const CConfig* const* config) override;
60
61 /*!
62 * \brief Print information about the interpolation.
63 */
64 void PrintStatistics(void) const override;
65
66 /*!
67 * \brief Compute the value of a radial basis function, this is static so it can be re-used.
68 * \param[in] type - of radial basis function
69 * \param[in] radius - the characteristic dimension
70 * \param[in] dist - distance
71 * \return value of the RBF.
72 */
73 static su2double Get_RadialBasisValue(RADIAL_BASIS type, const su2double radius, const su2double dist);
74
75 /*!
76 * \brief Compute the RBF "generator" matrix with or without polynomial terms.
77 * \note Multiplying C_inv_trunc by a column vector gives specific coefficients for given "known values",
78 * conversely, multiplying (on the left) by a row vector of polynomial and RBF values gives generic
79 * interpolation coefficients for a given target evaluation point.
80 * \param[in] type - Type of radial basis function.
81 * \param[in] usePolynomial - Whether to use polynomial terms.
82 * \param[in] radius - Normalizes point-to-point distance when computing RBF values.
83 * \param[in] coords - Coordinates of the donor points.
84 * \param[out] nPolynomial - Num of poly terms, -1 if !usePolynomial, nDim-1 if coords lie on plane, else nDim.
85 * \param[out] keepPolynomialRow - Size nDim, signals which (if any) iDim was removed from polynomial term.
86 * \param[out] C_inv_trunc - The generator matrix as described above.
87 */
88 static void ComputeGeneratorMatrix(RADIAL_BASIS type, bool usePolynomial, su2double radius,
89 const su2activematrix& coords, int& nPolynomial, vector<int>& keepPolynomialRow,
90 su2passivematrix& C_inv_trunc);
91
92 /*!
93 * \brief If the polynomial term is included in the interpolation, and the points lie on a plane, the matrix
94 * becomes rank deficient and cannot be inverted. This method detects that condition and corrects it by
95 * removing a row from P (the polynomial part of the interpolation matrix).
96 * \param[in] max_diff_tol - Tolerance to detect whether points are on a plane.
97 * \param[out] keep_row - Marks the dimensions of P kept.
98 * \param[in,out] P - Polynomial part of the interpolation matrix, one row may be eliminated.
99 * \return n_polynomial - Size of the polynomial part on exit (in practice nDim or nDim-1).
100 */
101 static int CheckPolynomialTerms(su2double max_diff_tol, vector<int>& keep_row, su2passivematrix& P);
102
103 private:
104 /*!
105 * \brief Helper function, prunes (by setting to zero) small interpolation coefficients,
106 * i.e. <= tolerance*max(abs(coeffs)). The vector is re-scaled such that sum(coeffs)==1.
107 * \param[in] tolerance - Relative pruning tolerance.
108 * \param[in] size - Size of the coefficient vector.
109 * \param[in,out] coeffs - Iterator to start of vector of interpolation coefficients.
110 * \return Number of non-zero coefficients after pruning and correction factor.
111 */
112 template <typename Float, typename Int, class ForwardIt>
113 static pair<Int, Float> PruneSmallCoefficients(Float tolerance, Int size, ForwardIt coeffs) {
114 /*--- Determine the pruning threshold. ---*/
115 Float thresh = 0.0;
116 auto end = coeffs;
117 for (Int i = 0; i < size; ++i) thresh = max(thresh, fabs(*(end++)));
118 thresh *= tolerance;
119
120 /*--- Prune and count non-zeros. ---*/
121 Int numNonZeros = 0;
122 Float coeffSum = 0.0;
123 for (auto it = coeffs; it != end; ++it) {
124 if (fabs(*it) > thresh) { // keep
125 coeffSum += *it;
126 ++numNonZeros;
127 } else {
128 *it = 0.0;
129 } // prune
130 }
131
132 /*--- Correct remaining coefficients, sum must be 1 for conservation. ---*/
133 Float correction = 1.0 / coeffSum;
134 while (coeffs != end) *(coeffs++) *= correction;
135
136 return make_pair(numNonZeros, correction);
137 }
138};
Base class for multiphysics interpolation.
A templated matrix/vector-like object.
Definition C2DContainer.hpp:374
static constexpr bool IsRowMajor
Definition C2DContainer.hpp:391
Main class for defining the problem; basically this class reads the configuration file,...
Definition CConfig.hpp:64
Parent class for defining the geometry of the problem (complete geometry, multigrid agglomerated geom...
Definition CGeometry.hpp:75
Main class for defining the interpolator, it requires a child class for each particular interpolation...
Definition CInterpolator.hpp:47
const int size
MPI Size.
Definition CInterpolator.hpp:50
Radial basis function interpolation.
Definition CRadialBasisFunction.hpp:37
void PrintStatistics(void) const override
Print information about the interpolation.
Definition CRadialBasisFunction.cpp:57
static void ComputeGeneratorMatrix(RADIAL_BASIS type, bool usePolynomial, su2double radius, const su2activematrix &coords, int &nPolynomial, vector< int > &keepPolynomialRow, su2passivematrix &C_inv_trunc)
Compute the RBF "generator" matrix with or without polynomial terms.
Definition CRadialBasisFunction.cpp:427
void SetTransferCoeff(CGeometry ****geometry, const CConfig *const *config) override
Set up transfer matrix defining relation between two meshes.
Definition CRadialBasisFunction.cpp:105
static su2double Get_RadialBasisValue(RADIAL_BASIS type, const su2double radius, const su2double dist)
Compute the value of a radial basis function, this is static so it can be re-used.
Definition CRadialBasisFunction.cpp:73
static int CheckPolynomialTerms(su2double max_diff_tol, vector< int > &keep_row, su2passivematrix &P)
If the polynomial term is included in the interpolation, and the points lie on a plane,...
Definition CRadialBasisFunction.cpp:508
A simple SIMD type relying on implicit vectorization, i.e. done by the compiler, explicitly vectorize...
Definition vectorization.hpp:89
double passivedouble
Definition code_config.hpp:129
passivedouble su2double
Definition code_config.hpp:181
RADIAL_BASIS
Types of radial basis functions.
Definition option_structure.hpp:452