CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   global variable in udf (https://www.cfd-online.com/Forums/fluent/70352-global-variable-udf.html)

mohsen zendehbad November 21, 2009 11: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 14:16

Hi,
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:

http://hpce.iitm.ac.in/website/Manua...help/index.htm

mohsen zendehbad November 22, 2009 05:30

DEAR ENRY:
thank you for your swift response.

MOHSEN


All times are GMT -4. The time now is 22:24.