[ANSYS, Inc. Logo] return to home search
next up previous contents index

5.2 Compiling a UDF Using the GUI

The general procedure for compiling a UDF source file and building a shared library for the resulting objects, and loading the compiled UDF library into ANSYS FLUENT using the graphical user interface (GUI) is as follows.

figure   

Note that in order to compile a UDF when running serial or parallel ANSYS FLUENT on a Windows system, then you must have Microsoft Visual Studio installed on your machine, preferably on the C: drive.

1.   Make sure that the UDF source file you want to compile is in the same folder that contains your case and data files.

figure   

Note that if you wish to compile a UDF while running ANSYS FLUENT on a Windows parallel network , then you must `share' the working folder where the UDF is located so that all computers on the cluster can see this folder. To share the working folder, open Windows Explorer and browse to the folder; right-click on the working folder, select Sharing and Security from the menu, click Share this folder, and click OK. If you forget to enable the sharing option for the folder using Windows Explorer, then ANSYS FLUENT will hang when you try to load the library in the Compiled UDFs dialog box.

2.   For UNIX/Linux, start ANSYS FLUENT from the directory that contains your case, data, and UDF source files. For Windows, start ANSYS FLUENT using FLUENT Launcher with the following settings:

  • Specify the folder that contains your case, data, and UDF source files in the Working Directory text box in the General Options tab.

  • Make sure that the batch file for the UDF compilation environment settings is correctly specified in the UDF Compiler tab (see Section  5.1.2 for further details).

3.   Read (or set up) your case file.

4.   Open the Compiled UDFs dialog box (Figure  5.2.1).

Define $\rightarrow$ User-Defined $\rightarrow$ Functions $\rightarrow$ Compiled...

Figure 5.2.1: The Compiled UDFs Dialog Box
figure

5.   In the Compiled UDFs dialog box click on Add... under Source Files to select the UDF source file (or files) you want to compile. This will open the Select File dialog box (shown in Figure  5.2.2).

Figure 5.2.2: The Select File Dialog Box
figure

6.   In the Select File dialog box, click the names of all of the desired files (e.g., udfexample.c), so that the complete paths to the source files are displayed under Source File(s). You can remove a selection by clicking the path in Source File(s) list and then clicking the Remove button. Click OK when your selections are complete.

The Select File dialog box will close and the file you selected (e.g., udfexample.c) will appear in the Source Files list in the Compiled UDFs dialog box (Figure  5.2.3). You can delete a file after adding it by selecting the source file and then clicking Delete in the Compiled UDFs dialog box.

Figure 5.2.3: The Compiled UDFs Dialog Box
figure

7.   In the Compiled UDFs dialog box, select additional header files that you want to include in the compilation by clicking Add... under Header File(s) and repeat the previous step.

8.   In the Compiled UDFs dialog box (Figure  5.2.3), enter the name of the shared library you want to build in the Library Name field (or leave the default name libudf), and click Build. All of the UDFs that are contained within each C source file you selected will be compiled and the build files will be stored in the shared library you specified (e.g., libudf).

As the compile/build process begins, a Warning dialog box (Figure  5.2.4) will appear reminding you that the source file(s) need to be in the same folder as the case and data files. Click OK to close the dialog and continue with the build.

Figure 5.2.4: The Warning Dialog Box
figure

As the build process progresses, the results of the build will be displayed on the console. You can also view the compilation history in the log file that is saved in your working folder.

Console messages for a successful compile/build for a source file named udfexample.c and a UDF library named libudf for a Windows architecture are shown below.

Deleted old libudf\ntx86\2d\libudf.dll
        1 file(s) copied.
(system "copy C:\Program Files\ANSYS Inc\v120\fluent\fluent12.0.9\src
\makefile_nt.udf 
libudf\ntx86\2d\makefile")
        1 file(s) copied.
(chdir "libudf")()
(chdir "ntx86\2d")()
udfexample.c
# Generating udf_names.c because of makefile udfexample.obj
udf_names.c
# Linking libudf.dll because of makefile user_nt.udf udf_names.obj
 udfexample.obj
Microsoft (R) Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation.  All rights reserved.

   Creating library libudf.lib and object libudf.exp

Done.

9.   In the Compiled UDFs dialog box (Figure  5.2.3), load the shared library that was just built into ANSYS FLUENT by clicking Load.

A message will be displayed on the console providing a status of the load process. For example:

"Z:/mywork"

Opening library "libudf"...
Library "libudf\ntx86\2d\libudf.dll" opened
	inlet_x_velocity
Done.

indicates that the shared library named libudf was successfully loaded (on a Windows machine) and it contains one function named inlet_x_velocity.

figure   

Note that compiled UDFs are displayed in ANSYS FLUENT dialog boxes with the associated UDF library name using the :: identifier. For example, a compiled UDF named inlet_x_velocity that is associated with a shared library named libudf will appear in ANSYS FLUENT dialog boxes as inlet_x_velocity::libudf. This visually distinguishes UDFs that are compiled from those that are interpreted.

After the compiled UDF(s) become visible and selectable in graphics dialog boxes in ANSYS FLUENT, they can be hooked to your model. See Chapter  6 for details. You can use the UDF Library Manager dialog box to unload the shared library, if desired. See Section  5.5 for details.

10.   Write the case file if you want the compiled function(s) in the shared library to be saved with the case. The functions will be loaded automatically into ANSYS FLUENT whenever the case is subsequently read.

figure   

If you do not want the shared library saved with your case file, then you must remember to load it into ANSYS FLUENT using the Compiled UDFs dialog box or the UDF Library Manager dialog box in subsequent sessions.


next up previous contents index Previous: 5.1.2 Compilers
Up: 5. Compiling UDFs
Next: 5.3 Compile a UDF
Release 12.0 © ANSYS, Inc. 2009-01-14