(4.3.11)
where U l is the laminar flame speed and u' is the turbulent fluctuation. Note that the partially premixed combustion model is assumed to be enabled (see Chapter 16 of the User's Guide), so that the unburned density and laminar flame speed are available as polynomials. See Chapter 6 for details on the NULLP, THREAD_STORAGE, and SV_VARS utilities.
/*******************************************************************/ /* UDF that specifies a custom turbulent flame speed and source */
/* for the premixed combustion model */
/*******************************************************************/
#include \
#include \ */
DEFINE_TURB_PREMIX_SOURCE(turb_flame_src, c, t, turb_flame_speed, source) {
real up = TRB_VEL_SCAL(c,t);
real ut, ul, grad_c, rho_u, DV[ND_ND];
ul = Ul_par_premix(C_FMEAN(c,t)); rho_u = rho_par_premix(C_FMEAN(c,t));
if( NNULLP(THREAD_STORAGE(t,SV_PREMIXC_G)) ) {
NV_V (DV, =, C_STORAGE_R_NV(c,t,SV_PREMIXC_G)); grad_c = sqrt( NV_DOT(DV, DV) ); }
ut = ul*sqrt( 1. + SQR(up/ul) );
*turb_flame_speed = ut; *source = rho_u*ut*grad_c; }
Activating a Turbulent Premixed Source UDF in FLUENT
Once you have compiled and linked the source code for a custom turbulent premixed source UDF, you can activate it in the User-Defined Function Hooks panel in FLUENT. See Section 8.2.5 for more details. 4.3.11 DEFINE_TURBULENT_VISCOSITY 功能和使用方法的介绍
你可以使用DEFINE_TURBULENT_VISOCITY macro to define a custom turbulent viscosity for the Spalart-Allmaras, k- , k- , and LES turbulence models.
Macro:
DEFINE_TURBULENT_VISCOSITY ( name, c, t)
Argument types: cell_t c
Thread *t
Function returns: real
There are three arguments to DEFINE_TURBULENT_VISCOSITY: name, c, and t. name is the name of the UDF, specified by you. 当你的UDF编译和连接时,你为函数所选择的名字会在FLUENT图形用户界面中变得可见,且可被选择。 c and t are variables that are passed by the FLUENT solver to your UDF. t is a pointer to the thread on which the turbulent viscosity is to be applied. c is an index that identifies a cell within the given thread. Your UDF will need to return the real value of the turbulent viscosity to the solver, as shown in the 例子: below. Note that the value of M_keCmu in the 例子: is defined through the graphical user interface, but made accessible to all UDFs. 例子:
下面的UDF名字为user_mu_t, defines a custom turbulent viscosity for the standard k- This function can be executed as an interpreted or compiled UDF in FLUENT. /********************************************************************/ /* UDF that specifies a custom turbulent viscosity for standard */
/* k-epsilon formulation using DEFINE_TURBULENT_VISCOSITY */ /********************************************************************/
#include \
DEFINE_TURBULENT_VISCOSITY(user_mu_t, c, t) {
real mu_t;
real rho = C_R(c,t); real k = C_K(c,t); real d = C_D(c,t);
mu_t = M_keCmu*rho*SQR(k)/d;
return mu_t;
turbulence model.
}
Activating a Turbulent Viscosity UDF in FLUENT
Once you have compiled and linked the source code for a custom turbulent viscosity UDF, you can activate it in the Viscous Model panel in FLUENT. See Section 8.2.9 for more details. 4.3.12 DEFINE_UDS_FLUX 功能和使用方法的介绍
你可以使用DEFINE_UDS_FLUX macro when you want to customize how the advective flux term is computed in your user-defined scalar (UDS) transport equation. Details on setting up and solving UDS transport equations are provided in Chapter 9.
Macro: DEFINE_UDS_FLUX ( name, f, t, i) Argument types: face_t f Thread *t int i Function returns: real
There are four arguments to DEFINE_UDS_FLUX: name, f, t, and i. name is the name of the UDF, specified by you. 当你的UDF编译和连接时,你为函数所选择的名字会在FLUENT图形用户界面中变得可见,且可被选择。 f, t, and i are variables that are passed by the FLUENT solver to your UDF.
t is a pointer to the thread on which the user-defined scalar flux is to be applied. f is an index that identifies a face within the given thread. i is an index that identifies the user-defined scalar. Your UDF will need to return the real value of the mass flow rate through the given face, as shown in the 例子: below. The advection term in the differential transport equation has the following most general form:
(4.3.12)
where is the user-defined scalar conservation quantity and is a vector field. In the default advection term,
is, by default, the product of the scalar density and the velocity vector:
(4.3.13)
To define the advection term in Equation 4.3-13 using DEFINE_UDS_FLUX, your UDF needs to return the scalar value
to FLUENT, where
is the same as defined in Equation 4.3-13 and is the face normal
vector of the face.
You will need to compute in your UDF using, for 例子:, predefined macros for velocity vector and scalar
density that Fluent has provided (see Chapter 6 for more details) or using your own prescription. The first case is illustrated in the sample C source code, shown below.
!! Note that if more than one scalar is being solved, you can use a conditional if statement in your UDF to define a different flux function for each i. i = 0 is associated with scalar-0 (the first scalar equation being solved).
!! Note also that must have units of mass flow rate in SI (i.e., kg/s).
/*********************************************************************/ /* sample C source code that computes dot product of psi and A */ /* Note that this is not a complete C function */
/*********************************************************************/
real NV_VEC(psi), NV_VEC(A); /* declaring vectors psi and A */ NV_D(psi, =, F_U(f,t), F_V(f,t), F_W(f,t)); /* defining psi in */
/* terms of velocity field */ NV_S(psi, *=, F_R(f,t)) /* multiplying density to get psi vector */
F_AREA(A, f, t) /* face normal vector returned from F_AREA */ return NV_DOT(psi, A); /* dot product of the two returned */
Additionally, since most quantities in FLUENT are not allocated in memory for interior faces, only for boundary faces (e.g., wall zones), your UDF will also need to calculate interior face values from the cell values
of adjacent cells. This is most easily done using the arithmetic mean method. Vector arithmetic can be coded in C using the NV_ and ND_ macros that Fluent has provided (see Chapter 6 for more details).
Note that if you had to implement the default advection term in a UDF without the fluid density in the definition of
(see above), you could simply put the following line in your DEFINE_UDS_FLUX UDF:
return F_FLUX(f,t) / rho;
where the denominator can be determined by averaging the adjacent cell's density values C_R(F_C0(f,t),F_C0_THREAD(f,t)) and C_R(F_C1(f,t),F_C1_THREAD(f,t)). 例子:
下面的UDF名字为my_uds_flux, returns the mass flow rate through the given face. This value is usually available within FLUENT through the F_FLUX(f,t) macro. The flux is positive when it goes from cell c0 to cell c1. The face flux normal vector always points from c0 to c1. Note that the face area normal vector (returned by F_AREA also points outwards (out of the domain) for boundary faces. The UDF can be executed as a compiled UDF in FLUENT.
/**********************************************************************/ /* UDF that implements a simplified advective term in the */ /* scalar transport equation */
/**********************************************************************/
#include \
DEFINE_UDS_FLUX(my_uds_flux, f, t, i) {
Thread *t0, *t1 = NULL; cell_t c0, c1 = -1;
real NV_VEC(psi_vec), NV_VEC(A);
/* neighboring cells of face f, and their (corresponding) threads */
t0 = F_C0_THREAD(f,t); c0 = F_C0(f,t);
if (NULL != F_C1_THREAD(f,t))
/* Alternative: if (! BOUNDARY_FACE_THREAD_P(t)) */ {
t1 = F_C1_THREAD(f,t); c1 = F_C1(f,t); } else {
t1 = NULL;