Manually Generate Fluid Property Tables

Fluid Property Tables

Fluid property tables provide the basic inputs to the Two-Phase Fluid Properties (2P) block. If you have REFPROP software by the National Institute of Standards and Technology installed, you can automatically generate these tables using the twoPhaseFluidTables function. If you obtain the fluid properties from a different source, such as CoolProp software, you can still generate the tables using a MATLAB® script. This tutorial shows how to create a script to generate the fluid temperature tables.

The tables must provide the fluid properties at discrete pressures and normalized internal energies. The pressures must correspond to the table columns and the normalized internal energies to the table rows. Setting pressure and normalized internal energy as the independent variables enables you to specify the liquid and vapor phase property tables on separate rectangular grids using MATLAB matrices.

The figure shows two fluid property grids in pressure-specific internal energy space (left) and pressure-normalized internal energy space (right). If you obtain the fluid property tables on a pressure-specific internal energy grid, you must transform that grid into its pressure-normalized internal energy equivalent. In this tutorial, this transformation is handled by the MATLAB script that you create.

Steps for Generating Property Tables

The MATLAB script that you create in this tutorial performs the following tasks:

  • Define property table criteria, including dimensions and pressure-specific internal energy domain.

  • Create rectangular grids in pressure-normalized internal energy space.

  • Map the grids onto pressure-specific internal energy space.

  • Obtain the fluid properties on the pressure-specific internal energy grids.

Before Generating Property Tables

You must obtain fluid property data in pressure-specific internal energy space, e.g., through direct calculation, from a proprietary database, or from a third-party source. In this tutorial, you create four MATLAB functions to provide example property data. In a real application, you must replace these functions with equivalent functions written to access real property data.

Create Fluid Property Functions

Create the following MATLAB functions. These functions provide the example property data you use in this tutorial. Ensure that the function files are on the MATLAB path. Use the function names and code shown:

  • Name — liquidTemperature

    function T = liquidTemperature(u, p) 
    % Returns artificial temperature data as a function 
    % of specific internal energy and pressure.
    T = 300 + 0.2*u - 0.08*p;

  • Name — vaporTemperature

    function T = vaporTemperature(u, p)
    % Returns artificial temperature data as a function 
    % of specific internal energy and pressure.
    T = -1000 + 0.6*u + 5*p;
  • Name — saturatedLiquidInternalEnergy

    function u = saturatedLiquidInternalEnergy(p)
    % Returns artificial data for saturated liquid specific
    % internal energy as a function of pressure.
    u = sqrt(p)*400 + 150;
  • Name — saturatedVaporInternalEnergy

    function u = saturatedVaporInternalEnergy(p)
    % Returns artificial data for saturated vapor specific
    % internal energy as a function of pressure.
    u = -3*p.^2 + 40*p + 2500;

Set Property Table Criteria

Start a new MATLAB script. Save the script in the same folder as the MATLAB functions you created to generate the example fluid property data. In the script, define the criteria for the property tables. Do this by entering the following code for the table dimensions and pressure-specific internal energy valid ranges:

% Number of rows in the liquid property tables
mLiquid = 25;
% Number of rows in the vapor property tables
mVapor = 25;
% Number of columns in the liquid and vapor property tables
n = 60;

% Minimum specific internal energy, kJ/kg
uMin = 30;
% Maximum specific internal energy, kJ/kg
uMax = 4000;
% Minimum pressure, MPa
pMin = 0.01;
% Maximum pressure, MPa
pMax = 15;

% Store minimum and maximum values in structure fluidTables
fluidTables.uMin = uMin;
fluidTables.uMax = uMax;
fluidTables.pMin = pMin;
fluidTables.pMax = pMax;

Create Pressure-Normalized Internal Energy Grids

Define the pressure and normalized internal energy vectors for the grid. These vectors provide the discrete pressure and normalized internal energy values associated with each grid point. The pressure vector is logarithmically spaced due to the wide pressure range considered in this example. However, you can use any type of spacing that suits your data. In your MATLAB script, add this code:

% Pressure vector, logarithmically spaced
fluidTables.p = logspace(log10(pMin), log10(pMax), n);

% Normalized internal energy vectors, linearly spaced
fluidTables.liquid.unorm = linspace(-1, 0, mLiquid)';
fluidTables.vapor.unorm = linspace(1, 2, mVapor)';

Map Grids Onto Pressure-Specific Internal Energy Space

Obtain the saturated liquid and vapor specific internal energies as functions of pressure. The saturation internal energies enable you to map the normalized internal energy vectors into equivalent vectors in specific internal energy space. In your MATLAB script, add this code:

