Академический Документы
Профессиональный Документы
Культура Документы
Once you have written your UDF using any text editor and have saved it with a .c extension in your working directory, you are now ready to interpret it. Follow the instructions in Section 7.2: Interpreting a UDF Source File Using the Interpreted UDFs Panel to interpret your UDF source le. Once interpreted, the UDF function name(s) will appear in drop-down lists in graphical panels in FLUENT, ready for you to hook to your CFD model. Alternatively, you can compile your UDF source le. See Chapter 8: Compiling UDF Source Files for details. Section 7.1: Introduction Section 7.2: Interpreting a UDF Source File Using the Interpreted UDFs Panel Section 7.3: Common Errors Made While Interpreting A Source File Section 7.4: Special Considerations for Parallel FLUENT
7.1
Introduction
An interpreted UDF is a function that is interpreted directly from a source le (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 le (e.g., udfexample.c) in a single step. Once a source le is interpreted, you can write the case le 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 le is subsequently read. Once interpreted (either manually through the Interpreted UDFs panel or automatically upon reading a case le), all of the interpreted UDFs that are contained within a source le 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 eortlessly between dierent architectures, operating systems, and FLUENT versions. If execution speed does become an issue, an interpreted UDF can always be run in compiled mode without modication.
7-1
7.1.1
UDFs are dened using DEFINE macros (see Chapter 4: Dening a UDF Using a DEFINE Macro) and the denitions for DEFINE macros are included in udf.h header le. Consequently, before you can interpret a UDF source le, udf.h will need to be accessible in your path, or saved locally within your working directory. The location of the udf.h le is: path/Fluent.Inc/fluent6.x/src/udf.h 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).
In general, you should not copy udf.h from the installation area. The compiler is designed to look for this le locally (in your current directory) rst. 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 le. You should not, under any circumstances, alter the udf.h le.
i
7.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
7-2
7.2 Interpreting a UDF Source File Using the Interpreted UDFs Panel
7.2
If you are running the parallel version of FLUENT on a network of Windows machines, you must share the working directory that contains your UDF source, case, and data les so that all of the compute nodes in the cluster can see it. To do this:
(a) Open the Windows Explorer application, right click on the folder for the working directory (e.g., mywork), select the Sharing... option, and specify a Share Name (e.g., mywork). 2. Start FLUENT from your working directory. 3. Read (or set up) your case le. 4. Open the Interpreted UDFs panel (Figure 7.2.1). Dene User-Dened Functions Interpreted...
7-3
5. In the Interpreted UDFs panel, select the UDF source le you want to interpret by either typing the complete path in the Source File Name eld or click Browse.... This will open the Select File panel (Figure 7.2.2).
6. In the Select File panel, highlight the directory path under Directories (e.g., /nfs/homeserver/home/clb/mywork/), and the desired le (e.g., udfexample.c) under Files. Once highlighted, the complete path to the source le will be displayed under Source File(s). Click OK The Select File panel will close and the complete path to the le you selected (e.g., udfexample.c) will appear under Source File Name in the Interpreted UDFs panel (Figure 7.2.1).
If you are running FLUENT on a network of Windows machines, you may need to type the les complete path in the Source File Name eld, instead of using the browser option. For example, to interpret udfexample.c that is located in a shared working directory named mywork, you would enter the following:
\\<fileserver>\mywork\udfexample.c
7-4
7.2 Interpreting a UDF Source File Using the Interpreted UDFs Panel
This text goes into the Source File Name eld in the Interpreted UDFs panel, replacing <fileserver> with the name of the computer on which your working directory (mywork) and source le (udfexample.c) are located.
7. In the Interpreted UDFs panel, specify the C preprocessor to be used in the CPP Command Name eld. You can keep the default cpp or you can select Use Contributed 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 overow. 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 language code to appear in your console window when the function interprets. This option will be saved in your case le, so that when you read the case in a subsequent FLUENT session, the assembly code will be automatically displayed. 10. Click Interpret to interpret your UDF. The results of the interpretation will be displayed in the console window. You can also view the compilation history in the log le that is saved in your working directory. The console message for a successful interpretation of a UDF named inlet x velocity is shown below.
7-5
inlet x velocity: .local.pointer thread (r0) .local.int nv (r1) 0 .local.end 0 save .local.int f (r3) 1 push.int 0 .local.pointer x (r4) 3 begin.data 8 bytes, 0 bytes initialized: 7 save . . . . . . 156 pre.inc.int f (r3) 158 pop.int 159 b .L3 (22) .L2: 161 restore 162 restore 163 ret.v
Note that if your compilation is unsuccessful, then FLUENT will report an error and you will need to debug your program. See Section 7.3: Common Errors Made While Interpreting A Source File.
11. Close the Interpreted UDFs panel when the interpreter has nished. 12. Write the case le 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 subsequently read. If the Display Assembly Listing option was chosen, then the assembly code will appear in the console window.
7-6
7.3
7.4
7-7
7-8