1.1. What is a User-Defined Function?

A user-defined function, or UDF, is a C or C++ function that can be dynamically loaded with the ANSYS Fluent solver to enhance its standard features. For example, you can use a UDF to:

UDFs are identified by a .c or .cpp extension (for example, myudf.c). One source file can contain a single UDF or multiple UDFs, and you can define multiple source files. See Appendix A: C Programming Basics for some basic information on C programming.

UDFs are defined using DEFINE macros provided by ANSYS Fluent (see DEFINE Macros). They are coded using additional macros and functions (also supplied by ANSYS Fluent) that access ANSYS Fluent solver data and perform other tasks. See Additional Macros for Writing UDFs for details.

Every UDF must contain the udf.h file inclusion directive (#include "udf.h") at the beginning of the source code file, which enables both the definition of DEFINE macros and other ANSYS Fluent-provided macros and functions, and their inclusion in the compilation process. See Including the udf.h Header File in Your Source File for details.

Source files containing UDFs can be either interpreted or compiled in ANSYS Fluent.

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 Hooking UDFs to ANSYS Fluent.

In summary, UDFs:


Release 18.2 - © ANSYS, Inc. All rights reserved.