usnistgov / REFPROP-wrappers

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

Python wrapper (ABFLSHdll) calculations not consistent with desktop program #601

Closed sykde closed 3 months ago

sykde commented 3 months ago

Description

Hello,

I noticed an inconsistency between the Python wrapper's REFPROPdll and ABFLSHdll routines compared to the output of the dekstop application. The mixture I'm working with is a pseudo-LNG: methane, ethane, propane, butane, and nitrogen, with molar fractions of 0.9400, 0.0470, 0.0080, 0.0020 and 0.0030 respectively. In the desktop application, if I request the calculation of all properties at T = 120.15 K and P = 0.2 MPa, I get a specific enthalpy of 11.676 kJ/kg, which corresponds to 198.98 J/mol. If I do the same for P = 0.2 MPa and H = 11.676 kJ/kg, I get the expected temperature value of 120.15 K. Using the python wrapper, that is not the case.

In the examples below, only ABFLSHdll is showcased, but the behaviour is the same when REFPROPdll is used.

Am I doing something wrong? Thanks in advance

RP = REFPROPFunctionLibrary(os.environ['RPPREFIX'])
RP.SETPATHdll(os.environ['RPPREFIX'])

p_kPa = 200.0
T_K = 120.15;
H_J_over_mol = 198.98

fluid = "methane * ethane * propane * butane * nitrogen"
z = [0.9400, 0.0470, 0.0080, 0.0020, 0.0030] # molar fractions

# Calculate the enthalpy at the specified P, T
r = RP.ABFLSHdll("PT",p_kPa,T_K,z,0)
r.h
# returns: 198.98, as expected - same value with H_J_over_mol

# Calculate the temperature at the specified P, H
r = RP.ABFLSHdll("PH",p_kPa,H_J_over_mol,z,0)
r.T 
# returns 1582.71, expected: 120.15

Versions

REFPROP Version: 10.0 Operating System and Version: Windows 11 (22H2, 22621.3737) Access Method: Python, Desktop program

Additional Information

A screenshot of the REFPROP desktop environment (results are the same if T, P or P, H are provided as input): image

A screenshot of the Python code above, showcasing the problem: image

Edit: Added some information for conciseness, fixed a typo

henningjp commented 3 months ago

You are very near the saturation curves. Try calling SATSPLN first before calling ABFLSH. The GUI calls SATSPLN by default to set the splines through the saturation curves. I get the correct answer with the Mathcad wrapper, and it calls SATSPLN by default also when the mixture is set.

sykde commented 3 months ago

Thank you for the prompt response!

The problem was indeed that the python wrapper does not seem to call SATSPLN. Calling it manually fixed the problem.

ianhbell commented 3 months ago

Good to hear! Thanks @henningjp for the fix