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 Figure 1.2: Solution Procedure for the Pressure-Based Segregated Solver, Figure 1.3: Solution Procedure for the Pressure-Based Coupled Solver, and Figure 1.4: Solution Procedure for the Density-Based Solver.
DEFINE_INIT (name, d)
|
Argument Type |
Description |
|
|
UDF name. |
|
|
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.
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 Additional Macros for Writing UDFs for a description of predefined macros such as C_CENTROID and ND_SUM.
After the UDF that you have defined using DEFINE_INIT is interpreted (Interpreting UDFs)
or compiled (Compiling UDFs), the name
of the argument that you supplied as the first DEFINE macro argument (for example, 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 Hooking DEFINE_INIT UDFs for details.