06 Udf Flow PDF
06 Udf Flow PDF
Introduction
The purpose of this tutorial is to provide guidelines and recommendations for setting up
and solving a flow uniformity problem with the help of a user-defined function (UDF).
This tutorial demonstrates how to do the following:
• Use the UDF to calculate the flow uniformity indexes for steady-state flow.
Prerequisites
This tutorial is written with the assumption that you have completed Tutorial 1 from
ANSYS FLUENT 12.0 Tutorial Guide, and that you are familiar with the ANSYS FLUENT
navigation pane and menu structure. Some steps in the setup and solution procedure will
not be shown explicitly.
For more details about UDFs, see ANSYS FLUENT 12.0 UDF Manual.
Problem Description
The problem considers a 3D flow passage. A schematic of the problem is shown in Figure 1.
There are two flow inlets and an outlet. The postprocessing planes (post-01, post-02, post-
03, and post-04) have already been created with the mesh.
c ANSYS, Inc. September 25, 2009 1
Calculation of Flow Uniformity
Preparation
4. Click the UDF Compiler tab and ensure that the Setup Compilation Environment for
UDF is enabled.
The path to the .bat file which is required to compile the UDF will be displayed as soon
as you enable Setup Compilation Environment for UDF.
If the UDF Compiler tab does not appear in the FLUENT Launcher dialog box by default,
click the Show More >> button to view the additional settings.
The Display Options are enabled by default. Therefore, after you read in the mesh, it
will be displayed in the embedded graphics window.
2
c ANSYS, Inc. September 25, 2009
Calculation of Flow Uniformity
Step 1: Mesh
ANSYS FLUENT will perform various checks on the mesh and will report the progress
in the console. Make sure the minimum volume reported is a positive number.
c ANSYS, Inc. September 25, 2009 3
Calculation of Flow Uniformity
Step 3: Models
Select the k-epsilon turbulence model.
4
c ANSYS, Inc. September 25, 2009
Calculation of Flow Uniformity
Step 6: Solution
Step 7: Postprocessing
c ANSYS, Inc. September 25, 2009 5
Calculation of Flow Uniformity
(b) Click Display... in the Geometry Attributes group box to open the Display Proper-
ties dialog box.
6
c ANSYS, Inc. September 25, 2009
Calculation of Flow Uniformity
c ANSYS, Inc. September 25, 2009 7
Calculation of Flow Uniformity
8
c ANSYS, Inc. September 25, 2009
Calculation of Flow Uniformity
• Each line after the first line has the parameters of a face-zone. They are defined in
the following order:
– POST BOUNDARY ZONE ID
– POST CELL ZONE ID 1
– POST CELL ZONE ID 2
– L XX
– L YX
– L ZX
– L XY
– L YY
– L ZY
Further detailed description of the parameters is given as follows:
1. POST BOUNDARY ZONE ID is the ID of the face zone.
2. POST CELL ZONE ID 1 and POST CELL ZONE ID 2 are the IDs of two adjacent
cell zones of the postprocessing face zone. They are the same if the face zone is
inside a cell zone.
3. L XX, L YX, L ZX are the direction cosines of the x-axis of the local coordinate.
The UDF uses a local coordinate for each face zone to compute the flow unifor-
mity. The local x-axis will be the major axis, and local y-axis will be the minor
axis. You should define the direction of longer length as x-axis, and the other
direction in the same plane as y-axis.
4. L XY, L YY, L ZY are the direction cosines of the y-axis of the local coordinate.
The UDF uses a local coordinate for each face zone to compute the flow unifor-
mity. The local x-axis will be the major axis, and local y-axis direction will be
the minor axis. You should define the direction of longer length as x-axis, and
the other direction in the same plane as y-axis.
• The definition of the direction cosines may affect the eccentricity because it reflects
the local flow distribution on the plane. The gamma does not depend on the direction
cosines.
c ANSYS, Inc. September 25, 2009 9
Calculation of Flow Uniformity
/**************************************************************/
/* */
/* User-Defined Functions for calculation of flow uniformity */
/* */
/**************************************************************/
#include "udf.h"
int ncount;
int npost;
float L_XX[50];
float L_YX[50];
float L_ZX[50];
float L_XY[50];
float L_YY[50];
float L_ZY[50];
float L_XZ[50];
float L_YZ[50];
float L_ZZ[50];
if((fpin=fopen("input.txt","r"))==NULL)
{
printf("Input file does not exist!");
}
fscanf(fpin, "%d",&npost);
for(i=0;i<npost;i++)
{
fscanf(fpin,"%d %d %d %f %f %f %f %f %f", &POST_BOUNDARY_ZONE_ID[i], &POST_CELL_ZONE_ID_1[i],
&POST_CELL_ZONE_ID_2[i], &L_XX[i], &L_YX[i], &L_ZX[i], &L_XY[i], &L_YY[i], &L_ZY[i]);
L_XZ[i]=L_YX[i]*L_ZY[i]-L_ZX[i]*L_YY[i];
L_YZ[i]=L_ZX[i]*L_XY[i]-L_XX[i]*L_ZY[i];
L_ZZ[i]=L_XX[i]*L_YY[i]-L_XY[i]*L_YX[i];
}
fclose(fpin);
}
Thread *tc;
cell_t c;
Domain *domain;
domain = Get_Domain(1);
thread_loop_c(tc,domain)
10
c ANSYS, Inc. September 25, 2009
Calculation of Flow Uniformity
{
begin_c_loop(c,tc)
{
C_UDMI(c,tc,0)=0;
C_UDMI(c,tc,1)=0;
C_UDMI(c,tc,2)=0;
C_UDMI(c,tc,3)=0;
}
end_c_loop(c,tc)
}
ncount=0;
}
face_t f, f_vmax;
cell_t c0, c1;
Thread *tf, *tc0, *tc1;
FILE *fp;
Domain *domain;
domain = Get_Domain(1);
if((fp=fopen("output.txt", "r"))==NULL)
{
fp=fopen("output.txt","w+");
fprintf(fp, "post-face eccent gamma unif_35 unif_65 vratio vmax \n");
fclose(fp);
}
fp=fopen("output.txt", "a");
x_min=BIGNUM;
y_min=BIGNUM;
x_max=-BIGNUM;
y_max=-BIGNUM;
tf=Lookup_Thread(domain, POST_BOUNDARY_ZONE_ID[flag]);
c ANSYS, Inc. September 25, 2009 11
Calculation of Flow Uniformity
begin_f_loop(f,tf)
{
f_node_loop(f,tf,k)
{
xn[0]=NODE_X(F_NODE(f,tf,k));
xn[1]=NODE_Y(F_NODE(f,tf,k));
xn[2]=NODE_Z(F_NODE(f,tf,k));
x_node_local = NVD_DOT(xn,L_XX[flag],L_YX[flag],L_ZX[flag]);
y_node_local = NVD_DOT(xn,L_XY[flag],L_YY[flag],L_ZY[flag]);
x_min=MIN(x_node_local,x_min);
x_max=MAX(x_node_local,x_max);
y_min=MIN(y_node_local,y_min);
y_max=MAX(y_node_local,y_max);
}
}
end_f_loop(f,tf)
x_mid=0.5*(x_min + x_max);
y_mid=0.5*(y_min + y_max);
L_major = x_max - x_min;
L_minor = y_max - y_min;
Message("================================================================\n");
Message("post-%d\n",flag);
Message("================================================================\n");
Message("Geometry information:\n");
Message("(x_min, x_mid, x_max) = (%f, %f, %f) [m]\n", x_min, x_mid, x_max);
Message("(y_min, y_mid, y_max) = (%f, %f, %f) [m]\n", y_min, y_mid, y_max);
Message("(L_major, L_minor) = (%f, %f) [m]\n\n", L_major, L_minor);
end_f_loop(f,tf)
vavg/=A_tot;
vratio=vmax/vavg;
F_CENTROID(x_vmax_global,f_vmax,tf);
x_vmax= NVD_DOT(x_vmax_global,L_XX[flag],L_YX[flag],L_ZX[flag]);
y_vmax= NVD_DOT(x_vmax_global,L_XY[flag],L_YY[flag],L_ZY[flag]);
eccent_x=2.0*(x_vmax-x_mid)/L_major;
eccent_y=2.0*(y_vmax-y_mid)/L_minor;
eccent=sqrt(eccent_x*eccent_x+eccent_y*eccent_y);
12
c ANSYS, Inc. September 25, 2009
Calculation of Flow Uniformity
Message("Eccentricity information:\n");
Message("(x_vmax, y_vmax) = (%f, %f) [m]\n", x_vmax, y_vmax);
Message("eccentricity = (%f, %f) -> %f \n\n",eccent_x, eccent_y, eccent);
Message("vmax = %f m/s occurs at face %d\n", vmax, f_vmax);
unif_35=a_35/A_tot*100;
unif_65=a_65/A_tot*100;
fprintf(fp, "post%d %9.3f %9.3f %9.3f %9.3f %9.3f %9.3f \n", flag, eccent, gamma,
unif_35, unif_65, vratio, vmax);
fclose(fp);
}
static void set_udm(int flag)
{
/* NOTE: THIS ROUTINE REQUIRES ALLOCATION OF */
/* 4 USER DEFINED MEMORY LOCATIONS IN FLUENT */
#define X_PRIME 0
#define Y_PRIME 1
#define Z_PRIME 2
#define V_MAG 3
float xc[ND_ND];
Thread *tc1,*tc2;
cell_t c;
Domain *domain;
domain = Get_Domain(1);
tc1=Lookup_Thread(domain, POST_CELL_ZONE_ID_1[flag]);
tc2=Lookup_Thread(domain, POST_CELL_ZONE_ID_2[flag]);
c ANSYS, Inc. September 25, 2009 13
Calculation of Flow Uniformity
begin_c_loop(c,tc1)
{
C_CENTROID(xc,c,tc1);
C_UDMI(c,tc1,X_PRIME)=NVD_DOT(xc,L_XX[flag],L_YX[flag],L_ZX[flag]);
C_UDMI(c,tc1,Y_PRIME)=NVD_DOT(xc,L_XY[flag],L_YY[flag],L_ZY[flag]);
C_UDMI(c,tc1,Z_PRIME)=NVD_DOT(xc,L_XZ[flag],L_YZ[flag],L_ZZ[flag]);
C_UDMI(c,tc1,V_MAG)=sqrt(C_VMAG2(c,tc1));
}
end_c_loop(c,tc1)
if(POST_CELL_ZONE_ID_1[flag] != POST_CELL_ZONE_ID_2[flag])
{
begin_c_loop(c,tc2)
{
C_CENTROID(xc,c,tc2);
C_UDMI(c,tc2,X_PRIME)=NVD_DOT(xc,L_XX[flag],L_YX[flag],L_ZX[flag]);
C_UDMI(c,tc2,Y_PRIME)=NVD_DOT(xc,L_XY[flag],L_YY[flag],L_ZY[flag]);
C_UDMI(c,tc2,Z_PRIME)=NVD_DOT(xc,L_XZ[flag],L_YZ[flag],L_ZZ[flag]);
C_UDMI(c,tc2,V_MAG)=sqrt(C_VMAG2(c,tc2));
}
end_c_loop(c,tc2)
}
}
DEFINE_ON_DEMAND(Uniform_steady)
{
int i=0;
read_input();
init_udm();
for(i=0; i<npost;i++)
{
set_udm(i);
cat_post(i);
}
}
Notes:
• The postprocessing face must be a real face zone and should be created in preprocess-
ing.
14
c ANSYS, Inc. September 25, 2009
Calculation of Flow Uniformity
================================================================
post-0
================================================================
Geometry information:
(x _min, x _mid, x _max) = (-0.030000, 0.000000, 0.030000) [m]
(y _min, y _mid, y _max) = (-0.030000, 0.000000, 0.030000) [m]
(L _major, L _minor) = (0.060000, 0.060000) [m]
Eccentricity information:
(x _vmax, y _vmax) = (0.002929, 0.001147) [m]
eccentricity = (0.097642, 0.038245) -> 0.104865
Eccentricity information:
(x _vmax, y _vmax) = (0.004870, -0.003402) [m]
eccentricity = (0.162350, -0.113398) -> 0.198032
c ANSYS, Inc. September 25, 2009 15
Calculation of Flow Uniformity
Eccentricity information:
(x _vmax, y _vmax) = (-0.018510, -0.001128) [m]
eccentricity = (0.816052, -0.112719) -> 0.823800
Eccentricity information:
(x _vmax, y _vmax) = (0.000981, 0.005763) [m]
eccentricity = (0.032705, 0.192102) -> 0.194866
Output in a file:
16
c ANSYS, Inc. September 25, 2009
Calculation of Flow Uniformity
• set udm: It computes the local coordinate in the selected cell zones based on the
directional cosines provided by users. It stores the local coordinates in udm-0, udm-1,
and udm-2, and velocity magnitude of the selected cell zones in udm-3.
c ANSYS, Inc. September 25, 2009 17
Calculation of Flow Uniformity
x max − x min
x mid = (3)
2
y max − y min
y mid = (4)
2
2. Calculation of velocity index (eccentricity).
Compute the location (x and y coordinates) of the maximum velocity and the distance
between this location and the center of the face. Find the maximum velocity and
velocity ratio.
Eccentricity (ε) is defined as:
2 (x vmax − x mid)
εx= (5)
L major
2 (y vmax − y mid)
εy= (6)
L minor
q
ε= ε x2 + ε y2 (7)
Velocity ratio (ν ratio) can be defined as the ratio of the maximum velocity to the
average velocity.
ν max
ν ratio = (8)
ν avg
3. Calculation of flow uniformity.
Compute the uniformity index (area based), gamma, and vel space. The uniformity
index is based on these reference velocities: ν 65 (65% of the maximum velocity) and
ν 35 (35% of the maximum velocity).
18
c ANSYS, Inc. September 25, 2009
Calculation of Flow Uniformity
(|ν i − ν avg|A i)
P
γ =1− (11)
2ν avgA total
4. Output parameters.
(a) On the screen:
The parameters of the output on the screen can be explained as follows:
• (x max, y max) = Location of the maximum velocity
• eccentricity = (ε x, ε y) ⇒ ε
• vmax = maximum velocity
• vratio = ν ratio
• uniformity index = ϕ 65/ϕ 35
• gamma = γ
(b) In the output file:
The parameters in the output file can be explained as follows:
• time = flow time
• eccent = ε
• gamma = γ
• unif 35 = ϕ 35
• unif 65 = ϕ 65
• vmax = maximum velocity
Summary
In this tutorial, a flow uniformity problem was set up and solved for a steady state flow
with the help of UDF.
c ANSYS, Inc. September 25, 2009 19