![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Description
DEFINE_INIT is a general-purpose macro that you can use to specify a set of initial values for your solution. DEFINE_INIT accomplishes the same result as patching, but does it in a different way, by means of a UDF. A DEFINE_INIT function is executed once per initialization and is called immediately after the default initialization is performed by the solver. Since it is called after the flow field is initialized, it is typically used to set initial values of flow quantities. For an overview of the ANSYS FLUENT solution process which shows when a DEFINE_INIT UDF is called, refer to Figures 1.9.1, 1.9.2, and 1.9.3.
Usage
DEFINE_INIT( name, d) |
Argument Type | Description |
symbol name | UDF name. |
Domain *d | Pointer to the domain over which the initialization function is |
to be applied. The domain argument provides access to all cell | |
and face threads in the mesh. For multiphase flows, the pointer | |
that is passed to the function by the solver is the mixture-level | |
domain. | |
Function returns | |
void | |
There are two arguments to DEFINE_INIT: name and d. You supply name, the name of the UDF. d is passed from the ANSYS FLUENT solver to your UDF.
Example
The following UDF, named my_init_func, initializes flow field variables in a solution. It is executed once, at the beginning of the solution process. The function can be executed as an interpreted or compiled UDF in ANSYS FLUENT.
/*********************************************************************** UDF for initializing flow field variables ************************************************************************/ #include "udf.h" DEFINE_INIT(my_init_func,d) { cell_t c; Thread *t; real xc[ND_ND]; /* loop over all cell threads in the domain */ thread_loop_c(t,d) { /* loop over all cells */ begin_c_loop_all(c,t) { C_CENTROID(xc,c,t); if (sqrt(ND_SUM(pow(xc[0] - 0.5,2.), pow(xc[1] - 0.5,2.), pow(xc[2] - 0.5,2.))) < 0.25) C_T(c,t) = 400.; else C_T(c,t) = 300.; } end_c_loop_all(c,t) } } |
The macro ND_SUM(a,b,c) computes the sum of the first two arguments (2D) or all three arguments (3D). It is useful for writing functions involving vector operations so that the same function can be used for 2D and 3D. For a 2D case, the third argument is ignored. See Chapter 3 for a description of predefined macros such as C_CENTROID) and ND_SUM.
Hooking an Initialization UDF to
ANSYS FLUENT
After the UDF that you have defined using DEFINE_INIT is interpreted (Chapter 4) or compiled (Chapter 5), the name of the argument that you supplied as the first DEFINE macro argument (e.g., my_init_func) will become visible and selectable via the User-Defined Function Hooks dialog box in ANSYS FLUENT. Note that you can hook multiple init functions to your model. See Section 6.1.5 for details.