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
3434CCoolProp::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
7681void 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
8491void 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
127140CCoolProp::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