@@ -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
7270CDataDrivenFluid::~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
168165void 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) {
178180void 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
185191void 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
192201void 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
197213void 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
293311void 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