Documentation 6b54b78464
Loading...
Searching...
No Matches
CCoolProp.hpp
Go to the documentation of this file.
1/*!
2 * \file CCoolProp.hpp
3 * \brief Defines the state-of-the-art fluid model from CoolProp library.
4 * \author P. Yan, G. Gori, A. Guardone
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#include "CFluidModel.hpp"
30#if defined(HAVE_COOLPROP) && !defined(CODI_FORWARD_TYPE) && !defined(CODI_REVERSE_TYPE)
31#define USE_COOLPROP
32namespace CoolProp {
33class AbstractState;
34}
35#endif
36#include <memory>
37
38/*!
39 * \class CCoolProp
40 * \brief Child class for defining fluid model from CoolProp library.
41 * \author: P.Yan
42 */
43class CCoolProp final : public CFluidModel {
44 private:
45 su2double Gamma{1.4}; /*!< \brief Ratio of Specific Heats. */
46 su2double Gas_Constant{297}; /*!< \brief specific Gas Constant. */
47 su2double Pressure_Critical{0.0}; /*!< \brief critical pressure */
48 su2double Temperature_Critical{0.0}; /*!< \brief critical temperature */
49 su2double acentric_factor{0.0}; /*!< \brief acentric factor */
50 const su2double dp{0.01}; /*!< threshold for pressure */
51 const su2double dt{0.01}; /*!< threshold for temperature */
52#ifdef USE_COOLPROP
53 std::unique_ptr<CoolProp::AbstractState> fluid_entity; /*!< \brief fluid entity */
54#endif
55 /*!
56 * \brief Avoid critical pressure
57 * \param[in,out] Pressure: Modified so that it is not too close to critical pressure to avoid issues in CoolProp.
58 */
59 void CheckPressure(su2double& Pressure) const {
60 if (Pressure > Pressure_Critical)
61 Pressure = fmax(Pressure, (1 + dp) * Pressure_Critical);
62 else
63 Pressure = fmin(Pressure, (1 - dp) * Pressure_Critical);
64 }
65
66 /*!
67 * \brief Avoid critical temperature
68 * \param[in,out] Temperature: Modified so that it is not too close to critical temperature to avoid issues in
69 * CoolProp.
70 */
71 void CheckTemperature(su2double& Temperature) const {
72 if (Temperature > Temperature_Critical)
73 Temperature = fmax(Temperature, (1 + dt) * Temperature_Critical);
74 else
75 Temperature = fmin(Temperature, (1 + dt) * Temperature_Critical);
76 }
77
78 public:
79 /*!
80 * \brief Constructor of the class.
81 */
82 CCoolProp(const string& fluidname);
83
84#ifdef USE_COOLPROP
85 /*!
86 * \brief Destructor of the class.
87 * \note Needs to be defined in the .cpp to allow using only a forward declaration of CoolProp::AbstractState.
88 */
89 ~CCoolProp();
90
91 /*!
92 * \brief Set the Dimensionless State using Density and Internal Energy
93 * \param[in] rho - first thermodynamic variable.
94 * \param[in] e - second thermodynamic variable.
95 */
96 void SetTDState_rhoe(su2double rho, su2double e) override;
97
98 /*!
99 * \brief Set the Dimensionless State using Pressure and Temperature
100 * \param[in] P - first thermodynamic variable.
101 * \param[in] T - second thermodynamic variable.
102 */
103 void SetTDState_PT(su2double P, su2double T) override;
104
105 /*!
106 * \brief Set the Dimensionless State using Pressure and Density
107 * \param[in] P - first thermodynamic variable.
108 * \param[in] rho - second thermodynamic variable.
109 */
110 void SetTDState_Prho(su2double P, su2double rho) override;
111
112 /*!
113 * \brief Set the Dimensionless Internal Energy using Pressure and Density
114 * \param[in] P - first thermodynamic variable.
115 * \param[in] rho - second thermodynamic variable.
116 */
117 void SetEnergy_Prho(su2double P, su2double rho) override;
118
119 /*!
120 * \brief Set the Dimensionless State using Enthalpy and Entropy
121 * \param[in] th1 - first thermodynamic variable (h).
122 * \param[in] th2 - second thermodynamic variable (s).
123 */
124 void SetTDState_hs(su2double h, su2double s) override;
125
126 /*!
127 * \brief Set the Dimensionless State using Density and Temperature
128 * \param[in] th1 - first thermodynamic variable (rho).
129 * \param[in] th2 - second thermodynamic variable (T).
130 */
131 void SetTDState_rhoT(su2double rho, su2double T) override;
132
133 /*!
134 * \brief Set the Dimensionless State using Pressure and Entropy
135 * \param[in] th1 - first thermodynamic variable (P).
136 * \param[in] th2 - second thermodynamic variable (s).
137 */
138 void SetTDState_Ps(su2double P, su2double s) override;
139
140 /*!
141 * \brief compute some derivatives of enthalpy and entropy needed for subsonic inflow BC
142 * \param[in] th1 - first thermodynamic variable (P).
143 * \param[in] th2 - second thermodynamic variable (rho).
144 */
145 void ComputeDerivativeNRBC_Prho(su2double P, su2double rho) override;
146#endif
147
148 /*!
149 * \brief Get the value of the critical pressure.
150 * \return Critical pressure.
151 */
152 su2double GetPressure_Critical(void) const { return Pressure_Critical; }
153
154 /*!
155 * \brief Get the value of the critical temperature.
156 * \return Critical temperature.
157 */
158 su2double GetTemperature_Critical(void) const { return Temperature_Critical; }
159
160 /*!
161 * \brief Get the value of specific gas constant.
162 * \return Value of the constant: Gamma
163 */
164 su2double GetGas_Constant(void) const { return Gas_Constant; }
165
166 /*!
167 * \brief Get the value of specific gas constant.
168 * \return Value of the constant: Gamma
169 */
170 su2double GetGamma(void) const { return Gamma; }
171};
Defines the main fluid model class for thermophysical properties.
Child class for defining fluid model from CoolProp library.
Definition CCoolProp.hpp:43
su2double GetPressure_Critical(void) const
Get the value of the critical pressure.
Definition CCoolProp.hpp:152
su2double GetGas_Constant(void) const
Get the value of specific gas constant.
Definition CCoolProp.hpp:164
su2double GetGamma(void) const
Get the value of specific gas constant.
Definition CCoolProp.hpp:170
su2double GetTemperature_Critical(void) const
Get the value of the critical temperature.
Definition CCoolProp.hpp:158
Main class for defining the Thermo-Physical Model.
Definition CFluidModel.hpp:47
virtual void SetTDState_rhoe(su2double rho, su2double e)
virtual member that would be different for each gas model implemented
Definition CFluidModel.hpp:305
su2double Temperature
Temperature.
Definition CFluidModel.hpp:55
virtual void ComputeDerivativeNRBC_Prho(su2double P, su2double rho)
virtual member that would be different for each gas model implemented
Definition CFluidModel.hpp:364
virtual void SetTDState_PT(su2double P, su2double T)
virtual member that would be different for each gas model implemented
Definition CFluidModel.hpp:313
virtual void SetTDState_Prho(su2double P, su2double rho)
virtual member that would be different for each gas model implemented
Definition CFluidModel.hpp:321
su2double Pressure
Pressure.
Definition CFluidModel.hpp:53
virtual void SetEnergy_Prho(su2double P, su2double rho)
virtual member that would be different for each gas model implemented
Definition CFluidModel.hpp:330
virtual void SetTDState_hs(su2double h, su2double s)
virtual member that would be different for each gas model implemented
Definition CFluidModel.hpp:339
virtual void SetTDState_Ps(su2double P, su2double s)
virtual member that would be different for each gas model implemented
Definition CFluidModel.hpp:356
virtual void SetTDState_rhoT(su2double rho, su2double T)
virtual member that would be different for each gas model implemented
Definition CFluidModel.hpp:348
passivedouble su2double
Definition code_config.hpp:181