Compiled UDFs are built in the same way that the ANSYS Fluent executable itself is built.
Internally, a script called Makefile is used to invoke the system C
compiler to build an object code library that contains the native machine language translation
of your higher-level C source code. The object library is specific to the computer
architecture being used during the ANSYS Fluent session, as well as to the particular version of
the ANSYS Fluent executable being run. Therefore, UDF object libraries must be rebuilt any time
ANSYS Fluent is upgraded, when the computer’s operating system level changes, or when the
job is run on a different type of computer architecture. The generic process for compiling a
UDF involves two steps: compile/build and load.
The compile/build step takes one or more source files (for example,
myudf.c) containing at least one UDF and compiles them into object
files (for example, myudf.o or myudf.obj) and then
builds a “shared library” (for example, libudf) with
the object files. If you compile your source file using the GUI, this compile/build process is
executed when you click in the Compiled UDFs
dialog box. The shared library that you name (for example, libudf) is
automatically built for the architecture and version of ANSYS Fluent you are running during that
session (for example, lnam64/2d_host and
lnam64/2d_node), and will store the UDF object file(s).
If you compile your source file using the TUI, you must first set up target folders for
the shared libraries, modify a file named Makefile to specify source
parameters, and then execute the Makefile which directs the
compile/build process. Compiling a UDF using the TUI has the added advantage of allowing
precompiled object files derived from non-ANSYS Fluent sources to be linked to ANSYS Fluent (Link Precompiled Object Files From Non-ANSYS Fluent Sources). This option is not available using the
GUI.
After the shared library is built (using the TUI or GUI), you load the UDF library into
ANSYS Fluent before you can use it. You can do this using the Load button in
the Compiled UDFs dialog box. After being loaded, all of the compiled
UDFs that are contained within the shared library will become visible and selectable in
graphics dialog boxes in ANSYS Fluent. Note that compiled UDFs are displayed in ANSYS Fluent dialog
boxes with the associated UDF library name separated by two colons
(::). For example, a compiled UDF named
rrate that is associated with a shared library named
libudf would appear in ANSYS Fluent dialog boxes as
rrate::libudf. This distinguishes UDFs that are compiled from those
that are interpreted.
If you write your case file when a UDF library is loaded, the library will be saved with the case and will be automatically loaded whenever that case file is subsequently read. This process of “dynamic loading” saves you having to reload the compiled library every time you want to run a simulation.
Before you compile your UDF source file(s) using one of the two methods provided in Compiling a UDF Using the GUI and Compile a UDF Using the TUI, you must make sure that the udf.h header file is accessible in your path, or is saved locally within your working folder (Location of the udf.h File).
For more information, see the following sections: