Skip to content

Commit a6ae8f0

Browse files
committed
check pressure
1 parent 0fdd9a0 commit a6ae8f0

2 files changed

Lines changed: 27 additions & 53 deletions

File tree

SU2_CFD/include/fluid/CCoolProp.hpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,40 @@
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-
3938
/*!
4039
* \class CCoolProp
4140
* \brief Child class for defining fluid model from CoolProp library.
4241
* \author: P.Yan
4342
*/
4443
class CCoolProp final : public CFluidModel {
4544
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 */
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 */
5049
su2double acentric_factor{0.0}; /*!< \brief acentric factor */
5150
#ifdef USE_COOLPROP
52-
std::unique_ptr<CoolProp::AbstractState> fluid_entity; /*!< \brief fluid entity */
53-
su2double epsilon{0.01}; /*!< threshold for pressure */
51+
std::unique_ptr<CoolProp::AbstractState> fluid_entity; /*!< \brief fluid entity */
52+
su2double epsilon{0.01}; /*!< threshold for pressure */
5453
#endif
54+
/*!
55+
* \brief Avoid critical pressure
56+
* \return .
57+
*/
58+
void Check_Pressure(su2double Pressure) {
59+
if (abs(Pressure / Pressure_Critical - 1) < epsilon) {
60+
if (Pressure >= Pressure_Critical) {
61+
Pressure = Pressure_Critical * (1 + epsilon);
62+
} else {
63+
Pressure = Pressure_Critical * (1 - epsilon);
64+
}
65+
}
66+
}
5567

5668
public:
5769
/*!
@@ -146,5 +158,4 @@ class CCoolProp final : public CFluidModel {
146158
* \return Value of the constant: Gamma
147159
*/
148160
su2double GetGamma(void) const { return Gamma; }
149-
150161
};

SU2_CFD/src/fluid/CCoolProp.cpp

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -58,68 +58,38 @@ void CCoolProp::SetTDState_rhoe(su2double rho, su2double e) {
5858
if (fluid_entity->phase() == CoolProp::iphase_twophase) {
5959
// assume it is pure gas
6060
fluid_entity->specify_phase(CoolProp::iphase_gas);
61-
if (abs(Pressure / Pressure_Critical - 1) < epsilon) {
62-
if (Pressure >= Pressure_Critical){
63-
Pressure = Pressure_Critical * (1 + epsilon);
64-
}
65-
else {
66-
Pressure = Pressure_Critical * (1 - epsilon);
67-
}
68-
}
61+
Check_Pressure(Pressure);
6962
fluid_entity->update(CoolProp::PT_INPUTS, Pressure, Temperature);
7063
if (abs(fluid_entity->rhomass() / Density - 1) < epsilon) {
7164
// origial phase is near saturation gas, then just compute sound speed
7265
SoundSpeed2 = pow(fluid_entity->speed_sound(), 2);
73-
}
74-
else {
66+
} else {
7567
// original phase is not near saturation gas, then specify the phase as gas phase
7668
fluid_entity->specify_phase(CoolProp::iphase_gas);
7769
SetTDState_PT(Pressure, Temperature);
7870
}
79-
}
80-
else {
71+
} else {
8172
SoundSpeed2 = pow(fluid_entity->speed_sound(), 2);
8273
}
8374
}
8475

8576
void CCoolProp::SetTDState_PT(su2double P, su2double T) {
86-
if (abs(P / Pressure_Critical - 1) < epsilon) {
87-
if (P >= Pressure_Critical){
88-
P = Pressure_Critical * (1 + epsilon);
89-
}
90-
else {
91-
P = Pressure_Critical * (1 - epsilon);
92-
}
93-
}
77+
Check_Pressure(P);
9478
fluid_entity->update(CoolProp::PT_INPUTS, P, T);
9579
su2double rho = fluid_entity->rhomass();
9680
su2double e = fluid_entity->umass();
9781
SetTDState_rhoe(rho, e);
9882
}
9983

10084
void CCoolProp::SetTDState_Prho(su2double P, su2double rho) {
101-
if (abs(P / Pressure_Critical - 1) < epsilon) {
102-
if (P >= Pressure_Critical){
103-
P = Pressure_Critical * (1 + epsilon);
104-
}
105-
else {
106-
P = Pressure_Critical * (1 - epsilon);
107-
}
108-
}
85+
Check_Pressure(P);
10986
fluid_entity->update(CoolProp::DmassP_INPUTS, rho, P);
11087
su2double e = fluid_entity->umass();
11188
SetTDState_rhoe(rho, e);
11289
}
11390

11491
void CCoolProp::SetEnergy_Prho(su2double P, su2double rho) {
115-
if (abs(P / Pressure_Critical - 1) < epsilon) {
116-
if (P >= Pressure_Critical){
117-
P = Pressure_Critical * (1 + epsilon);
118-
}
119-
else {
120-
P = Pressure_Critical * (1 - epsilon);
121-
}
122-
}
92+
Check_Pressure(P);
12393
fluid_entity->update(CoolProp::DmassP_INPUTS, rho, P);
12494
StaticEnergy = fluid_entity->umass();
12595
}
@@ -132,14 +102,7 @@ void CCoolProp::SetTDState_hs(su2double h, su2double s) {
132102
}
133103

134104
void CCoolProp::SetTDState_Ps(su2double P, su2double s) {
135-
if (abs(P / Pressure_Critical - 1) < epsilon) {
136-
if (P >= Pressure_Critical){
137-
P = Pressure_Critical * (1 + epsilon);
138-
}
139-
else {
140-
P = Pressure_Critical * (1 - epsilon);
141-
}
142-
}
105+
Check_Pressure(P);
143106
fluid_entity->update(CoolProp::PSmass_INPUTS, P, s);
144107
su2double rho = fluid_entity->rhomass();
145108
su2double e = fluid_entity->umass();

0 commit comments

Comments
 (0)