ANSYS Fluent provides macros that allow the vectors connecting cell centroids and the vectors connecting cell and face centroids to be readily defined. These macros return information that is helpful in evaluating face values of scalars which are generally not stored, as well as the diffusive flux of scalars across cell boundaries. The geometry and gradients involved with these macros are summarized in Figure 3.2: Adjacent Cells c0 and c1 with Vector and Gradient Definitions.
To better understand the parameters that are returned by these
macros, it is best to consider how the aforementioned calculations
are evaluated. Assuming that the gradient of a scalar is available,
the face value of a scalar, , can be approximated by
(3–1) |
where is the vector that connects the cell centroid with
the face centroid. The gradient in this case is evaluated at the cell
centroid where
is also stored.
The diffusive flux, , across a face,
, of a scalar
is given by,
(3–2) |
where is the diffusion coefficient at the face. In ANSYS Fluent’s
unstructured solver, the gradient along the face normal direction
may be approximated by evaluating gradients along the directions that
connect cell centroids and along a direction confined within the plane
of the face. Given this,
maybe approximated as,
(3–3) |
where the first term on the right hand side represents the primary
gradient directed along the vector and the second term represents the ‘cross’
diffusion term. In this equation,
is the area normal vector of face
directed from cell
c0 to c1, is the distance between the cell centroids, and
is the unit normal vector in this direction.
is the average of the gradients at the two adjacent
cells. (For boundary faces, the variable is the gradient of the c0
cell.) This is shown in Figure 3.2: Adjacent Cells c0 and c1 with Vector and Gradient Definitions.
The cells on either side of a face may or may not belong to
the same cell thread. Referring to Figure 3.2: Adjacent Cells c0 and c1 with Vector and Gradient Definitions, if a face is on the boundary
of a domain, then only c0 exists. (c1 is undefined for an external face). Alternatively,
if the face is in the interior of the domain, then both c0 and c1 exist.
There are two macros, F_C0(f,t) and
F_C1(f,t), that can be used to identify
cells that are adjacent to a given face thread t. F_C0 expands to a function that returns
the index of a face’s neighboring c0 cell (Figure 3.2: Adjacent Cells c0 and c1 with Vector and Gradient Definitions), while F_C1 returns the cell index for c1 (Figure 3.2: Adjacent Cells c0 and c1 with Vector and Gradient Definitions), if it exists.
Table 3.25: Adjacent Cell Index Macros Defined in mem.h
| Macro | Argument Types | Returns |
|---|---|---|
| | | |
| | | |
See
DEFINE_UDS_FLUX
for an example
UDF that utilizes F_C0.
The cells on either side of a face may or may not belong to
the same cell thread. Referring to Figure 3.2: Adjacent Cells c0 and c1 with Vector and Gradient Definitions, if a face is on the boundary
of a domain, then only c0 exists. (c1 is undefined for an external face). Alternatively,
if the face is in the interior of the domain, then both c0 and c1 exist.
There are two macros, THREAD_T0(t) and THREAD_T1(t), that can be used to identify cell threads
that are adjacent to a given face f in a
face thread t. THREAD_T0 expands to a function that returns the cell thread of a given face’s
adjacent cell c0, and THREAD_T1 returns the cell thread for c1 (if it exists).
Table 3.26: Adjacent Cell Thread Macros Defined in mem.h
| Macro | Argument Types | Returns |
|---|---|---|
| | | cell thread pointer for cell c0 |
| | | cell thread pointer for cell c1 |
INTERIOR_FACE_GEOMETRY(f,t,A,ds,es,A_by_es,dr0,dr1) expands to a function that outputs the following variables to the
solver, for a given face f, on face thread
t. The macro is defined in the sg.h header file which is not included
in udf.h. You will need to include this file
in your UDF using the #include directive.
| | the area normal vector |
| | distance between the cell centroids |
| | the unit normal vector in the direction from cell c0 to c1 |
| | the value |
| | vector that connects the centroid of cell |
| | the vector that connects the
centroid of cell |
Note that INTERIOR_FACE_GEOMETRY can
be called to retrieve some of the terms needed to evaluate Equation 3–1 and Equation 3–3.
BOUNDARY_FACE_GEOMETRY(f,t,A,ds,es,A_by_es,dr0) expands to a function that outputs the following variables to the
solver, for a given face f, on face thread
t. It is defined in the sg.h header file which is not included in udf.h. You will need to include this file in your UDF
using the #include directive.
BOUNDARY_FACE_GEOMETRY can be called
to retrieve some of the terms needed to evaluate Equation 3–1 and Equation 3–3.
| | area normal vector |
| | distance between the cell centroid and the face centroid |
| | unit normal vector in the direction from centroid of cell c0 to the face centroid |
| | value
|
| | vector that connects the centroid of cell |
BOUNDARY_FACE_THREAD_P(t) expands
to a function that returns TRUE if Thread *t is a boundary face thread. The macro is defined
in threads.h which is included in udf.h. See
DEFINE_UDS_FLUX
for an example UDF that utilizes BOUNDARY_FACE_THREAD_P.
BOUNDARY_SECONDARY_GRADIENT_SOURCE(source,n,dphi,dx,A_by_es,k) expands to a function that outputs the following variables to the
solver, for a given face and face thread. It is defined in the sg.h header file which is not included
in udf.h. You will need to include this file
in your UDF using the #include directive.
Important: The use of BOUNDARY_SECONDARY_GRADIENT_SOURCE first requires that cell geometry information be defined, which
can be readily obtained by the use of the BOUNDARY_FACE_GEOMETRY macro (described previously in this section). See Implementing ANSYS Fluent’s P-1 Radiation Model Using User-Defined
Scalars for an example.
BOUNDARY_SECONDARY_GRADIENT_SOURCE can be called to retrieve some of the terms needed to evaluate Equation 3–3.
| | the cross diffusion term of the diffusive flux (that is, the second term on the right side of Equation 3–3) |
| | the |
| | a dummy scratch variable array that stores the facial gradient value during the computation |
| | the unit normal vector in the direction from centroid of cell c0 to the face centroid |
| | the value |
| | the diffusion coefficient at the face ( |
Important: Note that the gradient field variable addressed by the Svar value n is not always
allocated, and so your UDF must verify its status (using the NULLP or NNULLP function, as
described in NULLP & NNULLP
) and assign
a value as necessary. See Implementing ANSYS Fluent’s P-1 Radiation Model Using User-Defined
Scalars for an example.