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

A.14 Preprocessor Directives

The UDF interpreter supports C preprocessor directives including #define and #include.



Macro Substitution Directive Using #define


When you use the #define macro substitution directive, the C preprocessor (e.g., cpp) performs a simple substitution and expands the occurrence of each argument in macro using the replacement-text.

#define macro replacement-text

For example, the macro substitution directive given by

#define RAD 1.2345
will cause the preprocessor to replace all instances of the variable RAD in your UDF with the number 1.2345. There may be many references to the variable RAD in your function, but you only have to define it once in the macro directive; the preprocessor does the work of performing the substitution throughout your code.

In another example

#define AREA_RECTANGLE(X,Y) ((X)*(Y))

all of the references to AREA_RECTANGLE(X,Y) in you UDF are replaced by the product of (X) and (Y).



File Inclusion Directive Using #include


When you use the #include file inclusion directive, the C preprocessor replaces the line #include filename with the contents of the named file.

#include " filename "

The file you name must reside in your current folder. The only exception to this rule is the udf.h file, which is read automatically by the ANSYS FLUENT solver.

For example, the file inclusion directive given by

#include "udf.h"

will cause the udf.h file to be included with your source code.

The ANSYS FLUENT solver automatically reads the udf.h file from the following folder:

path $\backslash$ ANSYS Inc $\backslash$ v120 $\backslash$ fluent $\backslash$ fluent12.0. $\stackrel{\Downarrow}{x} \backslash$ src $\backslash$ udf.h

where path is the folder in which you have installed ANSYS FLUENT (by default, the path is C: $\backslash$ Program Files), and $x$ is replaced by the appropriate number for the release (e.g., 9 for fluent12.0.9). .


next up previous contents index Previous: A.13.3 Standard I/O Functions
Up: A. C Programming Basics
Next: A.15 Comparison with FORTRAN
Release 12.0 © ANSYS, Inc. 2009-01-14