Вы находитесь на странице: 1из 5

UDF Examples

1. Steady velocity function: A UDF is used to introduce this parabolic profile at the inlet. The C source code (vprofile.c) is shown below. /*********************************************************************** / /* vprofile.c*/ /* UDF for specifying steady-state velocity profile boundary condition */ /*********************************************************************** / #include "udf.h" DEFINE_PROFILE(inlet_x_velocity, thread, position) { real x[ND_ND]; /* this will hold the position vector */ real y; face_t f; begin_f_loop(f, thread) { F_CENTROID(x,f,thread); y = x[1]; F_PROFILE(f, thread, position) = 20. - y*y/(.0745*.0745)*20.; } end_f_loop(f, thread) } The function, named inlet_x_velocity, is defined using DEFINE_PROFILE and has two arguments: thread and position. Thread is a pointer to the face's thread, and position is an integer that is a numerical label for the variable being set within each loop. The function begins by declaring variable f as a face_t data type. A one-dimensional array x and variable y are declared as real data types. A looping macro is then used to loop over each face in the zone to create a profile, or an array of data. Within each loop, F_CENTROID outputs the value of the face centroid (array x) for the face with index f that is on the thread pointed to by thread. The y coordinate stored in x[1] is assigned to variable y, and is then used to calculate the x velocity. This value is then assigned to F_PROFILE, which uses the integer position (passed to it by the solver based on your selection of the UDF as the boundary condition for x velocity in the Velocity Inlet panel) to set the x velocity face value in memory. To make use of this interpreted UDF in FLUENT, you must first compile it.

2. Unsteady Velocity specification: The source code for the velocity profile UDF ( unsteady.c) is shown below. /**********************************************************************/ /* unsteady.c */ /* UDF for specifying a transient velocity profile boundary condition */ /**********************************************************************/ #include "udf.h" DEFINE_PROFILE(unsteady_velocity, thread, position) { face_t f; begin_f_loop(f, thread) { real t = RP_Get_Real("flow-time"); F_PROFILE(f, thread, position) = 20. + 5.0*sin(10.*t); } end_f_loop(f, thread) } The function, named unsteady_velocity, is defined using the DEFINE_PROFILE macro. The utility RP_Get_Real("flow-time") is used to look up the real flow time, which is assigned to the variable t. Before you can compile this UDF, you must specify an unsteady flow calculation in the Solver panel. Next you can open the Interpreted UDFs panel. Enter the name of the function in the text entry box under Source File Name and, if necessary, the name of your C preprocessor. Turn on Display Assembly Listing.

3. Momentum Source: /******************************************************************/ /* UDF that adds momentum source term and derivative to duct flow */ /******************************************************************/ #include "udf.h" #define CON 20.0

DEFINE_SOURCE(cell_x_source, cell, thread, dS, eqn) { real source; if (C_T(cell,thread) <= 288.) { /* source term */ source = -CON*C_U(cell,thread); /* derivative of source term w.r.t. x-velocity. */ dS[eqn] = -CON; } else source = dS[eqn] = 0.; return source; } The function, named cell_x_source, is defined on a cell using DEFINE_SOURCE. The constant C in Equation 10.2-1 is called CON in the function, and it is given a numerical value of 20 kg/m 3-s, which will result in the desired units of N/m 3 for the source. The temperature at the cell is returned by C_T(cell,thread). The function checks to see if the temperature is below (or equal to) 288 K. If it is, the source is computed ( C_U returns the value of the x velocity of the cell). If it is not, the source is set to 0.0. At the end of the function, the appropriate value for the source is returned to the FLUENT solver. The UDF is executed as interpreted.

4. Solidification via a Temperature-Dependent Viscosity: UDFs for properties (as well as sources) are called from within a loop on cells. For this reason, functions that specify properties are only required to compute the property for a single cell, and return the value to the FLUENT solver. The UDF in this example generates a variable viscosity profile to simulate solidification. The viscosity in the warm ( T > 288 K) fluid has a molecular value for the liquid (5.5 kg/m-s), while the viscosity for the cooler region ( T < 286 K) has a much larger value (1.0 kg/m-s). In the intermediate temperature range (286 K 288 K), the viscosity follows a linear profile that extends between the two values given above: This model is based on the assumption that as the liquid cools and rapidly becomes more viscous, its velocity will decrease, thereby simulating solidification. Here, no correction is made for the energy field to include the latent heat of freezing. The C source code for the UDF is shown below. /*********************************************************************/ /* UDF for specifying a temperature-dependent viscosity property */ /*********************************************************************/ #include "udf.h" DEFINE_PROPERTY(cell_viscosity, cell, thread) { real mu_lam; real temp = C_T(cell, thread); if (temp > 288.) mu_lam = 5.5e-3; else if (temp > 286.) mu_lam = 143.2135 - 0.49725 * temp; else mu_lam = 1.; return mu_lam; } The function, named cell_viscosity, is defined on a cell using DEFINE_PROPERTY. Two real variables are introduced: temp, the value of C_T(cell,thread), and mu_lam, the laminar viscosity computed by the function. The value of the temperature is checked, and based upon the range into which it falls, the appropriate value of mu_lam is computed. At the end of the function, the computed value for mu_lam is returned to the solver.

5. Wall Heat Flux: The wall heat flux function ( DEFINE_HEAT_FLUX) can be used to modify the way that the solver computes the heat flux between a wall and the neighboring fluid cells. For example, you can customize the heat transfer coefficient or the law-of-the-wall for temperature. The UDF presented below uses an internal heat transfer coefficient to specify the wall heat flux. It is another example of a UDF that utilizes the ADJUST function to adjust a computed value, and it is executed as a compiled UDF. The diffusive heat flux coefficients ( cid) are specified in this UDF. The diffusive heat flux ( qid) will then be computed by FLUENT using the following equation: qid = cid[0] + cid[1]*C_T(c0,t0) - cid[2]*F_T(f,t) cid[3]*pow(F_T(f,t),4) /*********************************************************************** / /* UDF for specifying the diffusive heat flux between a wall and */ /* neighboring cells */ /*********************************************************************** / #include "udf.h" static real h = 0.; */ /* heat transfer coefficient (W/m^2 C)

DEFINE_ADJUST(htc_adjust, domain) { /* Define the heat transfer coefficient. */ h = 120; } DEFINE_HEAT_FLUX(heat_flux, f, t, c0, t0, cid, cir) { cid[0] = 0.; cid[1] = h; cid[2] = h; cid[3] = 0.; }

Вам также может понравиться