[Fluent Inc. Logo] return to home search
next up previous contents index

8.2.2 Source Terms

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 $x$ component of the velocity, $v_x$, and has the opposite sign:

 S_x = - C v_x (8.2-1)

where $C$ 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, $S_x$, depends only on the solution variable, $v_x$. Its derivative with respect to $v_x$ is

 \frac{\partial S_x}{\partial v_x} = - C (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 $C$ in Equation  8.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  8.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.

Table 8.2.1: Properties of the Liquid Metal
Property Value
Density 8000 kg/m $^3$
Viscosity 5.5 $\times 10^{-3}$ kg/m-s
Specific Heat 680 J/kg-K
Thermal Conductivity 30 W/m-K

   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;
    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 $\rightarrow$ 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 drop-down list.(Note that the UDF name that is displayed in the drop-down 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.

Figure 8.2.8: The Fluid Panel

Figure 8.2.9: The Fluid Panel

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).

Figure 8.2.10: Temperature Contours Illustrating Liquid Metal Cooling

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.

Figure 8.2.11: Velocity Magnitude Contours Suggesting Solidification

The solidification is further illustrated by line contours of stream function (Figure  8.2.12).

Figure 8.2.12: Stream Function Contours Suggesting Solidification

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.

next up previous contents index Previous: 8.2.1 Boundary Conditions
Up: 8.2 Detailed UDF Examples
Next: 8.2.3 Physical Properties
© Fluent Inc. 2006-09-13