Trying to do isentropic compression of air in Excel

49 views
Skip to first unread message

Clifford Bradford

unread,
Dec 11, 2024, 3:23:50 PM12/11/24
to coolprop-users
OK so I'm trying to do a pretty basic calculation. Isentropic compression of humid air using PropSI in Excel.
So my inputs are:
Pin (Pa)  100939.25
Pout (Pa) 
216357.48
Tin (K) 
305.09444 
Relative humidity .5293 
-> water mole fraction at Pin and Tin using HAPropSI("psi_w", "RH", 0.5293, "P", Pin, "T",Tin) = 0.0249897

gas composition (humid air) is therefore:

N2 
0.7613856
O2 
0.2042647
Ar 
0.0090676
CO2 
0.0090676
H2O 
0.0249897

I calculate the entropy at Tin & Pin 
=PropsSI("SMASS","T",Tin,"P",Pin,"HEOS::"&MixtureString($N$3:$R$3,$N5:$R5))
6918.584

When I try to calculate the enthalpy at that same entropy at Pout
=PropsSI("HMASS","SMASS",6918.584,"P",Pout,"HEOS::"&MixtureString($N$3:$R$3,$N5:$R5))
I get an error message:
phase envelope must be built to carry out HSU_P_flash for mixture : PropsSI("HMASS","SMASS",6918.584111,"P",216357.4839,"HEOS::N2[.761385559130228]&O2[.204264662104985]&Ar[9.06759597888477E-03]&CO2[3.80254024920974E-04]&H2O[2.49896796898091E-02]")

If I do the calculation with "HEOS::Air" the calculation works so I guess it has something to with using the mixture function. I'd appreciate some help with this


Clifford Bradford

unread,
Dec 12, 2024, 3:29:40 PM12/12/24
to coolprop-users
As a follow up to the above:
I've attached a file with my trial calculations. 
  • The data in columns A-E are actual data from a GT low-pressure compressor where the Ambient pressure, relative humidity and T2 are the inlet conditions and P25 and T25 are the actual exit conditions so I'm trying to calculate the efficiency with humid air. 
  • Columns F-H are unit conversions
  • Columns I-M are the components of humid air. Column M calculates the water mole fraction and then the other columns have the dry air component scaled by (1-x_H2O)
  • Columns N-S is my calculation of the isentropic enthalpy rise using PropsSI and a humid air mix. 
    • I calculate the enthalpy and entropy at inlet conditions, h_in,air & s_in,air
    • I guess an outlet isentropic temperature, t_outi
    • I calculate the entropy at t_outi and Pout, s_out,air
    • I then use GoalSeek to change t_outi until  s_out,air matches  s_in,air. Based on this post  https://groups.google.com/g/coolprop-users/c/9Gmri-5HspI/m/BlvcpiUjBgAJ and the errors I was getting I figure that calculating enthalpy from pressure and entropy  for a mixture might not be doable.
    • I then calculate the isentropic outlet enthalpy and the enthalpy rise, h_outi,air & dh
  • In order to validate the calculation I redid the calculation using 
    • HAPropsSI with the measured humidity (cols T-X)
    • HAPropsSI with 0 RH (cols Y-AC), and
    • PropSI with dry air (Cols AD-AH)
Items that I've noted
  • all of the methods except HAPropsSI with humidity give a reasonable value of t_outi of ~222°F which makes sense relative to the measured Tout of 226°F. The dh from this calculation is also way out relative to other calculations.
Questions:
  1. Can anyone propose a way I can do the calculations with PropsSI and the humid air mix without having to use Goal Seek? Since the h(s,p) doesn't work, I guess some kind of iterative approach would be necessary? My final aim for this activity isn't to run this in Excel (although I do plan to do some GT simulations in the future) I suppose I could write some VB to do an iteration.
  2. Any idea why the HAPropsSI is so out of of whack? I think I've entered everything correctly but the t_outi and dh are clearly wrong.




Book2.xlsx

Clifford Bradford

unread,
Dec 18, 2024, 3:21:24 PM12/18/24
to coolprop-users
Here's my first cut at this in VBA. it's only been minimally tested. I've tried it with "HEOS::Air" and an air mix with humidity. I'll test it some more and see how it goes. I'd love to get some feedback.
One issue I had when I tried to run with the humid air mix was that if there was an error with any of the property calls (the "SMASS" and "CPMASS" in the While loop for example before I forced it to gas). The code would just die on that line since (I guess)  there was a type mismatch with the Error string returned from the property call and the VBA variables which are type Double. I fixed that by forcing them to gas (which is realistic) and I suppose I could make them all type Variant and implement some error checking...
I might attempt an h(s,p) code too since PropsSI apparently won't do that for a mixture
Here's the code.
If you want to use it in a spreadsheet (0) open the VBA IDE (1) make a Module in the VBA Project and copy the code in (2) Tools>>References check CoolProp


