Beruflich Dokumente
Kultur Dokumente
Interpreting UDFs
Once you have written your UDF using any text editor and have saved the source code file
it with a .c extension in your working directory, you are ready to interpret the source file.
Follow the instructions below in Section 4.2: Interpreting a UDF Source File Using the
Interpreted UDFs Panel. Once interpreted, the UDF function name(s) that you supplied
in the DEFINE macro(s) will appear in drop-down lists in graphical panels in FLUENT,
ready for you to hook to your CFD model. Alternatively, if you wish to compile your
UDF source file, see Chapter 5: Compiling UDFs for details.
• Section 4.2: Interpreting a UDF Source File Using the Interpreted UDFs Panel
4.1 Introduction
An interpreted UDF is a function that is interpreted directly from a source file (e.g.,
udfexample.c) at runtime. The process involves a visit to the Interpreted UDFs panel
where you can interpret all of the functions in a source file (e.g., udfexample.c) in a
single step. Once a source file is interpreted, you can write the case file and the names
and contents of the interpreted function(s) will be stored in the case. In this way, the
function(s) will be automatically interpreted whenever the case file is subsequently read.
Once interpreted (either manually through the Interpreted UDFs panel or automatically
upon reading a case file), all of the interpreted UDFs that are contained within a source
file will become visible and selectable in graphical user interface panel(s) in FLUENT.
Inside FLUENT, the source code is compiled into an intermediate, architecture-independent
machine code using a C preprocessor. This machine code then executes on an internal
emulator, or interpreter, when the UDF is invoked. This extra layer of code incurs a
performance penalty, but allows an interpreted UDF to be shared effortlessly between
different architectures, operating systems, and FLUENT versions. If execution speed
does become an issue, an interpreted UDF can always be run in compiled mode without
modification.
c Fluent Inc. September 11, 2006 4-1
Interpreting UDFs
where path is the directory in which you have installed the release directory, Fluent.Inc,
and x is replaced by the appropriate number for the release you have (e.g., 2 for
fluent6.2).
i In general, you should not copy udf.h from the installation area. The
compiler is designed to look for this file locally (in your current directory)
first. If it is not found in your current directory, the compiler will look
in the /src directory automatically. In the event that you upgrade your
release area, but do not remove an old copy of udf.h from your working
directory, you will not be accessing the most recent version of this file.
i You should not, under any circumstances, alter the udf.h file.
4.1.2 Limitations
Due to limitations in the interpreter used to compile interpreted UDF source code in
FLUENT, interpreted UDFs are limited in their use of the C programming language. In
particular, the following elements of C cannot be used in interpreted UDFs:
• goto statements
• non ANSI-C prototypes for syntax
• direct data structure references
• declarations of local structures
• unions
• pointers to functions
• arrays of functions
• multi-dimensional arrays
4-2
c Fluent Inc. September 11, 2006
4.2 Interpreting a UDF Source File Using the Interpreted UDFs Panel
4.2 Interpreting a UDF Source File Using the Interpreted UDFs Panel
This section presents the steps for interpreting a source file in FLUENT. Once interpreted,
the names of UDFs contained within the source file will appear in drop-down lists in
graphics panels in FLUENT.
The general procedure for interpreting a source file is as follows:
1. Make sure that the UDF source file is in the same directory that contains your case
and data files.
5. In the Interpreted UDFs panel, select the UDF source file you want to interpret by
either typing the complete path in the Source File Name field or click Browse....
This will open the Select File panel (Figure 4.2.2).
c Fluent Inc. September 11, 2006 4-3
Interpreting UDFs
6. In the Select File panel, highlight the directory path under Directories
(e.g., /nfs/homeserver/home/clb/mywork/ when running Linux), and the desired
file (e.g., udfexample.c) under Files. Once highlighted, the complete path to the
source file will be displayed under Source File(s). Click OK.
The Select File panel will close and the complete path to the file you selected (e.g.,
udfexample.c) will appear under Source File Name in the Interpreted UDFs panel
(Figure 4.2.1).
\\<fileserver>\mywork\udfexample.c
i This text goes into the Source File Name field in the
Interpreted UDFs panel, replacing <fileserver> with the name of
the computer on which your working directory (mywork) and source file
(udfexample.c) are located.
4-4
c Fluent Inc. September 11, 2006
4.2 Interpreting a UDF Source File Using the Interpreted UDFs Panel
7. In the Interpreted UDFs panel, specify the C preprocessor to be used in the CPP
Command Name field. You can keep the default cpp or you can select Use Con-
tributed CPP to use the preprocessor supplied by Fluent Inc.
If you installed the /contrib component from the “PrePost” CD, then by default,
the cpp preprocessor will appear in the panel. For Windows NT users, the standard
Windows NT installation of the FLUENT product includes the cpp preprocessor.
For Windows NT systems, if you are using the Microsoft compiler, then use the
command cl -E.
8. 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.
9. Keep the Display Assembly Listing option on if you want a listing of assembly lan-
guage code to appear in your console window when the function interprets. This
option will be saved in your case file, so that when you read the case in a subsequent
FLUENT session, the assembly code will be automatically displayed.
11. Close the Interpreted UDFs panel when the interpreter has finished.
12. Write the case file if you want the interpreted function(s) (e.g., inlet x velocity)
to be saved with the case, and automatically interpreted when the case is subse-
quently read. If the Display Assembly Listing option was chosen, then the assembly
code will appear in the console window.
c Fluent Inc. September 11, 2006 4-5
Interpreting UDFs
Error: /nfs/clblnx/home/clb/fluent/udfexample.c:
line 15: structure reference
4-6
c Fluent Inc. September 11, 2006
4.4 Special Considerations for Parallel FLUENT
You will need to see your system administrator to reset the FLUENT INC environment
variable.
c Fluent Inc. September 11, 2006 4-7
Interpreting UDFs
4-8
c Fluent Inc. September 11, 2006