usnistgov / REFPROP-issues

A repository solely used for reporting issues with NIST REFPROP
26 stars 13 forks source link

HS inputs yield non-trivial round-trip error #497

Open ianhbell opened 2 years ago

ianhbell commented 2 years ago

Description

Starting at a given temperature and vapor quality, calculating enthalpy and entropy, and then back-calculating temperature and density, the worst case errors in T are on the order of 0.1 mK. It's not terrible, but not great, and can be improved by iterating directly for temperature. Even the best points are still in error by 1e-5 K, and this should be able to be reduced by at least 4 orders of magnitude.

Example

import os
import ctREFPROP.ctREFPROP as c
import numpy as np
root = os.getenv('RPPREFIX')
RP = c.REFPROPFunctionLibrary(root)
RP.SETPATHdll(root)
print(RP.RPVersion())
for T in np.linspace(85.525, 369.89, 30):
    h, s = RP.REFPROPdll('PROPANE','QT','H;S',RP.MOLAR_BASE_SI,0,0,0.7,T,[1.0]).Output[0:2]
    r = RP.REFPROPdll('PROPANE','SH','T',RP.MOLAR_BASE_SI,0,0,s,h,[1.0])
    print(T-r.Output[0], r.herr)

yields

10.0.1.19
8.999844737900276e-05 
-7.145404184427662e-05 
-4.11215937816678e-05 
-2.2316277664913287e-05 
-8.284735712038582e-05 
-8.001106900223931e-05 
-7.981634749398836e-05 
-8.127104197797053e-05 
-8.327630195026359e-05 
-8.457914657356014e-05 
-8.372156261771124e-05 
-7.897759917341318e-05 
-6.827068438042261e-05 
-0.00019623966758786082 
-7.269539426602023e-05 
-0.00011312156976828192 
-0.00018883482877640745 
-0.000248888613782583 
-0.00027818723208383744 
-0.00025560947659641897 
-0.00015074893343580698 
-0.00023251936045198818 
-0.0002900623026107496 
-0.00023617050538859985 
-0.00030984821455604106 
-0.0002375717282916412 
-7.11073836896503e-05 
-6.171795257614576e-05 
-7.371280941015357e-05 
0.0 
ianhbell commented 2 years ago

In 10.0, the same script yields much smaller round-trip error, but many failures:

10.0.0.02
10000075.525 [HSFLSH error 260] h-s inputs are two-phase or out of bounds, iterative routine is not available to find a solution.
10000085.330689656 [HSFLSH error 260] h-s inputs are two-phase or out of bounds, iterative routine is not available to find a solution.
10000095.13637931 [HSFLSH error 260] h-s inputs are two-phase or out of bounds, iterative routine is not available to find a solution.
10000104.942068966 [HSFLSH error 260] h-s inputs are two-phase or out of bounds, iterative routine is not available to find a solution.
10000114.747758621 [HSFLSH error 260] h-s inputs are two-phase or out of bounds, iterative routine is not available to find a solution.
10000124.553448277 [HSFLSH error 260] h-s inputs are two-phase or out of bounds, iterative routine is not available to find a solution.
-3.8824055081931874e-11 
10000144.164827587 [HSFLSH error 260] h-s inputs are two-phase or out of bounds, iterative routine is not available to find a solution.
10000153.97051724 [HSFLSH error 260] h-s inputs are two-phase or out of bounds, iterative routine is not available to find a solution.
-8.895995051716454e-12 
-3.808509063674137e-12 
2.8421709430404007e-13 
1.0800249583553523e-12 
-6.821210263296962e-13 
4.888534022029489e-12 
1.3073986337985843e-12 
8.799361239653081e-11 
-5.400124791776761e-13 
-9.663381206337363e-13 
-3.007016857736744e-11 
5.115907697472721e-13 
-2.2737367544323206e-13 
-1.2846612662542611e-11 
-2.2737367544323206e-13 
-2.326601133972872e-10 
1.1368683772161603e-13 
-1.5916157281026244e-12 
1.0800249583553523e-12 
-1.2789769243681803e-10 
-2.3931079340400174e-10 [PSFLSH warning -235] Saturation state routine failed to converge and thus the phase is unknown; however, the state appears to be either single phase or metastable.  Additional analysis is needed.