Problem with two phase Fluid Tables properties for mixtures for Simscape Matlab using CoolProp

14 views (last 30 days)
Hi,
I need to generate Fluid Tables properties for a two-phase mixture in Matlab using CoolProp. Next I want to implement the properties into Simscape.
There is a function:
fluidTables = twoPhaseFluidTables(uRange,pRange,mLiquid,mVapor,n,substance,installPath)
Unfortunately I don't know how to make it work for the mixture of two different fluids.
Could I ask for some advice?
  2 Comments
Yifeng Tang
Yifeng Tang on 9 Apr 2025
Following the steps on this MATLAB Answer post: https://www.mathworks.com/matlabcentral/answers/2006947-binary-mixtures-using-coolprop-in-matlab?s_tid=srchtitle, you may define a mixture in CoolProp:
try
py.CoolProp.CoolProp.apply_simple_mixing_rule('R1234yf','R32','linear')
catch
%
end
py.CoolProp.CoolProp.PropsSI('HMASS','T',300,'P',101325,'R1234yf[0.8]&R32[0.2]')
Then I was hoping to use the twoPhaseFluidTables command to get the property table, but running into error.
installPath = 'py.CoolProp.CoolProp.PropsSI';
fluidTables = twoPhaseFluidTables([200 400],[0.5 1],50,50,100,'R1234yf[0.8]&R32[0.2]',installPath)
It gave me error message that CoolProp can't get saturation properties.
CoolProp failed to return fluid properties at P = 0.5 MPa, Q = 0.
saturationProperties = @(p, q) coolpropSaturationProperties(p, q, substance, coolpropFun);
= saturationProperties(p(j), 0);
Caused by:
Python Error: ValueError: Conformal state solver failed; error was Not able to get a solution : PropsSI("L","P",500000,"Q",0,"R1234yf[0.8]&R32[0.2]")
The error message seems to suggest it's an issue with CoolProp or this mixture I picked.
What mixture you have in mind? Maybe we can give that a try?
Adam
Adam on 10 Apr 2025
Thank you for your answer.
The mixture I need is: Isopentane - n-Butane 50:50
I followed similar steps as you:
% Import the CoolProp library
CP = py.importlib.import_module('CoolProp.CoolProp');
% Apply a simple linear mixing rule for the n-Butane and Isopentane pair
CP.apply_simple_mixing_rule('n-Butane', 'Isopentane', 'linear');
% Define the mixture of n-butane and isopentane in a 50:50 molar ratio
mixture = 'n-Butane[0.5]&Isopentane[0.5]';
% Get Fluid Tables
FluidTables = twoPhaseFluidTables([118,550],[0.050,10],25,25,60,'n-Butane[0.5]&Isopentane[0.5]','py.CoolProp.CoolProp.PropsSI')
I got error:
Error using CoolProp/CoolProp.__Props_err2 (line 358)
Python Error: ValueError: critical point finding routine found 2 critical points :
PropsSI("PCRIT","P",0,"T",0,"n-Butane[0.5]&Isopentane[0.5]")
Error in CoolProp/CoolProp.PropsSI (line 471)
Error in CoolProp/CoolProp.PropsSI (line 391)
Error in twoPhaseFluidTables>@()coolpropCriticalTriplePressure(substance,coolpropFun) (line 772)
criticalTriplePressure = @() coolpropCriticalTriplePressure(substance, coolpropFun);
Error in twoPhaseFluidTables (line 100)
[p_crit, u_crit, p_triple] = criticalTriplePressure();
Error in VCS_Comp_teststand_001_001_Config002_testFluidProperties (line 212)
FluidTables = twoPhaseFluidTables([118,550],[0.050,10],25,25,60,'n-Butane[0.5]&Isopentane[0.5]','py.CoolProp.CoolProp.PropsSI')
Do you think this can be fixed? And then generate Fluid Tables and import them into Simscape?

Sign in to comment.

Answers (1)

Yifeng Tang
Yifeng Tang on 10 Apr 2025
Hi Adam,
I think there is path forward, but it'll require some work.
The error message you and I saw was generated by the fact that CoolProp is unable to determine the critical point of this mixture. If I try to find the critical point manually using the wrapper function, I'll get a similar error
try
py.CoolProp.CoolProp.apply_simple_mixing_rule('n-Butane','Isopentane','linear');
catch
%
end
mixture = 'n-Butane[0.5]&Isopentane[0.5]';
py.CoolProp.CoolProp.PropsSI("PCRIT",'T',300,'P',101325,fluid)
Python Error: ValueError: critical point finding routine found 2 critical points : PropsSI("PCRIT","T",300,"P",101325,"n-Butane[0.5]&Isopentane[0.5]")
I can also attempt to query the internal energy at quality of 0 or 1 for different pressure, searching for the critical point, but found that the saturation line can't be computed beyond 10.1MPa for saturated liq or 3.5MPa for saturated vapor. Critical point of course needs these two pressure values to be the same :( You may try to slightly increase the pressure value in the code below and observe the error message.
py.CoolProp.CoolProp.PropsSI('UMASS','Q',0,'P',1.01e7,mixture)
py.CoolProp.CoolProp.PropsSI('UMASS','Q',1,'P',0.35e7,mixture)
As the twoPhaseFluidTables function attempts to locate the critical point, I don't see how this error can be by-passed, UNLESS we do this manually and stay below the critical point.
If your operation pressure is expected to be below 3.5MPa, I think we can generate this table manually by writing a few loops and call the wrapper function many times. 3.5MPa seems to indicate a saturation temperature around 440K. So maybe it's good enough?
py.CoolProp.CoolProp.PropsSI('T','Q',0,'P',0.35e7,mixture) % output: 440.8012
py.CoolProp.CoolProp.PropsSI('T','Q',1,'P',0.35e7,mixture) % output: 442.2485
If so, please refer to this documentation page (Manually Generate Fluid Property Tables) on how to populate this property table manually, as well we this documentation page (Two-Phase Fluid Properties (2P)) on more details of the "normalized internal energy" needed to define the table.
If you need additional assistance, please reach out to MathWorks Support or your MathWorks account team, and mention this MATLAB Answer post.

Categories

Find more on Two-Phase Fluid Library in Help Center and File Exchange

Tags

Products


Release

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!