![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
This section contains an application of a source term UDF. It is executed as an interpreted UDF in ANSYS 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, ANSYS 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 using 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.2-2) |
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.2-1 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.2-1 (
C_U returns the value of the
velocity of the cell). If it is not, the source is set to 0. At the end of the function, the appropriate value for the source is returned to the
ANSYS 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 = -CON*C_U(cell,thread); dS[eqn] = -CON; } else { source = dS[eqn] = 0.; } return source; } |
To make use of this UDF in ANSYS FLUENT, you will first need to interpret (or compile) the function, and then hook it to ANSYS FLUENT using the graphical user interface. Follow the procedure for interpreting source files using the Interpreted UDFs dialog box (Section 4.2), or compiling source files using the Compiled UDFs dialog box (Section 5.2).
To include source terms in the calculation, you will first need to open the Fluid dialog box (Figure 8.2.13) by selecting the fluid zone in the Cell Zone Conditions task page and clicking Edit....
Cell Zone Conditions
fluid-8
Edit...
Enable the Source Terms option in the Fluid dialog box and click the Source Terms tab. This will display the momentum source term parameters in the scrollable window. Then, click the Edit... button next to the X Momentum source term to open the X Momentum sources dialog box (Figure 8.2.14).
Enter 1 for the Number of Momentum sources in the X Momentum sources dialog box and then select the function name for the UDF ( udf cell_x_source) in the drop-down list that appears. (Note that the name that is displayed in the drop-down lists is your UDF name preceded by the word udf.) Click OK to accept the new cell zone condition and close the dialog box. The X Momentum parameter in the Fluid dialog box will now display 1 source. Click OK to fix the new momentum source term for the solution calculation and close the Fluid dialog box.
After 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.15).
Contours of velocity magnitude (Figure 8.2.16) 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.17).
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.2-1.