usnistgov / REFPROP-wrappers

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

Different return values while using ctREFPROP wrapper and REFPROP 10 GUI with the same inputs #584

Closed ksat00 closed 8 months ago

ksat00 commented 8 months ago

ctREFPROP is returning a different specific enthalpy value for a pre-defined mixture (R513A) using REFPROP 10 when using pressure and temperature as input compared to using the same inputs through REFPROP GUI or Excel VBA REFPROP interface. The default reference state is the same in all cases (IIR reference state). Excel VBA and REFPROP GUI give the same result.

Details

The example below is trying to calculate and print out the specific enthalpy of R513A at 0.370 MPa pressure and 9.53 °C temperature in a Python application. The value for specific enthalpy returned from ctREFPROP (version 0.10.2 from PyPI) with these inputs is 370.89 kJ/kg.

Sample code

import os
from ctREFPROP.ctREFPROP import REFPROPFunctionLibrary
RP = REFPROPFunctionLibrary(os.environ['RPPREFIX'])
RP.SETPATHdll(os.environ['RPPREFIX'])
units = RP.GETENUMdll(0,"SI WITH C").iEnum
print('REFPROP Version:', RP.RPVersion())
Ref = "R513A" #Fluid, a pre-defined mixture in REFPROP 10
setref = RP.SETMIXTUREdll(Ref)
PTemp = 0.370 #Pressure in MPa
TTemp = 9.53  #Temperature in °C
print('Input pressure (MPa):', PTemp, 'Input temperature (°C):', TTemp)
hTemp1 = RP.REFPROP1dll("PT","H",units,0,PTemp,TTemp,[1]) #Using simpler REFPROP1dll interface
print('Specific Enthalpy from REFPROP1dll: ',hTemp1.c)
htemp2 = RP.REFPROPdll('', 'PT', 'H', units,0,0,PTemp,TTemp,[1]) #Using full REFPROPdll interface
print('Specific Enthalpy from REFPROPdll: ', htemp2[1][0])

#

Output from the code above

image

Output from REFPROP 10 GUI using the same inputs

The value for specific enthalpy returned using REFPROP 10 GUI and Excel VBA is 383.55 kJ/kg with these same inputs.

image

Other Observations

There is no difference in return values for specific enthalpy for a pure fluid such as R134a in the same Python code (while using SETFLUIDSdll instead of SETMIXTUREdll). In the case with the pure fluid, the results are the same from ctREFPROP, REFPROP GUI and Excel VBA REFPROP interfaces. Is there an error in how the above code is using ctREFPROP module for calculating predefined mixture properties?

ianhbell commented 8 months ago

You need to also call the SETREFdll function to ensure you get the reference state you want.

ksat00 commented 8 months ago

I added an explicit call to SETREFdll in the sample code without having any noticeable effect on the results. To add further details, the issue does not appear as prominent for subcooled liquid state. For the subcooled liquid state example in the code segment below, I am getting much closer results from ctREFPROP and REFPROP GUI. Also want to make it clear that these are running on the same computer with the same REFPROP installation.

import os
from ctREFPROP.ctREFPROP import REFPROPFunctionLibrary
RP = REFPROPFunctionLibrary(os.environ['RPPREFIX'])
RP.SETPATHdll(os.environ['RPPREFIX'])
units = RP.GETENUMdll(0,"SI WITH C").iEnum
setref=RP.SETREFdll("IIR",1,[0],0,0,0,0)
print('REFPROP Version:', RP.RPVersion())
Ref = "R513A" #Refrigerant
setref = RP.SETMIXTUREdll(Ref)
PTemp = 0.370 #Pressure in MPa
TTemp = 9.53  #Temperature in °C

print('Superheated state')
print('Input pressure (MPa):', PTemp, 'Input temperature (°C):', TTemp)
hTemp1 = RP.REFPROP1dll("PT","H",units,0,PTemp,TTemp,[1]) #Using simpler REFPROP1dll interface
print('Specific Enthalpy from REFPROP1dll: ',hTemp1.c)
htemp2 = RP.REFPROPdll('', 'PT', 'H', units,0,0,PTemp,TTemp,[1]) #Using full REFPROPdll interface
print('Specific Enthalpy from REFPROPdll: ', htemp2[1][0])

PTemp = 0.370 #Pressure in MPa
TTemp = 3.00  #Temperature in °C
print('Subcooled Liquid State')
print('Input pressure (MPa):', PTemp, 'Input temperature (°C):', TTemp)
hTemp1 = RP.REFPROP1dll("PT","H",units,0,PTemp,TTemp,[1]) #Using simpler REFPROP1dll interface
print('Specific Enthalpy from REFPROP1dll: ',hTemp1.c)
htemp2 = RP.REFPROPdll('', 'PT', 'H', units,0,0,PTemp,TTemp,[1]) #Using full REFPROPdll interface
print('Specific Enthalpy from REFPROPdll: ', htemp2[1][0])

Output from ctREFPROP for both superheated vapor and subcooled liquid states

image

Output from REFPROP GUI for the same inputs

image

ianhbell commented 8 months ago

Please make sure you read the docs related to setting of reference state: https://refprop-docs.readthedocs.io/en/latest/DLL/high_level.html#f/_/REFPROPdll (and then search for SETREF within that block)

nist-aharvey commented 8 months ago

I can add that, since this is a mixture, there are two ways to do the reference state (even beyond choosing IIR, etc.). Either the convention can be applied for the mixture as a whole, or it can be applied for each individual component. I think the default for which way to do that may be different between the GUI and the DLL. In the GUI, try going into Options, Reference State, and switch the setting of "Apply Reference State to". I think that might resolve the difference you are seeing.

ksat00 commented 8 months ago

@ianhbell and @nist-aharvey Thank you for your comments and suggestions on setting the reference state for the mixture. Explicitly setting the reference state to DEFAULT ( setting hOut as 'DEF' while calling REFPROPdll with 'SETREF' as hIn) resolved the issue. With this setting, the values returned by ctREFPROP and GUI are identical for both superheated vapor and subcooled liquid in the above cases.