You can create saturation tables for pure fluids, binary, and multi-species mixtures. Fluent provides the following functions that you can use in UDFs to compute saturation properties for the bubble and dew points for a single species or multiple-species:
When using a single-species NIST real gas model, Fluent provides a function that you can use in your UDFs to obtain saturation properties for the bubble and dew points. You can specify either temperature or pressure and the function will return an array containing the pressures or temperatures, respectively, and the liquid and vapor phase densities.
void getsatvalues_NIST(int index, double x, double y[]);
| where: | |
index = 0 if x is a specified temperature | |
= 1 if x is a specified pressure | |
x = temperature or pressure (according to value of index) at which to obtain saturation properties | |
y[] = array of saturation properties |
The values returned in y[] depend on the choice of index.
| Array elements |
index=0
|
index=1
| |
|---|---|---|---|
| Bubble Point |
y[0]
| pressure (Pa) | temperature (K) |
y[1]
| density of liquid (kg/m3) | density of liquid (kg/m3) | |
| Dew Point |
y[2]
| pressure (Pa) | temperature (K) |
y[3]
| density of vapor (kg/m3) | density of vapor (kg/m3) |
This function can be used regardless of whether you have enabled the lookup table.
int getsatvalues_NIST_msp (int index, double x, double y[], int ibubbleordew)
This function is similar to the single-species function, getsatvalues_NIST, but it applies to multi-species. For a given temperature or pressure you can obtain the corresponding pressure or temperature and the liquid and vapor phase densities.
In the function, index, x, and ibubbleordew are inputs. If the index=0, the input for x is temperature and if the index=1, the input for x is pressure. If ibubbleordew=0, Fluent returns bubble point properties, otherwise it returns dew point properties. y[] is an array of saturation properties.
The function returns an integer indicating the number of interpolation points for a given temperature and pressure:
0—no interpolation points, which could indicate that the given temperature and pressure is outside of the saturation curve range.
1—interpolation point with a bubble or dew curve.
2—interpolation points in the retrograde region of the saturation curves.
When index = 0:
| Bubble Point | Dew Point | |
|---|---|---|
| Function Returns 1 | ||
y[0] | Pressure | Pressure |
y[1] | Density (liquid) | Density (vapor) |
| Function Returns 2 | ||
y[0] | Pressure | Pressure |
y[1] | Density (liquid) | Density (vapor) |
y[2] | Pressure | Pressure |
y[3] | Density (liquid) | Density (vapor) |
When index = 1:
| Bubble Point | Dew Point | |
|---|---|---|
| Function Returns 1 | ||
y[0] | Temperature | Temperature |
y[1] | Density (liquid) | Density (vapor) |
| Function Returns 2 | ||
y[0] | Temperature | Temperature |
y[1] | Density (liquid) | Density (vapor) |
y[2] | Temperature | Temperature |
y[3] | Density (liquid) | Density (vapor) |
void get_satprop_NIST_msp (index, z, minrho, maxrho, nsat, npts, p_bub, t_bub, p_dew, t_dew);
The 2nd function for multi-species can be used to generate a saturation table for variable compositions.
Inputs:
|
Argument |
Description |
|---|---|
|
|
0: composition in mass fractions >0: composition in mole fractions |
|
|
real array—composition of fluid (ensure sum=1) |
|
|
minimum density in moles per liter (0.1 is a reasonable default for most cases) |
|
|
maximum density in moles per liter (25 is a reasonable default for most cases) |
|
|
number of points in bubble/dew curves (minimum is 12) |
Outputs:
|
Argument |
Description |
|---|---|
|
|
actual number of bubble curve points returned by the function |
|
|
actual number of dew curve points returned by the function |
|
|
a pressure array of the bubble point curve returned by the function |
|
|
a temperature array of the bubble point curve returned by the function |
|
|
a pressure array of the dew point curve returned by the function |
|
|
a temperature array of the dew point curve returned by the function |
This function computes saturation data for the given composition in z. This could be a binary mixture, three species, or more.
To use get_satprop_NIST_msp in a UDF:
Start a Fluent session as normal.
Enter the text command define/user-defined/real-gas-models/nist-multispecies-real-gas-model and specify the number and species, but DO NOT activate the NIST-Table. This is only for generating user-defined bubble and dew point curves using NIST models.
Ensure that the number and order of components selected in Fluent matches the number and order of species in z of the get_satprop_NIST_msp function.
Note: The output temperature and pressure arrays appear in ascending order for dew points and descending order for bubble points. However, when the output is for single-species, that is, z[i]=1.0, all z[k]=0.0,(k=0,...,n; k!=i), they are in ascending order. The values for the critical condition are also presented in the output arrays. They are stored in the 1st element of the bubble point array and last element of the dew point array. For single-species, it is stored in the last element of the output arrays for both bubble and dew points.
This UDF, named getsat_msp, computes and writes saturation curves. It demonstrates how a binary phase envelope is calculated using the NIST real gas model.
#include "udf.h"
#include <string.h>
#define NUM_SAT 50
#define SMALL_NUM 1.e-6
DEFINE_ON_DEMAND(getsat_msp)
{
double t, p, y[10];
int np,index;
int nsat,npts[2];
double z[10]={0.}, minrho, maxrho;
double p_bub[NUM_SAT],t_bub[NUM_SAT],p_dew[NUM_SAT],t_dew[NUM_SAT];
FILE *fp1, *fp2;
int i,j,k,ncomps=2;
fp1 = fopen("NIST_Bub_Pnts_Curve.xy", "w");
fp2 = fopen("NIST_Dew_Pnts_Curve.xy", "w");
/* test on udf built NIST table - sat */
minrho = 0.1;
maxrho = 25.;
nsat = NUM_SAT;
z[0] = 0.;
fprintf(fp1, "(title \"Sat Bubble P-T\")");
fprintf(fp1, "\n(labels \"Temperature (K)\" \"Pressure (kPa)\")\n");
fprintf(fp2, "(title \"Sat Dew P-T\")");
fprintf(fp2, "\n(labels \"Temperature (K)\" \"Pressure (kPa)\")\n");
for (j=0; j<21; j++)
{
if (z[0] > 1.) z[0] = 1.;
z[1] = 1. - z[0];
if (z[1] < 0.) z[1] = 0.;
get_satprop_NIST_msp(0,z,minrho,maxrho,nsat,npts,p_bub,t_bub,p_dew,t_dew);
/* bubble */
for (i=0; i<1; i++)
fprintf(fp1, "\n((xy/key/label \"z[0]=%g numpts=%d\")\n",z[i],npts[0]);
if (fabs(z[0])<SMALL_NUM || fabs(z[0]-1.)<SMALL_NUM || fabs(z[1])<SMALL_NUM || fabs(z[1]-1.)<SMALL_NUM)
{
for (i=0;i<npts[0];i++)
fprintf(fp1, "%g\t %g\t \n",t_bub[i],p_bub[i]/1000.);
}
else
{
for (i=npts[0]-1;i>-1;i--)
fprintf(fp1, "%g\t %g\t \n",t_bub[i],p_bub[i]/1000.);
}
fprintf(fp1, ")\n");
/* dew */
for (i=0; i<1; i++)
fprintf(fp2, "\n((xy/key/label \"z[0]=%g numpts=%d\")\n",z[i],npts[1]);
for (i=0;i<npts[1];i++)
fprintf(fp2, "%g\t %g\t \n",t_dew[i],p_dew[i]/1000.);
fprintf(fp2, ")\n");
z[0] += 0.05;}
}
fclose(fp1);
fclose(fp2);
}