Skip to content

Commit 8b95cd7

Browse files
authored
Merge pull request #2021 from PENGYAN777/feature_coolprop
CoolProp enhancement
2 parents f2b75c5 + ec67733 commit 8b95cd7

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

SU2_CFD/include/fluid/CCoolProp.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class CCoolProp final : public CFluidModel {
4848
su2double Temperature_Critical{0.0}; /*!< \brief critical temperature */
4949
su2double acentric_factor{0.0}; /*!< \brief acentric factor */
5050
const su2double dp{0.01}; /*!< threshold for pressure */
51+
const su2double dt{0.01}; /*!< threshold for temperature */
5152
#ifdef USE_COOLPROP
5253
std::unique_ptr<CoolProp::AbstractState> fluid_entity; /*!< \brief fluid entity */
5354
#endif
@@ -62,6 +63,18 @@ class CCoolProp final : public CFluidModel {
6263
Pressure = fmin(Pressure, (1 - dp) * Pressure_Critical);
6364
}
6465

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+
6578
public:
6679
/*!
6780
* \brief Constructor of the class.
@@ -155,4 +168,4 @@ class CCoolProp final : public CFluidModel {
155168
* \return Value of the constant: Gamma
156169
*/
157170
su2double GetGamma(void) const { return Gamma; }
158-
};
171+
};

SU2_CFD/src/fluid/CCoolProp.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,20 @@ void CCoolProp::SetTDState_rhoe(su2double rho, su2double e) {
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);
5858
if (fluid_entity->phase() == CoolProp::iphase_twophase) {
59-
// assume it is pure gas
60-
fluid_entity->specify_phase(CoolProp::iphase_gas);
59+
// impose gas phase
60+
Temperature = Temperature + 0.1;
6161
CheckPressure(Pressure);
62+
CheckTemperature(Temperature);
6263
fluid_entity->update(CoolProp::PT_INPUTS, Pressure, Temperature);
63-
if (abs(fluid_entity->rhomass() / Density - 1) < dp) {
64-
// origial phase is near saturation gas, then just compute sound speed
65-
SoundSpeed2 = pow(fluid_entity->speed_sound(), 2);
66-
} else {
67-
// original phase is not near saturation gas, then specify the phase as gas phase
68-
fluid_entity->specify_phase(CoolProp::iphase_gas);
69-
SetTDState_PT(Pressure, Temperature);
70-
}
64+
SoundSpeed2 = pow(fluid_entity->speed_sound(), 2);
7165
} else {
7266
SoundSpeed2 = pow(fluid_entity->speed_sound(), 2);
7367
}
7468
}
7569

7670
void CCoolProp::SetTDState_PT(su2double P, su2double T) {
7771
CheckPressure(P);
72+
CheckTemperature(T);
7873
fluid_entity->update(CoolProp::PT_INPUTS, P, T);
7974
su2double rho = fluid_entity->rhomass();
8075
su2double e = fluid_entity->umass();
@@ -130,4 +125,4 @@ CCoolProp::CCoolProp(const string& fluidname) {
130125
"or autodiff",
131126
CURRENT_FUNCTION);
132127
}
133-
#endif
128+
#endif

0 commit comments

Comments
 (0)