You are now ready to interpret or compile the profile UDF (named
inlet_x_velocity) that you created in Step
2 and that is contained within the source file named udfexample.c. In general, you must compile your function
as a compiled UDF if the source code contains structured reference
calls or other elements of C that are not handled by the ANSYS Fluent interpreter.
To determine whether you should compile or interpret your UDF, see
Differences Between Interpreted and Compiled UDFs.
Follow the procedure below to interpret your source file in ANSYS Fluent. For more information on interpreting UDFs, see Interpreting UDFs.
Important: Note that this step does not apply to Windows parallel networks. See Interpreting a UDF Source File Using the Interpreted UDFs Dialog Box for details.
Open the Interpreted UDFs dialog box.
Parameters & Customization → User Defined Functions
Interpreted...
In the Interpreted UDFs dialog box, indicate the UDF source file you want to interpret by clicking the Browse... button. This will open the Select File dialog box (Figure 8.5: The Select File Dialog Box).
In the Select File dialog box, select the desired file (for example, udfexample.c) and click . The Select File dialog box will close and the complete path to the file you selected will appear in the Source File Name field in the Interpreted UDFs dialog box (Figure 8.4: The Interpreted UDFs Dialog Box).
In the Interpreted UDFs dialog box, specify the C preprocessor to be used in the CPP Command Name field. You can keep the default cpp or you can select Use Contributed CPP to use the preprocessor supplied by ANSYS Fluent.
Keep the default Stack Size setting
of 10000, unless the number of local variables
in your function will cause the stack to overflow. In this case, set
the Stack Size to a number that is greater than
the number of local variables used.
If you want a listing of assembly language code to appear in your console when the function interprets, enable the Display Assembly Listing option. This option will be saved in your case file, so that when you read the case in a subsequent ANSYS Fluent session, the assembly code will be automatically displayed.
Click Interpret to interpret your UDF. If the Display Assembly Listing option was enabled, then the assembly code will appear in the console when the UDF is interpreted, as shown below.
inlet_x_velocity:
.local.pointer thread (r0)
.local.int position (r1)
0 .local.end
0 save
.local.int x (r3)
1 begin.data 8 bytes, 0 bytes initialized:
.local.float y (r4)
5 push.float 0
.local.float h (r5)
. .
. .
. .
142 pre.inc.int f (r6)
144 pop.int
145 b .L3 (28)
.L2:
147 restore
148 restore
149 ret.v
Important: Note that if your compilation is unsuccessful, then ANSYS Fluent will report an error and you will need to debug your program. See Common Errors Made While Interpreting A Source File for details.
Click Close when the interpreter has finished.
Write the case file. The interpreted UDF will be saved with the case file so that the function will be automatically interpreted whenever the case is subsequently read.
You can compile your UDF using the text user interface (TUI) or the graphical user interface (GUI) in ANSYS Fluent. The GUI option for compiling a source file on a Windows system is discussed below. For details about compiling on other platforms, using the TUI to compile your function, or for general questions about compiling UDFs in ANSYS Fluent, see Compiling UDFs.
As mentioned previously, make sure that you have started ANSYS Fluent in Windows using Fluent Launcher with the following settings:
Specify the folder that contains your case, data, and UDF source files in the Working Directory field in the General Options tab.
Make sure that the batch file for the UDF compilation environment settings is correctly specified in the Environment tab (see Compilers for further details).
Open the Compiled UDFs dialog box (Figure 8.6: The Compiled UDFs Dialog Box).
Parameters & Customization → User Defined Functions
Compiled...
Click Add... under Source Files in the Compiled UDFs dialog box. This will open the Select File dialog box (Figure 8.7: The Select File Dialog Box).
In the Select File dialog box,
select the file (for example, udfexample.c) you want to compile. The complete path to the source file will
then be displayed under Source File(s). Click . The Select File dialog box will
close and the file you added will appear in the Source Files list in the Compiled UDFs dialog box.
In a similar manner, select the Header Files that need to be included in the compilation.
In the Compiled UDFs dialog box, type the name of the shared library in the Library Name field (or leave the default name libudf). Click . This process will compile the code and will build a shared library in your working folder for the architecture you are running on.
As the compile/build process begins, a Question dialog box will appear, reminding you that the
UDF source file must be in the folder that contains your case and
data files (that is, your working folder). If you have an existing
library folder (for example, libudf), then you
will need to delete it prior to the build to ensure that the latest
files are used. Click to close the dialog
box and resume the compile/build process. The results of the build
will be displayed in the console. You can view the compilation history
in the log file that is saved in your working
folder.
Important: If the compile/build is unsuccessful, then ANSYS Fluent will report an error and you will need to debug your program before continuing. See Common Errors When Building and Loading a UDF Library for a list of common errors.
Click Load to load the shared
library into ANSYS Fluent. The console will report that the library has
been opened and the function (for example, inlet_x_velocity) loaded.
Opening library "E:\libudf"... Library "E:\libudf\win64\3d_host\libudf.dll" opened Opening library "E:\libudf"... Library "E:\libudf\win64\3d_node\libudf.dll" opened inlet_x_velocity Done.
See Compiling UDFs for more information on the compile/build process.