[Fluent Inc. Logo] return to home search
next up previous contents index

5.3 Cell Variables

Dependent cell data that are stored in a FLUENT solver can be accessed using macros listed in this section. The macros can be used to return real variables in SI units. The cell variables are available in both the segregated and the coupled solvers. Definitions for these cell variable macros can be found in the referenced header file (e.g., mem.h).

Flow Variable Macros


Table 5.3.1: Macros for Cell Flow Variables ( mem.h)
Name(Arguments) 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 $u$ velocity  
C_V(c,t) cell_t c, Thread *t $v$ velocity  
C_W(c,t) cell_t c, Thread *t $w$ velocity  
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 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  5.3.1. 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 FLUENT model to limit the cell gradient values.

Gradient (G) Vector Macros

Table  5.3.2 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 can not 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 $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 */

returns the $x$ component of the temperature gradient vector.


Table 5.3.2: Macros for Cell Gradients ( mem.h)
Name(Arguments) Argument Types Returns  
       
C_R_G(c,t) cell_t c, Thread *t density gradient vector  
C_R_G(c,t)[i] cell_t c, Thread *t, int i density gradient component  
C_P_G(c,t) cell_t c, Thread *t pressure gradient vector  
C_P_G(c,t)[i] cell_t c, Thread *t, int i pressure gradient component  
C_U_G(c,t) cell_t c, Thread *t velocity gradient vector  
C_U_G(c,t)[i] cell_t c, Thread *t, int i velocity gradient component  
C_V_G(c,t) cell_t c, Thread *t velocity gradient vector  
C_V_G(c,t)[i] cell_t c, Thread *t, int i velocity gradient component  
C_W_G(c,t) cell_t c, Thread *t velocity gradient vector  
C_W_G(c,t)[i] cell_t c, Thread *t, int i velocity gradient component  
C_T_G(c,t) cell_t c, Thread *t temperature gradient vector  
C_T_G(c,t)[i] cell_t c, Thread *t, int i temperature gradient  
    component  
C_H_G(c,t) cell_t c, Thread *t enthalpy gradient vector  
C_H_G(c,t)[i] cell_t c, Thread *t, int i enthalpy gradient component  
C_NUT_G(c,t) cell_t c, Thread *t turbulent viscosity for Spalart-  
    Allmaras gradient vector  
C_NUT_G(c,t)[i] cell_t c, Thread *t, int i turbulent viscosity for Spalart-  
    Allmaras gradient component  
C_K_G(c,t) cell_t c, Thread *t turbulent kinetic energy  
    gradient vector  
C_K_G(c,t)[i] cell_t c, Thread *t, int i turbulent kinetic energy  
    gradient component  
C_D_G(c,t) cell_t c, Thread *t turbulent kinetic energy  
    dissipation rate gradient  
    vector  
C_D_G(c,t)[i] cell_t c, Thread *t, int i turbulent kinetic energy  
    dissipation rate gradient  
    component  
C_O_G(c,t) cell_t c, Thread *t specific dissipation rate  
    gradient vector  
C_O_G(c,t)[i] cell_t c, Thread *t, int i specific dissipation rate  
    gradient component  
C_YI_G(c,t) cell_t c, Thread *t species mass fraction  
    gradient vector  
C_YI_G(c,t)[i] cell_t c, Thread *t, int i species mass fraction  
    gradient component  

Reconstruction Gradient (RG) Vector Macros

Table  5.3.3 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 */

returns the $x$ component of the temperature reconstruction gradient vector.


Table 5.3.3: Macros for Cell Reconstruction Gradients (RG) ( mem.h)
Name(Arguments) Argument Types Returns  
       
C_R_RG(c,t) cell_t c, Thread *t density RG vector  
C_R_RG(c,t)[i] cell_t c, Thread *t, int i density RG component  
C_P_RG(c,t) cell_t c, Thread *t pressure RG vector  
C_P_RG(c,t)[i] cell_t c, Thread *t, int i pressure RG component  
C_U_RG(c,t) cell_t c, Thread *t velocity RG vector  
C_U_RG(c,t)[i] cell_t c, Thread *t, int i velocity RG component  
C_V_RG(c,t) cell_t c, Thread *t velocity RG vector  
C_V_RG(c,t)[i] cell_t c, Thread *t, int i velocity RG component  
C_W_RG(c,t) cell_t c, Thread *t velocity RG vector  
C_W_RG(c,t)[i] cell_t c, Thread *t, int i velocity RG component  
C_T_RG(c,t) cell_t c, Thread *t temperature RG vector  
C_T_RG(c,t)[i] cell_t c, Thread *t, int i temperature RG component  
C_H_RG(c,t) cell_t c, Thread *t enthalpy RG vector  
C_H_RG(c,t)[i] cell_t c, Thread *t, int i enthalpy RG component  
C_NUT_RG(c,t) cell_t c, Thread *t turbulent viscosity for Spalart-  
    Allmaras RG vector  
C_NUT_RG(c,t)[i] cell_t c, Thread *t, int i turbulent viscosity for Spalart-  
    Allmaras RG component  
