Documentation a537f1bdf2
Loading...
Searching...
No Matches
CIncIdealGasPolynomial.hpp
Go to the documentation of this file.
1/*!
2 * \file CIncIdealGasPolynomial.hpp
3 * \brief Defines the incompressible Ideal Gas model with polynomial Cp.
4 * \author T. Economon
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 <array>
31
32#include "CFluidModel.hpp"
33
34/*!
35 * \class CIncIdealGasPolynomial
36 * \brief Child class for defining a custom incompressible ideal gas model.
37 * \author: T. Economon
38 */
39template <int N>
40class CIncIdealGasPolynomial final : public CFluidModel {
41 public:
42 /*!
43 * \brief Constructor of the class.
44 */
45 CIncIdealGasPolynomial(su2double val_gas_constant, su2double val_operating_pressure, su2double val_Temperature_Ref) {
46 /* In the incompressible ideal gas model, the thermodynamic pressure is decoupled
47 from the governing equations and held constant. The density is therefore only a
48 function of temperature variations. We also use a molecular weight (g/mol) and the
49 universal gas constant to compute the specific gas constant for the fluid. The gas
50 is incompressible, so Cp = Cv (gamma = 1). */
51 Gas_Constant = val_gas_constant;
52 Pressure = val_operating_pressure;
53 Gamma = 1.0;
54 Std_Ref_Temp_ND = val_Temperature_Ref;
55 }
56
57 /*!
58 * \brief Set the temperature polynomial coefficients for variable Cp.
59 * \param[in] config - configuration container for the problem.
60 */
61 void SetCpModel(const CConfig* config, su2double val_Temperature_Ref) override {
62 for (int i = 0; i < N; ++i) {
63 /*--- Note that we use cp = dh/dt here. ---*/
64 coeffs_[i] = config->GetCp_PolyCoeffND(i);
65 }
66 Temperature_Min = config->GetTemperatureLimits(0);
67 }
68
69 /*!
70 * \brief Set the Dimensionless State using Temperature.
71 * \param[in] t - Temperature value at the point.
72 */
73 void SetTDState_T(su2double t, const su2double *val_scalars = nullptr) override {
74 /* The EoS only depends upon temperature. */
75 Temperature = t;
76 Density = Pressure / (Temperature * Gas_Constant);
77
78 /* Evaluate the new Cp and enthalpy from the coefficients and temperature. */
79 Cp = coeffs_[0];
80 Enthalpy = coeffs_[0] * (t - Std_Ref_Temp_ND);
81 su2double t_i = 1.0;
82 su2double tref_i = 1.0;
83 for (int i = 1; i < N; ++i) {
84 t_i *= t;
85 tref_i *= Std_Ref_Temp_ND;
86 Cp += coeffs_[i] * t_i;
87 Enthalpy += coeffs_[i] * (t_i * t - tref_i * Std_Ref_Temp_ND) / (i + 1);
88 }
89 Cv = Cp / Gamma;
90 }
91
92 /*!
93 * \brief Set the Dimensionless State using enthalpy.
94 * \param[in] val_enthalpy - Enthalpy value at the point.
95 */
96 void SetTDState_h(su2double val_enthalpy, const su2double* val_scalars = nullptr) override {
97 Enthalpy = val_enthalpy;
98 /*--- convergence criterion for temperature in [K], high accuracy needed for restarts. ---*/
99 const su2double toll = 1e-5;
100 su2double temp_iter = 300.0;
101 su2double Cp_iter = 0.0;
102 su2double delta_temp_iter = 1e10;
103 su2double delta_enthalpy_iter;
104 const int counter_limit = 20;
105
106 int counter = 0;
107
108 /*--- Compute temperature given enthalpy using Newton-Raphson. ---*/
109 while ((abs(delta_temp_iter) > toll) && (counter++ < counter_limit)) {
110 /* Evaluate the new Cp and enthalpy from the coefficients and temperature. */
111 Cp_iter = coeffs_[0];
112 su2double Enthalpy_iter = coeffs_[0] * (temp_iter - Std_Ref_Temp_ND);
113 su2double t_i = 1.0;
114 su2double tref_i = 1.0;
115 for (int i = 1; i < N; ++i) {
116 t_i *= temp_iter;
117 tref_i *= Std_Ref_Temp_ND;
118 Cp_iter += coeffs_[i] * t_i;
119 Enthalpy_iter += coeffs_[i] * (t_i * temp_iter - tref_i * Std_Ref_Temp_ND) / (i + 1);
120 }
121
122 delta_enthalpy_iter = Enthalpy - Enthalpy_iter;
123
124 delta_temp_iter = delta_enthalpy_iter / Cp_iter;
125
126 temp_iter += delta_temp_iter;
127 if (temp_iter < Temperature_Min) {
128 cout << "Warning: Negative temperature has been found during Newton-Raphson." << endl;
129 temp_iter = Temperature_Min;
130 break;
131 }
132 }
133
134 Temperature = temp_iter;
135 Cp = Cp_iter;
136 if (counter == counter_limit) {
137 cout << "Warning: Newton-Raphson exceeds max. iterations in temperature computation." << endl;
138 }
139 Density = Pressure / (Temperature * Gas_Constant);
140 Cv = Cp / Gamma;
141 }
142
143 private:
144 su2double Gas_Constant{0.0}; /*!< \brief Specific Gas Constant. */
145 su2double Gamma{0.0}; /*!< \brief Ratio of specific heats. */
146 su2double Std_Ref_Temp_ND{0.0}; /*!< \brief Nondimensional standard reference temperature for enthalpy. */
147 array<su2double, N> coeffs_; /*!< \brief Polynomial coefficients for heat capacity as a function of temperature. */
148 su2double Temperature_Min; /*!< \brief Minimum temperature value allowed in Newton-Raphson iterations. */
149};
Defines the main fluid model class for thermophysical properties.
Main class for defining the problem; basically this class reads the configuration file,...
Definition CConfig.hpp:64
su2double GetCp_PolyCoeffND(unsigned short val_index) const
Get the temperature polynomial coefficient for specific heat Cp.
Definition CConfig.hpp:4288
su2double GetTemperatureLimits(int iVar) const
Get Temperature limits for incompressible flows.
Definition CConfig.hpp:2277
Main class for defining the Thermo-Physical Model.
Definition CFluidModel.hpp:47
su2double Cp
Specific Heat Capacity at constant pressure.
Definition CFluidModel.hpp:64
su2double Temperature
Temperature.
Definition CFluidModel.hpp:55
su2double Cv
Specific Heat Capacity at constant volume.
Definition CFluidModel.hpp:65
su2double Enthalpy
Enthalpy.
Definition CFluidModel.hpp:50
su2double Pressure
Pressure.
Definition CFluidModel.hpp:53
su2double Density
Density.
Definition CFluidModel.hpp:52
Child class for defining a custom incompressible ideal gas model.
Definition CIncIdealGasPolynomial.hpp:40
void SetCpModel(const CConfig *config, su2double val_Temperature_Ref) override
Set the temperature polynomial coefficients for variable Cp.
Definition CIncIdealGasPolynomial.hpp:61
void SetTDState_T(su2double t, const su2double *val_scalars=nullptr) override
Set the Dimensionless State using Temperature.
Definition CIncIdealGasPolynomial.hpp:73
CIncIdealGasPolynomial(su2double val_gas_constant, su2double val_operating_pressure, su2double val_Temperature_Ref)
Constructor of the class.
Definition CIncIdealGasPolynomial.hpp:45
void SetTDState_h(su2double val_enthalpy, const su2double *val_scalars=nullptr) override
Set the Dimensionless State using enthalpy.
Definition CIncIdealGasPolynomial.hpp:96
passivedouble su2double
Definition code_config.hpp:181
FORCEINLINE ARRAY_T abs(const ARRAY_T &x)
Definition special_vectorization.hpp:117