FLUENT V6 - Reading experimental/tabulated values of material properties or profiles


FLUENT provides for a variety of methods for specifying material properties, including polynomial functions, piece-wise linear functions, etc. User-defined functions can also be used to specify material properties and variable profiles. However, using tabulated experimental data or complicated functions that can not be easily expressed analytically is difficult.
The following user-defined function demonstrates how tabulated data can be read into FLUENT and used to specify a material property in a UDF. The example corresponds to specifying the viscosity as a function of temperature. The tabulated data should be in an ascii file (two column format) and the number of rows in the file is specified in the UDF. In this example, the data file is called "viscosity.dat" and there are 53 rows (pairs) of data. The viscosity will be linearly interpolated between the tabulated values.


#include "udf.h"

int NPts_mu = 53; /* number of entries in viscosity table */

/* Locate the place in the interpolation vector using bisection algorithm*/
int locate(float xx[], int n, float x)
{
int j = 0;
int jm = 0;
int jl = 0;
int ju = n+1;
int ascnd = 0;

ascnd = (xx[n] >= xx[1]);
while (ju-jl > 1)
{
jm = (ju+jl) >> 1;
if (x >= xx[jm] == ascnd)
jl = jm;
else
ju = jm;
}

if (x == xx[1])
j = 1;
else if (x == xx[n])
j = n-1;
else
j = jl;

return j;
}

float *temp_vec_mu,*visc_vec;
#define FAST_LOOKUP TRUE /* use bisection algorithm for interpolation */
#define TABLE_MESSAGES TRUE
#define DISPLAY_TABLES TRUE

/* Obtaine mu given temperature */
float get_mu_from_T(float xdata)
{
int i = 0;
int j = 0;
float xL,xU,ydata;

#if FAST_LOOKUP
j = locate(temp_vec_mu,NPts_mu,xdata);
xL = temp_vec_mu[j];
xU = temp_vec_mu[j+1];
ydata = visc_vec[j] + (xdata-xL)/(xU-xL)*( visc_vec[j+1] - visc_vec[j] );
#else
for ( i=1; i<NPts_mu ;i++ )
{
xL = temp_vec_mu[i];
xU = temp_vec_mu[i+1];
if ( (xdata>=xL)&&(xdata<=xU) )
{
ydata = visc_vec[i] + (xdata-xL)/(xU-xL)*( visc_vec[i+1] - visc_vec[i] );
break;
}
}
#endif

if ( xdata>temp_vec_mu[NPts_mu] )
{
#if TABLE_MESSAGES
Message("n temperature is above the bound of visc-array n");
#endif
ydata = visc_vec[NPts_mu];
}
if ( xdata<temp_vec_mu[1] )
{
#if TABLE_MESSAGES
Message("n temperature is below the bound of visc-array n");
#endif
ydata = visc_vec[1];
}

return ydata;
}

/* Read in the data file containing viscosity as a function of temperature */
DEFINE_ON_DEMAND(read_viscosity)
{
int i = 0;
float xdata,ydata;
FILE* fp;

fp = fopen("viscosity.dat","r");
if ( fp!=NULL )
{
#if !RP_NODE
Message(" n");
Message("Reading file viscosity.dat n");
Message(" n");
#endif
}
else
{
#if !RP_NODE
Message(" n");
Message("Error opening file n");
Message(" n");
#endif
}

temp_vec_mu = (float *) malloc(NPts_mu*sizeof(float));
visc_vec = (float *) malloc(NPts_mu*sizeof(float));

if ( (temp_vec_mu==NULL)||(visc_vec==NULL) )
{
#if !RP_NODE
Message("Memory allocation error n");
#endif
}

for ( i=1;i<=NPts_mu;i++ )
{
fscanf(fp,"%f %e n",&xdata,&ydata);
temp_vec_mu[i] = xdata;
visc_vec[i] = ydata;
#if DISPLAY_TABLES
#if !RP_NODE
Message("%.1f %e n",temp_vec_mu[i],visc_vec[i]);
#endif
}
#else
}
#if !RP_NODE
Message(" n");
#endif
#endif

fclose(fp);
}

/* Interpolate viscosity from look-up table and assign to cell value */
DEFINE_PROPERTY(viscosity,c,t)
{
float mu_lam;
float temp = C_T(c,t);

/* interpolate mu_lam */
mu_lam = get_mu_from_T(temp);

return mu_lam;
}


Sample data file "viscosity.dat":

500.0 3.03460E-05
700.0 3.94144E-05
1000.0 5.07830E-05
1200.0 5.71540E-05
1500.0 6.62424E-05
1800.0 7.51254E-05
2100.0 8.19802E-05
2400.0 9.23992E-05
2700.0 1.00744E-04
3000.0 1.08866E-04
3500.0 1.21942E-04
4000.0 1.34458E-04
4500.0 1.46520E-04
5000.0 1.58330E-04
5500.0 1.70196E-04
6000.0 1.82438E-04
6500.0 1.94962E-04
7000.0 2.06702E-04
7200.0 2.10910E-04
7500.0 2.16686E-04
8000.0 2.25596E-04
8500.0 2.34400E-04
9000.0 2.43092E-04
9500.0 2.51136E-04
10000.0 2.57698E-04
10500.0 2.61604E-04
11000.0 2.61396E-04
11500.0 2.55446E-04
12000.0 2.42620E-04
12500.0 2.22876E-04
13000.0 1.97606E-04
13500.0 1.69612E-04
14000.0 1.41774E-04
14500.0 1.16876E-04
15000.0 9.62224E-05
15500.0 8.01648E-05
16000.0 6.83390E-05
16500.0 6.00368E-05
17000.0 5.44842E-05
17500.0 5.09870E-05
18000.0 4.89790E-05
18500.0 4.80194E-05
19000.0 4.80168E-05
19500.0 4.83648E-05
20000.0 4.86812E-05
20500.0 4.89374E-05
21000.0 4.89330E-05
21500.0 4.84956E-05
22000.0 4.75116E-05
22500.0 4.59512E-05
23000.0 4.51756E-05
23500.0 4.43232E-05
24000.0 4.40476E-05





Show Form
No comments yet. Be the first to add a comment!