Error using CoolProp with MATLAB

1,199 views
Skip to first unread message

Tom Egel

unread,
Oct 27, 2015, 1:04:22 PM10/27/15
to coolprop-users
I'm having mixed success running CoolProp from MATLAB here are some examples:
  1. Runs with no errors:

    CoolProp.PropsSI('DMASS', 'T', T, 'P', p/1000, 'INCOMP::MEG-50%')

    CoolProp.PropsSI('UMASS','T',T,'P',p/1000, 'INCOMP::MEG-50%)

    CoolProp.PropsSI('VISCOSITY','T',T,'P',p/1000, 'INCOMP::MEG-50%')

  2. Generates errors:

    CoolProp.PropsSI('ISOTHERMAL_COMPRESSIBILITY','T',T,'P',p/1000, 'INCOMP::MEG-50%')

    CoolProp.PropsSI('ISOBARIC_EXPANSION_COEFFICIENT','T',T,'P',p/1000, 'INCOMP::MEG-50%')

Error messages:
Warning: calc_rhomolar_reducing is not implemented for this backend
Error using CoolPropMATLAB_wrap
Fatal error.
Error in CoolProp.PropsSI (line 2)
  [varargout{1:max(1,nargout)}] = CoolPropMATLAB_wrap(246,varargin{:});


I've used REFPROP in the past, but this is the first attempt with CoolProp.  Ethylene-Glycol mix does not exist in REFPROP, hoping CoolProp could help

Any idea what could be happening?

Thanks,
Tom

 

Ian Bell

unread,
Oct 27, 2015, 1:46:32 PM10/27/15
to Tom Egel, coolprop-users

Tom,

Hopefully Jorrit can chime in here, but those outputs are not defined for incompressible fluids, and I believe they cannot be defined for incompressible fluids.  For "normal" fluids like propane, that should work fine.  Did you try that first?

Ian

--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-user...@googlegroups.com.
To post to this group, send email to coolpro...@googlegroups.com.
Visit this group at http://groups.google.com/group/coolprop-users.
For more options, visit https://groups.google.com/d/optout.

Tom Egel

unread,
Oct 27, 2015, 2:06:47 PM10/27/15
to coolprop-users, tom....@gmail.com
Thanks for the clarification.  I also found a page that confirms this: http://www.coolprop.org/fluid_properties/Incompressibles.html. "A call to the top-level function PropsSI can provide: temperature, pressure, density, heat capacity, internal energy, enthalpy, entropy, viscosity and thermal conductivity. Hence, the available output keys are: T, P, D, C, U, H, S, V, L, Tmin and Tmax." 

Thanks for your help.

Vittorio Carosella

unread,
Oct 27, 2015, 3:20:45 PM10/27/15
to coolprop-users
Hi Tom
I had a similar problem for the calculation of Grashof number for natural convection.
I have calculated the coefficient of isobaric expansion as follows:

T = 273.15 + 20
p = 101325
DT=1
Density1 = PropsSI('D','T',T-DT,'P',p, 'INCOMP::MEG-50%')
Density2 = PropsSI('D','T',T+DT,'P',p, 'INCOMP::MEG-50%')
Volume1=1/Density1
Volume2=1/Density2
VolumeAverage = (Volume1 + Volume2) / 2
ISOBARIC_EXPANSION_COEFFICIENT =(Volume2 - Volume1)/((2 * DT) * VolumeAverage)
The result for this example is: 0.000499860618376 1/K

For the isothermal, a similar method is also valid.
Hope this can be usefull
Regards

Jorrit Wronski

unread,
Oct 28, 2015, 5:17:47 AM10/28/15
to coolprop-users

 

Hi

 

The isothermal expansion coefficient is defined as “1/v * (dv/dT)|p”, which then can be converted to “-1/rho * (drho/dT)|p”. The latter is indeed defined in CoolProp, see the following example in Python:

 

import CoolProp.CoolProp as CP

rho = CP.PropsSI('D','T',273.15+25,'P',10e5,'INCOMP::MEG-50%')

drhodT = CP.PropsSI('d(Dmass)/d(T)|P','T',273.15+25,'P',10e5,'INCOMP::MEG-50%')

print(-1.0/rho * drhodT)

0.000521758207783

 

There are a few partial derivatives defined for incompressible fluids, but not all of them. They have not gotten all the love the deserve and the implementation is a little patchy, but the following functions should be available: drhodTatPx, dsdTatPx, dhdTatPx, dsdTatPxdT , dhdTatPxdT, dsdpatTx, dhdpatTx. Note that all partial derivatives require a constant concentration, which is denoted by the “x”, but this “x” is not included in the derivative string: “drhodTatPx” translates to “d(Dmass)/d(T)|P”

 

Regards,

Jorrit

--

Tom Egel

unread,
Oct 29, 2015, 11:43:04 AM10/29/15
to coolprop-users
Thanks Vittorio.  I'll give this a try.

--Tom

Tom Egel

unread,
Oct 29, 2015, 11:46:45 AM10/29/15
to coolprop-users, jo...@ipu.dk
Hi Jorrit,
I tried your code, but still get the same error.  Here's the ML transcript:

rho = CoolProp.PropsSI('D','T',273.15+25,'P',10e5,'INCOMP::MEG-50%')

rho =

   1.0622e+03
 
>> drhodT = CoolProp.PropsSI('d(Dmass)/d(T)|P','T',273.15+25,'P',10e5,'INCOMP::MEG-50%')
Warning: calc_rhomolar_reducing is not implemented for this backend 
Error using CoolPropMATLAB_wrap
Fatal error.

Error in CoolProp.PropsSI (line 2)
  [varargout{1:max(1,nargout)}] = CoolPropMATLAB_wrap(246,varargin{:});


Any ideas what might be happening?

Thanks,
Tom

To post to this group, send email to coolpr...@googlegroups.com.

Ian Bell

unread,
Oct 29, 2015, 11:48:20 AM10/29/15
to Tom Egel, coolprop-users, Jorrit Wronski
Tom,

What version of CoolProp do you use?

Ian

To post to this group, send email to coolpro...@googlegroups.com.

Tom Egel

unread,
Oct 29, 2015, 1:25:41 PM10/29/15
to coolprop-users, tom....@gmail.com, jo...@ipu.dk
Hi Ian,
I believe the version is 5.1.1 since I downloaded from this page: http://sourceforge.net/projects/coolprop/files/CoolProp/5.1.1/MATLAB/ 

Is there a command I can run to get the version?

Thanks,
Tom

Ian Bell

unread,
Oct 29, 2015, 1:30:33 PM10/29/15
to Tom Egel, coolprop-users, Jorrit Wronski
Right then, that would be 5.1.1, see this example for MATLAB that shows how to get the version: http://www.coolprop.org/coolprop/wrappers/MATLAB/index.html#example-code

Ian Bell

unread,
Oct 29, 2015, 1:31:11 PM10/29/15
to Tom Egel, coolprop-users, Jorrit Wronski
Perhaps you want to try the development version of CoolProp: http://www.coolprop.org/coolprop/wrappers/MATLAB/index.html#pre-compiled-binaries

Tom Egel

unread,
Nov 2, 2015, 11:38:04 AM11/2/15
to coolprop-users, tom....@gmail.com, jo...@ipu.dk
Hi Ian,
I'm getting the following errors with the Dev version:
>> CoolProp.get_global_param_string('version')
ans =
5.1.2dev

>> CoolProp.PropsSI('ISOTHERMAL_COMPRESSIBILITY','T',273.15 + 20,'P',101325, 'INCOMP::MEG-50%')
Warning: Incompressible fluids only support a limited subset of partial derivatives. 
Error using CoolPropMATLAB_wrap
Fatal error.

Error in CoolProp.PropsSI (line 2)
  [varargout{1:max(1,nargout)}] = CoolPropMATLAB_wrap(262,varargin{:});


I assume this is due to the incompressible fluid?

--Tom

Jorrit Wronski

unread,
Nov 2, 2015, 12:38:38 PM11/2/15
to Tom Egel, coolprop-users

Dear Tom,

 

Please have a look at my older email. Internally, incomrpessibles are not treated like the other fluids. In particular, they do not provide the exact same functionality.

 

You can use these steps to get the compressibility though:

import CoolProp.CoolProp as CP

rho = CP.PropsSI('D','T',273.15+25,'P',10e5,'INCOMP::MEG-50%')

drhodT = CP.PropsSI('d(Dmass)/d(T)|P','T',273.15+25,'P',10e5,'INCOMP::MEG-50%')

print(-1.0/rho * drhodT)

0.000521758207783

.. and the following functions should be available: drhodTatPx, dsdTatPx, dhdTatPx, dsdTatPxdT , dhdTatPxdT, dsdpatTx, dhdpatTx. Note that all partial derivatives require a constant concentration, which is denoted by the “x”, but this “x” is not included in the derivative string: “drhodTatPx” translates to “d(Dmass)/d(T)|P”

Tom Egel

unread,
Nov 2, 2015, 2:24:28 PM11/2/15
to coolprop-users, tom....@gmail.com, jo...@ipu.dk
Thanks Jorrit.  I was able to get that to work as well.

There seems to be an upper limit to the temperature range. If I go beyond 373.15K, I get the following errors:
Warning: Your temperature 374.150000 is not between 173.150000 and 373.150000.
Error using CoolPropMATLAB_wrap
Fatal error.

Error in CoolProp.PropsSI (line 2)
  [varargout{1:max(1,nargout)}] = CoolPropMATLAB_wrap(246,varargin{:});

Error in CoolProp_2D (line 44)
            propout(iRow, jCol) = CoolProp.PropsSI(PROPERTY, PARAMETER1, ...

Is this correct?

Thanks,
Tom

Ian Bell

unread,
Nov 2, 2015, 2:56:54 PM11/2/15
to Tom Egel, Jorrit Wronski, coolpro...@googlegroups.com

Jorrit,

Could you add a few small notes about derivatives in the docs?  Would be useful for folks.

Ian

Tom Egel

unread,
Nov 4, 2015, 12:59:35 PM11/4/15
to coolprop-users, tom....@gmail.com, jo...@ipu.dk
Thanks for everyone's help on this.  I was able to get a MATLAB script working using the partial derivative functions from Jorrit.  I did have to use the dev version to get this to work.  v5.1.1 gave an error.

Here are the key lines:
Fluid = 'INCOMP::MEG-35%';
T = 273; % Temperature [K]
p = 10e5; % Pressure [Pa]
rho=CoolProp.PropsSI('DMASS', 'T', T, 'P', p, Fluid);
drhodT = CoolProp.PropsSI('d(Dmass)/d(T)|P','T',T,'P',p,Fluid);
alpha = -1./F.rho .* drhodT; % Isobaric Expansion Coefficient [1/K]
drhodP = CoolProp_2D('d(Dmass)/d(P)|P','T',T,'P',p,Fluid);
F.kappa = 1./F.rho .* drhodP; % Isothermal Compressibility [1/Pa]
F.beta = 1./F.kappa; % Bulk Modulus [Pa]

For the incompressible fluids, CP returned 0 for Isothermal Compressibilty which makes sense.  Bulk modulus then becomes inf.

I appreciate the prompt response in helping out a newbie like me. 

Thanks,
Tom

Ian Bell

unread,
Nov 5, 2015, 6:54:53 AM11/5/15
to Tom Egel, Jorrit Wronski, coolpro...@googlegroups.com

Jorrit is going to update the docs, but I am quite surprised that 'd(Dmass)/d(P)|P' didn't throw an error.  The second P should be a T.  It would be nice in general if you provided complete examples rather than a selection of lines.

Jorrit, could we also consider to actually implement the desired functions, overriding the base class functions for the isobaric expansion coefficient for instance?

Tom Egel

unread,
Nov 12, 2015, 12:24:18 PM11/12/15
to coolprop-users, tom....@gmail.com, jo...@ipu.dk
Sorry about that. Typo on my part.  Here is the corrected code:
Fluid = 'INCOMP::MEG-35%';
T = 273; % Temperature [K]
p = 10e5; % Pressure [Pa]
rho=CoolProp.PropsSI('DMASS', 'T', T, 'P', p, Fluid);
drhodT = CoolProp.PropsSI('d(Dmass)/d(T)|P','T',T,'P',p,Fluid);
alpha = -1./F.rho .* drhodT; % Isobaric Expansion Coefficient [1/K]
drhodP = CoolProp.PropsSI('d(Dmass)/d(P)|T','T',T,'P',p,Fluid);
F.kappa = 1./F.rho .* drhodP; % Isothermal Compressibility [1/Pa]
F.beta = 1./F.kappa; % Bulk Modulus [Pa]

The CoolProp_2D function in my previous post is a MATLAB function I wrote to create 2D lookup tables of the CoolProp properties using arrays of temperature and pressure as inputs.  This function calls CoopProp.PropsSI in a nested FOR loop (T,P) to build the tables. These tables are then used to define the fluid properties in a Simulink/Simscape simulation model of a cooling system.  I'll post the model to the MATLAB Central File Exchange when completed and add a link here.  Thanks for the great support!

--Tom 

jmse...@aol.com

unread,
Nov 30, 2017, 3:27:30 AM11/30/17
to coolprop-users
Hi,

I am trying to find isobaric expansion and isothermal expansion coefficients for a range of MEG/freshwater mixtures at a range of temperatures and pressures.

Whilst searcing the internet extensively this is the closest I have come to success.

I have neither Mathlab or CoolProp and don't have the spare funds to purchase this software.

Can anybody help me with this, either by pointing me in the direction of some freeware or by sending me something that they have allready modelled?

Or even perhaps model this for me and I will reimburse for the time,

Many Thanks

Matthis Thorade

unread,
Nov 30, 2017, 3:58:40 AM11/30/17
to coolprop-users
Hi,
instead of hijacking an old thread, you should better open a new one!
If you prefer to use opensource software (whatever your reason), then Python plus CoolProp seem to be a good choice. Both are free of charge, and opensource (free as in speech).
You can get a first impression of what CoolProp can do on their homepage:
http://www.coolprop.org/
or on the github developer page:
https://github.com/CoolProp/CoolProp
If that looks interesting, you should install Python, either from python.org or the Anaconda distribution.
The fluid you mentioned seems to be implemented in the incormpressibles package:
http://www.coolprop.org/fluid_properties/Incompressibles.html#the-different-fluids
If you get stuck installing or using these, you can of course ask another question, but better do it in a new thread dedicated to that topic.
Best regards,
Matthis

jmse...@aol.com

unread,
Nov 30, 2017, 4:37:41 AM11/30/17
to coolprop-users
OK many thanks will try what you suggest
Reply all
Reply to author
Forward
0 new messages