Skip to content

Commit c6f2c46

Browse files
Implemented ideal gas approximation for data-driven fluid model, such that initial values for density and energy no longer need to be provided by the user
1 parent b4320bc commit c6f2c46

9 files changed

Lines changed: 106 additions & 143 deletions

File tree

Common/include/CConfig.hpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,7 @@ class CConfig {
523523
n_Datadriven_files;
524524
ENUM_DATADRIVEN_METHOD Kind_DataDriven_Method; /*!< \brief Method used for datset regression in data-driven fluid models. */
525525

526-
su2double DataDriven_Relaxation_Factor, /*!< \brief Relaxation factor for Newton solvers in data-driven fluid models. */
527-
DataDriven_initial_density, /*!< \brief Initial density value for Newton solvers in data-driven fluid models. */
528-
DataDriven_initial_energy; /*!< \brief Initial static energy value for Newton solvers in data-driven fluid models. */
526+
su2double DataDriven_Relaxation_Factor; /*!< \brief Relaxation factor for Newton solvers in data-driven fluid models. */
529527

530528
STRUCT_TIME_INT Kind_TimeIntScheme_FEA; /*!< \brief Time integration for the FEA equations. */
531529
STRUCT_SPACE_ITE Kind_SpaceIteScheme_FEA; /*!< \brief Iterative scheme for nonlinear structural analysis. */
@@ -3875,17 +3873,6 @@ class CConfig {
38753873
*/
38763874
su2double GetRelaxation_DataDriven(void) const { return DataDriven_Relaxation_Factor; }
38773875

3878-
/*!
3879-
* \brief Get initial value for the density in the Newton solvers in the data-driven fluid model.
3880-
* \return Initial density value.
3881-
*/
3882-
su2double GetDensity_Init_DataDriven(void) const { return DataDriven_initial_density; }
3883-
/*!
3884-
* \brief Get initial value for the static energy in the Newton solvers in the data-driven fluid model.
3885-
* \return Initial dstatic energy value.
3886-
*/
3887-
su2double GetEnergy_Init_DataDriven(void) const { return DataDriven_initial_energy; }
3888-
38893876
/*!
38903877
* \brief Returns the name of the fluid we are using in CoolProp.
38913878
*/

Common/src/CConfig.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,10 +1176,6 @@ void CConfig::SetConfig_Options() {
11761176
addStringListOption("FILENAMES_INTERPOLATOR", n_Datadriven_files, DataDriven_Method_FileNames);
11771177
/*!\brief DATADRIVEN_NEWTON_RELAXATION \n DESCRIPTION: Relaxation factor for Newton solvers in data-driven fluid model. \n \ingroup Config*/
11781178
addDoubleOption("DATADRIVEN_NEWTON_RELAXATION", DataDriven_Relaxation_Factor, 0.05);
1179-
/*!\brief DATADRIVEN_FLUID_INITIAL_DENSITY \n DESCRIPTION: Initial value for the density in the Newton solvers in the data-driven fluid model. \n \ingroup Config*/
1180-
addDoubleOption("DATADRIVEN_FLUID_INITIAL_DENSITY", DataDriven_initial_density, 1.225);
1181-
/*!\brief DATADRIVEN_FLUID_INITIAL_ENERGY \n DESCRIPTION: Initial value for the static energy in the Newton solvers in the data-driven fluid model. \n \ingroup Config*/
1182-
addDoubleOption("DATADRIVEN_FLUID_INITIAL_ENERGY", DataDriven_initial_energy, 1e5);
11831179

11841180
/*!\brief CONFINEMENT_PARAM \n DESCRIPTION: Input Confinement Parameter for Vorticity Confinement*/
11851181
addDoubleOption("CONFINEMENT_PARAM", Confinement_Param, 0.0);

SU2_CFD/include/fluid/CDataDrivenFluid.hpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,18 @@ class CDataDrivenFluid final : public CFluidModel {
4949
ENUM_DATADRIVEN_METHOD Kind_DataDriven_Method =
5050
ENUM_DATADRIVEN_METHOD::LUT; /*!< \brief Interpolation method for data set evaluation. */
5151

52+
string varname_rho, /*!< \brief Controlling variable name for density. */
53+
varname_e; /*!< \brief Controlling variable name for static energy. */
54+
5255
size_t idx_rho, /*!< \brief Interpolator index for density input. */
5356
idx_e; /*!< \brief Interpolator index for energy input. */
5457

5558
su2double Newton_Relaxation, /*!< \brief Relaxation factor for Newton solvers. */
5659
rho_start, /*!< \brief Starting value for the density in Newton solver processes. */
5760
e_start, /*!< \brief Starting value for the energy in Newton solver processes. */
58-
rho_init, /*!< \brief Initial value for the density from config. */
59-
e_init, /*!< \brief Initial value for the energy from config. */
60-
Newton_Tolerance; /*!< \brief Normalized tolerance for Newton solvers. */
61+
Newton_Tolerance, /*!< \brief Normalized tolerance for Newton solvers. */
62+
rho_min, rho_max, /*!< \brief Minimum and maximum density values in data set. */
63+
e_min, e_max; /*!< \brief Minimum and maximum energy values in data set. */
6164

6265
unsigned long MaxIter_Newton; /*!< \brief Maximum number of iterations for Newton solvers. */
6366

@@ -67,6 +70,13 @@ class CDataDrivenFluid final : public CFluidModel {
6770
d2sdedrho, /*!< \brief Entropy second derivative w.r.t. density and static energy. */
6871
d2sdrho2; /*!< \brief Entropy second derivative w.r.t. static density. */
6972

73+
su2double R_idealgas, /*!< \brief Approximated ideal gas constant. */
74+
Cp_idealgas, /*!< \brief Approximated ideal gas specific heat at constant pressure. */
75+
gamma_idealgas, /*!< \brief Approximated ideal gas specific heat ratio. */
76+
Cv_idealgas, /*!< \brief Approximated ideal gas specific heat at constant volume. */
77+
P_middle, /*!< \brief Pressure computed from the centre of the data set. */
78+
T_middle; /*!< \brief Temperature computed from the centre of the data set. */
79+
7080
su2double Enthalpy, /*!< \brief Fluid enthalpy value [J kg^-1] */
7181
dhdrho_e, /*!< \brief Enthalpy derivative w.r.t. density. */
7282
dhde_rho; /*!< \brief Enthalpy derivative w.r.t. static energy. */
@@ -77,8 +87,6 @@ class CDataDrivenFluid final : public CFluidModel {
7787

7888
vector<su2double*> outputs_rhoe; /*!< \brief Pointers to output variables. */
7989

80-
bool set_local_rhoe = false;
81-
8290
/*--- Class variables for the multi-layer perceptron method ---*/
8391
#ifdef USE_MLPCPP
8492
MLPToolbox::CLookUp_ANN* lookup_mlp; /*!< \brief Multi-layer perceptron collection. */
@@ -142,6 +150,7 @@ class CDataDrivenFluid final : public CFluidModel {
142150
*/
143151
void Run_Newton_Solver(su2double Y_target, su2double* Y, su2double* X, su2double* dYdX);
144152

153+
void ComputeIdealGasQuantities();
145154
public:
146155
/*!
147156
* \brief Constructor of the class.
@@ -197,18 +206,6 @@ class CDataDrivenFluid final : public CFluidModel {
197206
*/
198207
void SetTDState_Ps(su2double P, su2double s) override;
199208

200-
/*!
201-
* \brief Set the initial guess for the density in Newton solvers.
202-
* \param[in] rho - Initial value for density.
203-
*/
204-
void SetInitialDensity(su2double rho) override { rho_start = rho; }
205-
206-
/*!
207-
* \brief Set the initial guess for the static energy in Newton solvers.
208-
* \param[in] e - Initial value for static energy.
209-
*/
210-
void SetInitialEnergy(su2double e) override { e_start = e; }
211-
212209
/*!
213210
* \brief Get fluid model extrapolation instance.
214211
* \return Query point lies outside fluid model data range.

SU2_CFD/include/fluid/CFluidModel.hpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,6 @@ class CFluidModel {
345345
*/
346346
void SetEddyViscosity(su2double val_Mu_Turb) { Mu_Turb = val_Mu_Turb; }
347347

348-
/*!
349-
* \brief Set the initial guess for the density in Newton solvers
350-
* \param[in] rho - Initial value for density.
351-
*/
352-
virtual void SetInitialDensity(su2double rho) {}
353-
354-
/*!
355-
* \brief Set the initial guess for the static energy in Newton solvers
356-
* \param[in] e - Initial value for static energy.
357-
*/
358-
virtual void SetInitialEnergy(su2double e) {}
359-
360348
/*!
361349
* \brief Get fluid model extrapolation instance
362350
* \return Query point lies outside fluid model data range.

SU2_CFD/src/fluid/CDataDrivenFluid.cpp

Lines changed: 85 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ CDataDrivenFluid::CDataDrivenFluid(const CConfig* config, bool display) : CFluid
3535
rank = SU2_MPI::GetRank();
3636
Kind_DataDriven_Method = config->GetKind_DataDriven_Method();
3737

38+
varname_rho = "Density";
39+
varname_e = "Energy";
40+
3841
/*--- Set up interpolation algorithm according to data-driven method. Currently only MLP's are supported. ---*/
3942
switch (Kind_DataDriven_Method) {
4043
case ENUM_DATADRIVEN_METHOD::MLP:
@@ -46,7 +49,7 @@ CDataDrivenFluid::CDataDrivenFluid(const CConfig* config, bool display) : CFluid
4649
#endif
4750
break;
4851
case ENUM_DATADRIVEN_METHOD::LUT:
49-
lookup_table = new CLookUpTable(config->GetDataDriven_FileNames()[0], "Density", "Energy");
52+
lookup_table = new CLookUpTable(config->GetDataDriven_FileNames()[0], varname_rho, varname_e);
5053
break;
5154
default:
5255
break;
@@ -60,13 +63,8 @@ CDataDrivenFluid::CDataDrivenFluid(const CConfig* config, bool display) : CFluid
6063
/*--- Preprocessing of inputs and outputs for the interpolation method. ---*/
6164
MapInputs_to_Outputs();
6265

63-
/*--- Set initial values for density and energy based on config options. ---*/
64-
rho_init = config->GetDensity_Init_DataDriven();
65-
e_init = config->GetEnergy_Init_DataDriven();
66-
67-
/*--- Set default Newton solver density and energy values. ---*/
68-
rho_start = rho_init;
69-
e_start = e_init;
66+
/*--- Compute approximate ideal gas properties ---*/
67+
ComputeIdealGasQuantities();
7068
}
7169

7270
CDataDrivenFluid::~CDataDrivenFluid() {
@@ -89,8 +87,8 @@ void CDataDrivenFluid::MapInputs_to_Outputs() {
8987
input_names_rhoe.resize(2);
9088
idx_rho = 0;
9189
idx_e = 1;
92-
input_names_rhoe[idx_rho] = "Density";
93-
input_names_rhoe[idx_e] = "Energy";
90+
input_names_rhoe[idx_rho] = varname_rho;
91+
input_names_rhoe[idx_e] = varname_e;
9492

9593
/*--- Required outputs for the interpolation method are entropy and its partial derivatives with respect to energy and
9694
* density. ---*/
@@ -128,7 +126,11 @@ void CDataDrivenFluid::SetTDState_rhoe(su2double rho, su2double e) {
128126
Density = rho;
129127
StaticEnergy = e;
130128

131-
Evaluate_Dataset(rho, e);
129+
/*--- Clip density and energy values to prevent extrapolation. ---*/
130+
Density = min(rho_max, max(rho_min, Density));
131+
StaticEnergy = min(e_max, max(e_min, StaticEnergy));
132+
133+
Evaluate_Dataset(Density, StaticEnergy);
132134

133135
/*--- Compute speed of sound. ---*/
134136
auto blue_term = (dsdrho_e * (2 - rho * pow(dsde_rho, -1) * d2sdedrho) + rho * d2sdrho2);
@@ -158,14 +160,14 @@ void CDataDrivenFluid::SetTDState_rhoe(su2double rho, su2double e) {
158160
dhdP_rho = dhde_rho * (1 / dPde_rho);
159161
dsdrho_P = dsdrho_e - dPdrho_e * (1 / dPde_rho) * dsde_rho;
160162
dsdP_rho = dsde_rho / dPde_rho;
161-
162-
if (set_local_rhoe) {
163-
rho_start = Newton_Relaxation * Density + (1 - Newton_Relaxation) * rho_init;
164-
e_start = Newton_Relaxation * StaticEnergy + (1 - Newton_Relaxation) * e_init;
165-
}
166163
}
167164

168165
void CDataDrivenFluid::SetTDState_PT(su2double P, su2double T) {
166+
167+
/*--- Approximate density and static energy with ideal gas law. ---*/
168+
rho_start = P / (R_idealgas * T);
169+
e_start = Cv_idealgas * T;
170+
169171
/*--- Run 2D Newton solver for pressure and temperature ---*/
170172
Run_Newton_Solver(P, T, &Pressure, &Temperature, &dPdrho_e, &dPde_rho, &dTdrho_e, &dTde_rho);
171173
}
@@ -178,24 +180,44 @@ void CDataDrivenFluid::SetTDState_Prho(su2double P, su2double rho) {
178180
void CDataDrivenFluid::SetEnergy_Prho(su2double P, su2double rho) {
179181
/*--- Run 1D Newton solver for pressure at constant density. ---*/
180182
Density = rho;
181-
StaticEnergy = e_start;
183+
184+
/*--- Approximate static energy through ideal gas law. ---*/
185+
su2double e_idealgas = Cv_idealgas * (P / (R_idealgas * rho));
186+
StaticEnergy = min(e_max, max(e_idealgas, e_min));
187+
182188
Run_Newton_Solver(P, &Pressure, &StaticEnergy, &dPde_rho);
183189
}
184190

185191
void CDataDrivenFluid::SetTDState_rhoT(su2double rho, su2double T) {
186192
/*--- Run 1D Newton solver for temperature at constant density. ---*/
187193
Density = rho;
188-
StaticEnergy = e_start;
194+
195+
/*--- Approximate static energy through ideal gas law. ---*/
196+
StaticEnergy = Cv_idealgas * T;
197+
189198
Run_Newton_Solver(T, &Temperature, &StaticEnergy, &dTde_rho);
190199
}
191200

192201
void CDataDrivenFluid::SetTDState_hs(su2double h, su2double s) {
193202
/*--- Run 2D Newton solver for enthalpy and entropy. ---*/
203+
204+
/*--- Approximate density and static energy through ideal gas law under isentropic assumption. ---*/
205+
su2double T_init = h / Cp_idealgas;
206+
su2double P_init = P_middle * pow(T_init / T_middle, gamma_idealgas/(gamma_idealgas - 1));
207+
208+
e_start = h * Cv_idealgas / Cp_idealgas;
209+
rho_start = P_init / (R_idealgas * T_init);
194210
Run_Newton_Solver(h, s, &Enthalpy, &Entropy, &dhdrho_e, &dhde_rho, &dsdrho_e, &dsde_rho);
195211
}
196212

197213
void CDataDrivenFluid::SetTDState_Ps(su2double P, su2double s) {
198214
/*--- Run 2D Newton solver for pressure and entropy ---*/
215+
216+
/*--- Approximate initial state through isentropic assumption and ideal gas law. ---*/
217+
su2double T_init = T_middle * pow(P / P_middle, (gamma_idealgas - 1)/gamma_idealgas);
218+
e_start = Cv_idealgas * T_init;
219+
rho_start = P / (R_idealgas * T_init);
220+
199221
Run_Newton_Solver(P, s, &Pressure, &Entropy, &dPdrho_e, &dPde_rho, &dsdrho_e, &dsde_rho);
200222
}
201223

@@ -255,7 +277,6 @@ void CDataDrivenFluid::Run_Newton_Solver(su2double Y1_target, su2double Y2_targe
255277

256278
su2double delta_Y1, delta_Y2, delta_rho, delta_e, determinant;
257279

258-
set_local_rhoe = false;
259280
/*--- Initiating Newton solver ---*/
260281
while (!converged && (Iter < MaxIter_Newton)) {
261282
/*--- Determine thermodynamic state based on current density and energy. ---*/
@@ -284,10 +305,7 @@ void CDataDrivenFluid::Run_Newton_Solver(su2double Y1_target, su2double Y2_targe
284305
nIter_Newton = Iter;
285306

286307
/*--- Evaluation of final state. ---*/
287-
Density = rho;
288-
StaticEnergy = e;
289-
SetTDState_rhoe(Density, StaticEnergy);
290-
set_local_rhoe = true;
308+
SetTDState_rhoe(rho, e);
291309
}
292310

293311
void CDataDrivenFluid::Run_Newton_Solver(su2double Y_target, su2double* Y, su2double* X, su2double* dYdX) {
@@ -323,3 +341,47 @@ void CDataDrivenFluid::Run_Newton_Solver(su2double Y_target, su2double* Y, su2do
323341

324342
nIter_Newton = Iter;
325343
}
344+
345+
void CDataDrivenFluid::ComputeIdealGasQuantities() {
346+
/*--- Compute approximate ideal gas properties from the middle of the reference data set. These properties are used to approximate the initial condition of the Newton solvers using the ideal gas law. ---*/
347+
su2double rho_average, e_average;
348+
349+
/*--- Obtain minimum and maximum density and static energy from data set. ---*/
350+
switch (Kind_DataDriven_Method)
351+
{
352+
case ENUM_DATADRIVEN_METHOD::LUT:
353+
rho_min = *lookup_table->GetTableLimitsX().first;
354+
e_min = *lookup_table->GetTableLimitsY().first;
355+
rho_max = *lookup_table->GetTableLimitsX().second;
356+
e_max = *lookup_table->GetTableLimitsY().second;
357+
rho_average = 0.5*(*lookup_table->GetTableLimitsX().first + *lookup_table->GetTableLimitsX().second);
358+
e_average = 0.5*(*lookup_table->GetTableLimitsY().first + *lookup_table->GetTableLimitsY().second);
359+
break;
360+
case ENUM_DATADRIVEN_METHOD::MLP:
361+
#ifdef USE_MLPCPP
362+
rho_min = lookup_mlp->GetInputNorm(iomap_rhoe, idx_rho).first;
363+
e_min = lookup_mlp->GetInputNorm(iomap_rhoe, idx_e).first;
364+
rho_max = lookup_mlp->GetInputNorm(iomap_rhoe, idx_rho).second;
365+
e_max = lookup_mlp->GetInputNorm(iomap_rhoe, idx_e).second;
366+
rho_average = 0.5*(lookup_mlp->GetInputNorm(iomap_rhoe, idx_rho).first + lookup_mlp->GetInputNorm(iomap_rhoe, idx_rho).second);
367+
e_average = 0.5*(lookup_mlp->GetInputNorm(iomap_rhoe, idx_e).first + lookup_mlp->GetInputNorm(iomap_rhoe, idx_e).second);
368+
#endif
369+
break;
370+
default:
371+
rho_average = 1.0;
372+
e_average = 1.0;
373+
rho_min = 1.0;
374+
e_min = 1.0;
375+
break;
376+
}
377+
378+
/*--- Compute thermodynamic state from middle of data set. ---*/
379+
SetTDState_rhoe(rho_average, e_average);
380+
P_middle = Pressure;
381+
T_middle = Temperature;
382+
383+
R_idealgas = P_middle / (rho_average * T_middle);
384+
Cv_idealgas = e_average / T_middle;
385+
Cp_idealgas = Enthalpy / T_middle;
386+
gamma_idealgas = (R_idealgas / Cv_idealgas) + 1;
387+
}

0 commit comments

Comments
 (0)