usnistgov / REFPROP-issues

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

Unset the reference state for propane by selecting a new fluid example not working as expected. #648

Open veronica-yyc opened 1 year ago

veronica-yyc commented 1 year ago

Description

Utilizing your linked tutorial (which is lovely) link, I noticed that your Reference states example doesn't return the values expected. I believe the author intends to reset the reference state by resetting the fluid, but the reference state does not get reset as expected. Not sure if this is just an outdated example, or if the programming is behaving as expected.

Steps to Reproduce

  1. link to the tutorial, copy code below "Reference States" heading
  2. Run cell, inspect third returned statement

Expected behavior: [What you expect to happen]

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)

Actual behavior: [What actually happens]

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: RP.RPVersion() returns '10.0' Operating System and Version: Windows 10 Access Method:

# Import the main class from the Python library
from ctREFPROP.ctREFPROP import REFPROPFunctionLibrary

Additional Information

image

ianhbell commented 1 year ago

In the beta (email me at ian.bell@nist.gov to get access), this example yields the correct result:

import os
os.environ['RPPREFIX'] = os.getenv('HOME')+'/REFPROP10beta'

import numpy as np
root = os.getenv('RPPREFIX')
import ctREFPROP.ctREFPROP as ct
RP = ct.REFPROPFunctionLibrary(root)
RP.SETPATHdll(root)

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)")

yielding

array('d', [199999.55654680828, 999.9992602411847]) :::::: (should be 200000, 1000)
array('d', [100355.85901674398, 607.0441737657444]) :::::: (should be ~0, ~0)
array('d', [199999.55654680828, 999.9992602411847]) :::::: (should be 200000, 1000)