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

8.1.5 Step 4: Interpret or Compile the Source File

You are now ready to interpret or compile the profile UDF (named inlet_x_velocity) that you created in Step 2 and is contained within the source file named myexample.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 Section  1.5.1.



Interpret the Source File


Follow the procedure below to interpret your source file in ANSYS FLUENT. For more information on interpreting UDFs, see Chapter  4.

figure   

Note that this step does not apply to Windows parallel networks. See Section  4.2 for details.

1.   Open the Interpreted UDFs dialog box.

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

Figure 8.1.4: The Interpreted UDFs Dialog Box
figure

2.   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.1.5).

Figure 8.1.5: The Select File Dialog Box
figure

In the Select File dialog box, select the desired file (e.g., myexample.c) and click OK. The Select File dialog box will close and the complete path to the file you selected will appear in the Source File Name text box in the Interpreted UDFs dialog box (Figure  8.1.4).

3.   In the Interpreted UDFs dialog box, specify the C preprocessor to be used in the CPP Command Name text box. You can keep the default cpp or you can select Use Contributed CPP to use the preprocessor supplied by ANSYS FLUENT.

4.   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.

5.   Enable the Display Assembly Listing option if you want a listing of assembly language code to appear in your console when the function interprets. 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.

6.   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

figure   

Note that if your compilation is unsuccessful, then ANSYS FLUENT will report an error and you will need to debug your program. See Section  4.3 for details.

7.   Click Close when the interpreter has finished.

8.   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.



Compile the Source File


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 Chapter  5.

1.   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 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).

2.   Open the Compiled UDFs dialog box (Figure  8.1.6).

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

Figure 8.1.6: The Compiled UDFs Dialog Box
figure

3.   Click Add... under Source Files in the Compiled UDFs dialog box . This will open the Select File dialog box (Figure  8.1.7).

Figure 8.1.7: The Select File Dialog Box
figure

In the Select File dialog box, select the desired file (e.g., udfexample.c) you want to compile. The complete path to the source file will then be displayed under Source File(s). Click OK. 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.

4.   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 Build. 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 Warning dialog box will appear, reminding you that the UDF source file must be in the folder that contains your case and data files (i.e., your working folder). If you have an existing library folder (e.g., libudf) then you will need to remove it prior to the build, to ensure that the latest files are used. Click OK 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.

figure   

If the compile/build is unsuccessful, then ANSYS FLUENT will report an error and you will need to debug your program before continuing. See Section  5.6 for a list of common errors.

5.   Click Load to load the shared library into ANSYS FLUENT. The console will report that the library has been opened and the function (e.g., inlet_x_velocity) loaded.

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

See Chapter  5 for more information on the compile/build process.


next up previous contents index Previous: 8.1.4 Step 3: Start
Up: 8.1 Step-By-Step UDF Example
Next: 8.1.6 Step 5: Hook
Release 12.0 © ANSYS, Inc. 2009-01-14