![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
The macros listed in Table 3.2.3- 3.2.19 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 (e.g., mem.h).
Cell Centroid (
C_CENTROID)
The macro listed in Table 3.2.3 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.
See Section 2.2.8 for an example UDF that utilizes C_CENTROID.
Cell Volume (
C_VOLUME)
The macro listed in Table 3.2.4 can be used to obtain the real cell volume for 2D, 3D, and axisymmetric simulations.
See Section 2.7.4 for an example UDF that utilizes C_VOLUME.
Number of Faces (
C_NFACES) and Nodes (
C_NNODES) in a Cell
The macro C_NFACES shown in Table 3.2.5 returns the integer number of faces for a given cell. C_NNODES , also shown in Table 3.2.2, returns the integer number of nodes for a given cell.
Cell Face Index (
C_FACE)
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.
Cell Face Index (
C_FACE_THREAD)
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.
Flow Variable Macros for Cells
You can access flow variables using macros listed in Table 3.2.8.
Macro | Argument Types | Returns |
C_R(c,t) | cell_t c, Thread *t | density |
C_P(c,t) | cell_t c, Thread *t | pressure |
C_U(c,t) | cell_t c, Thread *t |
![]() |
C_V(c,t) | cell_t c, Thread *t |
![]() |
C_W(c,t) | cell_t c, Thread *t |
![]() |
C_T(c,t) | cell_t c, Thread *t | temperature |
C_H(c,t) | cell_t c, Thread *t | enthalpy |
C_K(c,t) | cell_t c, Thread *t | turb. kinetic energy |
C_NUT(c,t) | cell_t c, Thread *t | turbulent viscosity
for Spalart-Allmaras |
C_D(c,t) | cell_t c, Thread *t | turb. kinetic energy
dissipation rate |
C_O(c,t) | cell_t c, Thread *t | specific dissipation rate |
C_YI(c,t,i) |
cell_t c,
Thread *t,
int i
note: int i is species index |
species mass fraction |
Gradient (G) and Reconstruction Gradient (RG) Vector Macros
You can access gradient and reconstruction gradient vectors (and components) for many of the cell variables listed in Table 3.2.8. 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.
Gradient (G) Vector Macros
Table 3.2.9 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 doesn't 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
component;
1 for
; and
2 for
). For example,
C_T_G(c,t)[0]; /* returns the x-component of the cell temperature gradient vector */ |
returns the
component of the temperature gradient vector.
Macro | Argument Types | Returns |
C_R_G(c,t) | cell_t c, Thread *t | density gradient vector |
C_P_G(c,t) | cell_t c, Thread *t | pressure gradient vector |
C_U_G(c,t) | cell_t c, Thread *t | velocity gradient vector |
C_V_G(c,t) | cell_t c, Thread *t | velocity gradient vector |
C_W_G(c,t) | cell_t c, Thread *t | velocity gradient vector |
C_T_G(c,t) | cell_t c, Thread *t | temperature gradient vector |
C_H_G(c,t) | cell_t c, Thread *t | enthalpy gradient vector |
C_NUT_G(c,t) | cell_t c, Thread *t | turbulent viscosity for Spalart-
Allmaras gradient vector |
C_K_G(c,t) | cell_t c, Thread *t | turbulent kinetic energy
gradient vector |
C_D_G(c,t) | cell_t c, Thread *t | turbulent kinetic energy
dissipation rate gradient vector |
C_O_G(c,t) | cell_t c, Thread *t | specific dissipation rate
gradient vector |
C_YI_G(c,t,i) |
cell_t c,
Thread *t,
int i
note: int i is species index |
species mass fraction
gradient vector |
|
Note that you can access vector components of each of the variables listed in Table
3.2.9 by using the integer index
[i] for each macro listed in Table
3.2.9. For example,
C_T_G(c,t)[i] will access a component of the temperature gradient vector.
|
|
C_R_G can be used only in the density-based solver, and
C_P_G can be used only in the pressure-based solver.
|
|
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 Section 6.1.6). The available gradient variables will be displayed in the console.
|
Note that the
showgrad.c UDF is only useful 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) { int ns = 0 ; spe_loop (ns,nspm) if (NNULLP(THREAD_STORAGE(t, SV_Y_I(ns)+SV_Y_0_RG-SV_Y_0 ))) { Message0("....show-grad:Reconstruction Gradient of Species %d is " "available \n ",ns); } } /********************************************************************/ /********************************************************************/ /********************************************************************/ /********************************************************************/ 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) { int ns = 0 ; spe_loop (ns,nspm) if (NNULLP(THREAD_STORAGE(t, SV_Y_I(ns)+SV_Y_0_G-SV_Y_0 ))) { Message0("....show-grad:Gradient of Species %d is available \n ",ns); } } } } |
Reconstruction Gradient (RG) Vector Macros
Table 3.2.10 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
component;
1 for
; and
2 for
). For example,
C_T_RG(c,t)[0]; /* returns the x-component of the cell temperature reconstruction gradient vector */ |
returns the
component of the temperature reconstruction gradient vector.
Macro | Argument Types | Returns |
C_R_RG(c,t) | cell_t c, Thread *t | density RG vector |
C_P_RG(c,t) | cell_t c, Thread *t | pressure RG vector |
C_U_RG(c,t) | cell_t c, Thread *t | velocity RG vector |
C_V_RG(c,t) | cell_t c, Thread *t | velocity RG vector |
C_W_RG(c,t) | cell_t c, Thread *t | velocity RG vector |
C_T_RG(c,t) | cell_t c, Thread *t | temperature RG vector |
C_H_RG(c,t) | cell_t c, Thread *t | enthalpy RG vector |
C_NUT_RG(c,t) | cell_t c, Thread *t | turbulent viscosity for Spalart-
Allmaras RG vector |
C_K_RG(c,t) | cell_t c, Thread *t | turbulent kinetic energy RG
vector |
C_D_RG(c,t) | cell_t c, Thread *t | turbulent kinetic energy
dissipation rate RG vector |
C_YI_RG(c,t,i) |
cell_t c,
Thread *t,
int i
note: int i is species index |
species mass fraction RG vector |
|
Note that you can access vector components by using the integer index
[i] for each macro listed in Table
3.2.10. For example,
C_T_RG(c,t)[i] will access a component of the temperature reconstruction gradient vector.
|
|
C_P_RG can be used in the pressure-based solver only when the second order discretization scheme for pressure is specified.
|
|
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.
Previous Time Step Macros
The
_M1 suffix can be applied to some of the cell variable macros in Table
3.2.8 to allow access to the value of the variable at the previous time step (i.e.,
). 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.2.11.
|
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.
|
Macro | Argument Types | Returns |
C_R_M1(c,t) | cell_t c, Thread *t | density, previous time step |
C_P_M1(c,t) | cell_t c, Thread *t | pressure, previous time step |
C_U_M1(c,t) | cell_t c, Thread *t | velocity, previous time step |
C_V_M1(c,t) | cell_t c, Thread *t | velocity, previous time step |
C_W_M1(c,t) | cell_t c, Thread *t | velocity, previous time step |
C_T_M1(c,t) | cell_t c, Thread *t | temperature, previous time step |
C_YI_M1(c,t,i) |
cell_t c,
Thread *t,
int i
note: int i is species index |
species mass fraction,
previous time step |
See Section 2.7.4 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.2.11 to allow access to the value of the variable at the time step before the previous one (i.e.,
). 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.2.12.
|
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.
|
Macro | Argument Types | Returns |
C_R_M2(c,t) | cell_t c, Thread *t | density, second previous time step |
C_P_M2(c,t) | cell_t c, Thread *t | pressure, second previous time step |
C_U_M2(c,t) | cell_t c, Thread *t | velocity, second previous time step |
C_V_M2(c,t) | cell_t c, Thread *t | velocity, second previous time step |
C_W_M2(c,t) | cell_t c, Thread *t | velocity, second previous time step |
C_T_M2(c,t) | cell_t c, Thread *t | temperature, second previous time step |
C_YI_M2(c,t,i) | cell_t c, Thread *t, int i | species mass fraction, second
previous time step |
Derivative Macros
The macros listed in Table 3.2.13 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.
Macro | Argument Types | Returns |
C_STRAIN_RATE_MAG(c,t) | cell_t c, Thread *t | strain rate magnitude |
C_DUDX(c,t) | cell_t c, Thread *t | velocity derivative |
C_DUDY(c,t) | cell_t c, Thread *t | velocity derivative |
C_DUDZ(c,t) | cell_t c, Thread *t | velocity derivative |
C_DVDX(c,t) | cell_t c, Thread *t | velocity derivative |
C_DVDY(c,t) | cell_t c, Thread *t | velocity derivative |
C_DVDZ(c,t) | cell_t c, Thread *t | velocity derivative |
C_DWDX(c,t) | cell_t c, Thread *t | velocity derivative |
C_DWDY(c,t) | cell_t c, Thread *t | velocity derivative |
C_DWDZ(c,t) | cell_t c, Thread *t | velocity derivative |
Material Property Macros
The macros listed in Tables 3.2.14- 3.2.16 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 (e.g., mem.h).
Macro | Argument Types | Returns |
C_MU_L(c,t) | cell_t c, Thread *t | laminar viscosity |
C_MU_T(c,t) | cell_t c, Thread *t | turbulent viscosity |
C_MU_EFF(c,t) | cell_t c, Thread *t | effective viscosity |
C_K_L(c,t) | cell_t c, Thread *t | thermal conductivity |
C_K_T(c,t,prt) | cell_t c, Thread *t, real prt | turbulent thermal
conductivity |
C_K_EFF(c,t,prt) | cell_t c, Thread *t, real prt | effective thermal
conductivity |
C_DIFF_L(c,t,i,j) |
cell_t c,
Thread *t,
int i,
int j |
laminar species
diffusivity |
C_DIFF_EFF(c,t,i) | cell_t c, Thread *t, int i | effective species
diffusivity |
Macro | Argument Types | Returns |
C_FMEAN(c,t) | cell_t c, Thread *t | primary mean
mixture fraction |
C_FMEAN2(c,t) | cell_t c, Thread *t | secondary mean
mixture fraction |
C_FVAR(c,t) | cell_t c, Thread *t | primary mixture
fraction variance |
C_FVAR2(c,t) | cell_t c, Thread *t | secondary mixture
fraction variance |
C_PREMIXC(c,t) | cell_t c, Thread *t | reaction progress |
variable | ||
C_LAM_FLAME_SPEED(c,t) | cell_t c, Thread *t | laminar flame speed |
C_SCAT_COEFF(c,t) | cell_t c, Thread *t | scattering coefficient |
C_ABS_COEFF(c,t) | cell_t c, Thread *t | absorption coefficient |
C_CRITICAL_STRAIN_
RATE(c,t) |
cell_t c, Thread *t | critical strain rate |
C_LIQF(c,t) | cell_t c, Thread *t | liquid fraction in a cell |
C_POLLUT(c,t,i) | cell_t c, Thread *t, int i |
![]() mass fraction (see table below) |
|
C_LIQF is available only in fluid cells and only if solidification is turned ON.
|
Note: Concentration in particles
/kg. For mass fraction concentrations in the table above, see
this equation in the separate
Theory Guide for the defining equation.
Reynolds Stress Model Macros
The macros listed in Table 3.2.18 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.
Macro | Argument Types | Returns |
C_RUU(c,t) | cell_t c, Thread *t |
![]() |
C_RVV(c,t) | cell_t c, Thread *t |
![]() |
C_RWW(c,t) | cell_t c, Thread *t |
![]() |
C_RUV(c,t) | cell_t c, Thread *t |
![]() |
C_RVW(c,t) | cell_t c, Thread *t |
![]() |
C_RUW(c,t) | cell_t c, Thread *t |
![]() |
VOF Multiphase Model Macro
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.
Macro | Argument Types | Returns |
C_VOF(c,t) |
cell_t c,
Thread *t
(has to be a phase thread) |
volume fraction for the
phase corresponding to phase thread t. |