CFD Online Discussion Forums

CFD Online Discussion Forums (
-   FLUENT (
-   -   global variable in udf (

mohsen zendehbad November 21, 2009 12:03

global variable in udf
i am writing a DEFINE_SOURCE, how can i define a global variable in udf whose value doesn't reset by the repetition of the udf for each cell in the zone.

enry November 21, 2009 15:16

when you need a global variable you have to define that variable OUTSIDE of any single function, so the variable is visible to all functions within a UDF source file .I past to you a text that you can find in UDF guide.

Global variables are variables that are defined outside of any single function and are
visible to all function(s) within a UDF source file. Global variables can also be used
by other functions outside of the source file unless they are declared as static (see
Section A.5.3: Static Variables). Global variables are typically declared at the beginning
of a file, after preprocessor directives as in

#include "udf.h"
real volume; /* real variable named volume is declared globally */
DEFINE_ADJUST(compute_volume, domain)
/* code that computes volume of some zone */
volume = ....

Otherwise, If you have a global variable that is declared in one source code file, but a function in another source file needs to use it, then it must be defined in the other source file as an EXTERNAL variable.

See also:

mohsen zendehbad November 22, 2009 06:30

thank you for your swift response.


All times are GMT -4. The time now is 20:47.