Skip to content

Commit ce9b4ab

Browse files
committed
nothing
1 parent 21d3908 commit ce9b4ab

2 files changed

Lines changed: 99 additions & 98 deletions

File tree

SU2_CFD/include/fluid/CCoolProp.hpp

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -30,46 +30,36 @@
3030
#if defined(HAVE_COOLPROP) && !defined(CODI_FORWARD_TYPE) && !defined(CODI_REVERSE_TYPE)
3131
#define USE_COOLPROP
3232
namespace CoolProp {
33-
class AbstractState;
33+
class AbstractState;
3434
}
3535
#endif
3636
#include <memory>
3737

38+
3839
/*!
3940
* \class CCoolProp
4041
* \brief Child class for defining fluid model from CoolProp library.
4142
* \author: P.Yan
4243
*/
4344
class 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 */
45+
private:
46+
su2double Gamma{1.4}; /*!< \brief Ratio of Specific Heats. */
47+
su2double Gas_Constant{297}; /*!< \brief specific Gas Constant. */
48+
su2double Pressure_Critical{0.0}; /*!< \brief critical pressure */
49+
su2double Temperature_Critical{0.0}; /*!< \brief critical temperature */
50+
su2double acentric_factor{0.0}; /*!< \brief acentric factor */
5151
#ifdef USE_COOLPROP
52-
std::unique_ptr<CoolProp::AbstractState> fluid_entity; /*!< \brief fluid entity */
52+
std::unique_ptr<CoolProp::AbstractState> fluid_entity; /*!< \brief fluid entity */
5353
#endif
54-
/*!
55-
* \brief Avoid critical pressure
56-
* \param[in,out] Pressure: Modified so that it is not too close to critical pressure to avoid issues in CoolProp.
57-
*/
58-
void CheckPressure(su2double& Pressure) const {
59-
if (Pressure > Pressure_Critical)
60-
Pressure = fmax(Pressure, (1 + dp) * Pressure_Critical);
61-
else
62-
Pressure = fmin(Pressure, (1 - dp) * Pressure_Critical);
63-
}
64-
65-
public:
66-
/*!
67-
* \brief Constructor of the class.
68-
*/
69-
CCoolProp(string fluidname);
54+
55+
public:
56+
/*!
57+
* \brief Constructor of the class.
58+
*/
59+
CCoolProp(string fluidname);
7060

7161
#ifdef USE_COOLPROP
72-
/*!
62+
/*!
7363
* \brief Destructor of the class.
7464
* \note Needs to be defined in the .cpp to allow using only a forward declaration of CoolProp::AbstractState.
7565
*/
@@ -132,27 +122,28 @@ class CCoolProp final : public CFluidModel {
132122
void ComputeDerivativeNRBC_Prho(su2double P, su2double rho) override;
133123
#endif
134124

135-
/*!
136-
* \brief Get the value of the critical pressure.
137-
* \return Critical pressure.
138-
*/
139-
su2double GetPressure_Critical(void) const { return Pressure_Critical; }
125+
/*!
126+
* \brief Get the value of the critical pressure.
127+
* \return Critical pressure.
128+
*/
129+
su2double GetPressure_Critical(void) const { return Pressure_Critical; }
130+
131+
/*!
132+
* \brief Get the value of the critical temperature.
133+
* \return Critical temperature.
134+
*/
135+
su2double GetTemperature_Critical(void) const { return Temperature_Critical; }
136+
137+
/*!
138+
* \brief Get the value of specific gas constant.
139+
* \return Value of the constant: Gamma
140+
*/
141+
su2double GetGas_Constant(void) const { return Gas_Constant; }
142+
143+
/*!
144+
* \brief Get the value of specific gas constant.
145+
* \return Value of the constant: Gamma
146+
*/
147+
su2double GetGamma(void) const { return Gamma; }
140148

141-
/*!
142-
* \brief Get the value of the critical temperature.
143-
* \return Critical temperature.
144-
*/
145-
su2double GetTemperature_Critical(void) const { return Temperature_Critical; }
146-
147-
/*!
148-
* \brief Get the value of specific gas constant.
149-
* \return Value of the constant: Gamma
150-
*/
151-
su2double GetGas_Constant(void) const { return Gas_Constant; }
152-
153-
/*!
154-
* \brief Get the value of specific gas constant.
155-
* \return Value of the constant: Gamma
156-
*/
157-
su2double GetGamma(void) const { return Gamma; }
158149
};

