This section contains an application of a source term UDF. It is executed as an interpreted UDF in ANSYS Fluent.
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.1: Properties of the Liquid Metal) 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, , and has the
opposite sign:
(8–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, , depends only on the solution
variable,
. Its derivative
with respect to
is
(8–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–1 is called CON in the function, and it is given a numerical value
of 20 kg/-s, which will result in the desired units
of N/
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–1 (C_U returns
the value of the x 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.
Table 8.1: Properties of the Liquid Metal
|
Property |
Value |
|---|---|
|
Density |
8000 kg/ |
|
Viscosity |
5.5 |
|
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 = -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 (Interpreting a UDF Source File Using the Interpreted UDFs Dialog Box), or compiling source files using the Compiled UDFs dialog box (Compiling a UDF Using the GUI).
To include source terms in the calculation, you will first need to open the Fluid dialog box (Figure 8.22: The Fluid Dialog Box) by selecting the fluid zone in the Cell Zone Conditions task page and clicking .
Setup →
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 button next to the X Momentum source term to open the X Momentum sources dialog box (Figure 8.23: The X Momentum sources Dialog Box).
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 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 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.24: Temperature Contours Illustrating Liquid Metal Cooling).
Contours of velocity magnitude (Figure 8.25: Velocity Magnitude Contours Suggesting Solidification) 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.26: 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–1.