usnistgov / REFPROP-wrappers

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

How to correctly find thermal conductivity, surface tension and heat of vaporization in MatLAB #178

Closed Yili-Zhang closed 5 years ago

Yili-Zhang commented 5 years ago

Hi,

I could never get a correct result with the thermal conductivity function, surface tension function and the heat of vaporization (pure fluid) function with MatLAB. Here are the codes I applied:

%% Thermal Conductivity
K=RP.REFPROPdll('Ethonal','T','TCX',MASS_SI,int8(0),int8(0),300,NaN,{1.0});
K_num=double(K.Output);
k_t=K_num(1);

%% Surface Tension
SIG=RP.REFPROPdll('Water','T','STN',MASS_SI,int8(0),int8(0),T_inter2,NaN,{1.0});
SIG_num=double(SIG.Output);
sigma_I=SIG_num(1);

%% Heat of vaporization
I_FG=RP.REFPROPdll('Water','T','HEATVAPZ',MASS_SI,int8(0),int8(0),T_sat,NaN,{1.0});
I_FG_num=double(I_FG.Output);
i_fg=I_FG_num(1);

And here are the results:

k_t =

    -9999990

sigma_I =

    -9999990

i_fg =

    -9999990

May I know where is wrong with the code? Thanks!

-Yili

ianhbell commented 5 years ago

The core issue is a very subtle one: the properties that are coming from phase equilibrium calculations require you to specify a vapor fraction, even if in the end it doesn't matter. For heat of vaporization and surface tension, any value from 0 to 1 would do, because it only matters that you are at equilibrium. For thermal conductivity, the vapor quality DOES matter because that could be either the saturated vapor or saturated liquid thermal conductivity.

So your first call would read (for instance):

Q = 1;
RP.REFPROPdll('Ethanol','TQ','TCX',MASS_SI,int8(0),int8(0),300,Q,{1.0});

Additional comments: 1) Ethanol is mis-spelled 2) You should 100% of the time check the ierr error code coming from a call to REFPROPdll. The herr string provides sometimes useful error message. 3) The unit system should not be hard-coded, the enumerated value should be obtained from a call to GETENUMdll. E.g.: RP.GETENUMdll(int8(0), "DEFAULT").iEnum

Yili-Zhang commented 5 years ago

Hi,

Thanks for your instructions. It helped a lot. After added the Quality features, both surface tension and the heat of vaporization worked:

>> I_FG=RP.REFPROPdll('Ethanol','TQ','HEATVAPZ',MASS_SI,int8(0),int8(0),500,1,{1.0});
I_FG_num=double(I_FG.Output);
i_fg=I_FG_num(1)

i_fg =

  346.1581
>> SIG=RP.REFPROPdll('Ethanol','TQ','STN',MASS_SI,int8(0),int8(0),500,1,{1.0});
SIG_num=double(SIG.Output);
sigma_I=SIG_num(1)

sigma_I =

    1.5185

However, for the thermal conductivity, I wonder if the quality is really necessary, for the combination of temperature and pressure also works:

>> K=RP.REFPROPdll('Water','TP','TCX',MASS_SI,int8(0),int8(0),300,12.8,{1.0});
K_num=double(K.Output);
k_H=K_num(1)

k_H =

  616.4826

In the additional commends, I have a few questions:

  1. What is the exact code (full code ready to be executed) to check on errors?
  2. Before running every program, I would use those two lines to set up the refprop as well as its unit system:
    RP = py.ctREFPROP.ctREFPROP.REFPROPFunctionLibrary('C:\Program Files (x86)\REFPROP');
    MASS_SI=RP.GETENUMdll(int8(0), "MASS SI").iEnum;

    And the unit system has been working fine so far. For the code you proposed, my I know how exactly I could incorporate into (or replace) the current setup?

Thanks a lot!

-Yili

ianhbell commented 5 years ago
  1. Indeed, TP will work if you have a homogeneous state (subcooled liquid, superheated gas, etc.). TQ would also work if you want saturated liquid (Q=0) or saturated vapor (Q=1)
  2. One example might be
    if RP.ierr > 100
    error(RP.herr)
    end
  3. Sorry, that's my mistake, got my eyes crossed. You're doing things exactly correctly.
Yili-Zhang commented 5 years ago

Hi,

Thanks for the reply. Actually I'm using Ethanol's thermal conductivity under its two-phase conditions (0<Q<1). In this case, may I still use TP to find K, or I have to use TQ (or PQ)?

Thanks,

-Yili

ianhbell commented 5 years ago

The thermal conductivity of a two-phase mixture for a pure fluid is not defined. There are two possible values, one for the saturated liquid, another for the saturated liquid, and a no-mans-land in between. Besides, for a pure fluid, TP can NEVER be used to specify the state for a pure fluid for 0 < Q < 1. See https://github.com/usnistgov/REFPROP-issues/issues/82

Yili-Zhang commented 5 years ago

I see. Thanks for your help.