![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Description
You can use DEFINE_UDS_FLUX to customize how the advective flux term is computed in your user-defined scalar (UDS) transport equations. See this section in the separate User's Guide for details on setting up and solving UDS transport equations.
Usage
DEFINE_UDS_FLUX( name,f,t,i) |
Argument Type | Description |
symbol name | UDF name. |
face_t f | Face index. |
Thread *t | Pointer to face thread on which the user-defined scalar flux |
is to be applied. | |
int i | Index that identifies the user-defined scalar for which the |
flux term is to be set. | |
Function returns | |
real | |
There are four arguments to DEFINE_UDS_FLUX: name, f, t, and i. You supply name, the name of the UDF. f, t, and i are variables that are passed by the ANSYS FLUENT solver to your UDF. Your UDF will need to return the real value of the mass flow rate through the given face to the solver.
The advection term in the differential transport equation has the following most general form:
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:
To define the advection term in Equation
2.7-1 using
DEFINE_UDS_FLUX, your UDF needs to return the scalar value
to
ANSYS FLUENT, where
is the same as defined in Equation
2.7-1 and
is the face normal vector of the face.
|
Note that the advective flux field that is supplied by your UDF should be divergence-free (i.e., it satisfies the continuity equation). In discrete terms this means that the sum of fluxes over all the faces of each cell should be zero. If the advective field is not divergence-free, then
![]() ![]()
|
You will need to compute
in your UDF using, for example, predefined macros for velocity vector and scalar density that
ANSYS FLUENT has provided (see Chapter
3) 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 =
![]()
|
|
Note also that
![]()
|
/********************************************************************* 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 */ /* defining psi in terms of velocity field */ NV_D(psi, =, F_U(f,t), F_V(f,t), F_W(f,t)); 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 ANSYS 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 (see Chapter 3).
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),THREAD_T0(t)) and
C_R(F_C1(f,t),THREAD_T1(t)).
Example
The following UDF, named my_uds_flux, returns the mass flow rate through a given face. The flux is usually available through the ANSYS FLUENT-supplied macro F_FLUX(f,t) (Section 3.2.4). The sign of flux that is computed by the ANSYS FLUENT solver is positive if the flow direction is the same as the face area normal direction (as determined by F_AREA - see Section 3.2.4), and is negative if the flow direction and the face area normal directions are opposite. By convention, face area normals always point out of the domain for boundary faces, and they point in the direction from cell c0 to cell c1 for interior faces.
The UDF must be executed as a compiled UDF.
/**********************************************************************/ /* UDF that implements a simplified advective term in the */ /* scalar transport equation */ /**********************************************************************/ #include "udf.h" DEFINE_UDS_FLUX(my_uds_flux,f,t,i) { cell_t c0, c1 = -1; Thread *t0, *t1 = NULL; real NV_VEC(psi_vec), NV_VEC(A), flux = 0.0; c0 = F_C0(f,t); t0 = F_C0_THREAD(f,t); F_AREA(A, f, t); /* If face lies at domain boundary, use face values; */ /* If face lies IN the domain, use average of adjacent cells. */ if (BOUNDARY_FACE_THREAD_P(t)) /*Most face values will be available*/ { real dens; /* Depending on its BC, density may not be set on face thread*/ if (NNULLP(THREAD_STORAGE(t,SV_DENSITY))) dens = F_R(f,t); /* Set dens to face value if available */ else dens = C_R(c0,t0); /* else, set dens to cell value */ NV_DS(psi_vec, =, F_U(f,t), F_V(f,t), F_W(f,t), *, dens); flux = NV_DOT(psi_vec, A); /* flux through Face */ } else { c1 = F_C1(f,t); /* Get cell on other side of face */ t1 = F_C1_THREAD(f,t); NV_DS(psi_vec, =, C_U(c0,t0),C_V(c0,t0),C_W(c0,t0),*,C_R(c0,t0)); NV_DS(psi_vec, +=, C_U(c1,t1),C_V(c1,t1),C_W(c1,t1),*,C_R(c1,t1)); flux = NV_DOT(psi_vec, A)/2.0; /* Average flux through face */ } /* ANSYS FLUENT will multiply the returned value by phi_f (the scalar's value at the face) to get the "complete'' advective term. */ return flux; } |
Hooking a UDS Flux Function to
ANSYS FLUENT
After the UDF that you have defined using DEFINE_UDS_FLUX 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_uds_flux) will become visible and selectable in the User-Defined Scalars dialog box in ANSYS FLUENT. See Section 6.6.2 for details.