You are on page 1of 3

AN OVERVIEW OF UDF CHAPTER 6

CHAPTER 6

AN OVERVIEW OF UDF
6.1 INTRODUCTION TO UDF
A user-defined function, or UDF, is a function that you program that can be dynamically
loaded with the FLUENT solver to enhance the standard features of the code .UDFs are written
in the C programming language. They are defined using DEFINE macros that are supplied by
Fluent Inc. They access data from the FLUENT solver using predefined macros and functions
also supplied by Fluent Inc .Every UDF contains the udf.h file inclusion directive(#include
“udf.h”) at the beginning of the source code file, which allows definition for DEFINE macros and
other Fluent-provided macros and functions to be included during the compilation process
.UDFs are executed as either interpreted or compiled functions in FLUENT .Values that are
passed to the solver by a UDF or returned by the solver to a UDF must be specified in SI units.
6.1.1 Use of UDF
UDF allows us to customize FLUENT to fit our particular modeling needs. UDFs
can be used for a variety of applications, some of which are listed below:
 Customization of boundary conditions, material property definitions, surface and volume
reaction rates, source terms in FLUENT transport equations, source terms in user
defined scalar (UDF) transport equations, diffusivity functions, etc.
 Adjustment of computed values on a once-per-iteration basis.
 Initialization of a solution
 Asynchronous execution of a UDF (on demand).
 Post-processing enhancement
 Enhancement of existing FLUENT models
6.1.2 Limitations
Although the UDF capability in FLUENT can address a wide range of application,
it is not possible to address every application using UDFs. Not all solution variables or

20
AN OVERVIEW OF UDF CHAPTER 6

FLUENT models can be accessed by UDFs. Specific heat values, for example, cannot
be modified; this would require additional solver capabilities.

6.2 STEP BY STEP PROCEDURE


There are seven steps to code a UDF and use it effectively in the FLUENT model.
Step 1: Define the problem:
The first step in creating a UDF and using it in your FLUENT model involves defining
the model equations.
Step 2: Create a C source file:
After determining the equation that defines our UDF, use any text editor to create a
text file containing C code. Save the source code file with a .c extension (e.g,
udfexample.c) in your working directory. The source code listing contains only a
single UDF or it may contain multiple concatenation functions.
Step 3: Start FLUENT and read in (or set up) the case file:
Once having created UDF, the next step is to begin the problem setup in FLUENT.
1. Start FLUENT from your working directory.
2. Read (or set up) your case file.
Step 4: Interpret the source file:
Now the UDF is interpreted, and is contained within the source file named
udfexample.c.
1. Open the Interpreted UDFs panel.
2. Specify the source file by either typing the Source File Name or clicking
Browse...to select the UDF source file name from the appropriate directory in
the Select File panel. Highlight the directory path under Directories, the
desired file (e.g., udfexample.c) under Files, and click OK.
3. 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 Fluent Inc.
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. Click Display Assembly Listing if you would like a listing of assembly language
code to appear in your console window as your function is interpreted.
6. Click Interpret to interpret your UDF.

21
AN OVERVIEW OF UDF CHAPTER 6

7. Click Close when the interpreter has finished.


8. Write the case file. The interpreted UDF, named inlet x velocity, will be saved
with the case file so that the function will be automatically interpreted whenever
the case is subsequently read. If the Display Assembly Listing option was
chosen, then the assembly code will appear in the console window upon reading.
Step 5: Hook the UDF to FLUENT.
Having interpreted the UDF, following the method outlined in Step 4, we now
hook the function to FLUENT using a graphical user interface panel.
Step 6: Run the calculation.
Run the calculation as usual.
Step 7: Analyze the numerical solution and compare it to expected results.
Once the solution is run to convergence,

22

You might also like