![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Now that you have determined the shape of the velocity profile that defines the UDF, you can use any text editor to create a file containing C code that implements the function. Save the source code file with a .c extension (e.g., myexample.c) in your working folder. The following UDF source code listing contains only a single function. Your source file can contain multiple concatenated functions. (Refer to Appendix A for basic information on C programming.)
Below is an example of how the profile described in Step 1 can be implemented in a UDF. The functionality of the UDF is designated by the leading DEFINE macro. Here, the DEFINE_PROFILE macro is used to indicate to the solver that the code that follows will provide profile information at boundaries. Other DEFINE macros will be discussed later in this manual. (See Chapter 2 for details about DEFINE macro usage.)
/*********************************************************************** myexample.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, h; face_t f; h = 0.016; /* inlet height in m */ begin_f_loop(f,thread) { F_CENTROID(x, f, thread); y = 2.*(x[1]-0.5*h)/h; /* non-dimensional y coordinate */ F_PROFILE(f, thread, position) = 0.1*(1.0-y*y); } end_f_loop(f, thread) } |
The first argument of the
DEFINE_PROFILE macro,
inlet_x_velocity, is the name of the UDF that you supply. The name will appear in the boundary condition dialog box after the function is interpreted or compiled, enabling you to hook the function to your model. Note that the UDF name you supply cannot contain a number as the first character. The equation that is defined by the function will be applied to all cell faces (identified by
f in the face loop) on a given boundary zone (identified by
thread). The thread is defined automatically when you hook the UDF to a particular boundary in the
ANSYS FLUENT GUI. The index is defined automatically through the
begin_f_loop utility. In this UDF, the
begin_f_loop macro (Section
3.3) is used to loop through all cell faces in the boundary zone. For each face, the coordinates of the face centroid are accessed by
F_CENTROID (Section
3.2.4). The
coordinate
y is used in the parabolic profile equation and the returned velocity is assigned to the face through
F_PROFILE.
begin_f_loop and
F_PROFILE (Section
3.2.6) are
ANSYS FLUENT-supplied macros. Refer to Chapter
3 for details on how to utilize predefined macros and functions supplied by
ANSYS FLUENT to access
ANSYS FLUENT solver data and perform other tasks.