Documentation 6b54b78464
Loading...
Searching...
No Matches
CDataDrivenFluid.hpp
Go to the documentation of this file.
1/*!
2 * \file CDataDrivenFluid.hpp
3 * \brief Defines a template fluid model class using multilayer perceptrons
4 * for theromodynamic state definition
5 * \author E.C.Bunschoten
6 * \version 8.5.0 "Harrier"
7 *
8 * SU2 Project Website: https://su2code.github.io
9 *
10 * The SU2 Project is maintained by the SU2 Foundation
11 * (http://su2foundation.org)
12 *
13 * Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)
14 *
15 * SU2 is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
19 *
20 * SU2 is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with SU2. If not, see <http://www.gnu.org/licenses/>.
27 */
28
29#pragma once
30
31#include <vector>
32#include "../../../Common/include/containers/CLookUpTable.hpp"
33#if defined(HAVE_MLPCPP)
34#define MLP_CUSTOM_TYPE su2double
35#include "../../../subprojects/MLPCpp/include/CLookUp_ANN.hpp"
36#define USE_MLPCPP
37#endif
38#include "CFluidModel.hpp"
39
40/*!
41 * \class MiniTable2D
42 * \brief Simple 2D thermodynamic table used to identify the starting point for the Newton solver.
43 * \author: E.C.Bunschoten.
44 */
46 size_t nP{5},
47 n_vars;
48 su2activematrix TD_data;
49 su2vector<su2double> TD_data_min,TD_data_max;
50 public:
51 MiniTable2D()=default;
52
53 /*!
54 * \brief Set the number of table nodes
55 * \param[in] nP_in - Number of table nodes.
56 */
57 void SetNPoints(const size_t nP_in) { nP=nP_in; }
58
59 /*!
60 * \brief Set the number of thermodynamic variables in the table.
61 * \param[in] n_vars_in - Number of thermodynamic variables.
62 */
63 void SetNVars(const size_t n_vars_in) { n_vars = n_vars_in; }
64
65 /*!
66 * \brief Specify the thermodynamic data at a table node.
67 * \param[in] iVar - Variable index.
68 * \param[in] iX - Table node index.
69 * \param[in] val_var - Thermodynamic state value.
70 */
71 void SetTableData(const size_t iVar, const size_t iX, const su2double val_var) {
72 TD_data[iVar][iX] = val_var;
73 }
74
75 /*!
76 * \brief Size table data arrays.
77 */
78 void SizeTable();
79
80 /*!
81 * \brief Normalize thermodynamic data for regularization.
82 */
83 void ScaleTableData();
84
85 /*!
86 * \brief Find the node in the table closest to the query.
87 * \param[in] iX - Index of the first thermodynamic variable.
88 * \param[in] val_x - Query of the first thermodynamic variable.
89 * \param[in] iY - Index of the second thermodynamic variable.
90 * \param[in] val_y - Query of the second thermodynamic variable.
91 * \returns Nearest neighbor index.
92 */
93 size_t FindNode(const size_t iX, const su2double val_x, const size_t iY, const su2double val_y) const;
94};
95
96/*!
97 * \class CDataDrivenFluid
98 * \brief Template class for fluid model definition using multi-layer perceptrons for
99 * fluid dynamic state definition.
100 * \author: E.C.Bunschoten.
101 */
102class CDataDrivenFluid final : public CFluidModel {
103 protected:
104 int rank{MASTER_NODE}; /*!< \brief MPI Rank. */
106 ENUM_DATADRIVEN_METHOD::LUT; /*!< \brief Interpolation method for data set evaluation. */
107
108 string varname_rho, /*!< \brief Controlling variable name for density. */
109 varname_e; /*!< \brief Controlling variable name for static energy. */
110
111 su2double Newton_Relaxation, /*!< \brief Relaxation factor for Newton solvers. */
112 rho_start, /*!< \brief Starting value for the density in Newton solver processes. */
113 e_start, /*!< \brief Starting value for the energy in Newton solver processes. */
116 Newton_Tolerance, /*!< \brief Normalized tolerance for Newton solvers. */
117 rho_min, rho_max, /*!< \brief Minimum and maximum density values in data set. */
118 e_min, e_max; /*!< \brief Minimum and maximum energy values in data set. */
119
120 unsigned long MaxIter_Newton; /*!< \brief Maximum number of iterations for Newton solvers. */
121
122 su2double dsde_rho, /*!< \brief Entropy derivative w.r.t. density. */
123 dsdrho_e, /*!< \brief Entropy derivative w.r.t. static energy. */
124 d2sde2, /*!< \brief Entropy second derivative w.r.t. static energy. */
125 d2sdedrho, /*!< \brief Entropy second derivative w.r.t. density and static energy. */
126 d2sdrho2; /*!< \brief Entropy second derivative w.r.t. static density. */
127
128 su2double Enthalpy, /*!< \brief Fluid enthalpy value [J kg^-1] */
129 dhdrho_e, /*!< \brief Enthalpy derivative w.r.t. density. */
130 dhde_rho; /*!< \brief Enthalpy derivative w.r.t. static energy. */
131
132 vector<string> output_names_rhoe; /*!< \brief Output variable names listed in the data-driven method input file name. */
133 vector<su2double*> outputs_rhoe; /*!< \brief Pointers to output variables. */
134
135 vector<vector<su2double*>> dsdrhoe; /*!< \brief Entropy Jacobian terms. */
136 vector<vector<vector<su2double*>>> d2sdrhoe2; /*!< \brief Entropy Hessian terms. */
137
138 bool use_MLP_derivatives; /*!< \brief Use physics-informed model. */
139
141 /*--- Class variables for the multi-layer perceptron method ---*/
142#ifdef USE_MLPCPP
143 MLPToolbox::CLookUp_ANN *lookup_mlp; /*!< \brief Multi-layer perceptron collection. */
144 MLPToolbox::CIOMap iomap_rhoe; /*!< \brief Input-output map. */
145#endif
146 vector<su2double> MLP_inputs; /*!< \brief Inputs for the multi-layer perceptron look-up operation. */
147
148 MiniTable2D coarse_TD_table; /*!< \brief Small thermodynamic table used to identify the starting point of the Newton solver processes. */
149 const size_t iRho{0},iE{1},iP{2},iT{3}; /*!< Indices of thermodynamic variables in the table. */
150 su2vector<su2double> vals_rho_table, vals_e_table; /*!< Density and static energy values of the table nodes. */
151
152 CLookUpTable* lookup_table; /*!< \brief Look-up table regression object. */
153 unsigned long LUT_idx_s,
159 vector<unsigned long> LUT_lookup_indices;
160
161 unsigned long outside_dataset, /*!< \brief Density-energy combination lies outside data set. */
162 nIter_Newton; /*!< \brief Number of Newton solver iterations. */
163
164 /*!
165 * \brief Map dataset variables to specific look-up operations.
166 */
168
169 /*!
170 * \brief Evaluate dataset through multi-layer perceptron.
171 * \param[in] rho - Density value.
172 * \param[in] e - Static energy value.
173 * \return Query point lies outside MLP normalization range (0 is inside, 1 is outside).
174 */
175 unsigned long Predict_MLP(su2double rho, su2double e);
176
177 /*!
178 * \brief Evaluate dataset through look-up table.
179 * \param[in] rho - Density value.
180 * \param[in] e - Static energy value.
181 * \return Query point lies outside table data range (0 is inside, 1 is outside).
182 */
183 unsigned long Predict_LUT(su2double rho, su2double e);
184
185 /*!
186 * \brief Evaluate the data set.
187 * \param[in] rho - Density value.
188 * \param[in] e - Static energy value.
189 */
191
192 /*!
193 * \brief 2D Newton solver for computing the density and energy corresponding to Y1_target and Y2_target.
194 * \param[in] Y1_target - Target value for output quantity 1.
195 * \param[in] Y2_target - Target value for output quantity 2.
196 * \param[in] Y1 - Pointer to output quantity 1.
197 * \param[in] Y2 - Pointer to output quantity 2.
198 * \param[in] dY1drho - Pointer to the partial derivative of quantity 1 w.r.t. density at constant energy.
199 * \param[in] dY1de - Pointer to the partial derivative of quantity 1 w.r.t. energy at constant density.
200 * \param[in] dY2drho - Pointer to the partial derivative of quantity 2 w.r.t. density at constant energy.
201 * \param[in] dY2de - Pointer to the partial derivative of quantity 2 w.r.t. energy at constant density.
202 */
203 void Run_Newton_Solver(const su2double Y1_target, const su2double Y2_target, const su2double & Y1, const su2double & Y2, const su2double & dY1drho,
204 const su2double & dY1de, const su2double & dY2drho, const su2double & dY2de);
205
206 /*!
207 * \brief 1D Newton solver for computing the density or energy corresponding to Y_target.
208 * \param[in] Y_target - Target quantity value.
209 * \param[in] Y - Pointer to output quantity.
210 * \param[in] X - Pointer to controlling variable (density or energy).
211 * \param[in] dYdX - Pointer to the partial derivative of target quantity w.r.t. controlling variable.
212 */
213 void Run_Newton_Solver(const su2double Y_target, const su2double & Y, su2double & X, const su2double & dYdX);
214
216
217 public:
218 /*!
219 * \brief Constructor of the class.
220 */
221 CDataDrivenFluid(const CConfig* config, bool display = true);
222
224 /*!
225 * \brief Set the Dimensionless State using Density and Internal Energy.
226 * \param[in] rho - first thermodynamic variable (density).
227 * \param[in] e - second thermodynamic variable (static energy).
228 */
229 void SetTDState_rhoe(su2double rho, su2double e) override;
230
231 /*!
232 * \brief Set the Dimensionless State using Pressure and Temperature.
233 * \param[in] P - first thermodynamic variable (pressure).
234 * \param[in] T - second thermodynamic variable (temperature).
235 */
236 void SetTDState_PT(su2double P, su2double T) override;
237
238 /*!
239 * \brief Set the Dimensionless State using Pressure and Density.
240 * \param[in] P - first thermodynamic variable (pressure).
241 * \param[in] rho - second thermodynamic variable (density).
242 */
243 void SetTDState_Prho(su2double P, su2double rho) override;
244
245 /*!
246 * \brief Set the Dimensionless Internal Energy using Pressure and Density.
247 * \param[in] P - first thermodynamic variable (pressure).
248 * \param[in] rho - second thermodynamic variable (density).
249 */
250 void SetEnergy_Prho(su2double P, su2double rho) override;
251
252 /*!
253 * \brief Set the Dimensionless Internal Energy using Pressure and Density.
254 * \param[in] rho - second thermodynamic variable (density).
255 */
256 void SetTDState_rhoT(su2double rho, su2double T) override;
257
258 /*!
259 * \brief Set the Dimensionless State using Enthalpy and Entropy.
260 * \param[in] h - first thermodynamic variable (h).
261 * \param[in] s - second thermodynamic variable (s).
262 */
263 void SetTDState_hs(su2double h, su2double s) override;
264
265 /*!
266 * \brief Set the Dimensionless State using Pressure and Entropy.
267 * \param[in] P - first thermodynamic variable (P).
268 * \param[in] s - second thermodynamic variable (s).
269 */
270 void SetTDState_Ps(su2double P, su2double s) override;
271
272 /*!
273 * \brief compute some derivatives of enthalpy and entropy needed for subsonic inflow BC
274 * \param[in] InputSpec - Input pair for FLP calls ("Pv").
275 * \param[in] th1 - first thermodynamic variable (P).
276 * \param[in] th2 - second thermodynamic variable (v).
277 *
278 */
279 void ComputeDerivativeNRBC_Prho(su2double P, su2double rho) override;
280
281 /*!
282 * \brief Get fluid model extrapolation instance.
283 * \return Query point lies outside fluid model data range.
284 */
285 unsigned long GetExtrapolation() const override { return outside_dataset; }
286
287 /*!
288 * \brief Get number of Newton solver iterations.
289 * \return Newton solver iteration count at termination.
290 */
291 unsigned long GetnIter_Newton() override { return nIter_Newton; }
292};
Defines the main fluid model class for thermophysical properties.
A templated matrix/vector-like object.
Definition C2DContainer.hpp:374
Main class for defining the problem; basically this class reads the configuration file,...
Definition CConfig.hpp:64
Template class for fluid model definition using multi-layer perceptrons for fluid dynamic state defin...
Definition CDataDrivenFluid.hpp:102
void SetTDState_hs(su2double h, su2double s) override
Set the Dimensionless State using Enthalpy and Entropy.
Definition CDataDrivenFluid.cpp:242
unsigned long LUT_idx_dsde_rho
Definition CDataDrivenFluid.hpp:154
su2double d2sde2
Entropy second derivative w.r.t. static energy.
Definition CDataDrivenFluid.hpp:124
MiniTable2D coarse_TD_table
Small thermodynamic table used to identify the starting point of the Newton solver processes.
Definition CDataDrivenFluid.hpp:148
void Evaluate_Dataset(su2double rho, su2double e)
Evaluate the data set.
Definition CDataDrivenFluid.cpp:287
su2double e_max
Minimum and maximum energy values in data set.
Definition CDataDrivenFluid.hpp:118
bool display_Newton_process
Definition CDataDrivenFluid.hpp:140
const size_t iT
Definition CDataDrivenFluid.hpp:149
su2double d2sdrho2
Entropy second derivative w.r.t. static density.
Definition CDataDrivenFluid.hpp:126
unsigned long GetExtrapolation() const override
Get fluid model extrapolation instance.
Definition CDataDrivenFluid.hpp:285
vector< su2double * > outputs_rhoe
Pointers to output variables.
Definition CDataDrivenFluid.hpp:133
su2double Newton_Tolerance
Normalized tolerance for Newton solvers.
Definition CDataDrivenFluid.hpp:116
const size_t iE
Definition CDataDrivenFluid.hpp:149
string varname_e
Controlling variable name for static energy.
Definition CDataDrivenFluid.hpp:109
su2double e_start
Starting value for the energy in Newton solver processes.
Definition CDataDrivenFluid.hpp:113
unsigned long Predict_LUT(su2double rho, su2double e)
Evaluate dataset through look-up table.
Definition CDataDrivenFluid.cpp:280
su2double e_query
Definition CDataDrivenFluid.hpp:115
su2double Newton_Relaxation
Relaxation factor for Newton solvers.
Definition CDataDrivenFluid.hpp:111
void Run_Newton_Solver(const su2double Y1_target, const su2double Y2_target, const su2double &Y1, const su2double &Y2, const su2double &dY1drho, const su2double &dY1de, const su2double &dY2drho, const su2double &dY2de)
2D Newton solver for computing the density and energy corresponding to Y1_target and Y2_target.
Definition CDataDrivenFluid.cpp:301
void SetTDState_Ps(su2double P, su2double s) override
Set the Dimensionless State using Pressure and Entropy.
Definition CDataDrivenFluid.cpp:250
void ComputeDerivativeNRBC_Prho(su2double P, su2double rho) override
compute some derivatives of enthalpy and entropy needed for subsonic inflow BC
Definition CDataDrivenFluid.cpp:258
su2double dsde_rho
Entropy derivative w.r.t. density.
Definition CDataDrivenFluid.hpp:122
unsigned long LUT_idx_d2sdedrho
Definition CDataDrivenFluid.hpp:157
bool use_MLP_derivatives
Use physics-informed model.
Definition CDataDrivenFluid.hpp:138
void SetTDState_rhoT(su2double rho, su2double T) override
Set the Dimensionless Internal Energy using Pressure and Density.
Definition CDataDrivenFluid.cpp:232
CLookUpTable * lookup_table
Look-up table regression object.
Definition CDataDrivenFluid.hpp:152
const size_t iRho
Definition CDataDrivenFluid.hpp:149
void MapInputs_to_Outputs()
Map dataset variables to specific look-up operations.
Definition CDataDrivenFluid.cpp:92
int rank
MPI Rank.
Definition CDataDrivenFluid.hpp:104
void SetTDState_rhoe(su2double rho, su2double e) override
Set the Dimensionless State using Density and Internal Energy.
Definition CDataDrivenFluid.cpp:146
su2double rho_min
Definition CDataDrivenFluid.hpp:117
unsigned long MaxIter_Newton
Maximum number of iterations for Newton solvers.
Definition CDataDrivenFluid.hpp:120
unsigned long Predict_MLP(su2double rho, su2double e)
Evaluate dataset through multi-layer perceptron.
Definition CDataDrivenFluid.cpp:268
string varname_rho
Controlling variable name for density.
Definition CDataDrivenFluid.hpp:108
void ComputeIdealGasQuantities()
Definition CDataDrivenFluid.cpp:393
vector< unsigned long > LUT_lookup_indices
Definition CDataDrivenFluid.hpp:159
su2double rho_max
Minimum and maximum density values in data set.
Definition CDataDrivenFluid.hpp:117
unsigned long LUT_idx_dsdrho_e
Definition CDataDrivenFluid.hpp:155
vector< string > output_names_rhoe
Output variable names listed in the data-driven method input file name.
Definition CDataDrivenFluid.hpp:132
unsigned long outside_dataset
Density-energy combination lies outside data set.
Definition CDataDrivenFluid.hpp:161
vector< vector< su2double * > > dsdrhoe
Entropy Jacobian terms.
Definition CDataDrivenFluid.hpp:135
su2double e_min
Definition CDataDrivenFluid.hpp:118
ENUM_DATADRIVEN_METHOD Kind_DataDriven_Method
Interpolation method for data set evaluation.
Definition CDataDrivenFluid.hpp:105
void SetTDState_Prho(su2double P, su2double rho) override
Set the Dimensionless State using Pressure and Density.
Definition CDataDrivenFluid.cpp:217
su2double rho_start
Starting value for the density in Newton solver processes.
Definition CDataDrivenFluid.hpp:112
su2double dsdrho_e
Entropy derivative w.r.t. static energy.
Definition CDataDrivenFluid.hpp:123
unsigned long LUT_idx_s
Definition CDataDrivenFluid.hpp:153
const size_t iP
Definition CDataDrivenFluid.hpp:149
void SetTDState_PT(su2double P, su2double T) override
Set the Dimensionless State using Pressure and Temperature.
Definition CDataDrivenFluid.cpp:207
su2double d2sdedrho
Entropy second derivative w.r.t. density and static energy.
Definition CDataDrivenFluid.hpp:125
su2double dhde_rho
Enthalpy derivative w.r.t. static energy.
Definition CDataDrivenFluid.hpp:130
unsigned long GetnIter_Newton() override
Get number of Newton solver iterations.
Definition CDataDrivenFluid.hpp:291
vector< su2double > MLP_inputs
Inputs for the multi-layer perceptron look-up operation.
Definition CDataDrivenFluid.hpp:146
void SetEnergy_Prho(su2double P, su2double rho) override
Set the Dimensionless Internal Energy using Pressure and Density.
Definition CDataDrivenFluid.cpp:222
su2double dhdrho_e
Enthalpy derivative w.r.t. density.
Definition CDataDrivenFluid.hpp:129
su2vector< su2double > vals_rho_table
Definition CDataDrivenFluid.hpp:150
su2double rho_query
Definition CDataDrivenFluid.hpp:114
unsigned long LUT_idx_d2sde2
Definition CDataDrivenFluid.hpp:156
unsigned long nIter_Newton
Number of Newton solver iterations.
Definition CDataDrivenFluid.hpp:162
~CDataDrivenFluid()
Definition CDataDrivenFluid.cpp:78
su2double Enthalpy
Fluid enthalpy value [J kg^-1].
Definition CDataDrivenFluid.hpp:128
unsigned long LUT_idx_d2sdrho2
Definition CDataDrivenFluid.hpp:158
su2vector< su2double > vals_e_table
Definition CDataDrivenFluid.hpp:150
vector< vector< vector< su2double * > > > d2sdrhoe2
Entropy Hessian terms.
Definition CDataDrivenFluid.hpp:136
Main class for defining the Thermo-Physical Model.
Definition CFluidModel.hpp:47
Look up table.
Definition CLookUpTable.hpp:43
Simple 2D thermodynamic table used to identify the starting point for the Newton solver.
Definition CDataDrivenFluid.hpp:45
size_t FindNode(const size_t iX, const su2double val_x, const size_t iY, const su2double val_y) const
Find the node in the table closest to the query.
Definition CDataDrivenFluid.cpp:460
void ScaleTableData()
Normalize thermodynamic data for regularization.
Definition CDataDrivenFluid.cpp:449
void SizeTable()
Size table data arrays.
Definition CDataDrivenFluid.cpp:445
void SetTableData(const size_t iVar, const size_t iX, const su2double val_var)
Specify the thermodynamic data at a table node.
Definition CDataDrivenFluid.hpp:71
MiniTable2D()=default
void SetNVars(const size_t n_vars_in)
Set the number of thermodynamic variables in the table.
Definition CDataDrivenFluid.hpp:63
void SetNPoints(const size_t nP_in)
Set the number of table nodes.
Definition CDataDrivenFluid.hpp:57
passivedouble su2double
Definition code_config.hpp:181
const int MASTER_NODE
Master node for MPI parallelization.
Definition option_structure.hpp:112
ENUM_DATADRIVEN_METHOD
Types of interpolation methods for data-driven fluid models.
Definition option_structure.hpp:700