usnistgov / REFPROP-wrappers

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

What to do when the Matlab fails to converge for mixture calculations? #511

Closed Alhabeeb86 closed 1 year ago

Alhabeeb86 commented 1 year ago

Hi, I'm linking Matlab with refprop, and for some cases I have this message:

''Error using refpropm (line 464) [SHFLSH error 248] single-phase iteration did not converge, T, deltaT = 0.18627E+12 0.15709E-02 K.''

Any suggestion to solve this issue ? Thanks

ianhbell commented 1 year ago

a) The refpropm interface is deprecated, please move to the python-based one. b) HS inputs are challenging, can you refactor into other kinds of inputs, ideally one that includes P, T, or D?

ianhbell commented 1 year ago

Also, need a runnable failing example

Alhabeeb86 commented 1 year ago

Thanks for your response, a) I didn't understand b) according to my model I just have enthalpy and entropy The example: P=refpropm('P','H',306.42641000,'S',1.38111000,'r1234yf');

ianhbell commented 1 year ago

a) https://github.com/usnistgov/REFPROP-wrappers/tree/master/wrappers/MATLAB b) what full version of REFPROP do you use?

Alhabeeb86 commented 1 year ago

a) Thanks, as I understand that I can continue use Matlab but with Python interface b) My REFPROP version is 9.1

ianhbell commented 1 year ago

HS inputs are tricky because you need to iterate on both temperature and density to match the given enthapy and entropy. They are the slowest and least reliable thermodynamic inputs. Often there is a way to restructure your problem to use PH, or PS inputs, for instance.

You should first try to upgrade to version 10.0, which has a lot of improvements to these routines.

Alhabeeb86 commented 1 year ago

Thanks for the comment. Unfortunately, I have no other option for inputs. So use Python's interface with Matlab doesn't solve the problem?

ianhbell commented 1 year ago

First try to upgrade to version 10, you need an improvement to flash calculations and this should hopefully help.

ianhbell commented 1 year ago

On my side, this:

import ctREFPROP.ctREFPROP as ct
import os
os.environ['RPPREFIX'] = os.getenv('HOME')+'/REFPROP10'
root = os.getenv('RPPREFIX')
RP = ct.REFPROPFunctionLibrary(root)
RP.SETPATHdll(root)
print(f'version: {RP.RPVersion()}')

z = [0, 0]
r1 = RP.REFPROPdll('R1234YF','HS','T',RP.MASS_BASE_SI,0,0,306.42641000e3,1.38111000e3,z)
print(r1.Output[0], r1.herr)

yields

version: 10.0
279.3272376575616

so the temperature works with version 10.0

ianhbell commented 1 year ago

In your case, the solution is to upgrade to version 10.0

Alhabeeb86 commented 1 year ago

Thanks a lot for your help, and I would like to say that I deleted the REFPROP and installed again (version 9.1) and it works.