The macros listed in Table 3.3: Macro for Cell Centroids Defined in metric.h –
Table 3.20: Macros for Multiphase Variables Defined in sg_mphase.h can be used to return real cell variables in SI units. They are identified
by the C_ prefix. These variables are available
in the pressure-based and the density-based solver. The quantities
that are returned are available only if the corresponding physical
model is active. For example, species mass fraction is available only
if species transport has been enabled in the Species Model dialog box in ANSYS Fluent. Definitions for these macros can be found
in the referenced header file (for example, mem.h).
The macro listed in Table 3.3: Macro for Cell Centroids Defined in metric.h can
be used to obtain the real centroid of a
cell. C_CENTROID finds the coordinate position
of the centroid of the cell c and stores
the coordinates in the x array. Note that
the x array is always one-dimensional, but
it can be x[2] or x[3] depending on whether you are using the 2D or 3D solver.
Table 3.3: Macro for Cell Centroids Defined in metric.h
| Macro | Argument Types | Outputs |
|---|---|---|
| | | |
See
DEFINE_INIT
for an example
UDF that utilizes C_CENTROID.
The macro listed in Table 3.4: Macro for Cell Volume Defined in mem.h can
be used to obtain the real cell volume for
2D, 3D, and axisymmetric simulations.
Table 3.4: Macro for Cell Volume Defined in mem.h
| Macro | Argument Types | Returns |
|---|---|---|
| | | |
See
DEFINE_UDS_UNSTEADY
C_VOLUME.
The macro C_NFACES shown in Table 3.5: Macros for Number of Node and Faces Defined in mem.h returns the integer number of faces
for a given cell. C_NNODES, also shown in
Table 3.2: Macro for Number of Nodes Defined in mem.h , returns the integer number
of nodes for a given cell.
Table 3.5: Macros for Number of Node and Faces Defined in mem.h
| Macro | Argument Types | Returns |
|---|---|---|
| | | |
| | | |
C_FACE expands to return the global
face index face_t f for the given cell_t c, Thread *t, and local
face index number i. Specific faces can be
accessed via the integer index i and all
faces can be looped over with c_face_loop. The macro is defined in mem.h.
Table 3.6: Macro for Cell Face Index Defined in mem.h
| Macro | Argument Types | Returns |
|---|---|---|
| | | global face index |
C_FACE_THREAD expands to return the Thread *t of the face_t f that
is returned by C_FACE (see above). Specific
faces can be accessed via the integer index i and all faces can be looped over with c_face_loop. The macro is defined in mem.h.
Table 3.7: Macro for Cell Face Index Defined in mem.h
| Macro | Argument Types | Returns |
|---|---|---|
| | | |
You can access flow variables using macros listed in Table 3.8: Macros for Cell Flow Variables Defined in mem.h or sg_mem.h.
Table 3.8: Macros for Cell Flow Variables Defined in mem.h or sg_mem.h
| Macro | Argument Types | Returns |
|---|---|---|
| | | density |
| | | pressure |
| | | u velocity |
| | | v velocity |
| | | w velocity |
| | | temperature |
| | | enthalpy |
| | | turb. kinetic energy |
| | | turbulent viscosity for Spalart-Allmaras |
| | | turb. kinetic energy dissipation rate |
| | | specific dissipation rate |
| | Note: | species mass fraction |
|
|
|
ignition mass fraction |
|
|
|
premixed combustion temperature |
|
|
|
value of variable |
Note: The C_YI(c,t,i) macro is not
available with the non/partially premixed models. See Species Fractions Calculations with the Non- and Partially-
Premixed Models for Information on calculating the species
fractions with the non-premixed and partially premixed models.
Table 3.9: Macro for Cell Porosity in mem.h
| Macro | Argument Types | Returns |
|---|---|---|
| | | porosity of fluid cell |
| | | porosity of fluid at the dual cell zone region in the non-equilibrium thermal model[a] |
[a] see | ||
When the non-premixed or partially premixed model is enabled, ANSYS Fluent uses
lookup tables to calculate temperature, density, and species fractions.
If you need to access these variables in your UDF, then note that
while density and temperature can be obtained through the macros C_R(c,t) and C_T(c,t), if you
need to access the species fractions, you will need to first retrieve
them by calling the species lookup functions Pdf_Yi(c,
t, n) or Pdf_XY(c,t,x,y). The
functions are defined in the header file pdf_props.h, which you will need to include in your UDF:
Pdf_XY returns the species mole and
mass fraction arrays x and y.
| Function: |
| Argument Type | Description |
|---|---|
| | Cell index. |
| | Pointer to thread. |
| | Array of species mole fractions. |
| | Array of species mass fractions. |
Function returns
void
Pdf_Yi returns the mass fraction of
species n.
| Function: |
| Argument Type | Description |
|---|---|
| | Cell index. |
| | Pointer to thread. |
| | Species index. |
Function returns
real
The species number in the lookup tables is stored in the integer
variable n_spe_pdf, which is also included
in the header file pdf_props.h.
You can access gradient and reconstruction gradient vectors
(and components) for many of the cell variables listed in Table 3.8: Macros for Cell Flow Variables Defined in mem.h or sg_mem.h. ANSYS Fluent calculates the gradient of
flow in a cell (based on the divergence theory) and stores this value
in the variable identified by the suffix _G. For example, cell temperature is stored in the variable C_T, and the temperature gradient of the cell is stored
in C_T_G. The gradients stored in variables
with the _G suffix are non-limited values
and if used to reconstruct values within the cell (at faces, for example),
may potentially result in values that are higher (or lower) than values
in the surrounding cells. Therefore, if your UDF needs to compute
face values from cell gradients, you should use the reconstruction
gradient (RG) values instead of non-limited gradient (G) values. Reconstruction
gradient variables are identified by the suffix _RG, and use the limiting method that you have activated in your ANSYS Fluent model
to limit the cell gradient values.
Table 3.10: Macros for Cell Gradients Defined in mem.h shows a list of cell gradient
vector macros. Note that gradient variables are available only when the equation for that variable is being solved.
For example, if you are defining a source term for energy, your UDF
can access the cell temperature gradient (using C_T_G), but it cannot get access to the x-velocity gradient (using C_U_G). The reason for this is that the solver continually
removes data from memory that it does not need. In order to retain
the gradient data (when you want to set up user-defined scalar transport
equations, for example), you can prevent the solver from freeing up
memory by issuing the text command solve/set/expert and then answering yes to the question,
“Keep temporary solver memory from being freed?” Note that when you do this, all of the gradient data is
retained, but the calculation requires more memory to run.
You can access a component of a gradient vector by specifying
it as an argument in the gradient vector call (0 for the x component; 1 for y; and 2 for z). For example,
C_T_G(c,t)[0]; /* returns the x-component of the cell temperature gradient vector */
Table 3.10: Macros for Cell Gradients Defined in mem.h
| Macro | Argument Types | Returns |
|---|---|---|
| | | pressure gradient vector |
| | | velocity gradient vector |
| | | velocity gradient vector |
| | | velocity gradient vector |
| | | temperature gradient vector |
| | | enthalpy gradient vector |
| | | turbulent viscosity for Spalart- Allmaras gradient vector |
| | | turbulent kinetic energy gradient vector |
| | | turbulent kinetic energy dissipation rate gradient vector |
| | | specific dissipation rate gradient vector |
| | Note: | species mass fraction gradient vector |
Important: Note that you can access vector components of each of the variables
listed in Table 3.10: Macros for Cell Gradients Defined in mem.h by using the integer
index [i] for each macro listed in Table 3.10: Macros for Cell Gradients Defined in mem.h . For example, C_T_G(c,t)[i] will access a component of the temperature gradient vector.
Important: C_P_G can be used only in the pressure-based
solver.
Important: C_YI_G can be used only in the density-based
solver. To use this in the pressure-based solver, you will need to
set the rpvar ’species/save-gradients? to #t.
As stated previously, the availability of gradient variables
is affected by your solver selection, which models are turned on,
the setting for the spatial discretization, and whether the temporary
solver memory is retained. To make it easy for you to verify what
gradient variables are available for your particular case and data
files, the following UDF (named showgrad.c) is provided. Simply compile this UDF, run your solution, and then
hook the UDF using the Execute on Demand dialog
box (as described in Hooking DEFINE_ON_DEMAND UDFs).
The available gradient variables will be displayed in the console.
Important: Note that the showgrad.c UDF is useful
only for single-phase models.
/*
* ON Demand User-Defined Functions to check *
* on the availability of Reconstruction Gradient and Gradients *
* for a given Solver and Solver settings: *
* *
* Availability of Gradients & Reconstruction Gradients depends on: *
* 1) the selected Solver (density based or pressure based) *
* 2) the selected Model *
* 3) the order of discretizations *
* 4) whether the temporary solver memory is being retained (to keep *
* temporary memory go to solve - set -expert and type YES *
* for "Keep temporary solver memory from being freed?") *
* *
* *
* How to use showgrad: *
* *
* - Read in your case & data file. *
* - Compile showgrad.c UDF. *
* - Load library libudf. *
* - Attach the showgrad UDF in the Execute on Demand dialog box. *
* - Run your solution. *
* - Click the Execute button in the Execute on Demand dialog box. *
* *
* A list of available Grads and Recon Grads will be displayed in the *
* console. *
* *
* 2004 Laith Zori *
*/ #include "udf.h"
DEFINE_ON_DEMAND(showgrad)
{
Domain *domain;
Thread *t; domain=Get_Domain(1);
if (! Data_Valid_P()) return;
Message0(" >>> entering show-grad: \n ");
thread_loop_c(t, domain)
{
Material *m = THREAD_MATERIAL(t);
int nspe = MIXTURE_NSPECIES(m);
int nspm = nspe-1;
Message0("::::\n ");
Message0(":::: Reconstruction Gradients :::: \n ");
Message0("::::\n ");
if (NNULLP(THREAD_STORAGE(t, SV_P_RG)))
{
Message0("....show-grad:Reconstruction Gradient of P is available \n ");
}
if (NNULLP(THREAD_STORAGE(t, SV_U_RG)))
{
Message0("....show-grad:Reconstruction Gradient of U is available \n ");
}
if (NNULLP(THREAD_STORAGE(t, SV_V_RG)))
{
Message0("....show-grad:Reconstruction Gradient of V is available \n ");
}
if (NNULLP(THREAD_STORAGE(t, SV_W_RG)))
{
Message0("....show-grad:Reconstruction Gradient of W is available \n ");
}
if (NNULLP(THREAD_STORAGE(t, SV_T_RG)))
{
Message0("....show-grad:Reconstruction Gradient of T is available \n ");
}
if (NNULLP(THREAD_STORAGE(t, SV_H_RG)))
{
Message0("....show-grad:Reconstruction Gradient of H is available \n ");
}
if (NNULLP(THREAD_STORAGE(t, SV_K_RG)))
{
Message0("....show-grad:Reconstruction Gradient of K is available \n ");
}
if (NNULLP(THREAD_STORAGE(t, SV_D_RG)))
{
Message0("....show-grad:Reconstruction Gradient of D is available \n ");
}
if (NNULLP(THREAD_STORAGE(t, SV_O_RG)))
{
Message0("....show-grad:Reconstruction Gradient of O is available \n ");
}
if (NNULLP(THREAD_STORAGE(t, SV_NUT_RG)))
{
Message0("....show-grad:Reconstruction Gradient of NUT is available \n ");
}
if (nspe && NNULLP(THREAD_STORAGE(t, SV_Y_RG)))
{
Message0("....show-grad:Reconstruction Gradient of Species is available \n ");
}
/********************************************************************/
/********************************************************************/
/********************************************************************/
/********************************************************************/
Message0("::::\n ");
Message0(":::: Gradients :::: \n ");
Message0("::::\n ");
if (NNULLP(THREAD_STORAGE(t, SV_P_G)))
{
Message0("....show-grad:Gradient of P is available \n ");
}
if (NNULLP(THREAD_STORAGE(t, SV_U_G)))
{
Message0("....show-grad:Gradient of U is available \n ");
}
if (NNULLP(THREAD_STORAGE(t, SV_V_G)))
{
Message0("....show-grad:Gradient of V is available \n ");
}
if (NNULLP(THREAD_STORAGE(t, SV_W_G)))
{
Message0("....show-grad:Gradient of W is available \n ");
}
if (NNULLP(THREAD_STORAGE(t, SV_T_G)))
{
Message0("....show-grad:Gradient of T is available \n ");
}
if (NNULLP(THREAD_STORAGE(t, SV_H_G)))
{
Message0("....show-grad:Gradient of H is available \n ");
}
if (NNULLP(THREAD_STORAGE(t, SV_K_G)))
{
Message0("....show-grad:Gradient of K is available \n ");
}
if (NNULLP(THREAD_STORAGE(t, SV_D_G)))
{
Message0("....show-grad:Gradient of D is available \n ");
}
if (NNULLP(THREAD_STORAGE(t, SV_O_G)))
{
Message0("....show-grad:Gradient of O is available \n ");
}
if (NNULLP(THREAD_STORAGE(t, SV_NUT_G)))
{
Message0("....show-grad:Gradient of NUT is available \n ");
}
if (nspe && NNULLP(THREAD_STORAGE(t, SV_Y_G)))
{
Message0("....show-grad:Gradient of Species is available \n ");
}
}
}
Reconstruction Gradient (RG) Vector Macros
Table 3.11: Macros for Cell Reconstruction Gradients (RG) Defined in mem.h shows a list of cell reconstruction
gradient vector macros. Like gradient variables, RG variables are
available only when the equation for that variable is being solved.
As in the case of gradient variables, you can retain all of the reconstruction
gradient data by issuing the text command solve/set/expert and then answering yes to the question Keep temporary solver memory from being freed?. Note
that when you do this, the reconstruction gradient data is retained,
but the calculation requires more memory to run.
You can access a component of a reconstruction gradient vector
by specifying it as an argument in the reconstruction gradient vector
call (0 for the x component; 1 for y; and 2 for z). For example,
C_T_RG(c,t)[0]; /* returns the x-component of the cell temperature
reconstruction gradient vector */
Table 3.11: Macros for Cell Reconstruction Gradients (RG) Defined in mem.h
| Macro | Argument Types | Returns |
|---|---|---|
| | | density RG vector |
| | | pressure RG vector |
| | | velocity RG vector |
| | | velocity RG vector |
| | | velocity RG vector |
| | | temperature RG vector |
| | | enthalpy RG vector |
| | | turbulent viscosity for Spalart-Allmaras RG vector |
| | | turbulent kinetic energy RG vector |
| | | turbulent kinetic energy dissipation rate RG vector |
| | Note: | species mass fraction RG vector |
Important: Note that you can access vector components by using the integer
index [i] for each macro listed in Table 3.11: Macros for Cell Reconstruction Gradients (RG) Defined in mem.h . For example, C_T_RG(c,t)[i] will access a component of the temperature reconstruction gradient
vector.
Important: C_P_RG can be used in the pressure-based
solver only when the second order discretization scheme for pressure
is specified.
Important: C_YI_RG can be used only in the density-based
solver.
As stated previously, the availability of reconstruction gradient variables is affected by your solver selection, which models are turned on, the setting for the spatial discretization, and whether the temporary solver memory is freed. To make it easy for you to verify which reconstruction gradient variables are available for your particular case and data files, a UDF (named showgrad.c) has been provided that will display the available gradients in the console. See the previous section for details.
The _M1 suffix can be applied to some
of the cell variable macros in Table 3.8: Macros for Cell Flow Variables Defined in mem.h or sg_mem.h to allow access to the value of the variable at the previous time
step (that is, ). These data may be useful in unsteady simulations.
For example,
C_T_M1(c,t);
returns the value of the cell temperature at the previous time step. Previous time step macros are shown in Table 3.12: Macros for Cell Time Level 1 Defined in mem.h .
Important: Note that data from C_T_M1 is available only if user-defined scalars are defined. It can also
be used with adaptive time stepping.
Table 3.12: Macros for Cell Time Level 1 Defined in mem.h
| Macro | Argument Types | Returns |
|---|---|---|
| | | density, previous time step |
| | | velocity, previous time step |
| | | velocity, previous time step |
| | | velocity, previous time step |
| | | temperature, previous time step |
| | Note: | species mass fraction, previous time step |
See
DEFINE_UDS_UNSTEADY
for an
example UDF that utilizes C_R_M1.
The M2 suffix can be applied to some
of the cell variable macros in Table 3.12: Macros for Cell Time Level 1 Defined in mem.h to allow access to the value of the variable at the time step before
the previous one (that is, ). These data may be useful in unsteady simulations.
For example,
C_T_M2(c,t);
returns the value of the cell temperature at the time step before the previous one (referred to as second previous time step). Two previous time step macros are shown in Table 3.13: Macros for Cell Time Level 2 Defined in mem.h .
Important: Note that data from C_T_M2 is available only if user-defined scalars are defined. It can also
be used with adaptive time stepping.
Table 3.13: Macros for Cell Time Level 2 Defined in mem.h
| Macro | Argument Types | Returns |
|---|---|---|
| | | density, second previous time step |
| | | velocity, second previous time step |
| | | velocity, second previous time step |
| | | velocity, second previous time step |
| | | temperature, second previous time step |
| | | species mass fraction, second previous time step |
The macros listed in Table 3.14: Macros for Cell Velocity Derivatives Defined in mem.h can
be used to return real velocity derivative
variables in SI units. The variables are available in both the pressure-based
and the density-based solver. Definitions for these macros can be
found in the mem.h header file.
Table 3.14: Macros for Cell Velocity Derivatives Defined in mem.h
| Macro | Argument Types | Returns |
|---|---|---|
| | | strain rate magnitude |
| | | velocity derivative |
| | | velocity derivative |
| | | velocity derivative |
| | | velocity derivative |
| | | velocity derivative |
| | | velocity derivative |
| | | velocity derivative |
| | | velocity derivative |
| | | velocity derivative |
The macros listed in Table 3.15: Macros for Diffusion Coefficients Defined in mem.h –
Table 3.17: Additional Material Property Macros Defined in sg_mem.h can be used to return real material property variables in SI units. The variables
are available in both the pressure-based and the density-based solver.
Argument real prt is the turbulent Prandtl
number. Definitions for material property macros can be found in the
referenced header file (for example, mem.h).
Table 3.15: Macros for Diffusion Coefficients Defined in mem.h
| Macro | Argument Types | Returns |
|---|---|---|
| | | laminar viscosity |
| | | turbulent viscosity[a] |
| | | effective viscosity |
| | | thermal conductivity |
| | | turbulent thermal conductivity |
| | | effective thermal conductivity |
| | | laminar species diffusivity |
| | | effective species diffusivity |
[a] In an Embedded LES case with SAS
or DES for the global turbulence model, the global turbulence model
is solved even inside the LES zone, although it does not affect the
velocity equations or any other model there. (This allows the global
turbulence model in a downstream RANS zone to have proper inflow turbulence
conditions.) Inside the LES zone, the turbulent eddy viscosity of
the “muted” global SAS or DES model can be accessed
through the | ||
Table 3.16: Macros for Thermodynamic Properties Defined in mem.h
| Name (Arguments) | Argument Types | Returns |
|---|---|---|
| | | specific heat |
| | | universal gas constant/molecular weight |
| | | turbulent viscosity for Spalart-Allmaras |
Table 3.17: Additional Material Property Macros Defined in sg_mem.h
| Macro | Argument Types | Returns |
|---|---|---|
| | | primary mean mixture fraction |
| | | secondary mean mixture fraction |
| | | primary mixture fraction variance |
| | | secondary mixture fraction variance |
| | | reaction progress variable |
| | | laminar flame speed |
| | | scattering coefficient |
| | | absorption coefficient |
| | | critical strain rate |
| | | liquid fraction in a cell |
| | | |
Important: C_LIQF is available only in fluid
cells and only if solidification is turned ON.
Table 3.18: Table of Definitions for Argument i of the Pollutant Species Mass Fraction Function C_POLLUT
i | Definitions |
|---|---|
0 | |
1 | |
2 | |
3 | |
4 | |
5 | |
Note: Concentration in particles /kg. For mass fraction concentrations in the table
above, see Equation 14–132 in the Fluent Theory Guide for the defining equation.
The macros listed in Table 3.19: Macros for Reynolds Stress Model Variables Defined in sg_mem.h can
be used to return real variables for the
Reynolds stress turbulence model in SI units. The variables are available
in both the pressure-based and the density-based solver. Definitions
for these macros can be found in the metric.h header file.
Table 3.19: Macros for Reynolds Stress Model Variables Defined in sg_mem.h
| Macro | Argument Types | Returns |
|---|---|---|
| | | uu Reynolds stress |
| | | vv Reynolds stress |
| | | ww Reynolds stress |
| | | uv Reynolds stress |
| | | vw Reynolds stress |
| | | uw Reynolds stress |
The macro C_VOF can be used to return real variables associated with the VOF multiphase model
in SI units. The variables are available in both the pressure-based
and the density-based solver, with the exception of the VOF variable,
which is available only for the pressure-based solver. Definitions
for these macros can be found in sg_mphase.h, which is included in udf.h.
Table 3.20: Macros for Multiphase Variables Defined in sg_mphase.h
| Macro | Argument Types | Returns |
|---|---|---|
| | (has to be a phase thread) | volume fraction for the phase corresponding
to phase thread |