1+ /* !
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+ */
27+
28+ #include " ../../include/fluid/CCoolProp.hpp"
29+
30+ #ifdef USE_COOLPROP
31+ #include " CoolProp.h"
32+ #include " AbstractState.h"
33+
34+ 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 ();
37+ Pressure_Critical = fluid_entity->p_critical ();
38+ Temperature_Critical = fluid_entity->T_critical ();
39+ acentric_factor = fluid_entity->acentric_factor ();
40+ }
41+
42+ CCoolProp::~CCoolProp () {}
43+
44+ void CCoolProp::SetTDState_rhoe (su2double rho, su2double e) {
45+ // cout<<"p "<<Pressure<<"Pc "<<Pressure_Critical<<"T "<<Temperature<<"Tc"<<Temperature_Critical<<endl;
46+ Density = rho;
47+ StaticEnergy = e;
48+ fluid_entity->update (CoolProp::DmassUmass_INPUTS, Density, StaticEnergy);
49+ Cp = fluid_entity->cpmass ();
50+ Cv = fluid_entity->cvmass ();
51+ Gamma = Cp / Cv;
52+ Pressure = fluid_entity->p ();
53+ Temperature = fluid_entity->T ();
54+ Entropy = fluid_entity->smass ();
55+ dPdrho_e = fluid_entity->first_partial_deriv (CoolProp::iP, CoolProp::iDmass, CoolProp::iUmass);
56+ dPde_rho = fluid_entity->first_partial_deriv (CoolProp::iP, CoolProp::iUmass, CoolProp::iDmass);
57+ dTdrho_e = fluid_entity->first_partial_deriv (CoolProp::iT, CoolProp::iDmass, CoolProp::iUmass);
58+ dTde_rho = fluid_entity->first_partial_deriv (CoolProp::iT, CoolProp::iUmass, CoolProp::iDmass);
59+ if (fluid_entity->phase () == 6 ) {
60+ fluid_entity->specify_phase (CoolProp::iphase_gas);
61+ SetTDState_PT (Pressure,Temperature);
62+ }
63+ else {
64+ SoundSpeed2 = pow (fluid_entity->speed_sound (), 2 );
65+ }
66+ }
67+
68+ void CCoolProp::SetTDState_PT (su2double P, su2double T) {
69+ fluid_entity->update (CoolProp::PT_INPUTS, P, T);
70+ su2double rho = fluid_entity->rhomass ();
71+ su2double e = fluid_entity->umass ();
72+ SetTDState_rhoe (rho, e);
73+ }
74+
75+ void CCoolProp::SetTDState_Prho (su2double P, su2double rho) {
76+ fluid_entity->update (CoolProp::DmassP_INPUTS, rho, P);
77+ su2double e = fluid_entity->umass ();
78+ SetTDState_rhoe (rho, e);
79+ }
80+
81+ void CCoolProp::SetEnergy_Prho (su2double P, su2double rho) {
82+ fluid_entity->update (CoolProp::DmassP_INPUTS, rho, P);
83+ StaticEnergy = fluid_entity->umass ();
84+ }
85+
86+ void CCoolProp::SetTDState_hs (su2double h, su2double s) {
87+ fluid_entity->update (CoolProp::HmassSmass_INPUTS, h, s);
88+ su2double rho = fluid_entity->rhomass ();
89+ su2double e = fluid_entity->umass ();
90+ SetTDState_rhoe (rho, e);
91+ }
92+
93+ void CCoolProp::SetTDState_Ps (su2double P, su2double s) {
94+ fluid_entity->update (CoolProp::PSmass_INPUTS, P, s);
95+ su2double Rho = fluid_entity->rhomass ();
96+ su2double e = fluid_entity->umass ();
97+ SetTDState_rhoe (Rho, e);
98+ }
99+
100+ void CCoolProp::SetTDState_rhoT (su2double rho, su2double T) {
101+ fluid_entity->update (CoolProp::DmassT_INPUTS, rho, T);
102+ su2double Rho = fluid_entity->rhomass ();
103+ su2double e = fluid_entity->umass ();
104+ SetTDState_rhoe (Rho, e);
105+ }
106+
107+ void CCoolProp::ComputeDerivativeNRBC_Prho (su2double P, su2double rho) {
108+ SetTDState_Prho (P, rho);
109+ dhdrho_P = fluid_entity->first_partial_deriv (CoolProp::iHmass,CoolProp::iDmass,CoolProp::iP);
110+ dhdP_rho = fluid_entity->first_partial_deriv (CoolProp::iHmass,CoolProp::iP,CoolProp::iDmass);
111+ dsdP_rho = fluid_entity->first_partial_deriv (CoolProp::iSmass,CoolProp::iP,CoolProp::iDmass);
112+ dsdrho_P = fluid_entity->first_partial_deriv (CoolProp::iSmass,CoolProp::iDmass,CoolProp::iP);
113+ }
114+
115+ #else
116+ CCoolProp::CCoolProp (string fluidname) {
117+ SU2_MPI::Error (" SU2 was not compiled with CoolProp (-Denable-coolprop=true). Note that CoolProp cannot be used with directdiff or autodiff" , CURRENT_FUNCTION);
118+ }
119+ #endif
0 commit comments