![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
This section contains an application of a physical property UDF. It is executed as an interpreted UDF in ANSYS FLUENT.
Solidification via a Temperature-Dependent Viscosity
UDFs for properties (as well as sources) are called from within a loop on cells. For this reason, functions that specify properties are only required to compute the property for a single cell, and return the value to the ANSYS FLUENT solver.
The UDF in this example generates a variable viscosity profile to simulate solidification, and is applied to the same problem that was presented in Section
8.2.2. The viscosity in the warm (
K) fluid has a molecular value for the liquid (5.5
kg/m-s), while the viscosity for the cooler region (
286 K) has a much larger value (1.0 kg/m-s). In the intermediate temperature range (286 K
288 K), the viscosity follows a linear profile (Equation
8.2-3) that extends between the two values given above:
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.
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.
/********************************************************************* 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; } |
This function can be executed as an interpreted or compiled UDF in ANSYS FLUENT. 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 make use of the user-defined property in ANSYS FLUENT, you will need to open the Create/Edit Materials dialog box (Figure 8.2.18) by selecting the liquid metal material in the Materials task page and clicking the Create/Edit... button..
Materials
liquid_metal
Create/Edit...
In the Create/Edit Materials dialog box, select user-defined in the drop-down list for Viscosity. This will open the User-Defined Functions dialog box (Figure 8.2.19), from which you can select the appropriate function name. In this example, only one option is available, but in other examples, you may have several functions from which to choose. (Recall that if you need to compile more than one interpreted UDF, the functions can be concatenated in a single source file prior to compiling.)
The results of this model are similar to those obtained in Section 8.2.2. Figure 8.2.20 shows the viscosity field resulting from the application of the user-defined function. The viscosity varies rapidly over a narrow spatial band from a constant value of 0.0055 to 1.0 kg/m-s.
The velocity field (Figure 8.2.21) demonstrates that the liquid slows down in response to the increased viscosity, as expected. In this model, there is a large "mushy'' region, in which the motion of the fluid gradually decreases. This is in contrast to the first model, in which a momentum source was applied and a more abrupt change in the fluid motion was observed.