usnistgov / REFPROP-wrappers

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

Incorrect Reference State Values #223

Closed MarkGordijn closed 4 years ago

MarkGordijn commented 5 years ago

Description

When doing the tutorial using a copy of the notebook tutorial (or my own jupyter notebook), the reference states calculated are incorrect.

Steps to Reproduce

  1. Open Tutorial.ipynb in Jupyter Notebooks.
  2. Run all cells from the start of the file.
  3. Reference States check for the IIR check give incorrect values.

The reference state should have a h=200 kJ/kg and s= 1 kJ/kg-K. Instead the following is calculated:

MASS_BASE_SI = RP.GETENUMdll(0, "MASS BASE SI").iEnum
RP.SETFLUIDSdll("PROPANE");
z = [1.0]+[0.0]*19

# Do a saturation call at one 273.15 K, check H and S are equal to the 
# default reference state (IIR, h = 200 kJ/kg, s = 1 kJ/kg-K for sat. liquid at 0 C)
r = RP.REFPROPdll("PROPANE", "QT", "H;S", MASS_BASE_SI, 0, 0, 0, 273.15, z)
print(r.Output[0:2], ":::::: (should be 200000, 1000)")

# Now we set the reference state to something else, in this case NBP
# with h,s = 0 at normal boiling point (saturated liquid at 1 atmosphere (101325 Pa))
icomp = 1
RP.SETREFdll("NBP", icomp, z, -1,-1,-1,-1) # -1 are placeholders, not needed, but must be passed

# Confirm that we get the right enthalpy and entropy at the reference state
# They should be 0 and 0 for H and S
r = RP.REFPROPdll("PROPANE", "PQ", "H;S", MASS_BASE_SI, 0,0, 101325, 0, z)
print(r.Output[0:2], ":::::: (should be ~0, ~0)")

# Unset the reference state for propane by selecting a new fluid
RP.SETFLUIDSdll("DECANE");

# This should be back to IIR again
r = RP.REFPROPdll("PROPANE", "QT", "H;S", MASS_BASE_SI, 0, 0, 0, 273.15, z)
print(r.Output[0:2], ":::::: (should be 200000, 1000)")

array('d', [199999.99999999994, 1000.0]) :::::: (should be 200000, 1000) array('d', [-1.4502312524103079e-11, 0.0]) :::::: (should be ~0, ~0) array('d', [99643.47646668972, 392.9541869991858]) :::::: (should be 200000, 1000)

Versions

REFPROP Version: 10.0002 Operating System and Version: Windows 10 64bit **Access Method: Python wrapper (Python 3.7.2 (Anaconda))

ianhbell commented 5 years ago

The **** means you have version 10.0, which had an unfortunate bug in the RPVersion function. You can email me (ian.bell@nist.gov) for a patch without this problem.

Note that in my example I am using ctREFPROP 0.8, which makes accessible the unit enumerations in the class itself without having to to call GETENUMdll to retrieve.

I ran your example

from ctREFPROP.ctREFPROP import REFPROPFunctionLibrary

root = 'D:/Program Files (x86)/REFPROP'
RP = REFPROPFunctionLibrary(root)
RP.SETPATHdll(root)

RP.SETFLUIDSdll("PROPANE");
z = [1.0]+[0.0]*19

# Do a saturation call at one 273.15 K, check H and S are equal to the 
# default reference state (IIR, h = 200 kJ/kg, s = 1 kJ/kg-K for sat. liquid at 0 C)
r = RP.REFPROPdll("PROPANE", "QT", "H;S", RP.MASS_BASE_SI, 0, 0, 0, 273.15, z)
print(r.Output[0:2], ":::::: (should be 200000, 1000)")

# Now we set the reference state to something else, in this case NBP
# with h,s = 0 at normal boiling point (saturated liquid at 1 atmosphere (101325 Pa))
icomp = 1
RP.SETREFdll("NBP", icomp, z, -1,-1,-1,-1) # -1 are placeholders, not needed, but must be passed

# Confirm that we get the right enthalpy and entropy at the reference state
# They should be 0 and 0 for H and S
r = RP.REFPROPdll("PROPANE", "PQ", "H;S", RP.MASS_BASE_SI, 0,0, 101325, 0, z)
print(r.Output[0:2], ":::::: (should be ~0, ~0)")

# Unset the reference state for propane by selecting a new fluid
RP.SETFLUIDSdll("DECANE");

# This should be back to IIR again
r = RP.REFPROPdll("PROPANE", "QT", "H;S", RP.MASS_BASE_SI, 0, 0, 0, 273.15, z)
print(r.Output[0:2], ":::::: (should be 200000, 1000)")

but I got the right result

