06 Udf Flow
06 Udf Flow
06 Udf Flow
Introduction
The purpose of this tutorial is to provide guidelines and recommendations for setting up and solving a ow uniformity problem with the help of a user-dened function (UDF). This tutorial demonstrates how to do the following: Modify the UDF for a specic case. Use the UDF to calculate the ow uniformity indexes for steady-state ow.
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 ow passage. A schematic of the problem is shown in Figure 1. There are two ow inlets and an outlet. The postprocessing planes (post-01, post-02, post03, and post-04) have already been created with the mesh.
Step 1: Mesh 1. Read the mesh le (flow-uniformity.msh.gz). File Read Mesh... As the mesh le is read, ANSYS FLUENT will report the progress in the console. Step 2: General Settings 1. Retain the default solver settings. General 2. Check the mesh (see Figure 2). General Check
Figure 2: Mesh Display 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. 3. Scale the mesh to centimeters. General Scale... (a) Select cm from Mesh Was Created In drop-down list. (b) Click Scale and close Scale Mesh dialog box.
Step 3: Models Select the k-epsilon turbulence model. Models Viscous Edit...
You will use the default uid properties of air for this problem. Hence, you need not make any changes to the material properties. Step 4: Boundary Conditions 1. Set the boundary conditions for vel-in-large. Boundary Conditions vel-in-large Edit...
(a) Select Magnitude, Normal to Boundary from the Velocity Specication Method drop-down list. (b) Enter 0.5 m/s for Velocity Magnitude. (c) Select Intensity and Hydraulic Diameter from the Specication Method drop-down list. (d) Enter 5% for Turbulent Intensity. (e) Enter 0.06 m for Hydraulic Diameter. (f) Click OK to close the Velocity Inlet dialog box. 2. Set the boundary conditions for velocity-in-small. Boundary Conditions vel-in-small Edit...
(a) Select Magnitude, Normal to Boundary from the Velocity Specication Method drop-down list. (b) Enter 2 m/s for Velocity Magnitude. (c) Select Intensity and Hydraulic Diameter from the Specication Method drop-down list. (d) Enter 5% for Turbulent Intensity. (e) Enter 0.02 m for Hydraulic Diameter. (f) Click OK to close the Velocity Inlet dialog box. 3. Set the boundary conditions for press-out. Boundary Conditions press-out Edit...
(a) Select Normal to Boundary from the Backow Direction Specication Method dropdown list. (b) Select Intensity and Hydraulic Diameter from the Specication Method drop-down list. (c) Enter 5% for Backow Turbulent Intensity. (d) Enter 0.06 m for Backow Hydraulic Diameter. (e) Click OK to close the Pressure Outlet dialog box. 4
Step 5: Operating Conditions Boundary Conditions Operating Conditions... 1. Retain the default operating conditions. Step 6: Solution 1. Retain the default solution control parameters. 2. Initialize the ow eld from vel-in-large. Solution Initialization 3. Start the calculation for 100 iterations. Run Calculation The solution will converge in approximately 60 iterations. 4. Save the case and data les (flow-1.cas/dat.gz). Step 7: Postprocessing 1. Display lled contours of velocity magnitude. Graphics and Animations Contours Set Up...
(a) Enable Filled in the Options list. (b) Select Velocity... and Velocity Magnitude from Contours of drop-down list. (c) Select post-01, post-02, post-03, and post-04 from the Surfaces list. (d) Enable Draw Mesh in the Options group box. The Mesh Display dialog box will open. i. Disable Edges and enable Faces in the Options group box. ii. Deslect all the surfaces from the Surfaces list and click the Outline. iii. Click Display and close Mesh Display dialog box. (e) Click Display and close Contours dialog box.
2. Manipulate the display using the Scene Description dialog box. Graphics and Animations Scene... (a) Select the surfaces as shown in the Scene Description dialog box.
(b) Click Display... in the Geometry Attributes group box to open the Display Properties dialog box.
i. Enable Lighting in the Visibility group box. ii. Disable Edges, Lines, and Nodes in the Visibility group box. iii. Enable Outer Faces in the Visibility group box. iv. Set the sliders for Red, Green, and Blue to 255 in the Colors group box. v. Set the slider for Transparency to 80. vi. Click Apply and close the Display Properties dialog box (see Figure 3). (c) Close Scene Description dialog box.
4. Calculate the ow uniformity. (a) Set up the input le (input.txt). The input le (input.txt) has to be processed before executing the UDF. For the details about the input le, see Appendix 1: Details of the Input File. (b) Set the Number of User-Dened Memory Locations to 4. Dene User-Dened Memory... (c) Save the case le (flow.cas.gz). (d) Compile the UDF. Dene User-Dened Functions Compiled...
i. Click Add... and select the source le, cat-general.c. For details about the UDF le (cat-general.c), refer to Appendix 2: Contents of UDF. ii. Click Build to build the library. A Warning dialog box opens, asking you to ensure that the UDF source les are in the same folder that contains the case and data les. Click OK. iii. Click Load to load the newly created UDF library. (e) Execute the UDF. Dene User-Dened Execute on Demand... i. Select Uniform steady::libudf from the Execute On Demand drop-down list. ii. Click Execute. (f) The output on the screen and in the le are shown in Appendix 3: Output of UDF. The UDF reads the input le (input.txt) and generates the output le (output.txt) automatically in each simulation. The parameters of the output are explained in Appendix 4: General Structure of UDF. If you want to preserve the old results, rename the output.txt le. Otherwise the data for the next run will be appended to the old le.
static void read_input() { int i=0; FILE *fpin; 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); } static void init_udm() { Thread *tc; cell_t c; Domain *domain; domain = Get_Domain(1); thread_loop_c(tc,domain)
10
static void cat_post(int flag) { float xf[ND_ND], x_vmax_global[ND_ND], x_vmax, y_vmax; float x_face_local, y_face_local; float xn[ND_ND],x_node_local,y_node_local; float x_min, x_max, x_mid, y_min, y_max, y_mid; float L_major, L_minor; float eccent_x, eccent_y, eccent; float vmag, vmax, vavg, vratio, vel_space; float A_face_vec[ND_ND], A_face_mag, A_tot; float a_35, v_35, unif_35, a_65, v_65, unif_65, gamma; int k; face_t f, f_vmax; cell_t c0, c1; Thread *tf, *tc0, *tc1; FILE *fp; Domain *domain; domain = Get_Domain(1);
#define BIGNUM 1e20 if((fp=fopen("output.txt", "r"))==NULL) { fp=fopen("output.txt","w+"); fprintf(fp, "post-face eccent gamma fclose(fp); } fp=fopen("output.txt", "a"); /* find local y,z min/max extents based on node values */
unif_35
unif_65
vratio
vmax \n");
11
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); /* velocity index (eccentricity) computation */ vmax=0.0; vavg=0.0; A_tot=0.0; tf=Lookup_Thread(domain, POST_BOUNDARY_ZONE_ID[flag]); tc0=Lookup_Thread(domain, POST_CELL_ZONE_ID_1[flag]); tc1=Lookup_Thread(domain, POST_CELL_ZONE_ID_2[flag]); begin_f_loop(f,tf) { F_AREA(A_face_vec,f,tf); A_face_mag=NV_MAG(A_face_vec); A_tot+=A_face_mag; c0=F_C0(f,tf); c1=F_C1(f,tf); vmag=0.5*(C_UDMI(c0,tc0,3)+C_UDMI(c1,tc1,3)); vavg+=vmag*A_face_mag; if(vmag > vmax) { vmax=vmag; f_vmax=f; } } 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
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); Message("vratio = %f\n", vratio); /* uniformity, gamma calculations */ v_35=0.35*vmax; v_65=0.65*vmax; a_35=0.0; a_65=0.0; gamma=0.0; begin_f_loop(f,tf) { F_AREA(A_face_vec,f,tf); A_face_mag=NV_MAG(A_face_vec); c0=F_C0(f,tf); c1=F_C1(f,tf); vmag=0.5*(C_UDMI(c0,tc0,3)+C_UDMI(c1,tc1,3)); if(vmag >= v_35) a_35+=A_face_mag; if(vmag >= v_65) a_65+=A_face_mag; gamma+=ABS(vmag-vavg)*A_face_mag; } end_f_loop(f,tf) gamma=1.0-gamma/(2.*vavg*A_tot); unif_35=a_35/A_tot*100; unif_65=a_65/A_tot*100; Message("uniformity index = %f/%f\n",unif_65,unif_35); Message("gamma = %f\n",gamma);
fprintf(fp, "post%d %9.3f %9.3f unif_35, unif_65, vratio, vmax); fclose(fp); } static void set_udm(int flag)
%9.3f
%9.3f
%9.3f
{ /* NOTE: THIS ROUTINE REQUIRES ALLOCATION OF */ /* 4 USER DEFINED MEMORY LOCATIONS IN FLUENT */ #define #define #define #define X_PRIME 0 Y_PRIME 1 Z_PRIME 2 V_MAG 3
13
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) } }
Notes: The postprocessing face must be a real face zone and should be created in preprocessing. Only Uniform-steady can be used as a Execute On Demand function. You can use the EXECUTE ON DEMAND macro for calculations which do not participate in the solution iterations, such as postprocessing.
14
15
Eccentricity information: (x _vmax, y _vmax) = (-0.018510, -0.001128) [m] eccentricity = (0.816052, -0.112719) -> 0.823800 vmax = 2.378441 m/s occurs at face 53 vratio = 1.149897 uniformity index = 99.176368/100.000000 gamma = 0.956343 ================================================================ post-3 ================================================================ 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.000981, 0.005763) [m] eccentricity = (0.032705, 0.192102) -> 0.194866 vmax = 1.677601 m/s occurs at face 334 vratio = 2.189714 uniformity index = 21.332038/55.492872 gamma = 0.802111
Output in a le:
16
17
1. Calculation of geometric parameters of the postprocessing face. (a) Length of major and minor axes: L major = x max x min L minor = y max y min where, L major = length of major axis L minor = length of minor axis x max = maximum x coordinate y max = maximum y coordinate x min = minimum x coordinate y min = minimum y coordinate (b) Center of the zone: x mid = x max x min 2 y max y min y mid = 2 (3) (4) (1) (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 dened as: x= y= 2 (x vmax x mid) L major 2 (y vmax y mid) L minor x2 + y2 (5) (6) (7)
Velocity ratio ( ratio) can be dened as the ratio of the maximum velocity to the average velocity. max ratio = (8) avg 3. Calculation of ow 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
The uniformity is dened as: 65 = 35 = where, A 65 = the area of which velocity is higher than 65 A 35 = the area of which velocity is higher than 35 Gamma is dened as, =1 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 le: The parameters in the output le can be explained as follows: time = ow time eccent = gamma = unif 35 = 35 unif 65 = 65 vmax = maximum velocity (| i avg|A i) 2 avgA total (11) A 65 100A total A 35 100A total (9) (10)
Summary
In this tutorial, a ow uniformity problem was set up and solved for a steady state ow with the help of UDF.
19