C_K_RG(c,t) cell_t c, Thread *t turbulent kinetic energy RG  
    vector  
C_K_RG(c,t)[i] cell_t c, Thread *t, int i turbulent kinetic energy  
    RG component  
C_D_RG(c,t) cell_t c, Thread *t turbulent kinetic energy  
    dissipation rate RG vector  
C_D_RG(c,t)[i] cell_t c, Thread *t, int i turbulent kinetic energy  
    dissipation rate RG  
    component  
C_YI_RG(c,t) cell_t c, Thread *t species mass fraction RG  
    vector  
C_YI_RG(c,t)[i] cell_t c, Thread *t, int i species mass fraction RG  
    component  

Previous Time Step Macros

The _M1 suffix can be applied to some of the cell variable macros in Table  5.3.1 to allow access to the value of the variable at the previous time step (i.e., $t - \Delta t$). 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  5.3.4.

!! Note that data from C_T_M1 is available only if user-defined scalars are used.


Table 5.3.4: Macros for Cell Time Level 1 ( mem.h)
Name(Arguments) 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) cell_t c, Thread *t species mass fraction,  
    previous time step  

The M2 suffix can be applied to some of the cell variable macros in Table  5.3.1 to allow access to the value of the variable at the time step before the previous one (i.e., $t - 2\Delta t$). 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. Two previous time step macros are shown in Table  5.3.5.

!! Note that data from C_T_M2 is available only if user-defined scalars are used.


Table 5.3.5: Macros for Cell Time Level 2 ( mem.h)
Name(Arguments) Argument Types Returns  
       
C_R_M2(c,t) cell_t c, Thread *t density, previous time step  
C_P_M2(c,t) cell_t c, Thread *t pressure, previous time step  
C_U_M2(c,t) cell_t c, Thread *t velocity, previous time step  
C_V_M2(c,t) cell_t c, Thread *t velocity, previous time step  
C_W_M2(c,t) cell_t c, Thread *t velocity, previous time step  
C_T_M2(c,t) cell_t c, Thread *t temperature, previous time step  
C_YI_M2(c,t) cell_t c, Thread *t species mass fraction,  
    previous time step  

Derivative Macros

The macros listed in Table  5.3.6 can be used to return real velocity derivative variables in SI units. The variables are available in both the segregated and the coupled solvers. Definitions for these macros can be found in the mem.h header file.


Table 5.3.6: Macros for Cell Velocity Derivatives ( mem.h)
Name(Arguments) 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  5.3.7- 5.3.9 can be used to return real material property variables in SI units. The variables are available in both the segregated and the coupled solvers. Definitions for these macros can be found in the referenced header file (e.g., mem.h).


Table 5.3.7: Macros for Diffusion Coefficients ( mem.h)
Name(Arguments) 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) cell_t c, Thread *t turbulent thermal  
    conductivity  
C_K_EFF(c,t) cell_t c, Thread *t effective thermal  
    conductivity  
C_DIFF_L(c,t,i,j) cell_t c, Thread *t, int i, laminar species  
  int j diffusivity  
C_DIFF_EFF(c,t,i) cell_t c, Thread *t, int i effective species  
    diffusivity  


Table 5.3.8: Macros for Thermodynamic Properties ( mem.h)
Name(Arguments) Argument Types Returns  
       
C_CP(c,t) cell_t c, Thread *t specific heat  
C_RGAS(c,t) cell_t c, Thread *t gas constant  
C_ABS_COEFF(c,t) cell_t c, Thread *t absorption coefficient  
C_SCAT_COEFF(c,t) cell_t c, Thread *t scattering coefficient  
C_NUT(c,t) cell_t c, Thread *t turbulent viscosity  
    for Spalart-Allmaras  


Table 5.3.9: Additional Material Property Macros ( sg_mem.h)
Name(Arguments) 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_CRITICAL_STRAIN_ cell_t c, Thread *t critical strain rate  
RATE(c,t)      
C_POLLUT(c,t,i) cell_t c, Thread *t, int i $i$th pollutant species  
    mass fraction  

Reynolds Stress Model Macros

The macros listed in Table  5.3.10 can be used to return real variables for the Reynolds stress turbulence model in SI units. The variables are available in both the segregated and the coupled solvers. Definitions for these macros can be found in the metric.h header file.


Table 5.3.10: Macros for Reynolds Stress Model Variables ( metric.h)
Name(Arguments) Argument Types Returns  
       
C_RUU(c,t) cell_t c, Thread *t $uu$ Reynolds stress  
C_RVV(c,t) cell_t c, Thread *t $vv$ Reynolds stress  
C_RWW(c,t) cell_t c, Thread *t $ww$ Reynolds stress  
C_RUV(c,t) cell_t c, Thread *t $uv$ Reynolds stress  
C_RVW(c,t) cell_t c, Thread *t $vw$ Reynolds stress  
C_RUW(c,t) cell_t c, Thread *t $uw$ Reynolds stress  

User-Defined Scalar Variables for Cells ( C_UDSI)

