Udf
Udf
In the Interpreted UDFs panel, name your function in the Source File Name field. If necessary, enter your C preprocessor type in the CPP Command Name
field and the size of the stack under Stack Size. Turn on Display Assembly Listing to see an assembly listing in your console window as the function compiles. Click on Compile and then Close the panel. To select this user-defined function as the velocity boundary condition for the zone of choice, open the Velocity Inlet panel.
In the X-Velocity drop-down list, select udf inlet_x_velocity, the name that was given to the function above. This function will now be used, rather than the value of (in this example) 0 that appears in the X-Velocity field. Click on OK to accept the new boundary condition and close the panel. In this example, a temporally periodic velocity boundary condition will be applied to the inlet of a tube using a UDF. The velocity has the form
(10.1.1)
The tube is 1 m long with a radius of 0.2 m. It is assumed to be filled with air with a density of 1 kg/m 3and a viscosity of 2 kg/m-s. The velocity of the air fluctuates about an equilibrium value, v 0, of 20 m/s, with an amplitude of 5 m/s and at a frequency of 10 rad/s.
Before you can compile this UDF, you must specify an unsteady flow calculation in the Solver panel. Define Models Solver... 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. Click on Compile and then Close the panel. Define User-Defined Functions Interpreted...
The sinusoidal velocity boundary condition defined by the UDF can now be selected for the X-Velocity in the inlet zone. In the Velocity Inlet panel, simply select udf unsteady_velocity in the drop-down list to the right of the X-Velocity field, and click on OK.
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 according to Equation 10.2-1 ( 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
(10.3.1)
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.
To make use of a user-defined property, you will use the Materials panel. In the drop-down list for Viscosity, select the user-defined option.
Once you select this option, the User-Defined Functions panel opens, from which you can select the appropriate function name. In this example, only one is available, but in another example, you might have several functions from which to choose. (Recall that if you need to compile more than one interpreted UDF, the functions can be concatenated prior to compiling. See Section 7.2.1 for details.)
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;