usnistgov / REFPROP-wrappers

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

Mixture Not Working in Matlab #268

Closed depcik closed 4 years ago

depcik commented 4 years ago

Description

I have been using REFPROP 10 well with single fluids, however it is not working with a mixture

Steps to Reproduce

Code

clear all;
RP = py.ctREFPROP.ctREFPROP.REFPROPFunctionLibrary('C:\Program Files (x86)\REFPROP10');
MOLSI = RP.GETENUMdll(int8(0), 'MOLAR BASE SI').iEnum;
MASSI = RP.GETENUMdll(int8(0), 'MASS BASE SI').iEnum;
iMass = int8(0);                            % 0: molar fractions; 1: mass fractions
iFlag = int8(0);                            % 0: don't call SATSPLN; 1: call SATSPLN
ierr = int8(0);
z = {1.0};                                  % Composition
% Set the flags for the desired behavior of the program
r = RP.FLAGSdll('Bounds', int8(1));
WF = 'R502.MIX';
% Properties
p1 = 1.5168e+05;    % Pressure at State 1: Pa
x1 = 1;             % Saturated vapor at State 1
% Get the enthalpy given the quality
r = RP.REFPROPdll(WF, 'PQ', 'H', MOLSI, iMass, iFlag, p1, x1, z);       % Specify the pressure and quality
o = double(r.Output);
h1 = o(1);      % [J/kg]
% In REFPROP for R502 - the enthalpy would be 326.16 kJ/kg at this pressure
r = RP.REFPROPdll(WF, 'PQ', 'T', MOLSI, iMass, iFlag, p1, x1, z);
o = double(r.Output);
T1 = o(1);      % [K]
% The temperature should be 236.89 K (get -9999990)
r = RP.REFPROPdll(WF, 'PQ', 'S', MOLSI, iMass, iFlag, p1, x1, z);
o = double(r.Output);
s1 = o(1);      % [J/kgK]
% And the entropy should be 1.5458 kJ/kgK

Behavior: I expect to get a value of 326.16 kJ/kg at that pressure, but I end up getting -9999990. Same thing with temperature (should be 236.89 K) and entropy (should be 1.5458 kJ/kgK)

Versions

REFPROP Version: 10 Operating System and Version:
Microsoft Windows 10 Access Method:
Python in Matlab

Additional Information

If possible, please post examples and/or screenshots of the issue.

ianhbell commented 4 years ago

Some comments:

ianhbell commented 4 years ago

Also:

depcik commented 4 years ago

OK, I have now been able to get values for h1, T1, and s1, but they are not correct. If you look at REFPROP10 for R-502 at a saturation pressure of 1.5168e+05 Pa (0.15168 MPa) you get: image

My code now is:

WF = 'R502.MIX';
sm = RP.SETMIXdll(WF, 'HMX.BNC', 'DEF');        % See SETUPdll for specifics
% Properties
p1 = 1.5168e+05;    % Pressure at State 1: Pa
x1 = 1;             % Saturated vapor at State 1
% Get the enthalpy given the quality
r = RP.REFPROPdll('', 'PQ', 'H', MASSI, iMass, iFlag, p1, x1, sm.z);       % Specify the pressure and quality
o = double(r.Output);
h1 = o(1);      % [J/kg]

That gives me an enthalpy value of 3.3779e+05 J/kg or 337.79 kJ/kg which is different than the REFPROP value of 326.16 kJ/kg. The temperature and entropy provide different values too.

ianhbell commented 4 years ago

So then it comes to reference states. Try changing the reference state in the GUI; with the appropriate selection the DLL and the GUI should agree (the default reference states in the GUI and the DLL are different, a historical decision that we have been forced to live with into the present).

depcik commented 4 years ago

If you look at the image I uploaded, it indicates that: "Ref. State: Default" which is what I am running with SETMIXdll. I just tried the other reference states in the GUI and I get different answers than Matlab.

depcik commented 4 years ago

Wait. If I apply the reference state to "Each pure component" in the GUI, then it looks like I get the same answers between the GUI and Matlab.

ianhbell commented 4 years ago

Right, I was about to type that response to you.

depcik commented 4 years ago

OK, it seems like I am good to go at this point. Thanks!

ianhbell commented 4 years ago

Yes, I am hoping we can get some docs together on the reference states, and precisely how they operate, as it is a mystery to me still.

ianhbell commented 4 years ago

But glad to hear you are resolved for now.