You can use C_UDSI when you want to access cell variables that are computed for user-defined scalar transport equations. Macros for accessing UDS cell variables are listed in Table  5.3.11. Some examples of usage for these macros include defining non-constant source terms for UDS transport equations and initializing equations. An example of C_UDSI usage is shown below.


Table 5.3.11: User-Defined Scalar Variables for Cells ( mem.h)
Name(Arguments) Argument Types Usage  
       
C_UDSI(c,t,i) cell_t c, Thread *t, int i user-defined scalar  
C_UDSI_G(c,t,i) cell_t c, Thread *t, int i user-defined scalar  
    gradient  
C_UDSI_M(c,t,i) cell_t c, Thread *t, int i user-defined scalar  
    previous time step  
C_UDSI_DIFF(c,t,i) cell_t c, Thread *t, int i user-defined scalar  
    diffusivity  

User-Defined Memory Variables for Cells ( C_UDMI)

You can use C_UDMI when you want to store cell variables that are computed for user-defined scalar transport equations. C_UDMI can be used to allocate up to 500 memory locations in order to store and retrieve the values of cell field variables computed by UDFs. These stored values can then be used for postprocessing, for example, or by other UDFs. An example of C_UDMI usage is shown below.


Table 5.3.12: User-Defined Memory Variables for Cells ( mem.h)
Name(Arguments) Argument Types Usage  
       
C_UDMI(c,t,i) cell_t c, Thread *t, int i stores data in user-defined cell  
    memory location for given  
    index  

There are three arguments to C_UDMI: c, thread, and i. c is the cell identifier, thread is a pointer to the cell thread, and i is an integer index that identifies the memory location where data is to be stored. An index i of 0 corresponds to user-defined memory location 0 (or udm-0).

Before you can use C_UDMI to store variables in memory, you will first need to allocate memory location(s) in the User-Defined Memory panel in FLUENT. (See Section  8.1.6 for more details.)

Define $\rightarrow$ User-Defined $\rightarrow$ Memory...

!! If you try using C_UDMI before you have allocated memory, then an error will result.

A variable will be created for every user-defined memory location that you allocate in the graphical user-interface. For example, if you specify 2 memory locations, then two variables, udm-0 and udm-1, will be available for data storage. (These names will appear in postprocessing panels.)

Example - UDM and UDS variable Usage

Below is an example of a UDF that begins by filling uds-0 with the cell temperature raised to the fourth power (using C_UDSI). Then it fills udm-0 with the gradient of this cell temperature, C_UDSI_G (using C_UDMI) that will be used later for post-processing.

/**********************************************************************
   UDF used to calculate gradient for post-processing

   User defined scaler (UDS) and user defined memory (UDM) are used.
   For any UDS, Fluent will automatically calculate the gradient.  So,
   we need to pass the variable to UDS, and fluent will calculate the
   gradient for you.  UDM is used to save the results.

   Steps to take to make it work:
   1. Build UDF library
   2. Read in the converged case and data
   3. Hook the UDF (Define->User Defined->Function->Compiled)
   4. Hook adjust function (Define->User Defined->Function Hooks->
      Adjust Function)
   5. Define UDM (Define->User Defined->Memory 1)
   6. Define UDS (Define->User Defined->Scalars 1)
   7. Define BC for UDS (the same as the function for which you 
      want gradient)
   8. Change UR for UDS to 1e-6 (Solve->Controls->Solution)
   9. Turn off all equations except UDS (Solve->Controls->Solution)
   10 Do A FEW iterations
   11 Execute store_gradient (Define->User Defined->Execute On Demand)

   NOTES on item 7 8 and 9
        step 7 is VERY IMPORTANT, otherwise the gradient close to the 
           boundary will not be correct.
        step 8 is VERY IMPORTANT, otherwise the solution will change.
           Fluent will try to solve an equation for UDS; we want to
           force it to be unchanged.
        step 9 will save you time as the solution is already converged.
        step 10 Three is determined to be the minimum.
**********************************************************************/
# include "udf.h"
# define domain_ID 2

DEFINE_ADJUST(adjust_gradient, domain)
{
  Thread *t;
  cell_t c;
  face_t f;

  domain = Get_Domain(domain_ID);

  /* Fill UDS with the variable. */
  thread_loop_c (t,domain)
    {
       begin_c_loop (c,t)
         {
           C_UDSI(c,t,0) = C_VOF(c,t);
         }
       end_c_loop (c,t)
    }
}

DEFINE_ON_DEMAND(store_gradient)
{
  Domain *domain;
  cell_t c;
  Thread *t;

  domain=Get_Domain(1);

  /* Fill the UDM with magnitude of gradient. */
  thread_loop_c (t,domain)
    {
       begin_c_loop (c,t)
         {
           C_UDMI(c,t,0) = NV_MAG(C_UDSI_G(c,t,0));
         }
       end_c_loop (c,t)
    }
}


next up previous contents index Previous: 5.2.2 Connectivity Variables
Up: 5. Accessing Solver Data
Next: 5.4 Face Variables
© Fluent Inc. 2003-01-22