Function isencomp(t_in As Double, p_in As Double, p_out As Double, fluid As String) As Double

'this function calculates the isentropic outlet temperature, t_outi
'of an isentropic compression from (t_in, p_in) to p_out of fluid described in CoolProp fluid string 'fluid'
'temps in K, press in Pa
'this function is needed because Coolprop can't calculate h(s,p) for fluid mixtures
    Dim r_gas As Double 'gas constant for gas, J/kg/K
    Dim t_outi As Double, t_outi1 As Double 'outlet temp for isentropic compression and iteration version, K
    Dim count As Long
    Dim s_in As Double 'inlet entropy, J/kg/K
    Dim resid As Variant 'residual
   
    r_gas = CoolProp.Props1SI(fluid, "GAS_CONSTANT") / CoolProp.Props1SI(fluid, "MOLAR_MASS")
    s_in = CoolProp.PropsSI("SMASS", "T|gas", t_in, "P", p_in, fluid)
    t_outi1 = 0
    t_outi = t_in * (p_out / p_in) ^ (0.4 / 1.4) 'calorically perfect guess
    count = 0
   
    While Abs(t_outi - t_outi1) > 0.0001 And count < 200
        t_outi1 = t_outi
        resid = CoolProp.PropsSI("SMASS", "T|gas", t_outi, "P", p_out, fluid) - s_in
        t_outi = t_outi - resid * t_outi / CoolProp.PropsSI("CPMASS", "T|gas", t_outi, "P", p_out, fluid) 'calorically perfect update
        count = count + 1
   Wend

isencomp = t_outi

End Function

Clifford Bradford

unread,
Dec 19, 2024, 3:01:50 PM12/19/24
to coolprop-users
Tested this out on a bunch more data. I have a bunch of data from an operating engine and I'm calculating the compressor efficiency. The function works fine but it's relatively slow. Any ideas to improve speed would be appreciated. To give some idea, the iterative loop maybe goes thru 5 iterations so it's relatively efficient. I've updated my latest version to optionally calculate the isentropic enthalpy rise as well.

Function isencomp(t_in As Double, p_in As Double, p_out As Double, fluid As String, Optional calcdhi As Boolean = False) As Variant

'this function calculates the isentropic outlet temperature, t_outi, and optionally the corresponding enthalpy, dh_outi = h(T_outi,p_out) - h(t_in,p_in)

'of an isentropic compression from (t_in, p_in) to p_out of fluid described in CoolProp fluid string 'fluid'
'temps in K, press in Pa
'this function is needed because Coolprop can't calculate h(s,p) for fluid mixtures
'if calcdhi is FALSE (the default) only t_outi is calculated if it's true the function returns a length 2 vector where the first element is t_outi and the second is dh_outi


    Dim r_gas As Double 'gas constant for gas, J/kg/K
    Dim t_outi As Double, t_outi1 As Double 'outlet temp for isentropic compression and iteration version, K
    Dim count As Long
    Dim s_in As Double 'inlet entropy, J/kg/K
    Dim resid As Variant 'residual
   
    r_gas = CoolProp.Props1SI(fluid, "GAS_CONSTANT") / CoolProp.Props1SI(fluid, "MOLAR_MASS")
    s_in = CoolProp.PropsSI("SMASS", "T|gas", t_in, "P", p_in, fluid)
    t_outi1 = 0
    t_outi = t_in * (p_out / p_in) ^ (0.4 / 1.4) 'calorically perfect guess
    count = 0
   
    While Abs(t_outi - t_outi1) > 0.0001 And count < 200
        t_outi1 = t_outi
        resid = CoolProp.PropsSI("SMASS", "T|gas", t_outi, "P", p_out, fluid) - s_in
        t_outi = t_outi - resid * t_outi / CoolProp.PropsSI("CPMASS", "T|gas", t_outi, "P", p_out, fluid) 'calorically perfect update
        count = count + 1
   Wend

If Not calcdhi Then
    isencomp = t_outi
Else
    Dim outi(1 To 2) As Double
    outi(1) = t_outi
    outi(2) = CoolProp.PropsSI("HMASS", "T|gas", t_outi, "P", p_out, fluid) - CoolProp.PropsSI("HMASS", "T|gas", t_in, "P", p_in, fluid)
    isencomp = outi
End If

End Function


Ian Bell

unread,
Dec 19, 2024, 7:13:13 PM12/19/24
to coolpro...@googlegroups.com
For pseudo-pure air, you can just use PS inputs in the PropsSI function...

--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/coolprop-users/5e7fba99-6fcc-4a89-8a87-d06d05f9020an%40googlegroups.com.

Clifford Bradford

unread,
Dec 20, 2024, 6:54:30 PM12/20/24
to coolprop-users
I need to be able to model humidity above the temperature range of HAPropsSI

Ian Bell

unread,
Dec 20, 2024, 7:24:37 PM12/20/24
to coolpro...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages