Documentation a537f1bdf2
Loading...
Searching...
No Matches
C1DInterpolation.hpp
Go to the documentation of this file.
1/*!
2 * \file C1DInterpolation.hpp
3 * \brief Classes for 1D interpolation.
4 * \author Aman Baig, 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
28#pragma once
29
30#include <cassert>
31#include <vector>
32#include <algorithm>
33#include "../option_structure.hpp"
34
35/*!
36 * \brief Base class for 1D interpolation.
37 * \ingroup LookUpInterp
38 */
40 protected:
41 std::vector<su2double> x, y; /*!< \brief Data points. */
42
43 /*!
44 * \brief Find containing interval.
45 * \param[in] xi - Point for which interpolation is required.
46 * \return The start index of the interval, or the size if the coordinate is out of bounds.
47 */
48 inline size_t lower_bound(su2double xi) const {
49 if (xi <= x.front() || xi >= x.back()) return x.size();
50
51 size_t lb = 0, ub = x.size() - 1;
52
53 while (ub - lb > 1) {
54 size_t mid = (lb + ub) / 2;
55 auto& change = (xi < x[mid]) ? ub : lb;
56 change = mid;
57 }
58 return lb;
59 }
60
61 public:
62 /*!
63 * \brief Virtual destructor of the C1DInterpolation class.
64 */
65 virtual ~C1DInterpolation() = default;
66
67 /*!
68 * \brief Virtual method for setting the coefficients of the respective spline.
69 * \param[in] X - the x values.
70 * \param[in] Data - the f(x) values.
71 */
72 virtual void SetSpline(const std::vector<su2double>& X, const std::vector<su2double>& Data) {
73 assert(X.size() == Data.size());
74 x = X;
75 y = Data;
76 }
77
78 /*!
79 * \brief Evaluate the value of the spline at a point.
80 */
81 virtual su2double EvaluateSpline(su2double Point_Interp) const = 0;
82 inline su2double operator()(su2double Point_Interp) const { return EvaluateSpline(Point_Interp); }
83};
84
85/*!
86 * \brief Akima 1D interpolation.
87 * \ingroup LookUpInterp
88 */
90 protected:
91 std::vector<su2double> b, c, d; /*!< \brief local variables for Akima spline cooefficients */
92
93 public:
95
96 /*!
97 * \brief Constructor of the CAkimaInterpolation class.
98 * \param[in] X - the x values (sorted low to high).
99 * \param[in] Data - the f(x) values.
100 */
101 CAkimaInterpolation(const std::vector<su2double>& X, const std::vector<su2double>& Data) {
103 }
104
105 /*!
106 * \brief Build the spline.
107 */
108 void SetSpline(const std::vector<su2double>& X, const std::vector<su2double>& Data) override;
109
110 /*!
111 * \brief Evaluate the value of the spline at a point.
112 */
113 su2double EvaluateSpline(su2double Point_Interp) const final;
114};
115
116/*!
117 * \brief Cubic spline interpolation.
118 * \ingroup LookUpInterp
119 */
120class CCubicSpline final : public CAkimaInterpolation {
121 public:
123
124 private:
125 const su2double startVal, endVal; /*!< \brief "boundary" values. */
126 const END_TYPE startDer, endDer; /*!< \brief 1st or 2nd derivative "boundary" conditions. */
127
128 public:
129 CCubicSpline() = default;
130
131 /*!
132 * \brief Constructor of the CCubicSpline class (defaults to natural spline).
133 * \param[in] X - the x values (sorted low to high).
134 * \param[in] Data - the f(x) values.
135 * \param[in] startCondition - 1st or 2nd derivative imposed at the start.
136 * \param[in] startValue - value of the derivative imposed at the start.
137 * \param[in] endCondition - 1st or 2nd derivative imposed at the end.
138 * \param[in] endValue - value of the derivative imposed at the end.
139 */
140 CCubicSpline(const std::vector<su2double>& X, const std::vector<su2double>& Data, END_TYPE startCondition = SECOND,
141 su2double startValue = 0.0, END_TYPE endCondition = SECOND, su2double endValue = 0.0)
142 : startVal(startValue), endVal(endValue), startDer(startCondition), endDer(endCondition) {
143 SetSpline(X, Data);
144 }
145
146 /*!
147 * \brief Build the spline.
148 */
149 void SetSpline(const std::vector<su2double>& X, const std::vector<su2double>& Data) override;
150};
151
152/*!
153 * \brief Linear interpolation.
154 * \ingroup LookUpInterp
155 */
157 public:
159
160 /*!
161 * \brief Constructor of the CLinearInterpolation class.
162 * \param[in] X - the x values (sorted low to high).
163 * \param[in] Data - the f(x) values.
164 */
165 CLinearInterpolation(const std::vector<su2double>& X, const std::vector<su2double>& Data) { SetSpline(X, Data); }
166
167 /*!
168 * \brief Evaluate the value of the spline at a point.
169 */
170 su2double EvaluateSpline(su2double Point_Interp) const override;
171};
172
173/*!
174 * \brief Corrects for interpolation type.
175 * \param[in] Inlet_Interpolated - the interpolated data after spline evaluation.
176 * \param[in] Theta - the angle of the vertex (in xy plane).
177 * \param[in] nDim - the dimensions of the case.
178 * \param[in] Coord - the coordinates of the vertex.
179 * \param[in] nVar_Turb - the number of turbulence variables as defined by turbulence model
180 * \param[in] ENUM_INLET_INTERPOLATIONTYPE - enum of the interpolation type to be done
181 * \returns the corrected Inlet Interpolated Data.
182 */
183std::vector<su2double> CorrectedInletValues(const std::vector<su2double>& Inlet_Interpolated, su2double Theta,
184 unsigned short nDim, const su2double* Coord, unsigned short nVar_Turb,
185 INLET_INTERP_TYPE Interpolation_Type);
186
187/*!
188 * \brief Prints the Inlet Interpolated Data
189 * \param[in] Inlet_Interpolated_Interpolated - the final std::vector for the interpolated data
190 * \param[in] Marker - name of the inlet marker
191 * \param[in] nVertex - total number of vertexes.
192 * \param[in] nDim - the dimensions of the problem.
193 * \param[in] nColumns - the number of columns in the final interpolated data
194 */
195void PrintInletInterpolatedData(const std::vector<su2double>& Inlet_Data_Interpolated, const std::string& Marker,
196 unsigned long nVertex, unsigned short nDim, unsigned short nColumns);
void PrintInletInterpolatedData(const std::vector< su2double > &Inlet_Data_Interpolated, const std::string &Marker, unsigned long nVertex, unsigned short nDim, unsigned short nColumns)
Prints the Inlet Interpolated Data.
std::vector< su2double > CorrectedInletValues(const std::vector< su2double > &Inlet_Interpolated, su2double Theta, unsigned short nDim, const su2double *Coord, unsigned short nVar_Turb, INLET_INTERP_TYPE Interpolation_Type)
Corrects for interpolation type.
Base class for 1D interpolation.
Definition C1DInterpolation.hpp:39
virtual void SetSpline(const std::vector< su2double > &X, const std::vector< su2double > &Data)
Virtual method for setting the coefficients of the respective spline.
Definition C1DInterpolation.hpp:72
std::vector< su2double > y
Data points.
Definition C1DInterpolation.hpp:41
virtual ~C1DInterpolation()=default
Virtual destructor of the C1DInterpolation class.
std::vector< su2double > x
Definition C1DInterpolation.hpp:41
su2double operator()(su2double Point_Interp) const
Definition C1DInterpolation.hpp:82
size_t lower_bound(su2double xi) const
Find containing interval.
Definition C1DInterpolation.hpp:48
virtual su2double EvaluateSpline(su2double Point_Interp) const =0
Evaluate the value of the spline at a point.
Akima 1D interpolation.
Definition C1DInterpolation.hpp:89
std::vector< su2double > c
Definition C1DInterpolation.hpp:91
CAkimaInterpolation(const std::vector< su2double > &X, const std::vector< su2double > &Data)
Constructor of the CAkimaInterpolation class.
Definition C1DInterpolation.hpp:101
std::vector< su2double > b
Definition C1DInterpolation.hpp:91
CAkimaInterpolation()=default
su2double EvaluateSpline(su2double Point_Interp) const final
Evaluate the value of the spline at a point.
Definition C1DInterpolation.cpp:37
std::vector< su2double > d
local variables for Akima spline cooefficients
Definition C1DInterpolation.hpp:91
void SetSpline(const std::vector< su2double > &X, const std::vector< su2double > &Data) override
Build the spline.
Definition C1DInterpolation.cpp:118
Cubic spline interpolation.
Definition C1DInterpolation.hpp:120
CCubicSpline()=default
CCubicSpline(const std::vector< su2double > &X, const std::vector< su2double > &Data, END_TYPE startCondition=SECOND, su2double startValue=0.0, END_TYPE endCondition=SECOND, su2double endValue=0.0)
Constructor of the CCubicSpline class (defaults to natural spline).
Definition C1DInterpolation.hpp:140
END_TYPE
Definition C1DInterpolation.hpp:122
@ FIRST
Definition C1DInterpolation.hpp:122
@ SECOND
Definition C1DInterpolation.hpp:122
void SetSpline(const std::vector< su2double > &X, const std::vector< su2double > &Data) override
Build the spline.
Definition C1DInterpolation.cpp:55
Linear interpolation.
Definition C1DInterpolation.hpp:156
su2double EvaluateSpline(su2double Point_Interp) const override
Evaluate the value of the spline at a point.
Definition C1DInterpolation.cpp:47
CLinearInterpolation(const std::vector< su2double > &X, const std::vector< su2double > &Data)
Constructor of the CLinearInterpolation class.
Definition C1DInterpolation.hpp:165
CLinearInterpolation()=default
passivedouble su2double
Definition code_config.hpp:181
INLET_INTERP_TYPE
type of radial spanwise interpolation data type for the inlet face
Definition option_structure.hpp:486