usnistgov / REFPROP-wrappers

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

Unknown errors (ierr) from SETFLUIDSdll and SETREFdll #618

Open schreibfheler opened 2 months ago

schreibfheler commented 2 months ago

Description

Calling the SETFLUIDSdll and SETREFdll throw errors that are undocumented in the REFPROP DLL documentation for certain fluids/mixtures.

Steps to Reproduce

Examples:

While 26 is a valid error code from SETREFdll, it is not listed under SETREFdll. 124 is a valid error code for SATTdll, however, not for SETREF. -710 is not listed as a valid error code for any dll in the documentation.

# SETFLUID example code
ierr_SETFLUID = RP.SETFLUIDSdll(hFld=fluid_str)

# SETREF example code
SETREF_output = RP.SETREFdll(hrf="NBP", ixflag=n_comp, x0=z_comp, h0=-1, s0=-1, T0=-1, P0=-1)  
ierr_SETREF = SETREF_output.ierr

Expected behavior:

The functions should throw errors that can be found in the documentation

Actual behavior:

The functions throw errors that cannot be found in the documentation

Versions

REFPROP Version: REFPROP version 10.0 Operating System and Version: Windows 10 64-bit Access Method: ctREFPROP 0.10.3

ianhbell commented 2 months ago

What are the corresponding herr that you get?

schreibfheler commented 2 months ago

I don't know why i didn't think of that...

Diethyl ether;Carbon dioxide ~ 0.9;0.1: ierr from SETFLUID: 26

SETFLUID doesn't return a herr, so i can't tell.

Propane;Methanol ~ 0.9;0.1: ierr from SETREF : -710

[CHECKSTATE warning -710] State appears to be two-phase: d(ln(P))/d(ln(D)) is positive.

Methane;Ethanol ~ 0.5;0.5: ierr from SETREF: 124

[SATT error 124] Iteration for saturation state did not converge for T = 670.429 K.

ianhbell commented 2 months ago

For SETFLUIDS, you need to use the ERRMSG function to get the error message. I can replicate the failure:

import os
import ctREFPROP.ctREFPROP as ct
os.environ['RPPREFIX'] = os.getenv('HOME')+'/REFPROP10'

root = os.getenv('RPPREFIX')
RP = ct.REFPROPFunctionLibrary(root)
RP.SETPATHdll(root)
print(RP.RPVersion())

ierr = RP.SETFLUIDSdll("Diethyl ether;Carbon dioxide")
print(ierr)
if ierr != 0:
    print(RP.ERRMSGdll(ierr))
    quit()

SETREF_output = RP.SETREFdll(hrf="NBP", ixflag=2, x0=[0.9, 0.1], h0=-1, s0=-1, T0=-1, P0=-1)  
ierr_SETREF = SETREF_output.ierr
print(SETREF_output.herr)

yielding

10.0
0
[SETUP warning 26] Minimum temperature for component 2 is greater than boiling point temperature: Tmin = 216.592 K, Tnbp = 194.686 K; will use default: IIR

The last two systems are LLE-containing and REFPROP has a tough time with them. I wouldn't trust those models.

schreibfheler commented 2 months ago

How can you tell, the last two systems contain LLE?

For my study, it's not crucial that RP results/properties are "correct" for a given mixture and composition. As long as the mixtures behave like "some" real mixture that might exist in reality, that is ok. E.g. if the saturation curves were leaning more to the right in real life than what RP says, it doesn't matter for me. However if the saturation curves are complete non-sense and no real fluid in the world behaves like this, this would be a problem. Are there any ierr's that might indicate this distinction? -> ierr=-710 -> non-sense properties -> drop mixture from my study.

ianhbell commented 2 months ago

I just know, since I have been working with LLE a lot recently. REFPROP explicitly does not consider the possibility of LLE, so it is easy to be misled on that front, as I have learned much to my chagrin.

No, I am afraid not, this is a very tricky question. You need to look at experimental data to know, that is really the only way.

schreibfheler commented 2 months ago

I see. Thanks a lot for your help!

Regarding my initially stated issue: is it intended that e.g. -710 cannot be found anywhere in the documentation, and if so, why?

ianhbell commented 2 months ago

Because SETREF doesn't expect that sort of an error. My recommendation as always is to ignore reference states entirely. That is especially a mess for mixtures.

schreibfheler commented 2 months ago

Okay, thanks again!

schreibfheler commented 1 month ago

Because SETREF doesn't expect that sort of an error. My recommendation as always is to ignore reference states entirely. That is especially a mess for mixtures.

I'd like to clarify what you mean by "ignore reference states entirely." Are you suggesting that it's best not to change the reference state from DEF? In my project, I set it to NBP, but I've noticed that in 1-2% of cases, the resulting enthalpies are extremely high (hundreds of thousands to millions). This issue seems random, and when I check the mixture in the GUI, the enthalpies appear normal. Could this behavior be related to your recommendation?

ianhbell commented 1 month ago

Yes, in my work I never change the reference state. As the reference state is arbitrary, the easiest solution is to never change it, and ignore absolute values of enthalpy and entropy and always calculate them from the model from properties that do not include reference states, like temperature and density. An enthalpy of a quadrillion could be a totally reasonable value, based on what reference state you select. Hence, best to ignore them. It is an even bigger mess in the mixture case, and there I would even more strongly recommend to not worry about them.