Chapter 5: Compiling UDFs

After you have written your UDF(s) and have saved the source file with a .c extension in your working folder, you are ready to compile the UDF source file, build a shared library from the resulting objects, and load the library into Ansys Fluent. After being loaded, the function(s) contained in the library will appear in drop-down lists in dialog boxes, ready for you to hook to your CFD model. Follow the instructions in Compiling a UDF Using the GUI to compile UDF source files using the graphical user interface (GUI). Compile a UDF Using the TUI explains how you can use the text user interface (TUI) to do the same. The text interface option provides the added capability of enabling you to link precompiled object files derived from non-Ansys Fluent sources (for example, Fortran sources) to your UDF (Link Precompiled Object Files From Non-Ansys Fluent Sources). This feature is not available in the GUI. Load and Unload Libraries Using the UDF Library Manager Dialog Box describes how you can load (and unload) multiple UDF libraries using the UDF Library Manager dialog box. The capability of loading more than one UDF library into Ansys Fluent raises the possibility of data contention if multiple libraries use the same user-defined scalar (UDS) and user-defined memory (UDM) locations. These clashes can be avoided if libraries reserve UDS or UDM prior to usage. See Reserve_User_Scalar_Vars and Reserving UDM Variables Using Reserve_User_Memory_Vars , respectively, for details.


Note:  If the case file being read by Ansys Fluent uses a compiled UDF library, then Ansys Fluent looks for a corresponding library. If the library is missing, then Ansys Fluent will attempt to automatically compile the UDF library on the current platform. Also, if the UDF library is found to be outdated based on time stamps (that is, the UDF source or user.udf or user_nt.udf files are modified after the UDF library is compiled), then during the reading of the case, Ansys Fluent automatically recompiles the UDF library. Note the following:

  • All required source and header files should be kept alongside the mesh/case file in the same directory.

  • In order to save the compilation settings, you should load the mesh/case file first, then manually compile and load the UDF library, and save the case file. These settings can be removed by unloading the UDF library from the current session and then saving the case file.