% Initialize the saturation internal energies of the liquid and vapor phases
fluidTables.liquid.u_sat = zeros(1, n);
fluidTables.vapor.u_sat = zeros(1, n);

% Obtain the saturation internal energies at the pressure vector values
for j = 1 : n
    fluidTables.liquid.u_sat(j) = saturatedLiquidInternalEnergy(fluidTables.p(j));
    fluidTables.vapor.u_sat(j) = saturatedVaporInternalEnergy(fluidTables.p(j));
end
This code calls two functions written to generate example data. Before using this code in a real application, you must replace the functions with equivalent expressions capable of accessing real data. The functions you must replace are:

  • saturatedLiquidInternalEnergy

  • saturatedVaporInternalEnergy

Map the normalized internal energy vectors onto equivalent specific internal energy vectors. In your MATLAB script, add this code:

% Map pressure-specific internal energy grid onto
% pressure-normalized internal energy space
fluidTables.liquid.u = (fluidTables.liquid.unorm + 1)*...
(fluidTables.liquid.u_sat - uMin) + uMin;
fluidTables.vapor.u = (fluidTables.vapor.unorm - 2)*...
(uMax - fluidTables.vapor.u_sat) + uMax;

Obtain Fluid Properties at Grid Points

You can now obtain the fluid properties at each grid point. The following code shows how to generate the temperature tables for the liquid and vapor phases. Use a similar approach to generate the remaining fluid property tables. In your MATLAB script, add this code:

% Obtain temperature tables for the liquid and vapor phases
for j = 1 : n
     for i = 1 : mLiquid
        fluidTables.liquid.T(i,j) = ...
liquidTemperature(fluidTables.liquid.u(i,j), fluidTables.p(j));
    end
    for i = 1 : mVapor
        fluidTables.vapor.T(i,j) = ...
vaporTemperature(fluidTables.vapor.u(i,j), fluidTables.p(j));
    end
end

This code calls two functions written to generate example data. Before using this code in a real application, you must replace the functions with equivalent expressions capable of accessing real data. The functions you must replace are:

  • liquidTemperature

  • vaporTemperature

To view the temperature tables generated, first run the script. Then, at the MATLAB command prompt, enter fluidTables. MATLAB lists the contents of the fluidTables structure array.

fluidTables =

      uMin: 30
      uMax: 4000
      pMin: 0.0100
      pMax: 15
         p: [1x20 double]
    liquid: [1x1 struct]
     vapor: [1x1 struct]

To list the property tables stored in the liquidsubstructure, at the MATLAB command prompt enter fluidTables.liquid.

  305.9992  305.9988  305.9983  305.9975  ...
  309.5548  309.7430  309.9711  310.2475  ...
  313.1103  313.4872  313.9440  314.4976  ...
  316.6659  317.2314  317.9169  318.747  ...
  ...       

Visualize Grids

To visualize the original grid in pressure-normalized internal energy space, at the MATLAB command prompt enter this code:

% Define p and unorm matrices with the grid
% point coordinates
pLiquid = repmat(fluidTables.p, mLiquid, 1);
pVapor = repmat(fluidTables.p, mVapor, 1);

unormLiquid = repmat(fluidTables.liquid.unorm, 1, n);
unormVapor = repmat(fluidTables.vapor.unorm, 1, n);

% Plot grid
figure;
hold on;

plot(unormLiquid, pLiquid, 'b.');
plot(unormVapor, pVapor, 'b.');

plot(zeros(1, n), fluidTables.p, 'k-');
plot(ones(1, n), fluidTables.p, 'k-');

hold off;
set(gca, 'yscale', 'log');
xlabel('Normalized Internal Energy');
ylabel('Pressure');
title('Grid in Normalized Internal Energy');

A figure opens with the pressure-normalized internal energy grid.

To visualize the transformed grid in pressure-specific internal energy space, at the MATLAB command prompt enter this code:

% Define horizontal and vertical axes

% Plot grid
figure;
hold on;

plot(fluidTables.liquid.u, pLiquid, 'b.');
plot(fluidTables.vapor.u, pVapor, 'b.');

plot(fluidtables.liquid.u_sat, fluidTables.p, 'k-');
plot(fluidtables.vapor.u_sat, fluidTables.p, 'k-');

hold off;
set(gca, 'yscale', 'log');
xlabel('Specific Internal Energy');
ylabel('Pressure');
title('Grid in Specific Internal Energy'); 

A figure opens with the pressure-specific internal energy grid.