A user-defined function, or UDF, is a function that you program that can be dynamically loaded with the ANSYS FLUENT solver to enhance the standard features of the code. For example, you can use a UDF to define your own boundary conditions, material properties, and source terms for your flow regime, as well as specify customized model parameters (e.g., DPM, multiphase models), initialize a solution, or enhance postprocessing. See Section 1.2 for more examples.
UDFs are written in the C programming language using any text editor and the source code file is saved with a .c extension (e.g., myudf.c). One source file can contain a single UDF or multiple UDFs, and you can define multiple source files. See Appendix A for some basic information on C programming.
UDFs are defined using DEFINE macros provided by ANSYS FLUENT (see Chapter 2). They are coded using additional macros and functions also supplied by ANSYS FLUENT that access ANSYS FLUENT solver data and perform other tasks. See Chapter 3 for details.
Every UDF must contain the udf.h file inclusion directive ( #include "udf.h") at the beginning of the source code file, which allows definitions of DEFINE macros and other ANSYS FLUENT-provided macros and functions to be included during the compilation process. See Section 1.4.1 for details. Note that values that are passed to a solver by a UDF or returned by the solver to a UDF are specified in SI units.
Source files containing UDFs can be either interpreted or compiled in ANSYS FLUENT. For interpreted UDFs, source files are interpreted and loaded directly at runtime, in a single-step process. For compiled UDFs, the process involves two separate steps. A shared object code library is first built and then it is loaded into ANSYS FLUENT. See Chapter 4 and Chapter 5. After being interpreted or compiled, UDFs will become visible and selectable in ANSYS FLUENT dialog boxes, and can be hooked to a solver by choosing the function name in the appropriate dialog box. This process is described in Chapter 6.
In summary, UDFs: