usnistgov / REFPROP-wrappers

Wrappers around NIST REFPROP for languages such as Python, MATLAB, etc.
190 stars 127 forks source link

Excel: dH/dT at constant T, or at constant P, wrong values at odd input values #369

Closed mscc3 closed 3 years ago

mscc3 commented 3 years ago

I'm calculating [dH/dT at constant T] and [dH/dT at constant P] along the saturation curve of pure hydrogen (normal). At random points along the saturation curve, the values seem wrong (either wildly off neighboring points or does not follow monotonic trend).

I've attached my Excel spreadsheet, with the erroneous cells highlighted in yellow: dHdPconstT issue.xlsx

REFPROP Version: 10.0 Operating System and Version: Windows Server 2012 R2 Standard
Access Method: Excel

ianhbell commented 3 years ago

Looks definitely like a bug in REFPROP. I did the same calc in CoolProp in Python (see below). The good news is that someone is adding the necessary functionality to allow you to do the same calculation with REFPROP (properly) via CoolProp: https://github.com/CoolProp/CoolProp/pull/2016

import CoolProp.CoolProp as CP
AS = CP.AbstractState('HEOS','Hydrogen')

for T in [20,21,22,23,24,24.5,24.6,24.7,24.8,24.9,25,25.1,26,27,28,29,30,31,32]:
    AS.update(CP.QT_INPUTS, 0, T)
    print(T, AS.p()/1e6, 
        AS.first_saturation_deriv(CP.iP, CP.iT)/1e6, 
        AS.first_partial_deriv(CP.iHmass, CP.iT, CP.iP)/1e3, 
        AS.first_partial_deriv(CP.iHmass, CP.iP, CP.iT)*1e3)

yielding:

20 0.09071732334006057 0.027617657841608252 9.569680983318609 9.49095706678348
21 0.12149840761459506 0.03407387041557597 10.137606644627084 8.989030394703883
22 0.15912551984413095 0.04131140374663652 10.77149134573546 8.362615861184162
23 0.20438492615086004 0.049340096548207764 11.489829482292697 7.568698648592552
24 0.25807295119862206 0.058170613131449854 12.318852961204753 6.543471989840751
24.5 0.2883297469698377 0.06289072158748031 12.786358600105498 5.915332571191474
24.6 0.29466718415726023 0.06385939768360037 12.884866166102602 5.778501235058626
24.7 0.30110190196812653 0.06483633760263062 12.985176905006137 5.637587081518182
24.8 0.3076347278472794 0.06582156258059983 13.087353919081233 5.492425383555522
24.9 0.3142664913876363 0.06681509475531505 13.191463370837269 5.342842800146556
25 0.3209980244684192 0.06781695721748456 13.297574670306513 5.188656816222791
25.1 0.32783016130897924 0.06882717405037898 13.405760676488367 5.02967513848883
26 0.3939855167772558 0.0782996064830327 14.486835461330283 3.3455272552445074
27 0.47788624891062176 0.08964985876512825 15.987049860744154 0.7418094585440225
28 0.5735904279844216 0.10191664188744448 17.976719216187313 -3.1278368403521295
29 0.6820507279881675 0.11517873498931043 20.807457175371827 -9.307820987067142
30 0.8043232153830606 0.12957037634399382 25.284408817694867 -20.322023752007635
31 0.9416498909175293 0.145346620215881 33.758516983754475 -44.01468886707482
32 1.095666764716423 0.16311039371319072 57.28680543820325 -120.35076540592554
EricLemmon commented 3 years ago

The problem you are seeing comes because you are sending it pressure and temperature as the inputs for the enthalpy derivatives. Since P and T are the same for the liquid or vapor at saturation, then the tolerances used to obtain the saturation states will determine which phase that Refprop believes the point resides. And in fact, it's not just the saturation states that are ambiguous, but also any two phase state in between. If you plot the saturated enthalpy derivatives for both the liquid and vapor and then overlay your calculated points, you will see that your output is jumping back and forth between the liquid and the vapor.

You should use TQ inputs for everything in this table. When you do this, you will find that the calculations are very smooth.

ianhbell commented 3 years ago

@EricLemmon is right, QT inputs are used in the Python example above.

mscc3 commented 3 years ago

Makes perfect sense, thank you!