|
| 1 | +/*! |
| 2 | + * \file CNasaGas.cpp |
| 3 | + * \brief Source of the NASA polynomial gas model. |
| 4 | + * \author Om Giri |
| 5 | + * \version 8.4.0 "Harrier" |
| 6 | + */ |
| 7 | + |
| 8 | +#include "../../include/fluid/CNasaGas.hpp" |
| 9 | + |
| 10 | +CNasaGas::CNasaGas(su2double gamma, su2double R, bool CompEntropy) : CIdealGas(gamma, R, CompEntropy) { |
| 11 | + // Constructor inherited from CIdealGas |
| 12 | +} |
| 13 | + |
| 14 | +void CNasaGas::SetCpModel(const CConfig* config, su2double val_Temperature_Ref) { |
| 15 | + for (int i = 0; i < 7; ++i) { |
| 16 | + CpLowPolyCoefficientsND[i] = config->GetNASA_CpLowPolyCoeff(i); |
| 17 | + CpHighPolyCoefficientsND[i] = config->GetNASA_CpHighPolyCoeff(i); |
| 18 | + } |
| 19 | + TransitionTemperatureND = config->GetNASA_TransitionTemperature() / val_Temperature_Ref; |
| 20 | +} |
| 21 | + |
| 22 | +void CNasaGas::ComputeProperties_T(su2double T) { |
| 23 | + Temperature = T; |
| 24 | + const array<su2double, 7>* c; |
| 25 | + |
| 26 | + if (T < TransitionTemperatureND) { |
| 27 | + c = &CpLowPolyCoefficientsND; |
| 28 | + } else { |
| 29 | + c = &CpHighPolyCoefficientsND; |
| 30 | + } |
| 31 | + |
| 32 | + /*--- NASA polynomials: |
| 33 | + Cp/R = a1*T^-2 + a2*T^-1 + a3 + a4*T + a5*T^2 + a6*T^3 + a7*T^4 |
| 34 | + H/RT = -a1*T^-2 + a2*log(T)/T + a3 + a4*T/2 + a5*T^2/3 + a6*T^3/4 + a7*T^4/5 + a8/T |
| 35 | + S/R = -a1*T^-2/2 - a2*T^-1 + a3*log(T) + a4*T + a5*T^2/2 + a6*T^3/3 + a7*T^4/4 + a9 |
| 36 | +
|
| 37 | + Note: SU2 usually uses a 7-coefficient form: |
| 38 | + Cp/R = a0 + a1*T + a2*T^2 + a3*T^3 + a4*T^4 |
| 39 | + H/RT = a0 + a1*T/2 + a2*T^2/3 + a3*T^3/4 + a4*T^4/5 + a5/T |
| 40 | + S/R = a0*log(T) + a1*T + a2*T^2/2 + a3*T^3/3 + a4*T^4/4 + a6 |
| 41 | +
|
| 42 | + Wait, standard NASA 7-coefficient format is: |
| 43 | + Cp/R = a0 + a1*T + a2*T^2 + a3*T^3 + a4*T^4 |
| 44 | + H/RT = a0 + a1*T/2 + a2*T^2/3 + a3*T^3/4 + a4*T^4/5 + a5/T |
| 45 | + S/R = a0*lnT + a1*T + a2*T^2/2 + a3*T^3/3 + a4*T^4/4 + a6 |
| 46 | +
|
| 47 | + I will use this standard 7-coefficient format. |
| 48 | + ---*/ |
| 49 | + |
| 50 | + Cp = ((*c)[0] + (*c)[1]*T + (*c)[2]*T*T + (*c)[3]*T*T*T + (*c)[4]*T*T*T*T) * Gas_Constant; |
| 51 | + Enthalpy = ((*c)[0] + (*c)[1]*T/2.0 + (*c)[2]*T*T/3.0 + (*c)[3]*T*T*T/4.0 + (*c)[4]*T*T*T*T/5.0 + (*c)[5]/T) * T * Gas_Constant; |
| 52 | + |
| 53 | + if (ComputeEntropy) { |
| 54 | + Entropy = ((*c)[0]*log(T) + (*c)[1]*T + (*c)[2]*T*T/2.0 + (*c)[3]*T*T*T/3.0 + (*c)[4]*T*T*T*T/4.0 + (*c)[6]) * Gas_Constant; |
| 55 | + // Note: This is partial entropy (temperature dependent part). Pressure part added in SetTDState_rhoe if needed. |
| 56 | + // However, SU2 CIdealGas includes log(1/rho) term. |
| 57 | + } |
| 58 | + |
| 59 | + // Cv = Cp - R |
| 60 | + Cv = Cp - Gas_Constant; |
| 61 | + // Gamma = Cp / Cv |
| 62 | + Gamma = Cp / Cv; |
| 63 | + Gamma_Minus_One = Gamma - 1.0; |
| 64 | +} |
| 65 | + |
| 66 | +void CNasaGas::SetTDState_rhoe(su2double rho, su2double e) { |
| 67 | + Density = rho; |
| 68 | + StaticEnergy = e; |
| 69 | + |
| 70 | + /*--- Solve for T using Newton-Raphson: e(T) = h(T) - R*T ---*/ |
| 71 | + su2double T_iter = Temperature; |
| 72 | + if (T_iter <= 0.0) T_iter = 1.0; // Initial guess |
| 73 | + |
| 74 | + for (int i = 0; i < 10; ++i) { |
| 75 | + ComputeProperties_T(T_iter); |
| 76 | + su2double e_iter = Enthalpy - Gas_Constant * T_iter; |
| 77 | + su2double de_dT = Cv; // de/dT = Cv for ideal gas even with variable Cp |
| 78 | + su2double deltaT = (e - e_iter) / de_dT; |
| 79 | + T_iter += deltaT; |
| 80 | + if (abs(deltaT) < 1e-8 * T_iter) break; |
| 81 | + } |
| 82 | + |
| 83 | + Temperature = T_iter; |
| 84 | + ComputeProperties_T(Temperature); |
| 85 | + |
| 86 | + Pressure = Density * Gas_Constant * Temperature; |
| 87 | + SoundSpeed2 = Gamma * Pressure / Density; |
| 88 | + |
| 89 | + /*--- Derivatives ---*/ |
| 90 | + dPde_rho = Density * Gas_Constant / Cv; |
| 91 | + dPdrho_e = Gas_Constant * Temperature - StaticEnergy * dPde_rho; // From P = rho*R*T and e = e(T) |
| 92 | + |
| 93 | + dTde_rho = 1.0 / Cv; |
| 94 | + dTdrho_e = 0.0; |
| 95 | + |
| 96 | + if (ComputeEntropy) { |
| 97 | + // Entropy was S(T). Now add pressure/density part: S = S(T) - R*ln(rho*R) + R*ln(R_ref?) |
| 98 | + // CIdealGas uses: Entropy = (1.0 / Gamma_Minus_One * log(Temperature) + log(1.0 / Density)) * Gas_Constant; |
| 99 | + // For NASA, S(T) already has the log(T) part. |
| 100 | + Entropy += log(1.0 / Density) * Gas_Constant; |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +void CNasaGas::SetTDState_PT(su2double P, su2double T) { |
| 105 | + Pressure = P; |
| 106 | + Temperature = T; |
| 107 | + ComputeProperties_T(T); |
| 108 | + Density = P / (Gas_Constant * T); |
| 109 | + StaticEnergy = Enthalpy - Gas_Constant * T; |
| 110 | + SetTDState_rhoe(Density, StaticEnergy); |
| 111 | +} |
| 112 | + |
| 113 | +void CNasaGas::SetTDState_Prho(su2double P, su2double rho) { |
| 114 | + Pressure = P; |
| 115 | + Density = rho; |
| 116 | + Temperature = P / (Density * Gas_Constant); |
| 117 | + ComputeProperties_T(Temperature); |
| 118 | + StaticEnergy = Enthalpy - Gas_Constant * Temperature; |
| 119 | + SetTDState_rhoe(Density, StaticEnergy); |
| 120 | +} |
| 121 | + |
| 122 | +void CNasaGas::SetTDState_rhoT(su2double rho, su2double T) { |
| 123 | + Density = rho; |
| 124 | + Temperature = T; |
| 125 | + ComputeProperties_T(T); |
| 126 | + Pressure = Density * Gas_Constant * T; |
| 127 | + StaticEnergy = Enthalpy - Gas_Constant * T; |
| 128 | + SetTDState_rhoe(Density, StaticEnergy); |
| 129 | +} |
| 130 | + |
| 131 | +void CNasaGas::SetTDState_Ps(su2double P, su2double s) { |
| 132 | + /*--- This would require another nested iteration to find T from P and s. |
| 133 | + For now, we can use an approximate T or a simple Newton solver. ---*/ |
| 134 | + su2double T_iter = Temperature; |
| 135 | + if (T_iter <= 0.0) T_iter = 1.0; |
| 136 | + |
| 137 | + for (int i = 0; i < 10; ++i) { |
| 138 | + ComputeProperties_T(T_iter); |
| 139 | + su2double s_iter = Entropy + log(Gas_Constant * T_iter / P) * Gas_Constant; |
| 140 | + su2double ds_dT = Cp / T_iter; |
| 141 | + su2double deltaT = (s - s_iter) / ds_dT; |
| 142 | + T_iter += deltaT; |
| 143 | + if (abs(deltaT) < 1e-8 * T_iter) break; |
| 144 | + } |
| 145 | + SetTDState_PT(P, T_iter); |
| 146 | +} |
0 commit comments