array('d', [199999.99999999994, 1000.0]) :::::: (should be 200000, 1000)
array('d', [-1.4502312524103079e-11, 0.0]) :::::: (should be ~0, ~0)
array('d', [199999.99999999994, 1000.0]) :::::: (should be 200000, 1000)

Let's start with the patch and see if it fixes this problem too.

ianhbell commented 5 years ago

P.S. Regarding your original posting, are you still having issues with subsequent calls? For mixtures, you should 100% of the time either use R410A.PPF or R410A.MIX to make clear whether you mean the pseudo-pure fluid (the former) or the predefined mixture (the latter).

MarkGordijn commented 5 years ago

Thank you @ianhbell for your help. I got the update after I sent an email to Dr. Lemmon . After copying the new files to the REFPROP directory and updating my ctREFPROP, I am still having the same issue. The RPVersion function is now returning 10.0002.

I ran your example code, updating the code to use my REFPROP directory. I ran the example in the base python environment and a virtual environment, both times it produced the same result. You can see that the output has not improved.

array('d', [199999.99999999994, 1000.0]) :::::: (should be 200000, 1000)
array('d', [-1.4502312524103079e-11, 0.0]) :::::: (should be ~0, ~0)
array('d', [99643.47646668972, 392.9541869991858]) :::::: (should be 200000, 1000)
ianhbell commented 5 years ago

Please provide a runnable example; I'd like to see exactly what you did. Can you also print out the results of the RPVersion function, just to make sure that you are loading the version of REFPROP that you think you are?

MarkGordijn commented 5 years ago

Reference States Code

I used your code as shown below.

from ctREFPROP.ctREFPROP import REFPROPFunctionLibrary

root = 'C:/Program Files (x86)/REFPROP'
RP = REFPROPFunctionLibrary(root)
RP.SETPATHdll(root)
print("REFPROP Version: ",RP.RPVersion())

RP.SETFLUIDSdll("PROPANE");
z = [1.0]+[0.0]*19

# Do a saturation call at one 273.15 K, check H and S are equal to the 
# default reference state (IIR, h = 200 kJ/kg, s = 1 kJ/kg-K for sat. liquid at 0 C)
r = RP.REFPROPdll("PROPANE", "QT", "H;S", RP.MASS_BASE_SI, 0, 0, 0, 273.15, z)
print(r.Output[0:2], ":::::: (should be 200000, 1000)")

# Now we set the reference state to something else, in this case NBP
# with h,s = 0 at normal boiling point (saturated liquid at 1 atmosphere (101325 Pa))
icomp = 1
RP.SETREFdll("NBP", icomp, z, -1,-1,-1,-1) # -1 are placeholders, not needed, but must be passed

# Confirm that we get the right enthalpy and entropy at the reference state
# They should be 0 and 0 for H and S
r = RP.REFPROPdll("PROPANE", "PQ", "H;S", RP.MASS_BASE_SI, 0,0, 101325, 0, z)
print(r.Output[0:2], ":::::: (should be ~0, ~0)")

# Unset the reference state for propane by selecting a new fluid
RP.SETFLUIDSdll("DECANE");

# This should be back to IIR again
r = RP.REFPROPdll("PROPANE", "QT", "H;S", RP.MASS_BASE_SI, 0, 0, 0, 273.15, z)
print(r.Output[0:2], ":::::: (should be 200000, 1000)")

Output

C:\Bitbucket Projects\rack-calculator>py refprop_test.py
REFPROP Version:  10.0002
array('d', [199999.99999999994, 1000.0]) :::::: (should be 200000, 1000)
array('d', [-1.4502312524103079e-11, 0.0]) :::::: (should be ~0, ~0)
array('d', [99643.47646668972, 392.9541869991858]) :::::: (should be 200000, 1000)
ianhbell commented 5 years ago

I was testing with the internal alpha release, and @EricLemmon and I are working to figure out how safe it would be to have you use the alpha. It seems this alpha repairs this bug with reference states.

EricLemmon commented 4 years ago

It appears that I dropped the ball on this, I apologize for that. Do you still want to try the alpha version to see if it helps?

MarkGordijn commented 4 years ago

Yes please

EricLemmon commented 4 years ago

Hi Mark,

I see this issue is still open. Did I send you the alpha version? If not, please email me (again?) to get the updated DLL. (eric.lemmon@nist.gov)

Eric

EricLemmon commented 4 years ago

I am not sure if I have heard back from you or if this has been taken care of. If it has not, please send an email to Ian Bell (ian.bell@nist.gov) and have him forward it to me. My NIST computer if down and I cannot access it.

EricLemmon commented 4 years ago

Hi Mark,

Since I believe this issue has been fixed, I will close it now, but please send us an email if you want the update. You can also still make comments after it is closed, or reopen it if you find that it has not been fixed.

Eric