
This section contains an application of a source term UDF. It is executed as an interpreted UDF in FLUENT.
Adding a Momentum Source to a Duct Flow
When a source term is being modeled with a UDF, it is important to understand the context in which the function is called. When you add a source term, FLUENT will call your function as it performs a global loop on cells. Your function should compute the source term and return it to the solver.
In this example, a momentum source will be added to a 2D Cartesian duct flow. The duct is 4 m long and 2 m wide, and will be modeled with a symmetry boundary through the middle. Liquid metal (with properties listed in Table 8.2.1) enters the duct at the left with a velocity of 1 mm/s at a temperature of 290 K. After the metal has traveled 0.5 m along the duct, it is exposed to a cooling wall, which is held at a constant temperature of 280 K. To simulate the freezing of the metal, a momentum source is applied to the metal as soon as its temperature falls below 288 K. The momentum source is proportional to the component of the velocity, , and has the opposite sign:
where is a constant. As the liquid cools, its motion will be reduced to zero, simulating the formation of the solid. (In this simple example, the energy equation will not be customized to account for the latent heat of freezing. The velocity field will be used only as an indicator of the solidification region.)
The solver linearizes source terms in order to enhance the stability and convergence of a solution. To allow the solver to do this, you need to specify the dependent relationship between the source and solution variables in your UDF, in the form of derivatives. The source term, , depends only on the solution variable, . Its derivative with respect to is
(8.22) 
The following UDF specifies a source term and its derivative. The function, named cell_x_source, is defined on a cell using DEFINE_SOURCE. The constant in Equation 8.21 is called CON in the function, and it is given a numerical value of 20 kg/m s, which will result in the desired units of N/m 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 8.21 ( C_U returns the value of the 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.
/****************************************************************** 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. xvelocity. */ dS[eqn] = CON; } else source = dS[eqn] = 0.; return source; } 
To make use of this UDF in FLUENT, you will first need to interpret (or compile) the function, and then hook it to FLUENT using the graphical user interface. Follow the procedure for interpreting source files using the Interpreted UDFs panel (Section 4.2), or compiling source files using the Compiled UDFs panel (Section 5.2).
To include source terms in the calculation you will first need to turn on the Source Terms option in the Fluid or Solid panel and click the Source Terms tab. This will display the momentum source term parameters in the scrollable window.
Define Boundary Conditions...
Next, click the Edit... button next to the X Momentum source term. This will open the X Momentum Sources panel where you will select the number of terms you wish to model (Figure 6.2.23). Increment the Number of Momentum sources counter to 1 and then choose the function namefor the UDF in this example ( udf cell_x_source from the dropdown list.(Note that the UDF name that is displayed in the dropdown lists is preceeded by the word udf.) Click OK to accept the new boundary condition and close the panel. The X Momentum parameter in the Fluid panel will now display 1 source. Click OK to close the Fluid panel and fix the new momentum source term for the solution calculation.
Once the solution has converged, you can view contours of static temperature to see the cooling effects of the wall on the liquid metal as it moves through the duct (Figure 8.2.10).
Contours of velocity magnitude (Figure 8.2.11) show that the liquid in the cool region near the wall has indeed come to rest to simulate solidification taking place.
The solidification is further illustrated by line contours of stream function (Figure 8.2.12).
To more accurately predict the freezing of a liquid in this manner, an energy source term would be needed, as would a more accurate value for the constant appearing in Equation 8.21.