Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
examples
1. Steady velocity function
A UDF is used to introduce this parabolic profile at the inlet. The C source code ( vprofile.c) is shown
below. The function makes use of Fluent-provided solver
functions that are described in Section 5.3.
/***********************************************************************/
/* vprofile.c
*/
/* UDF for specifying steady-state velocity profile boundary condition */
/***********************************************************************/
#include "udf.h"
DEFINE_PROFILE(inlet_x_velocity, thread, position)
{
real x[ND_ND];
/* this will hold the position vector */
real y;
face_t f;
begin_f_loop(f, thread)
{
F_CENTROID(x,f,thread);
y = x[1];
F_PROFILE(f, thread, position) = 20. - y*y/(.0745*.0745)*20.;
}
end_f_loop(f, thread)
}
The function, named inlet_x_velocity, is defined using DEFINE_PROFILE and has two arguments: thread
and position. Thread is a pointer to the face's
thread, and position is an integer that is a numerical label for the variable being set within each loop.
The function begins by declaring variable f as a face_t data type. A one-dimensional array x and variable y
are declared as real data types. A looping macro is
then used to loop over each face in the zone to create a profile, or an array of data. Within each loop,
F_CENTROID outputs the value of the face centroid (array x)
for the face with index f that is on the thread pointed to by thread. The y coordinate stored in x[1] is
assigned to variable y, and is then used to calculate the x
velocity. This value is then assigned to F_PROFILE, which uses the integer position (passed to it by the
solver based on your selection of the UDF as the
boundary condition for x velocity in the Velocity Inlet panel) to set the x velocity face value in memory.
To make use of this interpreted UDF in FLUENT, you must first compile it.
Define User-Defined Functions Interpreted...
In the Interpreted UDFs panel, name your function in the Source File Name field. If necessary, enter your C
preprocessor type in the CPP Command Name
field and the size of the stack under Stack Size. Turn on Display Assembly Listing to see an assembly
listing in your console window as the function compiles.
Click on Compile and then Close the panel.
To select this user-defined function as the velocity boundary condition for the zone of choice, open the
Velocity Inlet panel.
In the X-Velocity drop-down list, select udf inlet_x_velocity, the name that was given to the function
above. This function will now be used, rather than the value
of (in this example) 0 that appears in the X-Velocity field. Click on OK to accept the new boundary
condition and close the panel.
In this example, a temporally periodic velocity boundary condition will be applied to the inlet of a tube
using a UDF. The velocity has the form
(10.1.1)
The tube is 1 m long with a radius of 0.2 m. It is assumed to be filled with air with a density of 1 kg/m 3and
a viscosity of 2 kg/m-s. The velocity of the air
fluctuates about an equilibrium value, v 0, of 20 m/s, with an amplitude of 5 m/s and at a frequency of 10
rad/s.
Before you can compile this UDF, you must specify an unsteady flow calculation in the Solver panel.
Define Models Solver...
Next you can open the Interpreted UDFs panel. Enter the name of the function in the text entry box under
Source File Name and, if necessary, the name of your
C preprocessor. Turn on Display Assembly Listing. Click on Compile and then Close the panel.
Define User-Defined Functions Interpreted...
The sinusoidal velocity boundary condition defined by the UDF can now be selected for the X-Velocity in
the inlet zone. In the Velocity Inlet panel, simply select
udf unsteady_velocity in the drop-down list to the right of the X-Velocity field, and click on OK.
3. Momentum Source :
/******************************************************************/
/* UDF that adds momentum source term and derivative to duct flow */
/******************************************************************/
#include "udf.h"
#define CON
20.0
(10.3.1)
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.
/*********************************************************************/
/* 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;
}
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.
To make use of a user-defined property, you will use the Materials panel. In the drop-down list for
Viscosity, select the user-defined option.
Once you select this option, the User-Defined Functions panel opens, from which you can select the
appropriate function name. In this example, only one is
available, but in another example, you might have several functions from which to choose. (Recall that if
you need to compile more than one interpreted UDF, the
functions can be concatenated prior to compiling. See Section 7.2.1 for details.)
DEFINE_ADJUST(htc_adjust, domain)
{
/* Define the heat transfer coefficient. */
h = 120;
}
DEFINE_HEAT_FLUX(heat_flux, f, t, c0, t0, cid, cir)
{
cid[0] = 0.;
cid[1] = h;
cid[2] = h;
cid[3] = 0.;
}