SU2_CFD/src/fluid/CCoolProp.cpp

Lines changed: 60 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
/*!
2-
* \file CCoolProp.cpp
3-
* \brief Source of the fluid model from CoolProp.
4-
* \author P. Yan, G. Gori, A. Guardone
5-
* \version 7.5.1 "Blackbird"
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-2023, 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-
*/
2+
* \file CCoolProp.cpp
3+
* \brief Source of the fluid model from CoolProp.
4+
* \author P. Yan, G. Gori, A. Guardone
5+
* \version 7.4.0 "Blackbird"
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-2022, 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+
*/
2727

2828
#include "../../include/fluid/CCoolProp.hpp"
2929

3030
#ifdef USE_COOLPROP
31-
#include "AbstractState.h"
3231
#include "CoolProp.h"
32+
#include "AbstractState.h"
3333

3434
CCoolProp::CCoolProp(string fluidname) : CFluidModel() {
35-
fluid_entity = std::unique_ptr<CoolProp::AbstractState>(CoolProp::AbstractState::factory("HEOS", fluidname));
36-
Gas_Constant = fluid_entity->gas_constant() / fluid_entity->molar_mass();
35+
fluid_entity = std::unique_ptr<CoolProp::AbstractState>(CoolProp::AbstractState::factory("HEOS",fluidname));
36+
Gas_Constant = fluid_entity->gas_constant()/fluid_entity->molar_mass();
3737
Pressure_Critical = fluid_entity->p_critical();
3838
Temperature_Critical = fluid_entity->T_critical();
3939
acentric_factor = fluid_entity->acentric_factor();
@@ -55,41 +55,52 @@ void CCoolProp::SetTDState_rhoe(su2double rho, su2double e) {
5555
dPde_rho = fluid_entity->first_partial_deriv(CoolProp::iP, CoolProp::iUmass, CoolProp::iDmass);
5656
dTdrho_e = fluid_entity->first_partial_deriv(CoolProp::iT, CoolProp::iDmass, CoolProp::iUmass);
5757
dTde_rho = fluid_entity->first_partial_deriv(CoolProp::iT, CoolProp::iUmass, CoolProp::iDmass);
58-
if (fluid_entity->phase() == CoolProp::iphase_twophase) {
58+
if (fluid_entity->phase() == 6) {
5959
// assume it is pure gas
6060
fluid_entity->specify_phase(CoolProp::iphase_gas);
61-
CheckPressure(Pressure);
61+
if(abs(Pressure/Pressure_Critical-1)<0.01){
62+
// if P is very cloase to Pc, the CoolProp has issue
63+
Pressure = Pressure_Critical*0.99;
64+
}
6265
fluid_entity->update(CoolProp::PT_INPUTS, Pressure, Temperature);
63-
if (abs(fluid_entity->rhomass() / Density - 1) < dp) {
66+
if(abs(fluid_entity->rhomass()/Density-1)*100 < 1){
6467
// origial phase is near saturation gas, then just compute sound speed
6568
SoundSpeed2 = pow(fluid_entity->speed_sound(), 2);
66-
} else {
69+
}
70+
else{
6771
// original phase is not near saturation gas, then specify the phase as gas phase
6872
fluid_entity->specify_phase(CoolProp::iphase_gas);
69-
SetTDState_PT(Pressure, Temperature);
73+
SetTDState_PT(Pressure,Temperature);
7074
}
71-
} else {
75+
}
76+
else{
7277
SoundSpeed2 = pow(fluid_entity->speed_sound(), 2);
7378
}
7479
}
7580

7681
void CCoolProp::SetTDState_PT(su2double P, su2double T) {
77-
CheckPressure(P);
82+
if(abs(P/Pressure_Critical-1)<0.01) {
83+
P = Pressure_Critical * 0.99;
84+
}
7885
fluid_entity->update(CoolProp::PT_INPUTS, P, T);
7986
su2double rho = fluid_entity->rhomass();
8087
su2double e = fluid_entity->umass();
8188
SetTDState_rhoe(rho, e);
8289
}
8390

8491
void CCoolProp::SetTDState_Prho(su2double P, su2double rho) {
85-
CheckPressure(P);
92+
if(abs(P/Pressure_Critical-1)<0.01){
93+
P = Pressure_Critical*0.99;
94+
}
8695
fluid_entity->update(CoolProp::DmassP_INPUTS, rho, P);
8796
su2double e = fluid_entity->umass();
8897
SetTDState_rhoe(rho, e);
8998
}
9099

91-
void CCoolProp::SetEnergy_Prho(su2double P, su2double rho) {
92-
CheckPressure(P);
100+
void CCoolProp::SetEnergy_Prho(su2double P, su2double rho){
101+
if(abs(P/Pressure_Critical-1)<0.01){
102+
P = Pressure_Critical*0.99;
103+
}
93104
fluid_entity->update(CoolProp::DmassP_INPUTS, rho, P);
94105
StaticEnergy = fluid_entity->umass();
95106
}
@@ -101,8 +112,10 @@ void CCoolProp::SetTDState_hs(su2double h, su2double s) {
101112
SetTDState_rhoe(rho, e);
102113
}
103114

104-
void CCoolProp::SetTDState_Ps(su2double P, su2double s) {
105-
CheckPressure(P);
115+
void CCoolProp::SetTDState_Ps(su2double P, su2double s) {
116+
if(abs(P/Pressure_Critical-1)<0.01){
117+
P = Pressure_Critical*0.99;
118+
}
106119
fluid_entity->update(CoolProp::PSmass_INPUTS, P, s);
107120
su2double rho = fluid_entity->rhomass();
108121
su2double e = fluid_entity->umass();
@@ -115,19 +128,16 @@ void CCoolProp::SetTDState_rhoT(su2double rho, su2double T) {
115128
SetTDState_rhoe(rho, e);
116129
}
117130

118-
void CCoolProp::ComputeDerivativeNRBC_Prho(su2double P, su2double rho) {
131+
void CCoolProp::ComputeDerivativeNRBC_Prho(su2double P, su2double rho) {
119132
SetTDState_Prho(P, rho);
120-
dhdrho_P = fluid_entity->first_partial_deriv(CoolProp::iHmass, CoolProp::iDmass, CoolProp::iP);
121-
dhdP_rho = fluid_entity->first_partial_deriv(CoolProp::iHmass, CoolProp::iP, CoolProp::iDmass);
122-
dsdP_rho = fluid_entity->first_partial_deriv(CoolProp::iSmass, CoolProp::iP, CoolProp::iDmass);
123-
dsdrho_P = fluid_entity->first_partial_deriv(CoolProp::iSmass, CoolProp::iDmass, CoolProp::iP);
133+
dhdrho_P = fluid_entity->first_partial_deriv(CoolProp::iHmass,CoolProp::iDmass,CoolProp::iP);
134+
dhdP_rho = fluid_entity->first_partial_deriv(CoolProp::iHmass,CoolProp::iP,CoolProp::iDmass);
135+
dsdP_rho = fluid_entity->first_partial_deriv(CoolProp::iSmass,CoolProp::iP,CoolProp::iDmass);
136+
dsdrho_P = fluid_entity->first_partial_deriv(CoolProp::iSmass,CoolProp::iDmass,CoolProp::iP);
124137
}
125138

126139
#else
127140
CCoolProp::CCoolProp(string fluidname) {
128-
SU2_MPI::Error(
129-
"SU2 was not compiled with CoolProp (-Denable-coolprop=true). Note that CoolProp cannot be used with directdiff "
130-
"or autodiff",
131-
CURRENT_FUNCTION);
141+
SU2_MPI::Error("SU2 was not compiled with CoolProp (-Denable-coolprop=true). Note that CoolProp cannot be used with directdiff or autodiff", CURRENT_FUNCTION);
132142
}
133-
#endif
143+
#endif

0 commit comments

Comments
 (0)