2.3. Model-Specific DEFINE Macros

The DEFINE macros presented in this section are used to set parameters for a particular model in Ansys Fluent. Table 2.2: Quick Reference Guide for Model-Specific DEFINE FunctionsTable 2.6: Quick Reference Guide for Model-Specific DEFINE Functions MULTIPHASE ONLY provides a quick reference guide to the DEFINE macros, the functions they are used to define, and the dialog boxes where they are activated in Ansys Fluent. Definitions of each DEFINE macro are listed in udf.h. For your convenience, they are listed in Appendix B: DEFINE Macro Definitions.

Table 2.2: Quick Reference Guide for Model-Specific DEFINE Functions

Function

DEFINE Macro

Dialog Box Activated In

anisotropic thermal conductivity

DEFINE_ANISOTROPIC_CONDUCTIVITY

Create/Edit Materials

capillary pressure

DEFINE_CAPILLARY_PRESSURE

Potential/Electrochemistry

mixing constant

DEFINE_CPHI

User-Defined Function Hooks

homogeneous net mass reaction rate for all species, integrated over a time step

DEFINE_CHEM_STEP

User-Defined Function Hooks

species mass or UDS diffusivity

DEFINE_DIFFUSIVITY

Create/Edit Materials

diffusive reflectivity for discrete ordinates (DO) model

DEFINE_DOM_DIFFUSE_ REFLECTIVITY

User-Defined Function Hooks

source for DO model

DEFINE_DOM_SOURCE

User-Defined Function Hooks

specular reflectivity for DO model

DEFINE_DOM_SPECULAR_ REFLECTIVITY

User-Defined Function Hooks

electrochemical reaction kinetics parameter

DEFINE_EC_KINETICS_ PARAMETER

Reaction

electrochemical reaction rate

DEFINE_EC_RATE

User-Defined Function Hooks

reaction rates for the EDC model

DEFINE_EDC_MDOT

Species Model

scales for the EDC model

DEFINE_EDC_SCALES

Species Model

transfer currents for the electrolysis model

DEFINE_ELECTROLYSIS_ECHEM_RATE

Potential/Electrochemistry

relative permeability for the electrolysis model

DEFINE_ELECTROLYSIS_RELATIVE_PERMEABILITY

Potential/Electrochemistry

relative permeability for the Electrolysis model

DEFINE_ELECTROLYSIS_RELATIVE_PERMEABILITY

Potential/Electrochemistry

emissivity weighting factor for the radiative transfer equation of the non-gray P-1 model and the non-gray DO model

DEFINE_EMISSIVITY_ WEIGHTING_FACTOR

User-Defined Function Hooks

variation of scalar dissipation, mean mixture fraction grid, and mean progress variable grid for flamelet generation

DEFINE_FLAMELET_PARAMETERS

Species Model

source terms for momentum and energy equations for the cells located in a gap region

DEFINE_GAP_MODEL_ SOURCE

Edit Gap Region

auxiliary geometry definition

DEFINE_GEOMETRY

Auxiliary Geometry Definition

gray band absorption coefficient for DO model

DEFINE_GRAY_BAND_ABS_ COEFF

Create/Edit Materials

wall heat flux

DEFINE_HEAT_FLUX

User-Defined Function Hooks

ignition time source

DEFINE_IGNITE_SOURCE

User-Defined Function Hooks

inputs (such as heat transfer coefficients, heat flux augmentation/suppression factors, reference velocity, and temperature) for the semi-mechanistic boiling model

DEFINE_MASS_TR_PROPERTY

User-Defined Function Hooks

homogeneous net mass reaction rate for all species

DEFINE_NET_REACTION_RATE

User-Defined Function Hooks


Table 2.3: Quick Reference Guide for Model-Specific DEFINE Functions–Continued

Function

DEFINE Macro

Dialog Box Activated In

NOx formation rates (for Thermal NOx, Prompt NOx, Fuel NOx, and O Pathways) and upper limit for temperature PDF

DEFINE_NOX_RATE

NOx Model

discharge coefficient in a perforated wall

DEFINE_PERFORATED_CD

User-Defined Function Hooks

PDF lookup table

DEFINE_PDF_TABLE

User-Defined Function Hooks

particle surface reaction rate

DEFINE_PR_RATE

User-Defined Function Hooks

Prandtl numbers

DEFINE_PRANDTL

Viscous Model

species mass fraction

DEFINE_PROFILE

boundary condition (for example, Velocity Inlet)

velocity at a boundary

DEFINE_PROFILE

boundary condition

pressure at a boundary

DEFINE_PROFILE

boundary condition

temperature at a boundary

DEFINE_PROFILE

boundary condition

mass flux at a boundary

DEFINE_PROFILE

boundary condition

target mass flow rate for pressure outlet

DEFINE_PROFILE

Pressure Outlet

turbulence kinetic energy

DEFINE_PROFILE

boundary condition (for example, Velocity Inlet)

turbulence dissipation rate

DEFINE_PROFILE

boundary condition

specific dissipation rate

DEFINE_PROFILE

boundary condition

porosity

DEFINE_PROFILE

boundary condition

viscous resistance

DEFINE_PROFILE

boundary condition

inertial resistance

DEFINE_PROFILE

boundary condition

porous resistance direction vector

DEFINE_PROFILE

boundary condition

user-defined scalar boundary value

DEFINE_PROFILE

boundary condition

internal emissivity

DEFINE_PROFILE

boundary condition


Table 2.4: Quick Reference Guide for Model-Specific DEFINE Functions–Continued

Function

DEFINE Macro

Dialog Box Activated In

wall thermal conditions (heat flux, heat generation rate, temperature, heat transfer coefficient, external emissivity, external radiation and free stream temperature)

DEFINE_PROFILE

boundary condition

shell layer heat generation rate

DEFINE_PROFILE

Shell Conduction Layers

wall radiation (internal emissivity, irradiation)

DEFINE_PROFILE

boundary condition

wall momentum (shear stress x, y, z components swirl component, moving wall velocity components, roughness height, roughness constant)

DEFINE_PROFILE

boundary condition

wall species mass fractions

DEFINE_PROFILE

boundary condition

wall user-defined scalar boundary value

DEFINE_PROFILE

boundary condition

wall discrete phase boundary value

DEFINE_PROFILE

boundary condition

density (as function of temperature)

DEFINE_PROPERTY

Create/Edit Materials

density (as function of pressure for compressible liquids)

DEFINE_PROPERTY

Create/Edit Materials

viscosity

DEFINE_PROPERTY

Create/Edit Materials

mass diffusivity

DEFINE_PROPERTY

Create/Edit Materials

thermal conductivity

DEFINE_PROPERTY

Create/Edit Materials

thermal diffusion coefficient

DEFINE_PROPERTY

Create/Edit Materials


Table 2.5: Quick Reference Guide for Model-Specific DEFINE Functions–Continued

Function

DEFINE Macro

Dialog Box Activated In

absorption coefficient

DEFINE_PROPERTY

Create/Edit Materials

scattering coefficient

DEFINE_PROPERTY

Create/Edit Materials

laminar flame speed

DEFINE_PROPERTY

Create/Edit Materials

rate of strain

DEFINE_PROPERTY

Create/Edit Materials

speed of sound function

DEFINE_PROPERTY

Create/Edit Materials

user-defined mixing law for mixture materials (density viscosity, thermal conductivity)

DEFINE_PROPERTY

Create/Edit Materials

reacting channel inlet boundary conditions

DEFINE_REACTING_CHANNEL_BC

Reacting Channel Model

reacting channel solver

DEFINE_REACTING_CHANNEL_SOLVER

User-Defined Function Hooks

species characteristic time for reaching chemical equilibrium

DEFINE_RELAX_TO_EQUILIBRIUM

User-Defined Function Hooks

blending function for the Stress-Blended Eddy Simulation (SBES) model

DEFINE_SBES_BF

Viscous Model

scattering phase function

DEFINE_SCAT_PHASE_FUNC

Create/Edit Materials

solar intensity

DEFINE_SOLAR_INTENSITY

Radiation Model

back diffusion

DEFINE_SOLIDIFICATION_PARAMS

Solidification and Melting

mushy zone

DEFINE_SOLIDIFICATION_PARAMS

Solidification and Melting

soot nucleation, surface growth, and oxidation rates for soot mass fraction equation

DEFINE_SOOT_MASS_RATES

Soot Model

soot nucleation, surface growth, and oxidation rates for soot moment equations

DEFINE_SOOT_MOM_RATES

Soot Model

soot nucleation and coagulation rates for soot nuclei equation

DEFINE_SOOT_NUCLEATION_RATES

Soot Model

soot oxidation rate

DEFINE_SOOT_OXIDATION_RATE

Soot Model

soot precursor

DEFINE_SOOT_PRECURSOR

Soot Model

mass source

DEFINE_SOURCE

cell zone condition

momentum source

DEFINE_SOURCE

cell zone condition

energy source

DEFINE_SOURCE

cell zone condition

turbulence kinetic energy source

DEFINE_SOURCE

cell zone condition

turbulence dissipation rate source

DEFINE_SOURCE

cell zone condition

species mass fraction source

DEFINE_SOURCE

cell zone condition

user-defined scalar source

DEFINE_SOURCE

cell zone condition

P1 radiation model source

DEFINE_SOURCE

cell zone condition

spark kernel volume shape

DEFINE_SPARK_GEOM (R14.5 spark model only)

Set Spark Ignition

specific heat and sensible enthalpy

DEFINE_SPECIFIC_HEAT

Create/Edit Materials

surface reaction rate

DEFINE_SR_RATE

User-Defined Function Hooks

thickened flame model


DEFINE_THICKENED_FLAME_
MODEL

User-Defined Function Hooks

transition correlation numbers

DEFINE_TRANS

Viscous Model

time-varying profiles

DEFINE_TRANSIENT_PROFILE

cell zone condition

turbulent premixed source

DEFINE_TURB_PREMIX_ SOURCE

User-Defined Function Hooks

turbulent Schmidt number

DEFINE_TURB_SCHMIDT

Viscous Model

turbulent viscosity

DEFINE_TURBULENT_ VISCOSITY

Viscous Model

volume reaction rate

DEFINE_VR_RATE

User-Defined Function Hooks

wall function

DEFINE_WALL_FUNCTIONS

Viscous Model

wall nodal force

DEFINE_WALL_NODAL_FORCE

Wall

wall nodal displacement

DEFINE_WALL_NODAL_DISP

Wall

weighted-sum-of-gray-gases model (WSGGM) absorption coefficient

DEFINE_WSGGM_ABS_COEFF

Create/Edit Materials

soot absorption coefficient

DEFINE_WSGGM_ABS_COEFF

Create/Edit Materials

cell zone motion components in a moving reference frame, moving mesh, or solid motion simulation

DEFINE_ZONE_MOTION

cell zone condition


Table 2.6: Quick Reference Guide for Model-Specific DEFINE Functions MULTIPHASE ONLY

Function

DEFINE Macro

Dialog Box Activated In

volume fraction (all multiphase models)

DEFINE_PROFILE

boundary condition

contact angle (VOF)

DEFINE_PROFILE

Wall boundary condition

heat transfer coefficient (Eulerian)

DEFINE_PROPERTY

Phase Interaction

surface tension coefficient (VOF)

DEFINE_PROPERTY

Phase Interaction

cavitation surface tension coefficient (Mixture)

DEFINE_PROPERTY

Phase Interaction

cavitation vaporization pressure (Mixture)

DEFINE_PROPERTY

Phase Interaction

particle or droplet diameter (Mixture)

DEFINE_PROPERTY

Create/Edit Materials

diameter (Eulerian, Mixture)

DEFINE_PROPERTY

Secondary Phase

solids pressure (Eulerian, Mixture)

DEFINE_PROPERTY

Secondary Phase

radial distribution (Eulerian, Mixture)

DEFINE_PROPERTY

Secondary Phase

elasticity modulus (Eulerian, Mixture)

DEFINE_PROPERTY

Secondary Phase

viscosity (Eulerian, Mixture)

DEFINE_PROPERTY

Secondary Phase

temperature (Eulerian, Mixture)

DEFINE_PROPERTY

Secondary Phase

bulk viscosity (Eulerian)

DEFINE_PROPERTY

Secondary Phase

frictional viscosity (Eulerian)

DEFINE_PROPERTY

Secondary Phase

frictional pressure (Eulerian)

DEFINE_PROPERTY

Secondary Phase

frictional modulus (Eulerian)

DEFINE_PROPERTY

Secondary Phase

granular viscosity (Eulerian)

DEFINE_PROPERTY

Secondary Phase

granular bulk viscosity (Eulerian)

DEFINE_PROPERTY

Secondary Phase

granular conductivity (Eulerian)

DEFINE_PROPERTY

Secondary Phase

temperature source (Eulerian, Mixture)

DEFINE_SOURCE

boundary condition


2.3.1. DEFINE_ANISOTROPIC_CONDUCTIVITY

2.3.1.1. Description

You can use DEFINE_ANISOTROPIC_CONDUCTIVITY to specify the conductivity matrix in a solid, in order to simulate anisotropic thermal conductivity. For details about user-defined anisotropic conductivity, see User-Defined Anisotropic Thermal Conductivity in the User’s Guide.

2.3.1.2. Usage

DEFINE_ANISOTROPIC_CONDUCTIVITY (name, c, t, dmatrix)

Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index.

Thread *t

Pointer to the cell thread on which the anisotropic conductivity is to be applied.

Real dmatrix[ND_ND] [ND_ND]

Anisotropic conductivity matrix to be filled in by the user.

Function returns

void

There are four arguments to DEFINE_ANISOTROPIC_CONDUCTIVITY: name, c, t, and dmatrix. You supply name, the name of the UDF. c, t, and dmatrix are variables that are passed by the Ansys Fluent solver to your UDF. Your function will compute the conductivity matrix for a single cell and fill dmatrix with it. Note that anisotropic conductivity UDFs are called by Ansys Fluent from within a loop on cell threads. Consequently, your UDF will not need to loop over cells in a thread since Ansys Fluent is doing it outside of the function call.

2.3.1.3. Example

The following UDF, named cyl_ortho_cond computes the anisotropic conductivity matrix for a cylindrical shell that has different conductivities in radial, tangential, and axial directions. This function can be executed as a compiled UDF.

/******************************************************************************
 UDF for defining the anisotropic conductivity matrix for a cylindrical shell
 ******************************************************************************/
 #include "udf.h"

 /* Computation of anisotropic conductivity matrix for
 * cylindrical orthotropic conductivity */

 /* axis definition for cylindrical conductivity */
 static const real origin[3] = {0.0, 0.0, 0.0};
 static const real axis[3]  = {0.0, 0.0, 1.0};

 /* conductivities in radial, tangential and axial directions */
 static const real cond[3] = {1.0, 0.01, 0.01};

 DEFINE_ANISOTROPIC_CONDUCTIVITY(cyl_ortho_cond,c,t,dmatrix)
 {
    real x[3][3]; /* principal direction matrix for cell in cartesian coords. */
    real xcent[ND_ND];
    real R;
    C_CENTROID(xcent,c,t);
    NV_VV(x[0],=,xcent,-,origin);
   #if RP_3D
      NV_V(x[2],=,axis);
   #endif
   #if RP_3D
      R = NV_DOT(x[0],x[2]);
      NV_VS(x[0],-=,x[2],*,R);
   #endif
    R = NV_MAG(x[0]);
    if (R > 0.0)
       NV_S(x[0],/=,R);
   #if RP_3D
    N3V_CROSS(x[1],x[2],x[0]);
   #else
      x[1][0] = -x[0][1];
      x[1][1] = x[0][0];
   #endif
    /* dmatrix is computed as xT*cond*x */
    dmatrix[0][0] = cond[0]*x[0][0]*x[0][0]
       + cond[1]*x[1][0]*x[1][0]
   #if RP_3D
     + cond[2]*x[2][0]*x[2][0]
   #endif
   ;
    dmatrix[1][1] = cond[0]*x[0][1]*x[0][1]
     + cond[1]*x[1][1]*x[1][1]
   #if RP_3D
     + cond[2]*x[2][1]*x[2][1]
   #endif
     ;
    dmatrix[1][0] = cond[0]*x[0][1]*x[0][0]
     + cond[1]*x[1][1]*x[1][0]
   #if RP_3D
     + cond[2]*x[2][1]*x[2][0]
   #endif
   ;
    dmatrix[0][1] = dmatrix[1][0];

   #if RP_3D
    dmatrix[2][2] = cond[0]*x[0][2]*x[0][2]
     + cond[1]*x[1][2]*x[1][2]
     + cond[2]*x[2][2]*x[2][2]
     ;
    dmatrix[0][2] = cond[0]*x[0][0]*x[0][2]
     + cond[1]*x[1][0]*x[1][2]
     + cond[2]*x[2][0]*x[2][2]
     ;
    dmatrix[2][0] = dmatrix[0][2];
   dmatrix[1][2] = cond[0]*x[0][1]*x[0][2]
     + cond[1]*x[1][1]*x[1][2]
     + cond[2]*x[2][1]*x[2][2]
     ;
    dmatrix[2][1] = dmatrix[1][2];
   #endif
 }

2.3.1.4. Hooking an Anisotropic Conductivity UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_ANISOTROPIC_CONDUCTIVITY is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, cyl_ortho_cond) will become visible and selectable in the Create/Edit Materials dialog box in Ansys Fluent. See Hooking DEFINE_ANISOTROPIC_CONDUCTIVITY UDFs for details.

2.3.2. DEFINE_CAPILLARY_PRESSURE

2.3.2.1. Description

You can use DEFINE_CAPILLARY_PRESSURE to specify your own formulation of capillary pressure for the electrolysis and H2 pump model. For more information about the electrolysis and H2 pump model, see Electrolysis and H2 Pump Model in the Fluent Theory Guide.

2.3.2.2. Usage

DEFINE_CAPILLARY_PRESSURE (name, c, t, cp, dcpdalpha, s)

Argument Type

Description

symbol name

UDF name.

cell_t c

Cell or face index.

Thread *t

Pointer to the cell or face thread.

Thread *cp

Pointer to capillary pressure.

Real dcpdalpha

Pointer to the capillary pressure gradient in the space of the volume fraction of the liquid phase.

Real s

Liquid saturation.

Function returns

void

There are six arguments to DEFINE_CAPILLARY_PRESSURE: name, c, t, cp, dcpdalpha, and s. You supply name, the name of the UDF. c, t, cp, dcpdalpha, and s are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to set the values of cp, dcpdalpha.

2.3.2.3. Example

The following example shows how to use the DEFINE_CAPILLARY_PRESSURE UDF to assign constant values to capillary pressure and the capillary pressure gradient in the space of the volume fraction of the liquid phase.

/******************************************************************************
 #include "udf.h"

DEFINE_CAPILLARY_PRESSURE(capillary_pre,c,t,cp,dpcdalpha, s)
{
  *cp = 100;
  *dpcdalpha = 10000;
  return;
}

2.3.2.4. Example 2

The following UDF, named capillary_pre, calculates the capillary pressure using the Leverett function with the contact angle less than 90 degrees.

/******************************************************************************
 #include "udf.h"

DEFINE_CAPILLARY_PRESSURE(capillary_pre,c,t,cp,dpcdalpha,s)
{
  real av = 1.417;
  real bv = 2.12;
  real cv = 1.263;
  real theta = 60;
  real sigma = 0.0644;
  real porosity = 0.5;
  real perm = 1e-12;
 
  real Js = av * (1 - s) - bv * (1 - s) * (1 - s) + cv * pow(1 - s, 3);
  real dJsdalpha = - (av - 2 * bv * (1.0 - s) + 3 * cv * (1.0 - s) * (1.0 - s));
 
  *cp = sigma * cos(theta * M_PI / 180.) * sqrt(porosity / perm) * Js;
  *dpcdalpha = sigma * cos(theta * M_PI / 180.) * sqrt(porosity / perm) * dJsdalpha;
 
  return;
}

2.3.2.5. Hooking a Capillary Pressure UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_CAPILLARY_PRESSURE is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument will become visible and selectable in the Anode and Cathode tabs of the Potential/Electrochemistry dialog box in Ansys Fluent. See Hooking DEFINE_CAPILLARY_PRESSURE UDFs for details.

2.3.3. DEFINE_CHEM_STEP

2.3.3.1. Description

You can use DEFINE_CHEM_STEP to specify the change in mass fraction due to homogeneous reaction over a time step:

(2–2)

where is the initial mass fraction of species , is time, is the given time step, and is the net rate of change of the th species mass fraction. is th species mass fraction at the end of the integration.

DEFINE_CHEM_STEP UDFs are used for the laminar finite-rate (with the stiff chemistry solver), EDC and PDF Transport models.

2.3.3.2. Usage

DEFINE_CHEM_STEP (name, c, t, p, num_p, n_spe, dt, pres, temp, yk)

Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index of current particle.

Thread *t

Pointer to cell thread for particle.

Particle *p

Pointer to Particle data structure that represents a particle used by the PDF transport model.

int num_p

Not Used.

int n_spec

Number of volumetric species.

double *dt

Time step.

double *pres

Pointer to pressure.

double *temp

Pointer to temperature.

double *yk

Pointer to array of initial species mass fractions.

Function returns

void

There are nine arguments to DEFINE_CHEM_STEP: name, c, p, num_p, n_spe, dt, pres, temp, and yk. You supply name, the name of the UDF. c, p, n_spe, dt, pres, temp, and yk are variables that are passed by the Ansys Fluent solver to your UDF. num_p is not used by the function and can be ignored. The output of the function is the array of mass fractions yk after the integration step. The initial mass fractions in array yk are overwritten.

2.3.3.3. Example

The following UDF, named user_chem_step, assumes that the net volumetric reaction rate is the expression,

(2–3)

where is the number of species.

An analytic solution exists for the integral of this ODE as,

(2–4)

/***************************************************
   Example UDF that demonstrates DEFINE_CHEM_STEP
 ***************************************************/
 #include "udf.h"
 
 DEFINE_CHEM_STEP(user_chem_step,cell,thread,particle,nump,nspe,dt,pres,temp,yk)
 {
   int i;
   double c = 1./(double)nspe;
   double decay = exp(-(*dt));
   for(i=0;i<n_spe;i++)
      yk[i] = (yk[i]-c)*decay + c;
 } 

2.3.3.4. Hooking a Chemistry Step UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_CHEM_STEP is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_chem_step) will become visible and selectable in the User-Defined Function Hooks dialog box in Ansys Fluent. See Hooking DEFINE_CHEM_STEP UDFs for details.

2.3.4. DEFINE_CPHI

2.3.4.1. Description

You can use DEFINE_CPHI to set the value of the mixing constant (see Equation 7–153 and Equation 7–155 in the Theory Guide for details). It is useful for modeling flows where departs substantially from its default value of , which occurs at low Reynolds and/or high Schmidt numbers.

2.3.4.2. Usage

DEFINE_CPHI (name, c, t)

Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index.

Thread *t

Pointer to cell thread.

Function returns

real

There are three arguments to DEFINE_CPHI: name, c, and t. You supply name, the name of the UDF. c and t are passed by the Ansys Fluent solver to your UDF. Your UDF will need to compute the real value of the mixing constant () and return it to the solver.

2.3.4.3. Hooking a Mixing Constant UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_CPHI is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument will become visible and selectable in the User-Defined Function Hooks dialog box in Ansys Fluent whenever the Composition PDF Transport model is enabled. See Hooking DEFINE_CPHI UDFs for details.

2.3.5. DEFINE_CORNER_FLOW_CORRECTION_CCORNER

2.3.5.1. Description

You can use DEFINE_CORNER_FLOW_CORRECTION_CCORNER to specify a custom coefficient for which is used in the corner flow correction term to influence the strength of the corner flow correction if needed for a specific flow.

2.3.5.2. Usage

DEFINE_CORNER_FLOW_CORRECTION_CCORNER (name, c, t)

Argument Type

Description

symbol name

UDF name.

cell_t c

Index that identifies the cell on which the corner flow correction coefficient is to be applied.

Thread *t

Pointer to cell thread.

Function returns

real

There are three arguments to these functions: name, c, and t. You specify the name of the UDF. c and t are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF returns the real value for the corner flow correction coefficient .

2.3.5.3. Example

In the following example, a zonal approach is demonstrated. Depending on the x-coordinate, the corner flow correction coefficient has different values.

#include "udf.h"
DEFINE_CORNER_FLOW_CORRECTION_CCORNER(corner_flow_ccorner, c, t)
 {
    real corner_flow_correction_ccorner;
    real xc[ND_ND];
    C_CENTROID(xc,c,t);
    if (xc[0] > 2.0)
      corner_flow_correction_ccorner = 1.1;
    else
      corner_flow_correction_ccorner = 1.0;
    return corner_flow_correction_ccorner;
 }

2.3.5.4. Hooking a UDF for Corner Flow Correction Coefficient to Ansys Fluent

After the UDF that you have defined using DEFINE_CORNER_FLOW_CORRECTION_CCORNER is interpreted or compiled, the name of the argument that you supplied as the DEFINE macro argument (for example, corner_flow_ccorner) will become visible and selectable in the Viscous Model dialog box in the drop-down menu of the model coefficient.

2.3.6. DEFINE_CURVATURE_CORRECTION_CCURV

2.3.6.1. Description

You can use DEFINE_CURVATURE_CORRECTION_CCURV to specify a custom function for the coefficient which is used in the curvature correction term to influence the strength of the curvature correction, if needed for a specific flow. For more information, see Curvature Correction for the Spalart-Allmaras and Two-Equation Models in the Fluent Theory Guide.

The coefficient should be positive and in the case of a user defined function, the provided value of is automatically limited by max(,0).

2.3.6.2. Usage

DEFINE_CURVATURE_CORRECTION_CCURV (name, c, t)

Argument Type

Description

symbol name

UDF name.

cell_t c

Index that identifies the cell on which the curvature correction coefficient is to be applied.

Thread *t

Pointer to cell thread.

Function returns

real

There are 3 arguments for DEFINE_CURVATURE_CORRECTION_CCURV: name, c, and t. You supply name, the name of the UDF. c and t are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to return the real value for the curvature correction coefficient .

2.3.6.3. Example

In the following example, a zonal approach is demonstrated: Depending on the x-coordinate, the curvature correction coefficient has different values.

#include "udf.h"
DEFINE_CURVATURE_CORRECTION_CCURV(user_curvcor_ccurv, c, t)
{
  real curvature_correction_ccurv;
  real xc[ND_ND];
  C_CENTROID(xc,c,t);
  if (xc[0] > 2.0)
    curvature_correction_ccurv = 1.1;
  else
    curvature_correction_ccurv = 1.0;
  return curvature_correction_ccurv;
} 

2.3.6.4. Hooking a UDF for Curvature Correction Coefficient to Ansys Fluent

After the UDF that you have defined using DEFINE_CURVATURE_CORRECTION_CCURV is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name that you specified in the DEFINE macro argument (for example, user_curvcor_ccurv) will become visible and selectable in the Viscous Model dialog box in the drop-down menu for the curvature correction coefficient.

2.3.7. DEFINE_DIFFUSIVITY

2.3.7.1. Description

You can use DEFINE_DIFFUSIVITY to specify the diffusivity for the species transport equations (for example, mass diffusivity) or for user-defined scalar (UDS) transport equations. For details about UDS diffusivity, see User-Defined Scalar (UDS) Diffusivity in the User’s Guide.

2.3.7.2. Usage

DEFINE_DIFFUSIVITY (name, c, t, i)

Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index.

Thread *t

Pointer to cell thread on which the diffusivity function is to be applied.

int i

Index that identifies the species or user-defined scalar.

Function returns

real

There are four arguments to DEFINE_DIFFUSIVITY: name, c, t, and i. You supply name, the name of the UDF. c, t, and i are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to compute the diffusivity only for a single cell and return the real value to the solver.

Note that diffusivity UDFs are called by Ansys Fluent from within a loop on cell threads. Consequently, your UDF will not need to loop over cells in a thread since Ansys Fluent is doing it outside of the function call.

2.3.7.3. Example

The following UDF, named mean_age_diff, computes the diffusivity for the mean age of air using a user-defined scalar. Note that the mean age of air calculations do not require that energy, radiation, or species transport calculations have been performed. You will need to set uds-0 = at all inlets and outlets in your model. This function can be executed as an interpreted or compiled UDF.

/**********************************************************************
   UDF that computes diffusivity for mean age using a user-defined
   scalar.
 ***********************************************************************/
 
 #include "udf.h"
 
 DEFINE_DIFFUSIVITY(mean_age_diff,c,t,i)
 {
    return C_R(c,t) * 2.88e-05 + C_MU_EFF(c,t) / 0.7;
 } 

2.3.7.4. Hooking a Diffusivity UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_DIFFUSIVITY is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name that you specified in the DEFINE macro argument (for example, mean_age_diff) will become visible and selectable in the Create/Edit Materials dialog box in Ansys Fluent. See Hooking DEFINE_DIFFUSIVITY UDFs for details.

2.3.8. DEFINE_DOM_DIFFUSE_REFLECTIVITY

2.3.8.1. Description

You can use DEFINE_DOM_DIFFUSE_REFLECTIVITY to modify the inter-facial reflectivity computed by Ansys Fluent at diffusely reflecting semi-transparent walls, based on the refractive index values. During execution, a DEFINE_DOM_DIFFUSE_REFLECTIVITY function is called by Ansys Fluent for each semi-transparent wall and also for each band (in the case of a non-gray discrete ordinates (DO) model). Therefore the function can be used to modify diffuse reflectivity and diffuse transmissivity values at the interface.

2.3.8.2. Usage

DEFINE_DOM_DIFFUSE_REFLECTIVITY (name, t, nb, n_a, n_b, diff_ref_a, diff_tran_a, diff_ref_b, diff_tran_b)


Important:  Note that all of the arguments to a DEFINE macro need to be placed on the same line in your source code. Splitting the DEFINE statement onto several lines will result in a compilation error.


Argument Type

Description

symbol name

UDF name.

Thread *t

Pointer to the thread on which the discrete ordinate diffusivity function is to be applied.

int nb

Band number (needed for the non-gray discrete ordinates (DO) model).

real n_a

Refractive index of medium a.

real n_b

Refractive index of medium b.

real *diff_ref_a

Diffuse reflectivity at the interface facing medium a.

real *diff_tran_a

Diffuse transmissivity at the interface facing medium a.

real *diff_ref_b

Diffuse reflectivity at the interface facing medium b.

real *diff_tran_b

Diffuse transmissivity at the interface facing medium b.

Function returns

void

There are nine arguments to DEFINE_DOM_DIFFUSE_REFLECTIVITY: name, t, nb, n_a, n_b, diff_ref_a, diff_tran_a, diff_ref_b, and diff_tran_b. You supply name, the name of the UDF. t, nb, n_a, n_b, diff_ref_a, diff_tran_a, diff_ref_b, and diff_tran_b are variables that are passed by the Ansys Fluent solver to your UDF.

2.3.8.3. Example

The following UDF, named user_dom_diff_refl, modifies diffuse reflectivity and transmissivity values on both the sides of the interface separating medium a and b. The UDF is called for all the semi-transparent walls and prints the value of the diffuse reflectivity and transmissivity values for side a and b.


Important:  Note that in the example that follows, the DEFINE_DOM_DIFFUSE_REFLECTIVITY statement is broken up into two lines for the sake of readability. In your source file, you must make sure that the DEFINE statement is on one line only.


/* UDF to print the diffuse reflectivity and transmissivity 
 at semi-transparent walls*/
 
 #include "udf.h"
 
 DEFINE_DOM_DIFFUSE_REFLECTIVITY(user_dom_diff_refl,t,nband,n_a,n_b,diff_ref_a,diff_tran_a,diff_ref_b,diff_tran_b)
 {
   printf("diff_ref_a=%f diff_tran_a=%f \n", *diff_ref_a, *diff_tran_a);
   printf("diff_ref_b=%f diff_tran_b=%f \n", *diff_ref_b, *diff_tran_b);
 } 

2.3.8.4. Hooking a Discrete Ordinates Model (DOM) Diffuse Reflectivity UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_DOM_DIFFUSE_REFLECTIVITY is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_dom_diff_refl) will become visible and selectable in the User-Defined Function Hooks dialog box in Ansys Fluent.

See Hooking DEFINE_DOM_DIFFUSE_REFLECTIVITY UDFs for details.

2.3.9. DEFINE_DOM_SOURCE

2.3.9.1. Description

You can use DEFINE_DOM_SOURCE to modify the emission term, which is the first term on the right hand side in Equation 5–98 or Equation 5–99 in the Theory Guide, as well as the scattering term (second term on the right hand side of either equation) in the radiative transport equation for the discrete ordinates (DO) model.

2.3.9.2. Usage

DEFINE_DOM_SOURCE (name, c, t, ni, nb, emission, in_scattering, abs_coeff, scat_coeff)

Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index.

Thread *t

Pointer to cell thread.

int ni

Direction represented by the solid angle.

int nb

Band number (needed for the non-gray discrete ordinates (DO) model).

real *emission

Pointer to emission term in the radiative transport equation (Equation 5–98 in the Theory Guide)

real *in_scattering

Pointer to scattering term in the radiative transport equation (Equation 5–99 in the Theory Guide)

real *abs_coeff

Pointer to absorption coefficient.

real *scat_coeff

Pointer to scattering coefficient.

Function returns

void

There are nine arguments to DEFINE_DOM_SOURCE: name, t, c, ni, nb, emission, in_scattering, abs_coeff, and scat_coeff. You supply name, the name of the UDF. c, ni, nb, emission, in_scattering, abs_coeff, and scat_coeff are variables that are passed by the Ansys Fluent solver to your UDF. DEFINE_DOM_SOURCE is called by Ansys Fluent for each cell.

2.3.9.3. Example

In the following UDF, named dom, the emission term present in the radiative transport equation is modified. The UDF is called for all the cells and increases the emission term by .

/* UDF to alter the emission source term in the DO model */
 
 #include "udf.h"
 
 DEFINE_DOM_SOURCE(dom,c,t,ni,nb,emission,in_scattering,abs_coeff,scat_coeff)
 {
   /* increased the emission by 5% */

   *emission *= 1.05;
 
 } 

2.3.9.4. Hooking a DOM Source UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_DOM_SOURCE is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, dom) will become visible and selectable in the User-Defined Function Hooks dialog box in Ansys Fluent. Note that you can hook multiple discrete ordinate source term functions to your model. See Hooking DEFINE_DOM_SOURCE UDFs for details.

2.3.10. DEFINE_DOM_SPECULAR_REFLECTIVITY

2.3.10.1. Description

You can use DEFINE_DOM_SPECULAR_REFLECTIVITY to modify the inter-facial reflectivity of specularly reflecting semi-transparent walls. You may want to do this if the reflectivity is dependent on other conditions that the standard boundary condition does not allow for (see Specular Semi-Transparent Walls of the Theory Guide for more information). During Ansys Fluent execution, the same UDF is called for all the faces of the semi-transparent wall, for each of the directions.

2.3.10.2. Usage

DEFINE_DOM_SPECULAR_REFLECTIVITY (name, f, t, nband, n_a, n_b, ray_direction, en, internal_reflection, specular_reflectivity, specular_transmissivity)


Important:  Note that all of the arguments to a DEFINE macro need to be placed on the same line in your source code. Splitting the DEFINE statement onto several lines will result in a compilation error.


Argument Type

Description

symbol name

UDF name.

face_t f

Face index.

Thread *t

Pointer to face thread on which the specular reflectivity function is to be applied.

int nband

Band number (needed for non-gray discrete ordinates (DO) model).

real n_a

Refractive index of medium a.

real n_b

Refractive index of medium b.

real ray_direction

Direction vector () defined in Equation 5–116 in the Theory Guide.

real en

Interface normal vector () defined in Equation 5–116 in the Theory Guide.

int internal_reflection

Variable used to flag the code that total internal reflection has occurred.

real *specular_reflectivity

Specular reflectivity for the given direction .

real *specular_transmissivity

Specular transmissivity for the given direction .

Function returns

void

There are eleven arguments to DEFINE_DOM_SPECULAR_REFLECTIVITY: name, f, t, nband, n_a, n_b, ray_direction, en, internal_reflection, specular_reflectivity, and specular_transmissivity. You supply name, the name of the UDF. f, t, nband, n_a, n_b, ray_direction, en, internal_reflection, specular_reflectivity, and specular_transmissivity are variables that are passed by the Ansys Fluent solver to your UDF.

2.3.10.3. Example

In the following UDF, named user_dom_spec_refl, specular reflectivity and transmissivity values are altered for a given ray direction at face f.


Important:  Note that in the example that follows, the DEFINE_DOM_SPECULAR_REFLECTIVITY statement is broken up into three lines for the sake of readability. In your source file, you must make sure that the DEFINE statement is on one line only.


/* UDF to alter the specular reflectivity and transmissivity, at
  semi-transparent walls, along direction s at face f */
 
 #include "udf.h"
 
 DEFINE_DOM_SPECULAR_REFLECTIVITY(user_dom_spec_refl,f,t,nband,n_a,n_b,ray_direction,en,internal_reflection,specular_reflectivity,specular_transmissivity)
 {
   real angle, cos_theta;
   real PI = 3.141592;
   cos_theta = NV_DOT(ray_direction, en);
   angle = acos(cos_theta);
   if (angle > 0.785398  && angle < 1.047198)
      {
        *specular_reflectivity = 0.3;
        *specular_transmissivity = 0.7;
      }
 }

2.3.10.4. Hooking a Discrete Ordinates Model (DOM) Specular Reflectivity UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_DOM_SPECULAR_REFLECTIVITY is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_dom_spec_refl) will become visible and selectable in the User-Defined Function Hooks dialog box in Ansys Fluent.

See Hooking DEFINE_DOM_SPECULAR_REFLECTIVITY UDFs for details.

2.3.11. DEFINE_EC_KINETICS_PARAMETER

2.3.11.1. Description

You can use DEFINE_EC_KINETICS_PARAMETER to customize any of the kinetics parameters (anodic and cathodic transfer coefficient, exchange current density, and equilibrium potential) in the Butler-Volmer equation. The UDF can be hooked up from the Reaction dialog box.


Important:   DEFINE_EC_KINETICS_PARAMETER UDFs can be executed only as compiled UDFs.


2.3.11.2. Usage

DEFINE_EC_KINETICS_PARAMETER(name, f, fthread)

Argument Type

Description

symbol name

UDF name.

face_t f

Index that identifies a face within the given thread.

Thread *fthread

Pointer to face thread on which the surface rate reaction is to be applied

Function returns

double

There are three arguments to DEFINE_EC_KINETICS_PARAMETER: name, f, and fthread. You supply name, the name of the UDF. f and fthread are variables that are passed by the Ansys Fluent solver to your UDF. After your UDF is compiled and linked, the name that you have chosen for your function will become visible and selectable in the graphical user interface in Ansys Fluent. Your UDF will return a double value to the kinetics parameter which you have hooked up to.

2.3.11.3. Example - Electrochemical Reaction Kinetics Parameter Using UDF

The following compiled UDF, named ec_parameter_Eeq, computes temperature-dependent equilibrium potential through the UDF approach. You can use this type of UDF to compute any of the four kinetics parameters used in the electrochemical reaction (anodic transfer coefficient/anodic Tafel slope, cathodic transfer coefficient/cathodic Tefel slope, exchange current density, and equilibrium potential).

/*******************************************************************
Custom electrochemical reaction kinetics parameter UDF
********************************************************************/
#include "udf.h"
DEFINE_EC_KINETICS_PARAMETER(ec_parameter_Eeq, f, fthread)
{
  real T, Eeq;  
  T = F_T(f, fthread);
  Eeq = 0.8 + 0.0001 * T; 
  return Eeq;
}

2.3.11.4. Hooking an Electrochemical Reaction Kinetics Parameter UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_EC_KINETICS_PARAMETER is compiled and loaded (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, ec_parameter_Eeq) will become visible and selectable after you select the user-defined option for a kinetics parameter in the Reaction dialog box. See Hooking DEFINE_EC_KINETICS_PARAMETER UDFs for details.

2.3.12. DEFINE_EC_RATE

2.3.12.1. Description

You can use DEFINE_EC_RATE to specify a custom electrochemical reaction rate. A custom electrochemical reaction rate function defined using this macro will overwrite the default reaction rate specified in the Create/Edit Materials dialog box.

2.3.12.2. Usage

DEFINE_EC_RATE (name, f, t, r, V, i, didV, Eeq)

Argument Type

Description

symbol name

UDF name.

face_t f

Index that identifies a face within the given thread.

Thread *t

Pointer to face thread on which the electrochemical reaction is to be applied.

Reaction *r

Pointer to data structure for the reaction.

double V

Potential difference between electrode and electrolyte .

double *i

Pointer to the electric current density, .

double *didV

Pointer to the derivative of current density with respect to potential difference , .

double *Eeq

Pointer to the Equilibrium potential

Function returns

void

There are eight arguments to DEFINE_EC_RATE: name, f, t, r, V, i, didV, and Eeq. You supply name, the name of the UDF. f, t, r, and V are variables that are passed by the Ansys Fluent solver to your UDF. After your UDF is compiled and linked, the name that you have chosen for your function will become visible and selectable in the graphical user interface in Ansys Fluent. Your UDF will need to set three values referenced by the real pointers i didV, and Eeq.

2.3.12.3. Example - Electrochemical Reaction Rate Using UDF

The following compiled UDF, named user_ec_rate, implements the solver default Butler-Volmer equation through the UDF approach. You can customize a term (for example, the exchange current density i0 or the equilibrium potential Eeq) or the whole rate formula.

/*******************************************************************
 Custom electrochemical reaction rate UDF
 ********************************************************************/
 #include "udf.h"
 DEFINE_EC_RATE(user_ec_rate, f, fthread, r, V, current, didV, Eeq)
 {
   double alpha_a, alpha_c;
   double io;
   double T = F_T(f,fthread);
   double arg1, arg2;
   cxboolean tafelmethod = r->tafelmethod;
   int i;
   double eta;
   io      = update_echem_value(r->Pio, f, fthread);
   alpha_a = update_echem_value(r->Palpha_a, f, fthread);
   alpha_c = update_echem_value(r->Palpha_c, f, fthread);
   *Eeq    = update_echem_value(r->PEeq, f, fthread);
 
   if (tafelmethod) 
   {
     alpha_a = 2.303 * UNIVERSAL_GAS_CONSTANT * 298.15 /(alpha_a * FARADAY_CONSTANT);
     alpha_c = 2.303 * UNIVERSAL_GAS_CONSTANT * 298.15 /(alpha_c * FARADAY_CONSTANT);
   }
   eta = V - *Eeq;
   for(i = 0; i<r->n_reactants; i++)
     if( ABS( r->exp_reactant[i] ) > SMALL_S )
     {
       int ni = r->reactant[i];
       io *= pow((F_YI(f,fthread,ni)/MAX(r->yi_ref[ni],SMALL) + 1.0e-20), r->exp_reactant[i]);
     }
   for(i = 0; i<r->n_products; i++)
     if( ABS( r->exp_product[i] ) > SMALL_S )
     {
       int ni = r->product[i];
       io *= pow((F_YI(f,fthread,ni)/MAX(r->yi_ref[ni],SMALL) + 1.0e-20), r->exp_product[i]);
     }
   arg1 = FARADAY_CONSTANT / (UNIVERSAL_GAS_CONSTANT*T);
   arg2 = arg1*eta;
   *current = io*( exp( arg2*alpha_a ) - exp( -arg2*alpha_c ) );
   *didV = io*( arg1*alpha_a*exp( arg2*alpha_a ) + arg1*alpha_c*exp( -arg2*alpha_c ) );

   /* If multiple electrochemical reactions are used, you can define rate for each reaction
      using the following if-statement */
   /*
   if (STREQ(r->name, "reaction-1"))
   {
     ...
   }
   else if (STREQ(r->name, "reaction-2"))
   {
     ...
   }
 */
 } 

2.3.12.4. Hooking an Electrochemical Reaction Rate UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_EC_RATE is compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_ec_rate) will become visible and selectable in the User-Defined Function Hooks dialog box in Ansys Fluent. See Hooking DEFINE_EC_RATE UDFs for details.

2.3.13. DEFINE_EDC_MDOT

2.3.13.1. Description

In Ansys Fluent, the Eddy Dissipation Concept (EDC) model closes the species transport equations according to the terms given in The Eddy-Dissipation-Concept (EDC) Model in the Fluent Theory Guide. You can use the DEFINE_EDC_MDOT UDF to modify the reaction rate for the EDC model as shown in Equation 7–42 in the Fluent Theory Guide. Equation 7–42 can be rewritten as follows:

(2–5)

This UDF allows you to use your own formulation to calculate the term and the time scale in Equation 2–5.

2.3.13.2. Usage

DEFINE_EDC_MDOT (name, c, t, mdot, calc_tau, tau)


Important:
  • Note that all the arguments of a DEFINE macro need to be placed on the same line in your source code. Splitting the DEFINE statement into several lines will result in a compilation error.

  • DEFINE_EDC_MDOT functions can be executed only as compiled UDFs.


Argument Type

Description

symbol name

UDF name.

cell_t c

Cell or face index.

Thread *t

Pointer to the cell or face thread.

real *mdot

Pointer to parameter .

int calc_tau

Integer that indicates whether tau will be calculated (tau will be computed if calc_tau is set to a non-zero value).

real *tau

Pointer to value.

Function returns

void

There are six arguments to DEFINE_EDC_MDOT: name, c, t, mdot, calc_tau, and tau. You supply name, the name of the UDF. The variables c, t, mdot, calc_tau, and tau are passed by the Ansys Fluent solver to your UDF. The values of mdot and tau passed by the Ansys Fluent solver are those used by the solver unless they are reset by this routine. The routine may reset any or all of these values.

The calc_tau indicator is provided for efficiency purposes as DEFINE_EDC_MDOT will be called several times by the solver but will not always use the tau value. Enclosing the tau calculation with if (calc_tau) {}, as in Example, will thus maximize the efficiency of this routine.

2.3.13.3. Example

The following example is a source code template where the DEFINE_EDC_MDOT function is used to set the term for the EDC model.

/*******************************************************************
 Example UDF that demonstrates the use of DEFINE_EDC_MDOT to set the 
term mdot in the EDC model.
 ********************************************************************/
 #include <udf.h>
 
 DEFINE_EDC_MDOT(edc_mdot, c, t, mdot, calc_tau, tau)
 {
  real ted1 = MAX(C_D(c,t), 1.0e-03);
  real ted2 = C_D(c, t);
  real c2 = 0.4083;
  real c1 = 2.1377;
  real gamma2,gamma = c1 * pow( C_MU_L(c, t) * ted2 / (C_R(c, t) * SQR(C_K(c, t))), 0.25);
  gamma = MIN( gamma, 0.754877666248);
  gamma2 = gamma * gamma;
  *mdot = gamma2 / ((1. - gamma2 * gamma));
  if (calc_tau)
     {*tau=c2*sqrt(C_MU_L(c,t)/(ted1*C_R(c,t)));
      *tau = MAX(*tau, 1.e-8);}

 } 

2.3.13.4. Hooking a DEFINE_EDC_MDOT UDF to Ansys Fluent

After you have compiled and loaded (Compiling UDFs) the DEFINE_EDC_MDOT UDF and enabled the Eddy Dissipation Concept model, the name of the argument that you supplied as the first DEFINE macro argument will become visible and selectable in the Options group box of the Species Model dialog box in Ansys Fluent. See Hooking DEFINE_DOM_DIFFUSE_REFLECTIVITY UDFs for details.

2.3.14. DEFINE_EDC_SCALES

2.3.14.1. Description

In Ansys Fluent, the Eddy Dissipation Concept (EDC) model closes the species transport equations according to the terms given in The Eddy-Dissipation-Concept (EDC) Model in the Fluent Theory Guide. This UDF allows you to modify the coefficients (Equation 7–44) and (Equation 7–45) and the term (Equation 7–45).

2.3.14.2. Usage

DEFINE_EDC_SCALES (name, c, t, c1, c2, calc_tau, tau)


Important:
  • Note that all the arguments of a DEFINE macro need to be placed on the same line in your source code. Splitting the DEFINE statement into several lines will result in a compilation error.

  • DEFINE_EDC_SCALES functions can be executed only as compiled UDFs.


Argument Type

Description

symbol name

UDF name.

cell_t c

Cell or face index.

Thread *t

Pointer to the cell or face thread.

real *c1

Pointer to coefficient .

real *c2

Pointer to coefficient .

int calc_tau

Integer that indicates whether tau will be calculated (tau will be computed if calc_tau is set to a non-zero value).

real *tau

Pointer to value.

Function returns

void

There are seven arguments to DEFINE_EDC_SCALES: name, c, t, c1, c2, calc_tau, and tau. You supply name, the name of the UDF. The variables c, t, c1, c2, calc_tau, and tau are passed by the Ansys Fluent solver to your UDF. The values of c1, c2 and tau passed by the Ansys Fluent solver are those used by the solver unless they are reset by this routine. The routine may reset any or all of these values.

The calc_tau indicator is provided for efficiency purposes as DEFINE_EDC_SCALES will be called several times by the solver but will not always use the tau value. Enclosing the tau calculation with if (calc_tau) {}, as in Example, will thus maximize the efficiency of this routine.

2.3.14.3. Example

The following example is a source code template where the DEFINE_EDC_SCALES function is used to set the EDC model scales.

/*******************************************************************
 Example UDF that demonstrates the use of DEFINE_EDC_SCALES to set the 
EDC model scales.
 ********************************************************************/
 #include <udf.h>
 
 DEFINE_EDC_SCALES(edc_scales, c, t, c1, c2, calc_tau, tau)
 {
   real ted = MAX(C_D(c,t), 1.0e-03);

   *c1 = 2.1337;
   *c2 = 0.4082;

   if (calc_tau)
     *tau = (*c2)*sqrt(C_MU_L(c,t)/(ted*C_R(c,t)));
 } 

2.3.14.4. Hooking a DEFINE_EDC_SCALES UDF to Ansys Fluent

After you have compiled and loaded (Compiling UDFs) the DEFINE_EDC_SCALES UDF and enabled the Eddy Dissipation Concept model, the name of the argument that you supplied as the first DEFINE macro argument will become visible and selectable in the Options group box of the Species Model dialog box in Ansys Fluent. See Hooking DEFINE_EDC_SCALES UDFs for details.

2.3.15. DEFINE_ELECTROLYSIS_ECHEM_RATE

2.3.15.1. Description

In Ansys Fluent, the electrolysis model calculates the transfer currents and using the Butler-Volmer equations (Equation 20–66 and Equation 20–67 in the Fluent Theory Guide). You can use DEFINE_ELECTROLYSIS_ECHEM_RATE to modify the transfer current formulations by using an effective factor as follows:

This UDF allows you to use different values of the transfer current for the specific active surface area in different computational cells.

2.3.15.2. Usage

DEFINE_ELECTROLYSIS_ECHEM_RATE (name, c, t, f)


Important:
  • Note that all the arguments of a DEFINE macro need to be placed on the same line in your source code. Splitting the DEFINE statement into several lines will result in a compilation error.

  • DEFINE_ELECTROLYSIS_ECHEM_RATE functions can be executed only as compiled UDFs.


Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index.

Thread *t

Pointer to the cell thread.

real f

Pointer to the factor value.

Function returns

void

There are four arguments to DEFINE_ELECTROLYSIS_ECHEM_RATE: name, c, t, and f. You supply name, the name of the UDF. The variables c, t, and f are passed by the Ansys Fluent solver to your UDF. Your UDF will need to set the values of f.

2.3.15.3. Example

The following example shows how to use the DEFINE_ELECTROLYSIS_ECHEM_RATE UDF to assign a constant value to the effective factor f.

/******************************************************************************
 #include "udf.h"

DEFINE_ELECTROLYSIS_ECHEM_RATE (myrate, c, t, f)
{
  *f = 2;
  return;
}

2.3.15.4. Hooking a DEFINE_ELECTROLYSIS_ECHEM_RATE UDF UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_ELECTROLYSIS_ECHEM_RATE compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument will become visible and selectable in the Customization tab of the Potential/Electrochemistry dialog box in Ansys Fluent. See Hooking DEFINE_ELECTROLYSIS_ECHEM_RATE UDFs for details.

2.3.16. DEFINE_ELECTROLYSIS_RELATIVE_PERMEABILITY

2.3.16.1. Description

You can use DEFINE_ELECTROLYSIS_RELATIVE_PERMEABILITY to customize the relative permeability used in the transport equation of the volume fraction of liquid water (Equation 18–17). This UDF allows you to specify different relative permeabilities in different cell zones.

2.3.16.2. Usage

DEFINE_ELECTROLYSIS_RELATIVE_PERMEABILITY (name, c, t, rp, s)


Important:
  • Note that all the arguments of a DEFINE macro need to be placed on the same line in your source code. Splitting the DEFINE statement into several lines will result in a compilation error.

  • DEFINE_ELECTROLYSIS_RELATIVE_PERMEABILITY functions can be executed only as compiled UDFs.


Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index.

Thread *t

Pointer to the cell thread.

real *rp

Pointer to the relative permeability.

real s

Liquid saturation.

Function returns

void

There are five arguments to DEFINE_ELECTROLYSIS_RELATIVE_PERMEABILITY: name, c, t, rp, and s. You supply name, the name of the UDF. The variables c, t, rp, and s are passed by the Ansys Fluent solver to your UDF. Your UDF will need to set the values of rp.

2.3.16.3. Example

The following UDF, named myrate, models the relative permeability as a power function of the liquid saturation.

/******************************************************************************
 #include "udf.h"

DEFINE_ELECTROLYSIS_RELATIVE_PERMEABILITY (myrate, c, t, rp, s)
{
  *rp = pow(s, 3.0);
   return;
}

2.3.16.4. Hooking a DEFINE_ELECTROLYSIS_RELATIVE_PERMEABILITY UDF UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_ELECTROLYSIS_RELATIVE_PERMEABILITY compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument will become visible and selectable in the Customization tab of the Potential/Electrochemistry dialog box in Ansys Fluent. See Hooking DEFINE_ELECTROLYSIS_RELATIVE_PERMEABILITY UDFs for details.

2.3.17. DEFINE_EMISSIVITY_WEIGHTING_FACTOR

2.3.17.1. Description

When employing the non-gray P-1 radiation model or the non-gray discrete ordinates (DO) radiation model, you can use DEFINE_EMISSIVITY_WEIGHTING_FACTOR to modify the emissivity weighting factor . By default, the emissivity weighting factor is calculated internally by Ansys Fluent so it can be used in the emission term of the radiative transfer equation, as shown in Equation 5–64 and Equation 5–100 of the Theory Guide. This macro allows you to revise the calculated value.

2.3.17.2. Usage

DEFINE_EMISSIVITY_WEIGHTING_FACTOR (name, c, t, T, nb, emissivity_weighting_factor)

Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index.

Thread *t

Pointer to cell thread.

real T

Temperature.

int nb

Band number.

real *emissivity_weighting_factor

The emissivity weighting factor in the emission term of the radiative transfer equation for the non-gray P-1 model (Equation 5–64 in the Theory Guide) or the non-gray DO model (Equation 5–100 in the Theory Guide).

Function returns

void

There are six arguments to DEFINE_EMISSIVITY_WEIGHTING_FACTOR: name, c, t, T, nb, and emissivity_weighting_factor. You supply name, the name of the UDF. c, t, T, nb, and emissivity_weighting_factor are variables that are passed by the Ansys Fluent solver to your UDF. DEFINE_EMISSIVITY_WEIGHTING_FACTOR is called by Ansys Fluent for each cell.

2.3.17.3. Example

In the following UDF (named em_wt), the emissivity weighting factor present in the emission term of the radiative transfer equation for the non-gray DO model is modified. The UDF is called for all of the cells. It modifies the emissivity weighting factor so that it is no longer the value calculated internally by Ansys Fluent, but is instead changed to .

/* UDF to alter the emissivity weighting factor for the non-gray DO model */
 
 #include "udf.h"
 
 DEFINE_EMISSIVITY_WEIGHTING_FACTOR(em_wt,c,t,T,nb,emissivity_weighting_factor)
 {

   /* revise the calculated emissivity_weighting_factor to be a value of 1 */

   *emissivity_weighting_factor = 1.0;
 
 } 

2.3.17.4. Hooking an Emissivity Weighting Factor UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_EMISSIVITY_WEIGHTING_FACTOR is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, em_wt) will become visible and selectable in the User-Defined Function Hooks dialog box in Ansys Fluent. See Hooking DEFINE_EMISSIVITY_WEIGHTING_FACTOR UDFs for details.

2.3.18. DEFINE_FLAMELET_PARAMETERS

2.3.18.1. Description

You can use DEFINE_FLAMELET_PARAMETERS to specify a user-defined variation of scalar dissipation, mean mixture fraction grid, and mean progress variable grid for flamelet generation with non-premixed or partially premixed combustion models. The UDF is only available if either the Non-Premixed Combustion or Partially-Premixed Combustion model is enabled.

2.3.18.2. Usage

DEFINE_FLAMELET_PARAMETERS (name, Nf, Nc, Ns, xf, xc, xs)

Argument Type

Description

symbol name

UDF name.

Nf

Number of mean mixture fraction grid points in flamelet.

Nc

Number of mean progress variable grid points.

Ns

Maximum number of flamelets.

real *xf

Array to provide mean mixture fraction points.

real *xc

Array to provide mean progress variable points.

real *xs

Array to provide scalar dissipation values.

Function returns

void

There are seven arguments to DEFINE_FLAMELET_PARAMETERS: name, Nf, Nc, Ns, xf, xc, and xs. You supply name, the name of the UDF. Nf, Nc, Ns, xf, xc, and xs are variables that are passed by the Ansys Fluent solver to your UDF. DEFINE_FLAMELET_PARAMETERS does not output a value. The specified grid discretizations or scalar dissipation variations are stored in the arrays xf, xc, and xs, respectively.


Note:  If Automated Grid Refinement is enabled for steady diffusion flamelet generation (see Steady Diffusion Flamelet in the Fluent User's Guide), then you can only use DEFINE_FLAMELET_PARAMETERS UDFs to specify user-defined scalar dissipation variation. Ansys Fluent will ignore the user-defined grid for the mean mixture fraction and/or reaction progress.


2.3.18.3. Example

The following compiled UDF, named user_scad_fmean_grid, is used to provide the user-defined scalar dissipation variation and user-defined mean mixture fraction grid points for flamelet solution.

 #include "udf.h"
 #define fsto 0.056
 
 DEFINE_FLAMELET_PARAMETERS(user_scad_fmean_grid,nf,nc,ns,xf,xc,xs)
 {
    int i,np,np_rich ;

  /* The arrays xf,xc,xs passed by the solver contains default 
     discretization and default scalar dissipation variation*/

  /* These arrays can be over-written with user-defined grid or scalar 
     dissipation variation*/

  /* Flamelets with Scalar dissipation of
     0.01, 0.05, 0.1, 0.15, 0.2, 1, 4, 7, 10,... */


    for(i=0;i<ns;i++)
      {
       if (i < 5)
         xs[i] = 0.01*5*i;
       else
         xs[i] = 1.+(i-5)*3;
      }
 
  /* Sample UDF to provide user defined discretization for fmean grid
     for flamelet generation*/

  /* Divide fmean grid into 3 intervals: (1) f=0 to fsto, (2) fsto to 2.*fsto
     and (3) 2.*fsto to f=1.*/

  /* Place equal number of grid points in these three intervals*/

    if(nf > 0)
      {
       np = (int) nf/3;
       np_rich = 2*np;
      }
    for(i=0;i<nf;i++)
      {
       if(i <= np)
         {
          xf[i] = i*fsto/np;
         }
       else if(i <= np_rich)
         {
          xf[i] = fsto+fsto*(i-np)/(np_rich-np);
         }
       else
         {
          xf[i]= 2.*fsto + (1.-2*fsto)*(i-np_rich)/(nf-1-np_rich);
         }
      }
 } 

2.3.18.4. Hooking a Flamelet Parameters UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_FLAMELET_PARAMETERS is compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_scad_fmean_grid) will become visible and selectable in the User-Defined Function drop-down list under the Flamelet tab of the Species Model dialog box in Ansys Fluent. See Hooking DEFINE_FLAMELET_PARAMETERS UDFs for details.

2.3.19. DEFINE_GAP_MODEL_SOURCE

2.3.19.1. Description

You can use DEFINE_GAP_MODEL_SOURCE to specify source terms for momentum and energy equations for the cells located in a gap region. For details about using the gap model, see Controlling Flow in Narrow Gaps for Valves and Pumps in the Fluent User's Guide.

2.3.19.2. Usage

DEFINE_GAP_MODEL_SOURCE (name, c, tc, Source, dS)

Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index.

Thread *tc

Pointer to cell thread.

real Source[]

Source term.

real dS[]

Source term linearization term.

Function returns

real

There are five arguments to DEFINE_GAP_MODEL_SOURCE: name, c, tc, Source, and dS. You supply name, the name of the UDF. c and tc are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF returns the real value of Source and dS.

2.3.19.3. Example

The following compiled UDF, named gap_user_sources, is used to provide the source terms for momentum and energy equations for the cells located in a gap region.

#include "udf.h"

DEFINE_GAP_MODEL_SOURCE(gap_user_sources, c, tc, Source, dS)
{
real Vmag = ND_MAG(C_U(c,tc), C_V(c,tc), C_W(c,tc));
Source[EQ_X_MOM_GAP_SOURCE] = -0.5 * C_R(c,tc) * Vmag * C_U(c,tc);
Source[EQ_Y_MOM_GAP_SOURCE] = -0.5 * C_R(c,tc) * Vmag * C_V(c,tc);
Source[EQ_Z_MOM_GAP_SOURCE] = -0.5 * C_R(c,tc) * Vmag * C_W(c,tc);
Source[EQ_ENERGY_GAP_SOURCE] = 0.0;

dS[EQ_X_MOM_GAP_SOURCE] = -0.5 * C_R(c,tc) * Vmag ;
dS[EQ_Y_MOM_GAP_SOURCE] = -0.5 * C_R(c,tc) * Vmag ;
dS[EQ_Z_MOM_GAP_SOURCE] = -0.5 * C_R(c,tc) * Vmag ;
dS[EQ_ENERGY_GAP_SOURCE] = 0.0;

return;
} 

2.3.19.4. Hooking a Gap Model Source UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_GAP_MODEL_SOURCE is compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, gap_user_sources) will become visible and selectable in the Gap Source Terms drop-down list of the Edit Gap Region dialog box in Ansys Fluent. For details, see Hooking DEFINE_GAP_MODEL_SOURCE UDFs.

2.3.20. DEFINE_GEOMETRY

2.3.20.1. Description

You can use DEFINE_GEOMETRY to define an auxiliary geometry definition, as described in Managing Auxiliary Geometry Definitions in the Fluent User's Guide. Note that UDFs that are defined using DEFINE_GEOMETRY can only be executed as compiled UDFs.

2.3.20.2. Usage

DEFINE_GEOMETRY (name, o, x)

Argument Type

Description

symbol name

UDF name.

Geometry_Object *o

Pointer to the geometry object.

real *x

Pointer to the coordinate array (size 2 in 2D and 3 in 3D). This is passed into the function and contains the coordinate that must be modified by the UDF as a result of projection.

Function returns

void

There are three arguments to DEFINE_GEOMETRY: name, o, and x. You supply the name. The return value is an integer. This return value differs based on the arguments passed into this function. When the pointer o is NULL, this signifies that the geometry is being displayed via the graphical user interface, and the UDF must return the maximum number of triangles to be displayed, with the desired triangle edge length also filled in x. When the pointer o is not NULL, it signifies that the UDF is in projection mode, and the UDF must write the projected coordinate location into x. The return integer value specifies whether the projection is on a boundary edge (1) or the interior of the surface (0).

2.3.20.3. Example

The following UDF, named geometry_udf, is executed as a compiled UDF. Note that this example uses a sphere which has no boundaries, so it is fine to unconditionally return 0 for the integer value (to indicate that it is the interior of the surface).

#include "udf.h"

/**
 * @brief
 *   Project point to test geometry
 * @param o
 *   Pointer to geometry object
 * @param x
 *   Pointer to coordinate
 */
DEFINE_GEOMETRY(geometry_udf, o, x)
{
  if (NULLP(o))
  {
    /* Define edge-length and maximum number of facets for display */
    *x = 0.5; return 1000;
  }
  else
  {
    real radius = 2.5;
    real NV_VEC(center) = { 0 };
    real NV_VEC(r) = { 0 }, mag_r = 0, mag_d = 0;

    NV_D(center, =, 0.1, 0.2, 0.3);

    /* Vector from sphere center to coordinate */
    NV_VV(r, =, x, -, center);

    /* Normalize vector and scale by difference to radius */
    mag_r = (NV_MAG(r) + EPSILON);
    mag_d = (radius - mag_r) / mag_r;

    /* Add difference vector to original coordinate */
    NV_VS(x, +=, r, *, mag_d);
  }

  return 0;
}

2.3.20.4. Hooking a Dynamic Mesh Geometry UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_GEOMETRY is compiled (see Compiling UDFs for details), the name of the argument that you supplied as the first DEFINE macro argument will become visible in the Auxiliary Geometry Definition dialog box in Ansys Fluent. See Hooking DEFINE_GEOMETRY UDFs for details on how to hook your DEFINE_GEOMETRY UDF to Ansys Fluent.

2.3.21. DEFINE_GRAY_BAND_ABS_COEFF

2.3.21.1. Description

You can use DEFINE_GRAY_BAND_ABS_COEFF to specify a UDF for the gray band absorption coefficient as a function of temperature, that can be used with a non-gray discrete ordinates model.

2.3.21.2. Usage

DEFINE_GRAY_BAND_ABS_COEFF (name, c, t, nb)

Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index.

Thread *t

Pointer to cell thread.

int nb

Band number associated with non-gray model.

Function returns

real

There are four arguments to DEFINE_GRAY_BAND_ABS_COEFF: name, c, t, and nb. You supply name, the name of the UDF. The variables c, t, and nb are passed by the Ansys Fluent solver to your UDF. Your UDF will need to return the real value of the gray band coefficient to the solver.

2.3.21.3. Example

The following UDF, named user_gray_band_abs, specifies the gray-band absorption coefficient as a function of temperature that can be used for a non-gray discrete ordinates model.

#include "udf.h"
 
 DEFINE_GRAY_BAND_ABS_COEFF(user_gray_band_abs,c,t,nb)
 {
   real abs_coeff = 0;
   real T = C_T(c,t);

    switch (nb)
    {
      case 0 : abs_coeff = 1.3+0.001*T; break;
      case 1 : abs_coeff = 2.7 + 0.005*T; break;
     }
 
 return abs_coeff;
 
 } 

2.3.21.4. Hooking a Gray Band Coefficient UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_GRAY_BAND_ABS_COEFF is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_gray_band_abs) will become visible and selectable in the Create/Edit Materials dialog box for the Absorption Coefficient.

See Hooking DEFINE_GRAY_BAND_ABS_COEFF UDFs for details.

2.3.22. DEFINE_HEAT_FLUX

2.3.22.1. Description

You can use DEFINE_HEAT_FLUX to modify the heat flux at a wall. Despite the name, a DEFINE_HEAT_FLUX UDF is not the means to specify the actual heat flux entering a domain from the outside. To specify this type of heat flux, you would simply use a DEFINE_PROFILE function in conjunction with a heat flux thermal boundary condition. In contrast, a DEFINE_HEAT_FLUX UDF allows you to modify the way in which the dependence between the flux entering the domain and the wall and cell temperatures is modeled.


Important:  This function allows you to modify the heat flux at walls adjacent to a solid. Note, however, that for solids since only heat conduction is occurring, any extra heat flux that you add in a heat flux UDF can have a detrimental effect on the solution of the energy equation. These effects will likely show up in conjugate heat transfer problems. To avoid this, you will need to make sure that your heat flux UDF excludes the walls adjacent to solids, or includes only the necessary walls adjacent to fluid zones.


2.3.22.2. Usage

DEFINE_HEAT_FLUX (name,f,t,c0,t0,cid,cir)

Argument Type

Description

symbol name

UDF name.

face_t f

Index that identifies a wall face.

Thread *t

Pointer to wall face thread on which heat flux function is to be applied.

cell_t c0

Cell index that identifies the cell next to the wall.

Thread *t0

Pointer to the adjacent cell’s thread.

real cid[]

Array of fluid-side diffusive heat transfer coefficients.

real cir[]

Array of radiative heat transfer coefficients.

Function returns

void

There are seven arguments to DEFINE_HEAT_FLUX: name, f, t, c0, t0, cid, and cir. You supply name, the name of the UDF. f, t, c0, and t0 are variables that are passed by the Ansys Fluent solver to your UDF. Arrays cir[] and cid[] contain the linearizations of the radiative and diffusive heat fluxes, respectively, computed by Ansys Fluent based on the activated models. These arrays allow you to modify the heat flux in any way that you choose. Ansys Fluent computes the heat flux at the wall using these arrays after the call to DEFINE_HEAT_FLUX, so the total heat flux at the wall will be the currently computed heat flux (based on the activated models) with any modifications as defined by your UDF.

The diffusive heat flux (qid) and radiative heat flux (qir) are computed by Ansys Fluent according to the following equations:

qid = cid[0] + caf_fac*(cid[1]*C_T(c0,t0) - cid[2]*F_T(f,t)) - cid[3]*pow(F_T(f,t),4)
qir = cir[0] + cir[1]*C_T(c0,t0) - cir[2]*F_T(f,t) - cir[3]*pow(F_T(f,t),4) 

where caf_fac is the convective augmentation factor defined using the define/boundary-conditions/wall text command (for further details, see Augmented Heat Transfer in the User's Guide).

The sum of qid and qir defines the total heat flux from the fluid to the wall (this direction being positive flux), and, from an energy balance at the wall, equals the heat flux of the surroundings (exterior to the domain). Note that heat flux UDFs (defined using DEFINE_HEAT_FLUX) are called by Ansys Fluent from within a loop over wall faces.


Important:  In order for the solver to compute C_T and F_T, the values you supply to cid[1] and cid[2] should never be zero.


2.3.22.3. Example

Implementing Ansys Fluent’s P-1 Radiation Model Using User-Defined Scalars provides an example of the P-1 radiation model implementation through a user-defined scalar. An example of the usage of the DEFINE_HEAT_FLUX macro is included in that implementation.

2.3.22.4. Hooking a Heat Flux UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_HEAT_FLUX is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, heat_flux) will become visible and selectable in the User-Defined Function Hooks dialog box in Ansys Fluent. See Hooking DEFINE_HEAT_FLUX UDFs for details.

2.3.23. DEFINE_IGNITE_SOURCE

2.3.23.1. Description

You can use DEFINE_IGNITE_SOURCE to customize the ignition time source term in the autoignition model.

2.3.23.2. Usage

DEFINE_IGNITE_SOURCE (name, c, t, source)

Argument Type

Description

symbol name

UDF name

cell_t c

Cell index

Thread *t

Pointer to cell thread on which the ignition source term is to be applied

real *source

Pointer to the ignition source term

Function returns

void

There are four arguments to DEFINE_IGNITE_SOURCE: name, c, t, and source. You supply name, the name of the UDF. c, t and source are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to set the value referenced by the source pointer as shown in the example below.

2.3.23.3. Example

The following UDF, named ign_udf_src, specifies a custom source term in the ignition model. The source code must be executed as a compiled UDF in Ansys Fluent.

In the standard ignition model in Ansys Fluent, the source term for the ignition progress variable is given by a Livengood-Wu integral [7]:

(2–6)

where is the flow time step and is the correlation between spark time and knock, by Douaud and Eyzat [3]:

(2–7)

Here, is the octane number of the fuel, is the absolute pressure in atmospheres and is the temperature in Kelvin.

In the following UDF example, the Douaud and Eyzat correlation is used to calculate an induction time. See Additional Macros for Writing UDFs for details on the NNULLP, C_STORAGE_R, C_PREMIXC_T, C_P, C_R, CURRENT_TIMESTEP and C_IGNITE macros used below.

/*------------------------------------------------------------------
 This UDF produces an ignition model source in Ansys Fluent v12.0 or  
 later that uses the default parameters for the correlation of Douaud  
 and Eyzat for knock.            
 /*------------------------------------------------------------------*/
 
 #include "udf.h"
 
 real A = 0.01768;    /* Preexponential      */
 real Ea = 3800;     /* Activation temperature    */
 real O_N = 90.0;    /* Octane number      */
 real O_E = 3.402;    /* Octane number exponent    */
 real P_E = -1.7;    /* Pressure exponent     */
 
 static real A1 = 0.0;   /* Cached value of A*ON^OE   */
 static real dt = 0.0;   /* Cached time step      */
 static real p_op = 0.0;   /* Cached value of operating pressure */
 static cxboolean lit = FALSE; /* Cached burning flag    */
 
 DEFINE_IGNITE_SOURCE(ign_udf_src, c, t, source)
 {
    real rho = C_R(c,t);
    real time = 0.0;
    real prog = NNULLP(THREAD_STORAGE(t,SV_PREMIXC_M1)) ?
      C_STORAGE_R(c,t,SV_PREMIXC_M1) :
      C_STORAGE_R(c,t,SV_PREMIXC) ;
    real fuel = 1.0 - prog;
    real T = C_PREMIXC_T(c,t);
    real P = C_P(c,t);
    real ipv = C_IGNITE(c,t);

    if (c == 0)
      {
         dt = CURRENT_TIMESTEP;
         p_op = RP_Get_Real("operating-pressure");
         A1 = A * pow(O_N/100,O_E);
  }

    if (ipv > 1.0)
      lit = TRUE;
    P += p_op;
    P /= 101325.;  /* in atm */
    P = MAX(P,0.01);  /* minimum pressure for ignition */

    if (fuel > 0.99 || lit)
      time = A1 * pow(P,P_E) * exp(Ea/T);

    if (time > 0.0)
      {
         real max_source = rho*(5.0-ipv)/dt;
         real user_source = rho/time;
         *source = MIN(user_source,max_source);
      }
    else
      *source = 0.0;

    return;
 }

2.3.23.4. Hooking an Ignition Source UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_IGNITE_SOURCE is compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, ign_udf_src) will become visible and selectable in the User-Defined Function Hooks dialog box in Ansys Fluent. See Hooking DEFINE_IGNITE_SOURCE UDFs for details.

2.3.24. DEFINE_KW_GEKO Coefficients and Blending Function

2.3.24.1. Description

You can use DEFINE_KW_GEKO_CSEP, DEFINE_KW_GEKO_CNW, and DEFINE_KW_GEKO_CMIX to specify your own recipes for the calculation of the coefficients , , and , respectively. DEFINE_KW_GEKO_BF enables you to specify a user defined blending function.

2.3.24.2. Usage

DEFINE_KW_GEKO_CSEP (name, c, t)

DEFINE_KW_GEKO_CNW (name, c, t)

DEFINE_KW_GEKO_CMIX (name, c, t)

DEFINE_KW_GEKO_BF (name, c, t)

Argument Type

Description

symbol name

UDF name.

cell_t c

Index that identifies the cell on which the GEKO coefficient or blending function is to be applied.

Thread *t

Pointer to cell thread.

Function returns

real

There are three arguments to these functions: name, c, and t. You specify the name of the UDF. c and t are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF returns the real value of the GEKO coefficients or blending function to the solver.

2.3.24.3. Example

In the following example, a zonal approach is demonstrated. Depending on the x-coordinate, the GEKO blending function is 1.0 or the built-in version is used.

#include "udf.h"
DEFINE_KW_GEKO_BF(user_geko_bf, c, t)
 {
    real bf_value;
    real xc[ND_ND];
    C_CENTROID(xc,c,t);
    if (xc[0] > 2.0)
      bf_value = Get_Geko_Blending_Function(c,t,
                 C_R(c,t),C_MU_L(c,t), C_WALL_DIST(c,t),
                 C_K(c,t),C_O(c,t));
    else
      bf_value = 1.0;
    return bf_value;
 }

2.3.24.4. Hooking a UDF for GEKO Coefficients or Blending Function to Ansys Fluent

After the UDF that you have defined using DEFINE_KW_GEKO_CSEP, DEFINE_KW_GEKO_CNW, DEFINE_KW_GEKO_CMIX, or DEFINE_KW_GEKO_BF is interpreted or compiled, the name of the argument that you supplied as the DEFINE macro argument (for example, user_geko_bf) will become visible and selectable in the Viscous Model dialog box in the drop-down menu of the corresponding model coefficient or blending function.

2.3.25. DEFINE_MASS_TR_PROPERTY

2.3.25.1. Description

You can use DEFINE_MASS_TR_PROPERTY to change inputs (such as heat transfer coefficients, heat flux augmentation/suppression factors, reference velocity, and temperature) for the semi-mechanistic boiling model.

2.3.25.2. Usage

DEFINE_MASS_TR_PROPERTY (name, f, tf, c, tc, from_phase_index, from_species_index, to_phase_index, to_species_index, mass_transfer_index, tabular_data)


Important:  Note that all of the arguments to a DEFINE macro need to be placed on the same line in your source code. Splitting the DEFINE statement onto several lines will result in a compilation error.


Argument Type

Description

symbol name

UDF name.

face_t f

index of face on the thread pointed to by tf.

Thread *tf

Pointer to mixture level face thread.

cell_t c

Index of face on the thread pointed to by tc.

Thread *tc

Pointer to mixture level cell thread.

int from_phase_index

Index of phase from which mass is transferred.

int from_species_index

ID of species from which mass is transferred (ID= -1 if phase does not have mixture material).

int to_phase_index

Index of phase to which mass is transferred.

int to_species_index

ID of species to which mass is transferred (ID= -1 if phase does not have mixture material).

int mass_transfer_index

Index of mass transfer mechanism.

MT_Tabular_Data *tabular_data

Pointer to the tabular data structure such as tabular-pt or tabular-ptl.

Function returns

real

There are eleven arguments to DEFINE_MASS_TR_PROPERTY: name, f, tf, c, tc, from_phase_index, from_species_index, to_phase_index, to_species_index, mass_transfer_index, and tabular_data. You supply name, the name of the UDF. The variables c, mixture_thread, from_phase_index, from_species_index, to_phase_index, to_species_index, mass_transfer_index, and tabular_data are passed by the Ansys Fluent solver to your UDF. Your UDF will return the real input to the solver for a quantity where the UDF is hooked.

2.3.25.3. Example

The following UDF, named nuc_ht_coeff, defines a nucleate boiling heat transfer coefficient in a two-phase mixture problem.


Note:
  • The tabular-pt method supports the following functions for retrieving either temperature based on pressure or pressure based on temperature:

    • Get_Tabular_P_Given_T(tabular_data, T)

    • Get_Tabular_T_Given_P(tabular_data, p_abs)

  • The tabular_ptl method supports two additional functions for retrieving latent heat at given temperature or pressure:

    • Get_Tabular_L_Given_T(tabular_data, T)

    • Get_Tabular_L_Given_P(tabular_data, p_abs)



Important:  Note that in the example that follows, the DEFINE_MASS_TR_PROPERTY statement is broken up into two lines for the sake of readability. In your source file, you must make sure that the DEFINE statement is on one line only.


/* UDF to define a nucleate boiling heat transfer coefficient
   The "from" phase is the liquid phase and the "to" phase is the gas phase */

#include "udf.h"
#include "sg_mphase.h"
#define Tbulk 325
#define sigma 0.07

DEFINE_MASS_TR_PROPERTY(nuc_ht_coeff,f,t,c0,t0,from_index,from_species_index,to_index,to_species_index,mt_index,tabular_data)
 {
   int liq_phase = from_index;
   int gas_phase = to_index;
   Thread *ptl    = THREAD_SUB_THREAD(t0, liq_phase);
   Thread *ptg    = THREAD_SUB_THREAD(t0, gas_phase);
   real T_sat = C_MT_SAT_TEMPERATURE(c0,t0, mt_index);
   real T0 = C_T(c0, t0); 
   real Tw = F_T(f, t);
   real dT_sup = Tw - T_sat;
   real p_abs = C_P(c0,t0) + op_pres;

   real Psat_wall = Get_Tabular_P_Given_T(tabular_data, Tw);
   real Psat = Get_Tabular_P_Given_T(tabular_data, T_sat);
   real dP = MAX(Psat_wall - Psat, 0.);
   real h_lg = Get_Tabular_L_Given_P(tabular_data, p_abs);

   real rhol = C_R(c0, ptl);
   real rhog = C_R(c0, ptg);
   real mul = C_MU_L(c0, ptl);
   real cpl  = C_CP(c0, ptl);
   real kl   = C_K_L(c0, ptl);

   real tmp1 = 0.00122 * pow(kl, 0.79) * pow(cpl, 0.45) * pow(rhol, 0.49) * pow(dT_sup, 0.24) * pow(dP, 0.75);
   real tmp2 = pow(sigma, 0.5) * pow(mul, 0.29) * pow(h_lg, 0.24) * pow(rhog, 0.24);

   return tmp1 / tmp2;
 }

2.3.25.4. Hooking a DEFINE_MASS_TR_PROPERTY UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_MASS_TR_PROPERTY is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, nuc_ht_coeff) will become visible and selectable in the Evaporation-Condensation Model dialog box in Ansys Fluent. See Hooking DEFINE_MASS_TR_PROPERTY UDFs for details.

2.3.26. DEFINE_NET_REACTION_RATE

2.3.26.1. Description

You can use DEFINE_NET_REACTION_RATE to compute the homogeneous net molar reaction rates of all species. The net reaction rate of a species is the sum over all reactions of the volumetric reaction rates:

(2–8)

where is the net reaction rate of species and is the Arrhenius molar rate of creation/destruction of species in reaction .

A DEFINE_NET_REACTION_RATE UDF may be used for the laminar finite-rate (with the stiff chemistry solver), EDC, and PDF Transport models, as well as for the surface chemistry model. In contrast, the surface UDF function DEFINE_SR_RATE is used for the laminar finite-rate model when stiff chemistry is not used.

2.3.26.2. Usage

DEFINE_NET_REACTION_RATE (name, c, t, particle, pressure, temp, yi, rr, jac)

Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index of current particle.

Thread *t

Pointer to cell thread for particle.

Particle *particle

Pointer to Particle data structure that represents a particle used by the PDF transport model.

double *pressure

Pointer to pressure variable.

double *temp

Pointer to temperature variable.

double *yi

Pointer to array containing species mass fractions.

double *rr

Pointer to array containing net molar reaction rates.

double *jac

Pointer to array of Jacobians.

Function returns

void

There are nine arguments to DEFINE_NET_REACTION_RATE: name, c, t, particle, pressure, temp, yi, rr, and jac. You supply name, the name of the UDF. The variables c, t, particle, pressure, temp, yi, rr, and jac are passed by the Ansys Fluent solver to your UDF and have SI units. The outputs of the function are the array of net molar reaction rates, rr (with units kmol/m3-s for volumetric reactions and kmol/m2-s for the surface reactions), and the Jacobian array jac. The Jacobian is only required for surface chemistry, and is the derivative of the surface net reaction rate with respect to the species concentration.

DEFINE_NET_REACTION_RATE is called for all fluid zones (volumetric reactions as well as surface reactions in porous media) and for all wall thread zones whenever the Reaction option is enabled in the boundary conditions dialog box and the UDF is hooked to Ansys Fluent in the User-Defined Function Hooks dialog box.


Important:   DEFINE_NET_REACTION_RATE functions can be executed only as compiled UDFs.


2.3.26.3. Example

The following UDF, named net_rxn, assumes that the net volumetric reaction rate is the expression,

(2–9)

where is the number of species.

/***********************************************************
    Net Reaction Rate Example UDF
 ************************************************************/
 #include "udf.h"
 
 DEFINE_NET_REACTION_RATE(net_rxn,c,t,particle,pressure,temp,yi,rr,jac)
 {
   int i;
   for(i=0;i<n_spe;i++)
      rr[i] = 1./(real)n_spe - yi[i];
 } 

Note that during the course of the ODE solution, the species mass fractions can exceed realizable bounds. For optimal ODE performance, the species mass fractions should not be clipped, but derived quantities, such as concentrations which are raised to non-integer powers, must be bounded. Also, if density is required, for instance to calculate concentrations, it should be calculated from the temperature and species passed into the UDF. Finally, double precision should be used for all local variables.

2.3.26.4. Hooking a Net Reaction Rate UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_NET_REACTION_RATE is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, net_rxn) will become visible and selectable in the User-Defined Function Hooks dialog box in Ansys Fluent. See Hooking DEFINE_NET_REACTION_RATE UDFs for details.

2.3.27. DEFINE_NOX_RATE

2.3.27.1. Description

You can use the DEFINE_NOX_RATE to specify a custom NOx rate for thermal NOx, prompt NOx, fuel NOx, and N2O intermediate pathways that can either replace the internally-calculated NOx rate in the source term equation, or be added to the Ansys Fluent rate. Example 1 demonstrates this use of DEFINE_NOX_RATE. By default, the Add to Ansys Fluent Rate option is enabled UDF Rate group box in each of the tabs under Formation Model Parameters, so that user-defined rates are added to the Ansys Fluent-calculated rates. You can change this default by selecting Replace Ansys Fluent Rate, so that the Ansys Fluent-calculated rate for that NOx pathway will not be used and it will instead be replaced by the NOx rate you have defined in your UDF.


Important:  Note that a single UDF is used to define the different rates for the four NOx pathways: thermal NOx, prompt NOx, fuel NOx, and N2O intermediate pathway. That is, a NOx rate UDF can contain up to four separate rate functions that are concatenated in a single source file which you hook to Ansys Fluent.


DEFINE_NOX_RATE may also be used to calculate the upper limit for the integration of the temperature PDF (when temperature is accounted for in the turbulence interaction modeling). You can calculate a custom maximum limit () for each cell and then assign it to the POLLUT_CTMAX(Pollut_Par) macro (see NOx Macros for further details about data access macros). Example 2 demonstrates this use of DEFINE_NOX_RATE.


Important:  If you want to use DEFINE_NOX_RATE only for the purpose of specifying , then be sure that the user-defined NOx rate does not alter the internally-calculated rate for the source term calculation.


2.3.27.2. Usage

DEFINE_NOX_RATE (name, c, t, Pollut, Pollut_Par, NOx)

Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index.

Thread *t

Pointer to cell thread on which the NOx rate is to be applied.

Pollut_Cell *Pollut

Pointer to the data structure that contains the common data at each cell

Pollut_Parameter *Pollut_Par

Pointer to the data structure that contains auxiliary data.

NOx_Parameter *NOx

Pointer to the data structure that contains data specific to the NOx model.

Function returns

void

There are six arguments to DEFINE_NOX_RATE: name, c, t, Pollut, Pollut_Par, and NOx. You will supply name, the name of the UDF. c, t, Pollut, Pollut_Par, and NOx are variables that are passed by the Ansys Fluent solver to your function. A DEFINE_NOX_RATE function does not output a value. The calculated NOx rates (or other pollutant species rates) are returned through the Pollut structure as the forward rate POLLUT_FRATE(Pollut) and reverse rate POLLUT_RRATE(Pollut), respectively.


Important:  The data contained within the NOx structure is specific only to the NOx model. Alternatively, the Pollut structure contains data at each cell that are useful for all pollutant species (for example, forward and reverse rates, gas phase temperature, density). The Pollut_Par structure contains auxiliary data common to all pollutant species (for example, equation solved, universal gas constant, species molecular weights). Note that molecular weights extracted from the Pollut_Par structure (that is, Pollut_Par->sp[IDX(i)].mw for pollutant species—NO, HCN, and so on—and Pollut_Par->sp[i].mw for other species, such as O2) has units of kg/kmol.


2.3.27.3. Example 1

The following compiled UDF, named user_nox, exactly reproduces the default Ansys Fluent NOx rates for the prompt NOx pathway. Note that this UDF will replace the Ansys Fluent rate only if you select Replace Ansys Fluent Rate in the UDF Rate group box in the Prompt tab. Otherwise, the rate computed in the UDF will be added to Ansys Fluent’s default rate. See Hooking DEFINE_NOX_RATE UDFs for details.

See NOx Macros for details about the NOx macros (for example, POLLUT_EQN, MOLECON, ARRH) that are used in pollutant rate calculations in this UDF.

/*****************************************************************
 UDF example of User-Defined NOx Rate for Ansys Fluent 12 or later
 If used with the "Replace with UDF" radio buttons activated,
this UDF will exactly reproduce the default Ansys Fluent NOx
 rates for prompt NOx pathway.
The flag "Pollut_Par->pollut_io_pdf == IN_PDF" should always
 be used for rates other than that from char N, so that if
 requested, the contributions will be PDF integrated. Any
 contribution from char must be included within a switch
 statement of the form "Pollut_Par->pollut_io_pdf == OUT_PDF".
 *
 * Arguments:
 *  char nox_func_name         - UDF name
 *  cell_t c                   - Cell index
 *  Thread *t                 - Pointer to cell thread on
 *                         which the NOx rate is to be applied
 *  Pollut_Cell *Pollut           - Pointer to Pollut structure
 *  Pollut_Parameter *Pollut_Par  - Pointer to Pollut_Par structure
 *  NOx_Parameter *NOx            - Pointer to NOx structure
 
 *****************************************************************/
 
 #include "udf.h"
 
 DEFINE_NOX_RATE(user_nox, c, t, Pollut, Pollut_Par, NOx)
 {
 /* NOx->prompt_nox = Flag to indicate Prompt NOx is enabled
 * NOx->prompt_udf_replace = Flag to indicate UDF replace
 * Pollut_Par->nfstreams = Number of fuel streams
 * Pollut_Par->nfspe[i] = Number of fuel species in stream "i" 
 * NOx->equiv_ratio[i] = Equivalence ratio for stream "i"
 * NOx->c_number[i] = Carbon number for stream "i"
 * Pollut_Par->fuel_idx[j][i] = Index of jth species in stream "i"
 * Pollut_Par->fuel_dup[j][i] = Fuel species duplication check
 * Pollut_Par->uni_R = Universal gas constant in SI units
 * Pollut->temp_m = Mean gas temperature (K)
 * Pollut->press = Pressure in SI units
 * Pollut->oxy_order = Oxygen order (please refer to user manual)
 */
  POLLUT_FRATE(Pollut) = 0.0;
  POLLUT_RRATE(Pollut) = 0.0;

  switch (Pollut_Par->pollut_io_pdf) {
  case IN_PDF:
    /* Included source terms other than those from char */

    if (POLLUT_EQN(Pollut_Par) == EQ_NO) {

       /* Prompt NOx */
       if (NOx->prompt_nox && NOx->prompt_udf_replace) {
         int ifstream;
         real f=0., rf;

         Rate_Const K_PM = {6.4e6, 0.0, 36483.49436};

         for(ifstream=0; ifstream<Pollut_Par->nfstreams; ifstream++) {
            int i;
            real xc_fuel=0., eqr=NOx->equiv_ratio[ifstream];
            for (i=0; i<Pollut_Par->nfspe[ifstream]; i++) {
                if(!Pollut_Par->fuel_dup[i][ifstream])
                 xc_fuel += MOLECON(Pollut, Pollut_Par->fuel_idx[i][ifstream]);
            }
            f += (4.75 + 0.0819*NOx->c_number[ifstream]
              - 23.2*eqr + 32.0*pow(eqr, 2.) - 12.2*pow(eqr, 3.))*xc_fuel;
       }
       rf = ARRH(Pollut, K_PM);
       rf *= pow((Pollut_Par->uni_R*Pollut->temp_m/Pollut->press),
          (1.+Pollut->oxy_order));   
       rf *= pow(MOLECON(Pollut, O2), Pollut->oxy_order);
       rf *= MOLECON(Pollut, N2);

       POLLUT_FRATE(Pollut) += f*rf;
     }
    }
    break;

    case OUT_PDF:
    /* Char Contributions, must be included here */
    break;

  default:
  /* Not used */
  break;
  }
 } 

2.3.27.4. Example 2

The following compiled UDF, named nox_func_name, specifies a custom maximum limit () for the integration of the temperature PDF for each cell. Note that this UDF does not alter the internally-calculated NOx rate.

See NOx Macros for details about the NOx macro (POLLUT_CTMAX) used in this UDF.

/************************************************************
 UDF example of User-Defined Tmax value
 *
 * Arguments:
 *  char nox_func_name    				- UDF name
 *  cell_t c      						- Cell index
 *  Thread *t     						- Pointer to cell thread
 *         							 on which the NOx rate
 *         							 is to be applied
 *  Pollut_Cell *Pollut   				- Pointer to Pollut_Cell
 *         							 structure
 *  Pollut_Parameter *Pollut_Par 			- Pointer to Pollut_Parameter
 *         							 structure
 *  NOx_Parameter *NOx    				- Pointer to NOx_Parameter
 *         							 structure
 Ansys Fluent Version: 12.0 or later
 *************************************************************/
 
 #include "udf.h"
 
 int ud_nox_do_once=1;
 
 enum
 {
    CELL_TMAX=0,
    N_REQUIRED_UDM
 };
 
 /*Compute/assign Tmax at each cell*/
 real ud_eval_cell_tmax(cell_t c,Thread *t)
 {
    real tmax = 0.;

    /* Compute cell-based Tmax value */
    tmax = 1.1*C_T(c,t); /* This is only an example */

    return tmax;
 }
 
 DEFINE_NOX_RATE(user_nox, c, t, Pollut, Pollut_Par, NOx)
 {
    /* Assign cell-based Tmax value */
    POLLUT_CTMAX(Pollut_Par) = ud_eval_cell_tmax(c,t);
    /*POLLUT_CTMAX(Pollut_Par) = C_UDMI(c,t,CELL_TMAX);*/
 }
 
 DEFINE_ON_DEMAND(init_tmax)
 {
    Domain *domain;
    register Thread *t;
    register cell_t c;

    Message("Computing/Storing cell Tmax values\n");
    domain = Get_Domain(1);

    /* Store User-Defined Tmax at each cell */
    if(ud_nox_do_once == 1) {
      if(n_udm < N_REQUIRED_UDM)
         Error("Not enough udm allocated\n");

      thread_loop_c (t,domain)
         begin_c_loop (c,t)
           C_UDMI(c,t,CELL_TMAX) = ud_eval_cell_tmax(c,t);
         end_c_loop (c,t)
      ud_nox_do_once = 0;
    }
    Message("Computing cell Tmax values completed..\n");
 }

2.3.27.5. Hooking a NOx Rate UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_NOX_RATE is compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_nox) will become visible and selectable in the NOx Model dialog box in Ansys Fluent. See Hooking DEFINE_NOX_RATE UDFs for details.

2.3.28. DEFINE_PERFORATED_CD

2.3.28.1. Description

You can use the DEFINE_PERFORATED_CD to customize the formulation of the discharge coefficient , which is used in Equation 7–131 and Equation 7–132 in the Fluent User's Guide to estimate the injection mass flow rate in the perforated walls. The DEFINE_PERFORATED_CD UDF is only available for cases that involve discrete injections with the dynamic injection method.

2.3.28.2. Usage

DEFINE_PERFORATED_CD (name, t, cd, local_variables)


Important:
  • Note that all the arguments of a DEFINE macro need to be placed on the same line in your source code. Splitting the DEFINE statement into several lines will result in a compilation error.

  • DEFINE_PERFORATED_CD functions can be executed only as compiled UDFs.


Argument Type

Description

symbol name

UDF name.

Thread *t

Pointer to face thread.

real *cd

Pointer to parameter Cd

real *local_variables

Pointer to the variables that can be used in the formulation of Cd

Function returns

void

There are four arguments to DEFINE_PERFORATED_CD: name, t, cd, and local_variables. You supply name, the name of the UDF. The variables t and local_variables are passed by the Ansys Fluent solver to your UDF. Your UDF will need to compute the variable cd, which will be used to estimate the injection mass flow rate in the perforated wall when the dynamic injection method is used.

The array local_variables contains values of several pre-defined variables calculated by Ansys Fluent and listed in Table 2.7: Variables Stored in the Array local_variables. They can be used to define your as a function of these variables. You can directly refer to the variable you want to use in your UDF by using either the integer index or the enumerator.

Table 2.7: Variables Stored in the Array local_variables

IndexEnumeratorVariable
0 DIA_DC Hole diameter
1 LEN_DC Hole length
2 AREA_DC Injection hole area
3 PRESS_INJ_DC Injection hole pressure
4 PRESS_EXT_DC Extraction hole pressure
5 TEMP_DC Injection hole temperature
6 DEN_DC Injection hole density
7 XVEL_DC X component of the injection hole velocity
8 YVEL_DC Y component of the injection hole velocity
9 ZVEL_DC Z component of the injection hole velocity

2.3.28.3. Example

The below examples shows the usage of DEFINE_PERFORATED_CD, named my_cdprofile, to compute the discharge coefficient as the following function:

The first example illustrates how to use the index to refer to the variables in the local_variables array.

/*****************************************************************
#include "udf.h"
DEFINE_PERFORATED_CD(my_cdprofile, t, cd, local_variables)
{
  if(local_variables[1] / local_variables[0] <2.0 )
    *cd = 0.6 + 0.1*local_variables[1] / local_variables[0];
  else
    *cd = 0.8;
  return;
}

The second example illustrates how to use the enumerator to refer to the variables in the local_variables array.

/*****************************************************************
#include "udf.h"
#include "perforated.h"
DEFINE_PERFORATED_CD(my_cdprofile, t, cd, local_variables)
{
  if(local_variables[LEN_DC] / local_variables[DIA_DC] <2.0 )
    *cd = 0.6 + 0.1*local_variables[LEN_DC] / local_variables[DIA_DC];
  else
    *cd = 0.8;
  return;
}

2.3.28.4. Hooking a DEFINE_PERFORATED_CD UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_PERFORATED_CD is compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, my_cdprofile) will become visible and selectable in the User-Defined Function Hooks dialog box in Ansys Fluent. See Hooking DEFINE_PERFORATED_CD UDFs for details.

2.3.29. DEFINE_PDF_TABLE

2.3.29.1. Description

The Non-Premixed and Partially-Premixed models in Ansys Fluent employ look-up tables that store the convolution of state-relations with assumed-shape PDFs as described by Equation 8–17 to Equation 8–20, Equation 8–25 and Equation 8–26 in the Theory Guide. Ansys Fluent solves transport equations for lower moments, such as the mean mixture fraction and the mean enthalpy, and interpolates the PDF table for the required variables:

  • Mean temperature

  • Mean density

  • Mean specific heat

  • Mean mixture molecular weight

  • Mean species mole fractions

  • Mean forward and reverse reaction rates of transported scalars with FGM tables

  • Mean heat release rate

  • Mean progress variable finite rate source term

You can use DEFINE_PDF_TABLE to customize the above variables.


Important:
  • When using DEFINE_PDF_TABLE, you must use Ansys Fluent's transport equations for mixture fraction; for non-adiabatic cases, you must use mean enthalpy.

  • The model settings and options that apply to your user-defined PDF Table must be set through the standard Ansys Fluent interface and a valid PDF table with the same settings and options must be generated or read into Ansys Fluent before you can use your UDF table. For example, if your PDF Table is a two-mixture fraction non-adiabatic table, you first generate/read a valid two-mixture fraction non-adiabatic PDF file. The reason for doing this is that Ansys Fluent will need to access some information about your system, such as the species order and the boundary compositions and temperatures through this default PDF table.

  • When generating your default Ansys Fluent PDF file, you must use the same thermodynamic database file as you used to create your PDF table.

  • You must ensure that the species order in your default Ansys Fluent PDF file is identical to the order in your PDF table. The default Ansys Fluent species order is in the material structure pdf-mixture, which is passed to the UDF.

  • DEFINE_PDF_TABLE must use the identical fuel and oxidizer boundary compositions and temperatures as in the corresponding default Ansys Fluent PDF file. If you are using the two mixture fraction model, the same applies for the secondary stream.

  • When you are using the Partially-Premixed or the Inert models, the DEFINE_PDF_TABLE UDF must return the properties of the burnt mixture.

  • The UDF cannot currently be used for calculation of pollutant rates. Instead, Ansys Fluent will perform these calculations. The species mass fractions obtained through DEFINE_PDF_TABLE are only used for post-processing purposes and will not be used for subsequent calculations, such as pollutant prediction. If you want to customize the pollutant calculations, you can use pollutant-specific UDFs provided by Ansys Fluent (such as DEFINE_SOOT_MASS_RATES, DEFINE_NOX_RATE, DEFINE_SOOT_MOM_RATES, and others).


Your UDF can access and use the variables and functions in the default PDF table, such as boundary composition values and the adiabatic enthalpy function, listed in the header files pdf_props.h and pdf_table.h, which you would need to include in your UDF.

The UDF is called for all fluid cells and boundary faces, every iteration, and care should be taken to efficiently interpolate your table.

2.3.29.2. Usage

DEFINE_PDF_TABLE (name, m, c, t, fmean, fvar, fmean2, fvar2, cmean, cvar, h, what, prop, x)


Important:
  • Note that all the arguments of a DEFINE macro need to be placed on the same line in your source code. Splitting the DEFINE statement into several lines will result in a compilation error.

  • DEFINE_PDF_TABLE functions can be executed only as compiled UDFs.


Argument Type

Description

symbol name

UDF name.

Material *m

Pointer to the mixture material pdf-mixture.

cell_t c

Cell or face index.

Thread *t

Pointer to the cell or face thread.

real fmean

Mean mixture fraction.

real fvar

Mixture fraction variance.

real fmean2

Secondary mean mixture fraction.

real fvar2

Secondary mixture fraction variance.

real cmean

Mean unnormalized progress variable (used with the partially premixed flamelet model).

real cvar

Progress variable variance (used with the partially premixed flamelet model).

real h

Mean enthalpy.

int what

Integer indicating the variables that the Ansys Fluent solver is expecting to be computed by the UDF as follows:

0 calculate the thermodynamic properties in array prop

1 or 2 calculate the thermodynamic properties and the species mole fractions x

3 calculate FGM scalar equations forward and reverse rates from Equation 8–120 in the Fluent Theory Guide.

real prop[MAX_PROP_UDF]

Thermodynamic variables as follows:

prop[TEMP_UDF] temperature

prop[DEN_UDF] density

prop[CP_UDF] specific heat

prop[MOL_WT_MIX_UDF] mean molecular weight

prop[TSS_SCALAR_START_UDF + 2 * i] forward rate of scalar i

prop[TSS_SCALAR_START_UDF + 2 * i + 1] reverse rate of scalar i

prop[SCALAR_PRMX_SOURCE_UDF] progress variable source term in 1/s

prop[SCALAR_HRR_UDF] heat release rate

real *x

Species mole fractions.

  

Function returns

void

There are fourteen arguments to DEFINE_PDF_TABLE. You supply name, the name of the UDF. The variables m, c, t, fmean, fvar, fmean2, fvar2, cmean, cvar, h, what are passed by the Ansys Fluent solver to your UDF. The output of the function are the array of thermodynamic variables prop and the array of mole fractions x.


Important:  For the DEFINE_PDF_TABLE UDF to work correctly, you must provide temperature, density, specific heat, molecular weight and species mole fractions through the array prop.


You can use macros listed in Table 2.8: Generic Macros Get_PDF to retrieve the local cell information extracted from the original PDF look-up table generated by Ansys Fluent using the Species Model dialog box. The output of these macros do not account for the customizations made by DEFINE_PDF_TABLE.

The macros use the following arguments:

  • cell_t c:  Cell index

  • Thread *t:  Pointer to thread

  • int n:  Species index

  • real fmean:  Mean mixture fraction

Table 2.8: Generic Macros Get_PDF

Macro

Returns

Get_Pdf_Xi(c,t,n)

real PDF mole fraction for species n

Get_Pdf_Yi(c,t,n)

real PDF mass fraction for species n

Get_Pdf_Temperature(c,t)

real PDF temperature [K]

Get_Pdf_Density(c,t)

real PDF density [kg/m3]

Get_Pdf_MolWeight(c,t)

real PDF mixture molecular weight

Get_Pdf_Tss_Revrates(c,t,n)

real PDF net chemical reverse rate of the FGM scalar n [1/s] as in Equation 8–119 in the Fluent Theory Guide

Get_Pdf_Tss_Fwdrates(c,t,n)

real PDF net chemical forward rate of the FGM scalar n [1/s] as in Equation 8–119 in the Fluent Theory Guide

Get_Pdf_Min_Enthalpy(c,t)

real local minimum PDF table static enthalpy [J/kg]

Get_Pdf_Max_Enthalpy(c,t)

real local maximum PDF table static enthalpy [J/kg]

Get_Pdf_HeatReleaserate(c,t)

real FGM heat release rate [J/m3/s]

Pdf_Adiabatic_Enthalpy (fmean)

real PDF adiabatic enthalpy for a given mixture fraction [J/kg]


An example of the usage of these macros is shown in Example.

2.3.29.3. Example

The following example is a source code template where the DEFINE_PDF_TABLE function is used to calculate properties and mole fractions from the PDF file loaded by the user.

  #include <udf.h>
  #include "pdf_props.h"
  #include "pdf_table.h"
  #define DEN_MIN 1E-4
  DEFINE_PDF_TABLE(pdf_table, m, c, t, fmean, fvar, fmean2, fvar2, cmean, cvar, h, what, prop, x)
  {
    int i;

    if NULLP(pf)
    Error("Please generate or read a Fluent PDF file first\n");
    
    #if 1
    if (what < 0) /*special call to return the FGM flame speed source*/
    {
      prop[SCALAR_PRMX_SOURCE_UDF] = Get_Premix_Frate_Source_Term(c, t)/C_R(c,t); /*This is the value 
                                                           of progress variable source term in 1/s */
    }
    else if (what == 1) /* get all pdf values : T, rho, MW, mole fractions, cp*/
    {
      prop[TEMP_UDF] = Get_Pdf_Temperature(c, t);
      prop[CP_UDF] = Get_Pdf_Cp(c,t);
      prop[DEN_UDF]  = Get_Pdf_Density(c,t);
      prop[MOL_WT_MIX_UDF] = Get_Pdf_MolWeight(c,t);
    
      for (i = 0; i < n_spe_pdf; i++)
      x[i] = Get_Pdf_Xi(c,t,i);  /*get pdf mole fraction of species i */
    
    }
    else if (what == 3) /*TSS SCALARS RATES*/
    {
      tss_num_scalars = RP_Get_Integer("pdftss/tss-num-scalars");
      if (tss_num_scalars > 0)
      {
        real fwdrate = 0.0;
        real revrate = 0.0;
        for (i = 0; i < tss_num_scalars; i++)
        {
          if ( PdfModel.premix_flamelet && NNULLP(t) && GENERIC_CELL_THREAD_P(t) )
          fwdrate = Get_Pdf_Tss_FwdRates(c, t, i);
    
          if ( PdfModel.premix_flamelet && NNULLP(t) && GENERIC_CELL_THREAD_P(t))
          revrate = Get_Pdf_Tss_RevRates(c, t, i) ;
    
          prop[TSS_SCALAR_START_UDF +  2 * i] = fwdrate;
          prop[TSS_SCALAR_START_UDF +  2 * i + 1] = revrate;
        }
      }
    }
    else /*(what == 2 || 0)*/
    {
      prop[TEMP_UDF] = Get_Pdf_Temperature(c, t);
      prop[CP_UDF] = Get_Pdf_Cp(c,t);
      prop[DEN_UDF]  = Get_Pdf_Density(c,t);
      prop[MOL_WT_MIX_UDF] = Get_Pdf_MolWeight(c,t);
    }
    
    #endif
    
  }
  

2.3.29.4. Hooking a DEFINE_PDF_TABLE UDF to Ansys Fluent

After you have enabled the Non-Premixed or Partially-Premixed models, generated or read a valid PDF table, and compiled (Compiling UDFs) the DEFINE_PDF_TABLE UDF, the name of the argument that you supplied as the first DEFINE macro argument will become visible and selectable in the User-Defined Function Hooks dialog box in Ansys Fluent. See Hooking DEFINE_PDF_TABLE UDFs for details.

2.3.30. DEFINE_PR_RATE

2.3.30.1. Description

You can use DEFINE_PR_RATE to specify a custom particle surface reaction for the multiple surface reactions particle model. During Ansys Fluent execution, the same UDF is called sequentially for all particle surface reactions, so DEFINE_PR_RATE can be used to define custom reaction rates for a single reaction, or for multiple reactions. The volumetric and wall surface reactions are not affected by the definition of this macro and will follow the designated rates. Note that a DEFINE_PR_RATE UDF is not called with the coupled solution option, so you will need to disable the Coupled Heat Mass Solution option in the Discrete Phase Model dialog box when using it. The auxiliary function, zbrent_pr_rate, which is provided below, can be used when there is no analytical solution for the overall particle reaction rate.

2.3.30.2. Usage

DEFINE_PR_RATE (name, c, t, r, mw, ci, tp, sf, dif_index, cat_index, rr)

Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index of current particle.

Thread *t

Pointer to cell thread for particle.

Reaction *r

Pointer to data structure that represents the current reaction.

real *mw

Pointer to array containing gaseous and surface species molecular weights

real *ci

Pointer to array containing gas partial pressures.

Tracked_Particle *tp

Pointer to Tracked_Particle data structure that contains data related to the particle being tracked.

real *sf

Pointer to array containing mass fractions of the solid species in the particle char mass at the current time step.

int dif_index

Diffusion controlled species as defined in the Reactions dialog box for the current reaction.

int cat_index

Catalyst species as defined in the Reactions dialog box for the current reaction.

real *rr

Pointer to array containing particle reaction rate (kg/s).

Function returns

void

There are eleven arguments to DEFINE_PR_RATE: name, c, t, r, mw, ci, tp, sf, dif_index, cat_index, and rr. You supply name, the name of the UDF. c, t, r, mw, ci, tp, sf, dif_index, cat_index, and rr are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to set the value referenced by the real pointer rr to the particle reaction rate in kg/s.

Note that tp is an argument to many particle-specific macros defined in DPM Macros. sf is the same as the order in which the species are defined in the Selected Solid Species list in the Create/Edit Materials dialog box, which is opened from the Edit Species names option for the Mixture Material.

DEFINE_PR_RATE is called by Ansys Fluent every time step during the particle tracking calculation. The auxiliary function zbrent_pr_rate is used when there is no analytical solution for the overall particle reaction rate. It uses Brent’s method to find the root of a function known to lie between and . The root will be refined until its accuracy has reached tolerance tol. This is demonstrated in Example 2.

2.3.30.3. Auxiliary function

zbrent_pr_rate (real (*func),(real,real[],int [],cxboolean [],char *,) real ruser[],int iuser[], cxboolean buser[],char *cuser,real x1 real x2,real tol,cxboolean *ifail)

Auxiliary function returns: real

2.3.30.4. Example 1

The following UDF, named user_pr_rate, specifies a particle reaction rate given by Equation 7–107 in the Theory Guide, where the effectiveness factor is defined as

where is the fractional conversion of the particle char mass. In this case, the UDF will be applied to all surface particle reactions defined in the Ansys Fluent model.

/* UDF of specifying the surface reaction rate of a particle */
 
 #include "udf.h"
 
 #define A1 0.002
 #define E1 7.9e7
 
 DEFINE_PR_RATE(user_pr_rate,c,t,r,mw,pp,tp,sf,dif_i,cat_i,rr)
 {
 /* Argument types
    cell_t c
    Thread *t
    Reaction *r (reaction structure)
    real *mw (species molecular weight)
    real *pp (gas partial pressures)
    Tracked_Particle *tp (particle structure)
    real *sf  (current mass fractions of solid species in
         particle char mass)
    int dif_i (index of diffusion controlled species)
    int cat_i (index of catalyst species)
    real *rr  (rate of reaction kg/s)
 */
 
 real ash_mass =
 TP_INIT_MASS(tp)*(1.-TP_CHAR_FRACTION(tp)-TP_VOLATILE_FRACTION(tp));
 
 real one_minus_conv =
 MAX(0.,(TP_MASS(tp) -ash_mass) / TP_INIT_MASS(tp)/ TP_CHAR_FRACTION(tp));
 
 real rate = A1*exp(-E1/UNIVERSAL_GAS_CONSTANT/TP_T(tp));
 
 *rr=-rate*TP_DIAM(tp)*TP_DIAM(tp)*M_PI*sf[0]*one_minus_conv;
 } 

2.3.30.5. Example 2

The following compiled UDF, named user_rate, specifies a particle reaction rate given by Equation 7–102 and Equation 7–105 in the Theory Guide. The reaction order on the kinetic rate is and the effectiveness factor is defined as

where is the fractional conversion of the particle char mass. In this case it is necessary to obtain a numerical solution for the overall surface reaction rate.

This UDF is called only for reaction 2, which means that the default Ansys Fluent solution will be used for the rest of the particle surface reactions defined.

/* UDF of specifying the surface reaction rate of a particle,
using a numerical solution */
 
 #include "udf.h"
 
 #define c1 5e-12
 #define A1 0.002
 #define E1 7.9e7
 #define tolerance 1e-4
 #define order 0.9
 
 real reaction_rate(real rate, real ruser[], int iuser[], cxboolean buser[],
char *cuser)
 
 /* Note that all arguments in the reaction_rate function call 
 in your .c source file MUST be on the same line or a 
 compilation error will occur */
 
 {
    return (ruser[2]*pow(MAX(0.,(ruser[0]-rate/ruser[1])),order) -rate);
 }
 
 DEFINE_PR_RATE(user_rate,c,t,r,mw,pp,tp,sf,dif_i,cat_i,rr)
 {
 if (!strcmp(r->name, "reaction-2"))
    {
    cxboolean ifail=FALSE;

    real ash_mass =
    TP_INIT_MASS(tp)*(1.-TP_CHAR_FRACTION(tp)-TP_VOLATILE_FRACTION(tp));

    real one_minus_conv =
    MAX(0.,(TP_MASS(tp) -ash_mass) / TP_INIT_MASS(tp)/ TP_CHAR_FRACTION(tp));

    real ruser[3];
    int iuser[1];  cxboolean buser[1];
    char cuser[30];
    real ratemin, ratemax, root;

    ruser[0] = pp[dif_i];
    ruser[1] = MAX(1.E-15, (c1*pow(0.5*(TP_T(tp)+C_T(c,t)),0.75)/TP_DIAM(tp)));
    ruser[2] = A1*exp(-E1/UNIVERSAL_GAS_CONSTANT/TP_T(tp));
    strcpy(cuser, "reaction-2");
    ratemin=0;
    ratemax=ruser[1]*pp[dif_i];

    /* arguments for auxiliary function zbrent_pr_rate */

    root = zbrent_pr_rate(reaction_rate, ruser, iuser, buser, cuser,
           ratemin, ratemax, tolerance, &ifail);

    if (ifail) root=MAX(1.E-15,ruser[1]);

    *rr=-root*TP_DIAM(tp)*TP_DIAM(tp)*M_PI*sf[0]*one_minus_conv;

    Message("Fail status %d\n", ifail);
    Message("Reaction rate for reaction %s : %g\n", cuser, *rr);

   }
 } 

In this example, a real function named reaction_rate is defined at the top of the UDF. The arguments of reaction_rate are real rate, and the pointer arrays real ruser[], integer iuser[], cxboolean buser[], and char *cuser, which must be declared and defined in the main body of the DEFINE_PR_RATE function.

Typically, if the particle surface reaction rate is described by

  rate = f(ruser[],iuser[],rate)

then the real function (in this example reaction_rate) should return

  f(ruser[],iuser[],rate) - rate

The variables cxboolean buser[] and char *cuser can be used to control the flow of the program in cases of complicated rate definitions.

ratemin and ratemax, hold the minimum and maximum possible values of the variable rate, respectively. They define the search interval where the numerical algorithm will search for the root of the equation, as defined in the function reaction_rate. The value of reaction rate rr will be refined until an accuracy specified by the value of tolerance tol is reached.

The variable ifail will take the value TRUE if the root of the function has not been found.

2.3.30.6. Hooking a Particle Reaction Rate UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_PR_RATE is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_pr_rate) will become visible and selectable in the User-Defined Function Hooks dialog box in Ansys Fluent. See Hooking DEFINE_PR_RATE UDFs for details.

2.3.31. DEFINE_PRANDTL UDFs

The following DEFINE macros can be used to specify Prandtl numbers in Ansys Fluent, for single-phase flows.

2.3.31.1. DEFINE_PRANDTL_D

2.3.31.2. Description

You can use DEFINE_PRANDTL_D to specify Prandtl numbers for turbulent dissipation ().

2.3.31.3. Usage

DEFINE_PRANDTL_D (name, c, t)

Argument Type

Description

symbol name

UDF name.

cell_t c

Index of cell on which the Prandtl number function is to be applied.

Thread *t

Pointer to cell thread.

Function returns

real

There are three arguments to DEFINE_PRANDTL_D: name, c, and t. You supply name, the name of the UDF. c and t are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to return the real value for the turbulent dissipation Prandtl number to the solver.

2.3.31.4. Example

An example of a DEFINE_Prandtl_D UDF is provided below in the source listing for DEFINE_PRANDTL_K.

2.3.31.5. Hooking a Prandtl Number UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_PRANDTL_D is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_pr_d) will become visible and selectable in the Viscous Model dialog box in Ansys Fluent. See Hooking DEFINE_PRANDTL UDFs for details.

2.3.31.6. DEFINE_PRANDTL_K

2.3.31.7. Description

You can use DEFINE_PRANDTL_K to specify Prandtl numbers for turbulence kinetic energy ().

2.3.31.8. Usage

DEFINE_PRANDTL_K (name, c, t)

Argument Type

Description

symbol name

UDF name.

cell_t c

Index that identifies the cell on which the Prandtl number function is to be applied.

Thread *t

Pointer to cell thread.

Function returns

real

There are three arguments to DEFINE_PRANDTL_K: name, c, and t. You supply name, the name of the UDF. c and t are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to return the real value for the kinetic energy Prandtl number to the solver.

2.3.31.9. Example

The following UDF implements a high-Re version of the RNG model, using the - option that is activated in Ansys Fluent.

Three steps are required:

  1. Set Cmu, C1eps, and C2eps as in the RNG model.

  2. Calculate Prandtl numbers for and using the UDF.

  3. Add the -r source term in the equation.

In the RNG model, diffusion in and equations appears as

while in the standard - model, it is given by

For the new implementation, a UDF is needed to define a Prandtl number as

in order to achieve the same implementation as the original RNG Model.

The following functions (which are concatenated into a single C source code file) demonstrate this usage. Note that the source code must be executed as a compiled UDF.

#include "udf.h"
 
 DEFINE_PRANDTL_K(user_pr_k,c,t)
 {
    real pr_k, alpha;
    real mu = C_MU_L(c,t);
    real mu_t = C_MU_T(c,t);

    alpha = rng_alpha(1., mu + mu_t, mu);

    pr_k = mu_t/((mu+mu_t)*alpha-mu);

    return pr_k;
 }
 
 DEFINE_PRANDTL_D(user_pr_d,c,t)
 {
    real pr_d, alpha;
    real mu = C_MU_L(c,t);
    real mu_t = C_MU_T(c,t);

    alpha = rng_alpha(1., mu + mu_t, mu);

    pr_d = mu_t/((mu+mu_t)*alpha-mu);

    return pr_d;
 }
 
 DEFINE_SOURCE(eps_r_source,c,t,dS,eqn)
 {
    real con, source;
    real mu = C_MU_L(c,t);
    real mu_t = C_MU_T(c,t);
    real k  = C_K(c,t);  real d  = C_D(c,t);
    real prod = C_PRODUCTION(c,t);

    real s = sqrt(prod/(mu+ mu_t)) ;
    real eta  = s*k/d;
    real eta_0 = 4.38;
    real term = mu_t*s*s*s/(1.0 + 0.012*eta*eta*eta);

    source = - term * (1. - eta/eta_0);
    dS[eqn] = - term/d;

    return source;
 } 

2.3.31.10. Hooking a Prandtl Number UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_PRANDTL_K is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_pr_k) will become visible and selectable in the Viscous Model dialog box in Ansys Fluent. See Hooking DEFINE_PRANDTL UDFs for details.

2.3.31.11. DEFINE_PRANDTL_O

2.3.31.12. Description

You can use DEFINE_PRANDTL_O to specify Prandtl numbers for specific dissipation ( in the - model).

2.3.31.13. Usage

DEFINE_PRANDTL_O (name, c, t)

Argument Type

Description

symbol name

UDF name.

cell_t c

Index that identifies the cell on which the Prandtl number function is to be applied.

Thread *t

Pointer to cell thread.

Function returns

real

There are three arguments to DEFINE_PRANDTL_O: name, c, and t. You supply name, the name of the UDF. c and t are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to return the real value for the specific dissipation Prandtl number to the solver.

2.3.31.14. Example

/* Specifying a Constant Specific Dissipation Prandtl Number */
 #include "udf.h"
 
 DEFINE_PRANDTL_O(user_pr_o,c,t)
 {
    real pr_o;
    pr_o = 2.;
    return pr_o;
 } 

2.3.31.15. Hooking a Prandtl Number UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_PRANDTL_O is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_pr_o) will become visible and selectable in the Viscous Model dialog box in Ansys Fluent. See Hooking DEFINE_PRANDTL UDFs for details.

2.3.31.16. DEFINE_PRANDTL_T

2.3.31.17. Description

You can use DEFINE_PRANDTL_T to specify Prandtl numbers that appear in the temperature equation diffusion term.

2.3.31.18. Usage

DEFINE_PRANDTL_T (name, c, t)

Argument Type

Description

symbol name

UDF name.

cell_t c

Index that identifies the cell on which the Prandtl number function is to be applied.

Thread *t

Pointer to cell thread.

Function returns

real

There are three arguments to DEFINE_PRANDTL_T: name, c, and t. You supply name, the name of the UDF. c and t are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to return the real value for the temperature Prandtl number to the solver.

2.3.31.19. Example

/* Specifying a Constant Temperature Prandtl Number */
 #include "udf.h"
 
 DEFINE_PRANDTL_T(user_pr_t,c,t)
 {
    real pr_t;
    pr_t = 0.85;
    return pr_t;
 } 

2.3.31.20. Hooking a Prandtl Number UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_PRANDTL_T is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_pr_t) will become visible and selectable in the Viscous Model dialog box in Ansys Fluent. See Hooking DEFINE_PRANDTL UDFs for details.

2.3.31.21. DEFINE_PRANDTL_T_WALL

2.3.31.22. Description

You can use DEFINE_PRANDTL_T_WALL to specify Prandtl numbers for thermal wall functions.

2.3.31.23. Usage

DEFINE_PRANDTL_T_WALL (name, c, t)

Argument Type

Description

symbol name

UDF name.

cell_t c

Index that identifies the cell on which the Prandtl number function is to be applied.

Thread *t

Pointer to cell thread.

Function returns

real

There are three arguments to DEFINE_PRANDTL_T_WALL: name, c, and t. You supply name, the name of the UDF. c and t are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to return the real value for the thermal wall function Prandtl number to the solver.

2.3.31.24. Example

/*************************************************************
  Specifying a constant thermal wall function Prandtl number
  ********************************************************* **/
 #include "udf.h"
 
 DEFINE_PRANDTL_T_WALL(user_pr_t_wall,c,t)
 {
    real pr_t_wall;
    pr_t_wall = 0.85;
    return pr_t_wall;
 } 

2.3.31.25. Hooking a Prandtl Number UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_PRANDTL_T_WALL is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_pr_t_wall) will become visible and selectable in the Viscous Model dialog box in Ansys Fluent. See Hooking DEFINE_PRANDTL UDFs for details.

2.3.32. DEFINE_PROFILE

2.3.32.1. Description

You can use DEFINE_PROFILE to define a custom boundary profile or cell zone condition that varies as a function of spatial coordinates or time. Some of the variables you can customize are:

  • velocity, pressure, temperature, turbulence kinetic energy, turbulence dissipation rate

  • mass flux

  • target mass flow rate as a function of physical flow time

  • species mass fraction (species transport)

  • volume fraction (multiphase models)

  • wall thermal conditions (temperature, heat flux, heat generation rate, heat transfer coefficients, and external emissivity, and so on)

  • shell layer heat generation rate

  • wall roughness conditions

  • wall shear and stress conditions

  • porosity

  • porous resistance direction vector

  • wall adhesion contact angle (VOF multiphase model)

  • source terms

  • fixed variables

Note that DEFINE_PROFILE allows you to modify only a single value for wall heat flux. Single values are used in the explicit source term which Ansys Fluent does not linearize. If you want to linearize your source term for wall heat flux and account for conductive and radiative heat transfer separately, you will need to use DEFINE_HEAT_FLUX to specify your UDF.

Some examples of boundary profile UDFs are provided below. For an overview of the Ansys Fluent solution process which shows when a DEFINE_PROFILE UDF is called, refer to Figure 1.2: Solution Procedure for the Pressure-Based Segregated Solver, Figure 1.3: Solution Procedure for the Pressure-Based Coupled Solver, and Figure 1.4: Solution Procedure for the Density-Based Solver.

2.3.32.2. Usage

DEFINE_PROFILE (name, t, i)

Argument Type

Description

symbol name

UDF name.

Thread *t

Pointer to thread on which boundary condition is to be applied.

int i

Index that identifies the variable that is to be defined. i is set when you hook the UDF with a variable in a boundary conditions dialog box through the graphical user interface. This index is subsequently passed to your UDF by the Ansys Fluent solver so that your function knows which variable to operate on.

Function returns

void

There are three arguments to DEFINE_PROFILE: name, t, and i. You supply name, the name of the UDF. t and i are variables that are passed by the Ansys Fluent solver to your UDF.

While DEFINE_PROFILE is usually used to specify a profile condition on a boundary face zone, it can also be used to specify, or fix, flow variables that are held constant during computation in a cell zone. See Fixing the Values of Variables in the User's Guide for more information on fixing values in a cell zone boundary condition. For these cases, the arguments of the macro will change accordingly.

Note that unlike source term and property UDFs, profile UDFs (defined using DEFINE_PROFILE) are not called by Ansys Fluent from within a loop on threads in the boundary zone. The solver passes only the pointer to the thread associated with the boundary zone to the DEFINE_PROFILE macro. Your UDF will need to do the work of looping over all of the faces in the thread, computing the face value for the boundary variable, and then storing the value in memory. Ansys Fluent has provided you with a face looping macro to loop over all faces in a thread (begin_f_loop...). See Additional Macros for Writing UDFs for details.

F_PROFILE is typically used along with DEFINE_PROFILE and is a predefined macro supplied by Ansys Fluent. F_PROFILE stores a boundary condition in memory for a given face and thread and is nested within the face loop as shown in the examples below. It is important to note that the index i that is an argument to DEFINE_PROFILE is the same argument to F_PROFILE. F_PROFILE uses the thread pointer t, face identifier f, and index i to set the appropriate boundary face value in memory. See Set Boundary Condition Value (F_PROFILE) for a description of F_PROFILE. Note that in the case of porosity profiles, you can also use C_PROFILE to define those types of functions. See the example UDFs provided below.

In multiphase cases a DEFINE_PROFILE UDF may be called more than once (particularly if the profile is used in a mixture domain thread). If this must be avoided, then add the prefix MP_ to the UDF name. The function will then be called only once even if it is used for more than one profile.

If your UDF uses solver storage, it is recommended that you include a NULL storage check; this can prevent an abnormal termination of Fluent if your UDF is called before the flow is initialized (that is, when the storages have not yet been allocated by the solver). For example, you could define the density in the following manner:

if(NNULLP(THREAD_STORAGE(thread, SV_DENSITY)))
  density = F_R(f,thread);
else
  density = 1.225; /*A reasonable value to prevent abnormal termination if flow is not initialized*/

2.3.32.3. Example 1 - Pressure Profile

The following UDF, named pressure_profile, generates a parabolic pressure profile according to the equation

Note that this UDF assumes that the mesh is generated such that the origin is at the geometric center of the boundary zone to which the UDF is to be applied. is 0.0 at the center of the inlet and extends to at the top and bottom of the inlet. The source code can be interpreted or compiled in Ansys Fluent.

/***********************************************************************
 UDF for specifying steady-state parabolic pressure profile boundary
 profile for a turbine vane
 ************************************************************************/
 
 #include "udf.h"
 
 DEFINE_PROFILE(pressure_profile,t,i)
 {
    real x[ND_ND];    /* this will hold the position vector */
    real y;
    face_t f;
    begin_f_loop(f,t)
      {
       F_CENTROID(x,f,t);
       y = x[1];
       F_PROFILE(f,t,i) = 1.1e5 - y*y/(.0745*.0745)*0.1e5;
      }
    end_f_loop(f,t)
 } 

The function named pressure_profile has two arguments: t and i. t is a pointer to the face’s thread, and i is an integer that is a numerical label for the variable being set within each loop.

Within the function body variable f is declared as a face. A one-dimensional array x and variable y are declared as real data types. Following the variable declarations, a looping macro is used to loop over each face in the zone to create a profile, or an array of data. Within each loop, F_CENTROID returns the value of the face centroid (array x) for the face with index f that is on the thread pointed to by t. The coordinate stored in x[1] is assigned to variable y, and is then used to calculate the pressure. This value is then assigned to F_PROFILE which uses the integer i (passed to it by the solver, based on your selection of the UDF as the boundary condition for pressure in the Pressure Inlet dialog box) to set the pressure face value in memory.

2.3.32.4. Example 2 - Velocity, Turbulent Kinetic Energy, and Turbulent Dissipation Rate Profiles

In the following example, DEFINE_PROFILE is used to generate profiles for the velocity, turbulent kinetic energy, and dissipation rate, respectively, for a 2D fully-developed duct flow. Three separate UDFs named x_velocity, k_profile, and dissip_profile are defined. These functions are concatenated in a single C source file and can be interpreted or compiled in Ansys Fluent.

The 1/7th power law is used to specify the velocity component:

A fully-developed profile occurs when is one-half the duct height. In this example, the mean velocity is prescribed and the peak (free-stream) velocity is determined by averaging across the channel.

The turbulent kinetic energy is assumed to vary linearly from a near-wall value of

to a free-stream value of

The dissipation rate is given by

where the mixing length is the minimum of and 0.085 . ( is the von Karman constant = 0.41.)

The friction velocity and wall shear take the forms:

The friction factor is estimated from the Blasius equation:

/**********************************************************************
  Concatenated UDFs for fully-developed turbulent inlet profiles
 ***********************************************************************/
 
 #include "udf.h"
 
 #define YMIN 0.0      /* constants */
 #define YMAX 0.4064
 #define UMEAN 1.0
 #define B 1./7.
 #define DELOVRH 0.5
 #define VISC 1.7894e-05
 #define CMU 0.09
 #define VKC 0.41
 
 
 /* profile for x-velocity */
 
 
 DEFINE_PROFILE(x_velocity,t,i)
 {
    real y, del, h, x[ND_ND], ufree;  /* variable declarations */
    face_t f;

    h = YMAX - YMIN;
    del = DELOVRH*h;
    ufree = UMEAN*(B+1.);

    begin_f_loop(f,t)
      {
         F_CENTROID(x,f,t);
         y = x[1];
         if (y <= del)
           F_PROFILE(f,t,i) = ufree*pow(y/del,B);
         else
           F_PROFILE(f,t,i) = ufree*pow((h-y)/del,B);
      }
    end_f_loop(f,t)
 }
 
 /* profile for kinetic energy */
 
 DEFINE_PROFILE(k_profile,t,i)
 {
    real y, del, h, ufree, x[ND_ND];
    real ff, utau, knw, kinf;
    face_t f;

    h = YMAX - YMIN;
    del = DELOVRH*h;
    ufree = UMEAN*(B+1.);
    ff = 0.045/pow(ufree*del/VISC,0.25);
    utau=sqrt(ff*pow(ufree,2.)/2.0);
    knw=pow(utau,2.)/sqrt(CMU);
    kinf=0.002*pow(ufree,2.);

    begin_f_loop(f,t)
      {
         F_CENTROID(x,f,t);
         y=x[1];

           if (y <= del)
             F_PROFILE(f,t,i)=knw+y/del*(kinf-knw);
           else
             F_PROFILE(f,t,i)=knw+(h-y)/del*(kinf-knw);
        }
      end_f_loop(f,t)
 }
 
 /* profile for dissipation rate */
 
 DEFINE_PROFILE(dissip_profile,t,i)
 {
    real y, x[ND_ND], del, h, ufree;
    real ff, utau, knw, kinf;
    real mix, kay;
    face_t f;

    h = YMAX - YMIN;
    del = DELOVRH*h;
    ufree = UMEAN*(B+1.);
    ff = 0.045/pow(ufree*del/VISC,0.25);
    utau=sqrt(ff*pow(ufree,2.)/2.0);
    knw=pow(utau,2.)/sqrt(CMU);
    kinf=0.002*pow(ufree,2.);

    begin_f_loop(f,t)
      {
         F_CENTROID(x,f,t);
         y=x[1];

         if (y <= del)
           kay=knw+y/del*(kinf-knw);
         else
           kay=knw+(h-y)/del*(kinf-knw);

         if (VKC*y < 0.085*del)
           mix = VKC*y;
         else
           mix = 0.085*del;

         F_PROFILE(f,t,i)=pow(CMU,0.75)*pow(kay,1.5)/mix;
        }
      end_f_loop(f,t)
 } 

2.3.32.5. Example 3 - Fixed Velocity UDF

In the following example DEFINE_PROFILE is used to fix flow variables that are held constant during computation in a cell zone. Three separate UDFs named fixed_u, fixed_v, and fixed_ke are defined in a single C source file. They specify fixed velocities that simulate the transient startup of an impeller in an impeller-driven mixing tank. The physical impeller is simulated by fixing the velocities and turbulence quantities using the fix option in Ansys Fluent. See Fixing the Values of Variables in the User’s Guide for more information on fixing variables.

/***********************************************************************
   Concatenated UDFs for simulating an impeller using fixed velocity
 ************************************************************************/
 
 #include "udf.h"
 
 #define FLUID_ID 1
 #define ua1 -7.1357e-2
 #define ua2 54.304
 #define ua3 -3.1345e3
 #define ua4 4.5578e4
 #define ua5 -1.9664e5
 
 #define va1 3.1131e-2
 #define va2 -10.313
 #define va3 9.5558e2
 #define va4 -2.0051e4
 #define va5 1.1856e5
 
 #define ka1 2.2723e-2
 #define ka2 6.7989
 #define ka3 -424.18
 #define ka4 9.4615e3
 #define ka5 -7.7251e4
 #define ka6 1.8410e5
 
 #define da1 -6.5819e-2
 #define da2 88.845
 #define da3 -5.3731e3
 #define da4 1.1643e5
 #define da5 -9.1202e5
 #define da6 1.9567e6
 
 
 DEFINE_PROFILE(fixed_u,t,i)
 {
    cell_t c;
    real x[ND_ND];
    real r;

    begin_c_loop(c,t)
      {
 /* centroid is defined to specify position dependent profiles */

         C_CENTROID(x,c,t);
         r =x[1];
         F_PROFILE(c,t,i) =
             ua1+(ua2*r)+(ua3*r*r)+(ua4*r*r*r)+(ua5*r*r*r*r);
       }
    end_c_loop(c,t)
 }
 
 
 DEFINE_PROFILE(fixed_v,t,i)
 {
    cell_t c;
    real x[ND_ND];
    real r;
    begin_c_loop(c,t)
      {
 /* centroid is defined to specify position dependent profiles*/

         C_CENTROID(x,c,t);
         r =x[1];
         F_PROFILE(c,t,i) =
         va1+(va2*r)+(va3*r*r)+(va4*r*r*r)+(va5*r*r*r*r);
       }
     end_c_loop(c,t)
 } 
 DEFINE_PROFILE(fixed_ke,t,i)
 {
    cell_t c;
    real x[ND_ND];
    real r;
    begin_c_loop(c,t)
      {
 /* centroid is defined to specify position dependent profiles*/

         C_CENTROID(x,c,t);
         r =x[1];
         F_PROFILE(c,t,i) =
         ka1+(ka2*r)+(ka3*r*r)+(ka4*r*r*r)+(ka5*r*r*r*r)+(ka6*r*r*r*r*r);
      }
    end_c_loop(c,t)
 } 

2.3.32.6. Example 4 - Wall Heat Generation Rate Profile

The following UDF, named wallheatgenerate, generates a heat generation rate profile for a planar conduction wall. After it has been interpreted or compiled, you can activate this UDF in the Wall boundary conditions dialog box in Ansys Fluent.

/* Wall Heat Generation Rate Profile UDF */
 
 #include "udf.h"
 
 DEFINE_PROFILE(wallheatgenerate,thread,i)
 {
    real source = 0.001;
    face_t f;
    begin_f_loop(f,thread)
        F_PROFILE(f,thread,i) = source;
    end_f_loop(f,thread)
 } 

2.3.32.7. Example 5 - Beam Direction Profile at Semi-Transparent Walls

The following UDF, named q_nx, where x is the direction vector i, j, k, specifies the beam direction normal to every face on the cylinder. After it has been interpreted or compiled, you can activate this UDF in the Wall boundary conditions dialog box in Ansys Fluent.

/* Beam Direction Profile UDF at Semi-Transparent Walls */
 
 #include "udf.h"
 
 DEFINE_PROFILE(q_ni, t, position)
 {
    real A[3], e_n[3];
    face_t f;
    real At;
    begin_f_loop(f, t)
       {
         F_AREA(A, f, t);
         At = NV_MAG(A);
         NV_VS(e_n,=,A,/,At);
         F_PROFILE(f, t, position) = -e_n[0];
       }
    end_f_loop(f, t)
 
 }
 
 
 DEFINE_PROFILE(q_nj, t, position)
 {
    real A[3], e_n[3];
    face_t f;
    real At;
    begin_f_loop(f, t)
       {
         F_AREA(A, f, t);
         At = NV_MAG(A);
         NV_VS(e_n,=,A,/,At);
         F_PROFILE(f, t, position) = -e_n[1];
       }
    end_f_loop(f, t) 
 }
 
 
 DEFINE_PROFILE(q_nk, t, position)
 {
    real A[3], e_n[3];
    face_t f;
    real At;
    begin_f_loop(f, t)
       {
         F_AREA(A, f, t);
         At = NV_MAG(A);
         NV_VS(e_n,=,A,/,At);
         F_PROFILE(f, t, position) = -e_n[2];
       }
    end_f_loop(f, t)
 
 }

2.3.32.8. Example 6 - Viscous Resistance Profile in a Porous Zone

You can either use F_PROFILE or C_PROFILE to define a viscous resistance profile in a porous zone. Below are two sample UDFs that demonstrate the usage of F_PROFILE and C_PROFILE, respectively. Note that porosity functions are hooked to Ansys Fluent in the Porous Zone tab in the appropriate Fluid cell zone conditions dialog box.

The following UDF, named vis_res, generates a viscous resistance profile in a porous zone. After it has been interpreted or compiled and loaded, you can activate this UDF in the Fluid cell zone condition dialog box in Ansys Fluent.

/* Viscous Resistance Profile UDF in a Porous Zone that utilizes F_PROFILE*/
 
 #include "udf.h"
 
 DEFINE_PROFILE(vis_res,t,i)
 {
    real x[ND_ND];
    real a;
    cell_t c;
    begin_c_loop(c,t)
      {
        C_CENTROID(x,c,t);
        if(x[1] < (x[0]-0.01))
           a = 1e9;
        else
           a = 1.0;
        F_PROFILE(c,t,i) = a;
      }
    end_c_loop(c,t)
 }
 
 /* Viscous Resistance Profile UDF in a Porous Zone that utilizes C_PROFILE*/
 
 #include "udf.h"
 
 DEFINE_PROFILE(porosity_function, t, nv)
 {
   cell_t c;
   begin_c_loop(c,t)
       C_PROFILE(c,t,nv) = 0.5;
   end_c_loop(c,t)
 } 

2.3.32.9. Example 7 - Porous Resistance Direction Vector

The following UDF contains profile functions for two porous resistance direction vectors that use C_PROFILE. These profiles can be hooked to corresponding direction vectors under Porous Zone in the Fluid cell zone condition dialog box.

/* Porous Resistance Direction Vector Profile that utilizes C_PROFILE*/
 
 #include "udf.h"
 
 DEFINE_PROFILE{dir1, t, nv}
 {
   cell_t c;
   begin_c_loop(c,t)
       C_PROFILE(c,t,nv) = 0.5;
   end_c_loop(c,t)
 }
 
 DEFINE_PROFILE{dir2, t, nv}
 {
   cell_t c;
   begin_c_loop(c,t)
       C_PROFILE(c,t,nv) = 0.3;
   end_c_loop(c,t)
 } 

2.3.32.10. Example 8 -Target Mass Flow Rate UDF as a Function of Physical Flow Time

For some unsteady problems, it is desirable that the target mass flow rate be a function of the physical flow time. This boundary condition can be applied using a DEFINE_PROFILE UDF. The following UDF, named tm_pout2, adjusts the mass flow rate from to when the physical time step is greater than seconds. After it has been interpreted or compiled, you can activate this UDF in the Pressure Outlet boundary condition dialog box in Ansys Fluent by selecting the Specify target mass-flow rate option, and then choosing the UDF name from the corresponding drop-down list.


Important:  Note that the mass flow rate profile is a function of time and only one constant value should be applied to all zone faces at a given time.


/* UDF for setting target mass flow rate in pressure-outlet   */
 /* at t0.2 sec the target mass flow rate set to 1.00 kg/s    */
 /* when t0.2 sec the target mass flow rate will change to 1.35 kg/s */
 
 #include "udf.h"
 DEFINE_PROFILE(tm_pout2, t, nv)
 {
    face_t f ;
    real flow_time = RP_Get_Real("flow-time");
    if (flow_time < 0.2)
      {
         printf("Time   = %f sec. \n",flow_time);
         printf("Targeted mass-flow rate set at 1.0 kg/s \n");
         begin_f_loop(f,t)
          {
             F_PROFILE(f,t,nv) = 1.0 ;
          }
         end_f_loop(f,t)
      }
    else
      {
         printf("Time   = %f sec. \n",flow_time);
         printf("Targeted mass-flow rate set at 1.35 kg/s \n") ;
 
         begin_f_loop(f,t)
           {
            F_PROFILE(f,t,nv) = 1.35 ;
           }
         end_f_loop(f,t)
  } } 

2.3.32.11. Example 9 - Mass Flow Rate UDF for a Mass-Flow Inlet or Mass-Flow Outlet

This UDF is used to provide a time-varying specification of the mass flow rate. This boundary condition can be applied using a DEFINE_PROFILE UDF. The following UDF, named mass_flow, initially specifies a mass flow rate of 3.0 kg/s for the first 10 milliseconds, then increases it to 4.0 kg/s for the next 10 milliseconds, and after that specifies 5.0 kg/s. The macro CURRENT_TIME looks up the current flow time. Since this is a built-in RP variable, it is available to all nodes. It is more efficient to access it once and store the value in a local variable, rather than accessing it for every face in the face loop.

After it has been interpreted or compiled, you can activate this UDF in the Mass-Flow Inlet or Mass-Flow Outlet boundary condition dialog box in Ansys Fluent by selecting the UDF from the Mass Flow Rate drop-down list.

#include "udf.h"
 
  DEFINE_PROFILE(mass_flow,th,i)
 {
   face_t f;
   real flow_time = CURRENT_TIME;
   begin_f_loop(f,th)
     {
       if(flow_time <= 0.01)
          F_PROFILE(f,th,i) = 3.0;
       else if(flow_time <=0.02)
          F_PROFILE(f,th,i) = 4.0;
       else
          F_PROFILE(f,th,i) = 5.0;
     }
    end_f_loop(f,th);
 }

2.3.32.12. Hooking a Boundary Profile UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_PROFILE is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, vis_res) will become visible and selectable in the appropriate boundary condition dialog box (for example, the Velocity Inlet dialog box), cell zone condition dialog box, and Shell Conduction Layers dialog box in Ansys Fluent. See Hooking DEFINE_PROFILE UDFs for details.

2.3.33. DEFINE_PROPERTY UDFs

2.3.33.1. Description

You can use DEFINE_PROPERTY to specify a custom material property in Ansys Fluent for single-phase flows and multiphase flows. DEFINE_PROPERTY can also be used to specify a custom material property for structural materials to be used in a fluid-structure interaction (FSI) simulation. If you are writing a user-defined mixing law UDF for a mixture material, you will need to use special utilities to access species material properties. These are described below. If you want to define a custom mass diffusivity property when modeling species transport, you must use DEFINE_DIFFUSIVITY instead of DEFINE_PROPERTY. See DEFINE_DIFFUSIVITY for details on DEFINE_DIFFUSIVITY UDFs. For an overview of the Ansys Fluent solution process which shows when a DEFINE_PROPERTY UDF is called, refer to Figure 1.2: Solution Procedure for the Pressure-Based Segregated Solver, Figure 1.3: Solution Procedure for the Pressure-Based Coupled Solver, and Figure 1.4: Solution Procedure for the Density-Based Solver.

Some of the properties you can customize using DEFINE_PROPERTY are:

  • density (as a function of temperature)

  • viscosity

  • thermal conductivity

  • absorption and scattering coefficients

  • laminar flame speed

  • rate of strain

  • user-defined mixing laws for density, viscosity, and thermal conductivity of mixture materials

  • partially-premixed unburnt properties for unburnt density, unburnt temperature, unburnt specific heat, and unburnt thermal diffusivity


Important:  If you would like to use a UDF to define specific heat properties, you must use the DEFINE_SPECIFIC_HEAT, as described in DEFINE_SPECIFIC_HEAT .



Important:  Note that when you specify a user-defined density function for a compressible liquid flow application, you must also include a speed of sound function in your model. Compressible liquid density UDFs can be used in the pressure-based solver and for single phase, multiphase mixture and cavitation models, only. See the example below for details.


For Multiphase Flows

  • surface tension coefficient (VOF model)

  • cavitation parameters including surface tension coefficient and vaporization pressure (Mixture, cavitation models)

  • heat transfer coefficient (Mixture model)

  • particle or droplet diameter (Mixture model)

  • speed of sound function (Mixture, cavitation models)

  • density (as a function of pressure) for compressible liquid flows only (Mixture, cavitation models)

  • granular temperature and viscosity (Mixture, Eulerian models)

  • granular bulk viscosity (Eulerian model)

  • granular conductivity (Eulerian model)

  • frictional pressure and viscosity (Eulerian model)

  • frictional modulus (Eulerian model)

  • elasticity modulus (Eulerian model)

  • radial distribution (Eulerian model)

  • solids pressure (Eulerian, Mixture models)

  • diameter (Eulerian, Mixture models)

  • saturation temperature

For an intrinsic FSI simulation, DEFINE_PROPERTY can be used to customize the following structural properties:

  • Young's Modulus

  • Poisson Ratio

  • Thermal Expansion

2.3.33.2. Usage

DEFINE_PROPERTY (name, c, t)

Argument Type Description
symbol name UDF name.
cell_t c Cell index.
Thread *t Pointer to cell thread on which the property function is to be applied.

Function returns

real

There are three arguments to DEFINE_PROPERTY: name, c, and t. You supply name, the name of the UDF. c and t are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to compute the real property only for a single cell and return it to the solver.

Note that like source term UDFs, property UDFs (defined using DEFINE_PROPERTY) are called by Ansys Fluent from within a loop on cell threads. The solver passes all of the variables needed to allow a DEFINE_PROPERTY UDF to define a custom material, since properties are assigned on a cell basis. Consequently, your UDF will not need to loop over cells in a zone since Ansys Fluent is already doing it.

2.3.33.3. Auxiliary Utilities

Some commonly-used auxiliary utilities for custom property UDFs are described below. They are generic_property, MATERIAL_PROPERTY, THREAD_MATERIAL, and mixture_species_loop.

generic_property is a general purpose function that returns the real value for the given property id for the given thread material. It is defined in prop.h and is used only for species properties.

The following Property_ID variables are available:

  • PROP_rho, density

  • PROP_mu, viscosity

  • PROP_ktc, thermal conductivity

generic_property (name, c, t, prop, id, T)

Argument TypeDescription
symbol name Function name.
cell_t c Cell index.
Thread *t Pointer to cell thread on which property function is to be applied.
Property *prop Pointer to property array for the thread material that can be obtained through the macro MATERIAL_PROPERTY(m) See below.
Property_ID id Property ID of the required property you want to define a custom mixing law for (for example, PROP_ktc for thermal conductivity). See below for list of variables.
real T Temperature at which the property is to be evaluated (used only if a polynomial method is specified).

Function returns

real

MATERIAL_PROPERTY is defined in materials.h and returns a real pointer to the Property array prop for the given material pointer m.

MATERIAL_PROPERTY (m)

Argument Type Description
Material *m Material pointer.

Function returns

real

THREAD_MATERIAL is defined in threads.h and returns real pointer m to the Material that is associated with the given cell thread t.


Important:  Note that in previous versions of Ansys Fluent, THREAD_MATERIAL took two arguments (t,i), but now only takes one (t).


THREAD_MATERIAL (t)

Argument Type

Description
Thread *t Pointer to cell thread.

Function returns

real

mixture_species_loop is defined in materials.h and loops over all of the species for the given mixture material.

mixture_species_loop (m,sp,i)

Argument Type Description
Material *m Material pointer.
Material *sp Species pointer.
int i Species index.

Function returns

real

2.3.33.4. Example 1 - Temperature-dependent Viscosity Property

The following UDF, named cell_viscosity, generates a variable viscosity profile to simulate solidification. The function is called for every cell in the zone. The viscosity in the warm ( K) fluid has a molecular value for the liquid (5.5 kg/m-s), while the viscosity for the cooler region ( 286 K) has a much larger value (1.0 kg/m-s). In the intermediate temperature range (286 K 288 K), the viscosity follows a linear profile that extends between the two values given above:

(2–10)

This model is based on the assumption that as the liquid cools and rapidly becomes more viscous, its velocity will decrease, thereby simulating solidification. Here, no correction is made for the energy field to include the latent heat of freezing. The source code can be interpreted or compiled in Ansys Fluent.

/*********************************************************************
   UDF that simulates solidification by specifying a temperature-
   dependent viscosity property
 **********************************************************************/
 #include "udf.h"
 
 DEFINE_PROPERTY(cell_viscosity,c,t)
 {
    real mu_lam;
    real temp = C_T(c,t);
    if (temp > 288.)
      mu_lam = 5.5e-3;
    else if (temp > 286.)
      mu_lam = 143.2135 - 0.49725 * temp;
    else
      mu_lam = 1.;
    return mu_lam;
 } 

The function cell_viscosity is defined on a cell. Two real variables are introduced: temp, the value of C_T(c,t), and mu_lam, the laminar viscosity computed by the function. The value of the temperature is checked, and based upon the range into which it falls, the appropriate value of mu_lam is computed. At the end of the function the computed value for the viscosity (mu_lam) is returned to the solver.

2.3.33.5. Example 2 - User-defined Mixing Law for Thermal Conductivity

You can use DEFINE_PROPERTY to define custom user-defined mixing laws for density, viscosity, and conductivity of mixture materials. In order to access species material properties your UDF will need to utilize auxiliary utilities that are described above.

The following UDF, named mass_wtd_k, is an example of a mass-fraction weighted conductivity function. The UDF utilizes the generic_property function to obtain properties of individual species. It also makes use of MATERIAL_PROPERTY and THREAD_MATERIAL.

/*********************************************************************
    UDF that specifies a custom mass-fraction weighted conductivity
 **********************************************************************/
 #include "udf.h"
 
 DEFINE_PROPERTY(mass_wtd_k,c,t)
 {
    real sum = 0.; int i;
    Material *sp;
    real ktc;
    Property *prop;
    mixture_species_loop(THREAD_MATERIAL(t),sp,i)
       {
         prop = (MATERIAL_PROPERTY(sp));
         ktc = generic_property(c,t,prop,PROP_ktc,C_T(c,t));
         sum += C_YI(c,t,i)*ktc;
       }
    return sum;
 } 

2.3.33.6. Example 3 - Surface Tension Coefficient UDF

DEFINE_PROPERTY can also be used to define a surface tension coefficient UDF for the multiphase VOF model. The following UDF specifies a surface tension coefficient as a quadratic function of temperature. The source code can be interpreted or compiled in Ansys Fluent.

/***************************************************************
 Surface Tension Coefficient UDF for the multiphase VOF Model
 ***************************************************************/
 
 #include "udf.h"
 DEFINE_PROPERTY(sfc,c,t)
 {
    real T = C_T(c,t);
    return 1.35 - 0.004*T + 5.0e-6*T*T;
 } 

2.3.33.7. Example 4 - Density Function for Compressible Liquids

Liquid density is not a constant but is instead a function of the pressure field. In order to stabilize the pressure solution for compressible flows in Ansys Fluent, an extra term related to the speed of sound is needed in the pressure correction equation. Consequently, when you want to define a custom density function for a compressible flow, your model must also include a speed of sound function. Although you can direct Ansys Fluent to calculate a speed of sound function by choosing one of the available methods (for example, piecewise-linear, polynomial) in the Create/Edit Materials dialog box, as a general guideline you should define a speed of sound function along with your density UDF using the formulation:

For simplicity, it is recommended that you concatenate the density and speed of sound functions into a single UDF source file.

The following UDF source code example contains two concatenated functions: a density function named superfluid_density that is defined in terms of pressure and a custom speed of sound function named sound_speed.

/********************************************************************
   Density and speed of sound UDFs.
 *********************************************************************/
#include "udf.h"

#define BMODULUS 2.2e9
#define rho_ref 1000.0
#define p_ref 101325

DEFINE_PROPERTY(superfluid_density, c, t)
{
    real rho;
    real p, dp;
    p = C_P(c,t) + op_pres;
    dp = p-p_ref;
    rho = rho_ref/(1.0-dp/BMODULUS);
    return rho;
}

DEFINE_PROPERTY(sound_speed, c,t)
{
    real a;
    real p, dp;
    p = C_P(c,t) + op_pres;
    dp = p-p_ref;  a = sqrt(BMODULUS*(1.-dp/BMODULUS)/rho_ref);
    return a;
}

2.3.33.8. Hooking a Property UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_PROPERTY is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, sound_speed) will become visible and selectable in dialog boxes in Ansys Fluent. See Hooking DEFINE_PROPERTY UDFs for details.

2.3.34. DEFINE_REACTING_CHANNEL_BC

2.3.34.1. Description

You can use DEFINE_REACTING_CHANNEL_BC to specify user-defined inlet conditions at any reacting channel inlet. Typically this UDF is used for manifolds where the flow in two (or more) reacting channels mix in a manifold into one (or more) reacting channels. During execution, the DEFINE_REACTING_CHANNEL_BC is called for every channel iteration. The UDF is available only if the reacting channel model is enabled.

2.3.34.2. Usage

DEFINE_REACTING_CHANNEL_BC (name, i, group)

Argument Type

Description

symbol name

UDF name.

int i

ID of the reacting channel group.

Channel_Group *group

Pointer to structure of reacting channel group.

Function returns

void

There are three arguments to DEFINE_REACTING_CHANNEL_BC: name, i, group. You supply name, the name of the UDF, while i and group are variables that are passed by the Ansys Fluent solver to your UDF. The variable i is the integer ID of the reacting channel group. The last argument is group, which is a pointer to the reacting channel group structure. The members of the structure group are described in the header file sg_reacting_channel.h.

2.3.34.3. Example

The following UDF, named tube3_bc_from_1_and_2, specifies the inlet conditions for a reacting channel. In this UDF example, the inlet conditions (mass-flow rate, pressure, temperature, and species mass fractions) of the reacting channel, tube 3, are defined using the mass-flow weighted outlet states from the reacting channels, tubes 1 and 2.

/*******************************************************************
 * User-defined function to specify the inlet boundary conditions at a reacting channel 
 * using mass weighted average outlet variables from two other reacting channels. 
 * In this UDF, the user defined inlet conditions for temperature, mass flow rate, 
 * species mass fraction, and pressure are applied
 ********************************************************************/

 #include "udf.h"
 #include "sg_reacting_channel.h"
 #define MAX_GROUPS 3   /* maximum number of groups defined in the interface*/
 #define total_tubes 3   /* total number of wall zones in all groups used as reacting channel*/

 static void outlet_average_variables(int *group_ids, int num_groups,Channel_Group *group)
 {
     if(num_groups > N_channel_groups-1 || NULLP(group_ids))
       {
         Message("incorrect number of groups\n");
         return;
       }
     else
       {
         Material *m =group->m;   /* Material of any group, specified in the interface*/
         int i,id,j,ns,nspe=MIXTURE_NSPECIES(m);
         real mf,sum_temp,sum_mf,sum_press;
         cxboolean group_found = FALSE;
         Channel_Tube tube;
         real *sum_yi = (real *) CX_Malloc(sizeof(real)*nspe);
         spe_loop(ns,nspe)
           sum_yi[ns] =0.;
         sum_temp =0.;
         sum_press =0.;
         sum_mf=0.;

         for(j=0;j<total_tubes;j++)
            /* Total number of wall zones selected in all groups in the interface in reacting channel model*/
           {
             group_found = FALSE;
             tube = channel_tubes[j];  /* structure for any wall zone,
                                          which is specified as reacting channel wall*/
             id = tube.group_id;   /* id of the group to which this wall zone belongs*/
             for(i=0;i<num_groups;i++)   /* loop over all groups*/
               if (id == group_ids[i])
                 {
                   group_found = TRUE;   /* the current wall zone is valid reacting channel zone
                                            and belongs to a group*/
                   break;
                 }
             if(!group_found) continue ;
             i = tube.n_bands-1;   /* last grid point of the 1D grid of reacting channel wall zone*/
             mf = tube.group->mf;   /* mass flow rate of the group*/
             sum_mf += mf;
             sum_temp += mf*tube.bands[i].T;   /* temperature at the last grid point,
                                                  i.e. at the exit of the current channel*/
             sum_press += mf*tube.bands[i].pressure;   /* similar to temperature, and other variables
                                                          at exit of current channel*/
             spe_loop(ns,nspe)
               sum_yi[ns] += mf*tube.bands[i].yi[ns];
           }
         if(sum_mf > SMALL)
           {
             group->mf = sum_mf;   /* here group is the current group, where udf is applied,
                                      the mass flow rate is sum of  mf from all other groups*/
             group->temp = sum_temp/sum_mf;   /* the temperature, pressure and mass fraction at this 
                                          group are mass weighted average from exit of other groups*/
             group->pressure = sum_press/sum_mf;
             spe_loop(ns,nspe)
               group->yi[ns] = sum_yi[ns]/sum_mf;
           }         CX_Free(sum_yi);
       }
 }
/* By default, the group will use conditions provided in the interface of the 
 * group in reacting channel model set up. 
 * The UDF can modify few or all inlet conditions. 
 * Any inlet conditions provided by the udf will overwrite the default conditions 
 * provided in the interface for any given group */


DEFINE_REACTING_CHANNEL_BC(tube3_bc_from_1_and_2,i,group)
 {
    int group_ids[MAX_GROUPS];
    int num_groups =0;
    group_ids[0] = 0;   /* id of the group 0 specified in gui or tui */
    group_ids[1] = 1;
    num_groups =2;   /* total number of groups from where the averaging is to be done,
                        in this case, averaged variables from 2 groups are used 
                        to specify the inlet conditions for the third group*/
    outlet_average_variables(group_ids,num_groups,group);
 }

2.3.34.4. Hooking a Reacting Channel Solver UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_REACTING_CHANNEL_BC is compiled (Compiling UDFs), the name that you specified in the DEFINE macro argument (for example, tube3_bc_from_1_and_2) will become visible and selectable in the Reacting Channel Model dialog box in Ansys Fluent. See Hooking DEFINE_REACTING_CHANNEL_SOLVER UDFs for details.

2.3.35. DEFINE_REACTING_CHANNEL_SOLVER

2.3.35.1. Description

You can use DEFINE_REACTING_CHANNEL_SOLVER to specify a user-defined heat transfer coefficient or heat flux at the reacting channel walls. During execution, the DEFINE_REACTING_CHANNEL_SOLVER is called for every channel iteration. The UDF is available only if the reacting channel model is enabled.

2.3.35.2. Usage

DEFINE_REACTING_CHANNEL_SOLVER (name, params, inlet_state, dist, dt, wall_temp, wall_hf, compute_htc)

Argument Type

Description

symbol name

UDF name.

int *params

Pointer to array of current channel parameters.

real *inlet_state

Pointer to array of inlet species composition, temperature and pressure.

real *dist

Pointer to array of axial distance of discrete points from channel inlet.

real *dt

Pointer to array of time step of integration at discrete points.

real *wall_temp

Pointer to array of channel wall temperature at discrete points.

real *wall_hf

Pointer to array of channel wall heat flux at discrete points

cxboolean *compute_htc

Pointer to a flag. Set TRUE only if heat transfer coefficient is computed with the UDF.

Function returns

void

There are eight arguments to DEFINE_REACTING_CHANNEL_SOLVER: name, params, inlet_state, dist, dt, wall_temp, wall_hf, compute_htc. You supply name, the name of the UDF, while params, inlet_state, dist, dt, wall_temp, wall_hf, and compute_htc are variables that are passed by the Ansys Fluent solver to your UDF. The variable params contains four integer values specifying the number of species, the number of discrete points along the channel axis, the index of the current channel, and the index of the current channel group. The array inlet_state has N +2 elements, where N is the number of species in the channel material. The first N element of the array contains the mass fraction of the species at the channel inlet. The next two elements are temperature and pressure at the channel inlet. The variables dist, dt, wall_temp, and wall_hf have M elements, where M is the number of discrete points specified along the axis of the channel from the channel inlet to the exit. Your UDF will need to set the Boolean variable compute_htc to TRUE if you want to set the heat transfer coefficient to the reacting channel wall using this UDF or set it to FALSE if you want to set the reacting channel wall heat flux. Your UDF will need to set the value of wall_hf with the heat transfer coefficient if the flag is true or the heat flux from the reacting channel if the flag is false.

2.3.35.3. Example

The following UDF, set_channel_htc, specifies the heat transfer coefficient at the reacting channel wall. The function must be executed as a compiled UDF in Ansys Fluent.

#include "udf.h"
#include "sg_reacting_channel.h"

/*
  
   There are following two main structures "defined in sg_reacting_channel.h"

   Channel_Group *channel_groups; //channel groups, containing information about inlet conditions, 
   material, model setting etc.
   Channel_Tubes *channel_tubes ' // wall zones, selected as reacting channels, information regarding 
   grid, heat flux, temperature and all other variables stored on this

  
   params is a pointer to integer array containing channel parameters. The array has following 
   four values stored 

   no of species = params[0];
   no of grid points in channel = params[1]
   id of channel = params[2];
   id of the group to which this channel belong = params[3];

   By just having id of channel, we can get all the information regarding a channel as following:

  
   id_channel = params[2];
   Channel_Tube tube =  channel_tubes[id_chanel];
   Channel_Group *group = tube.group;  //tube belongs to the group


   1. Getting the group variables like pressure, temperature, mass flow rate etc from the group 
      obtained above. All these are inlet conditions.

   real pressure = group->pressure.
   real temp = group->temp;
   real mf = group->mf;
   real yi[ns] = group->yi[ns];

   2. The variables like velocity, diameter, rho etc are either available at each grid point 
      of the tube or calculated at each grid point as follows

->Each tube has many grid points along the axial direction. Each grid point is called as bands. 
  All solution variables are stored in bands. 
    
        int nbands = params[1];
        
        For nth grid point, starting from inlet of the tube.

        Material *m = group->m ; //mixture material of the reacting channel group 
        real temp = tube.bands[n].T
        yk[ns] = tube.bands[n].yi[ns];
        pressure = tube.bands[n].pressure;


        
        //band is any grid point of the channel
        
        rho = tube.bands[n].rho;
        band_ktc = Thermal_Conductivity(0, NULL, m, temp, 0., yk,xk,0.);
                   //xk is the mole fraction, yk is the mass fraction
        band_dia = 2.*sqrt(MAX(0., channel_tubes[i].bands[j].area/M_PI));
                  //area of the bands is available and stored, diamete is calculated.
        band_mu =  Viscosity(0,NULL,m,temp,rho,yk,xk,0.);
        band_vel = tube.bands[n].vel;


   */

DEFINE_REACTING_CHANNEL_SOLVER(set_channel_htc,params,inlet_state,dist,dt,wall_temp,wall_hf,compute_htc)
{
    int g_pts, id_c = params[2],j, ns,nspecies= params[0];
    real Nu,Re,vel,channel_dia,visc,Prt,rho,ktc;
    real xk[MAX_SPE_EQNS],yk[MAX_SPE_EQNS];
    Channel_Tube tube =  channel_tubes[id_c];
    Channel_Group *group = tube.group;
    Material *m = group->m ;
    real p,temp,pgauge,mfrate;
    real op_pres_save;
    
    *compute_htc = TRUE ;
    g_pts = params[1];
    Prt=0.85;

    for (j=0;j++)
      {
        if (j == 0 || N_ITER < 1) /*first band or first iteration*/
          {
            spe_loop(ns,nspecies) /*initial conditions from the inlet bc of the group*/
              yk[ns] = group->yi[ns];
            temp = group->temp ;
          }
        else
          {
            spe_loop(ns,nspecies)
              yk[ns] = tube.bands[j-1].yi[ns];
            temp = tube.bands[j-1].T ;
          }

        mfrate = group->mf;
        p = group->pressure;
        Mole_Fraction(m,yk,xk);

        pgauge =0.;
        op_pres_save = op_pres;
        op_pres = group->pressure; /*channel inlet pressure can be different than the operating pressure*/

        rho =  Density(0,NULL,m,temp,pgauge,yk,0,0,0,0,0,0,0,0);
        channel_dia = 2.*sqrt(MAX(0., tube.bands[j].area/M_PI));
        vel = mfrate/(SMALL_S+rho*tube.bands[j].area);
        visc= Viscosity(0,NULL,m,temp,rho,yk,xk,0.);
        ktc = Thermal_Conductivity(0, NULL, m, temp, 0., yk,xk,0.);
        Re = rho*channel_dia*vel/visc;
        op_pres = op_pres_save;

        Nu=3.66;/*You can specify own correlation for Nusselt Number: For example, one formulation is given below*/
#if 1
        if(Re < 3000)
          Nu=3.66;
        else
          {/*use Gnielinksi correlation for turbulent flows*/
            real fac = 0.125/ (SMALL + pow((0.79*log(Re)-1.64), 2)); /*f/8*/
            Nu = 1.2*fac*(Re - 1000)*GVAR_TURB(coeff, ke_prt)/(SMALL + (1. + 12.7 *sqrt(SMALL+fac) * (pow(GVAR_TURB(coeff, ke_prt),0.66) -1)));
            Nu *= pow((temp/tube.bands[j].wall_temp),0.36); /*temperature correction*/
          }
#endif
        wall_hf[j] = Nu*ktc/channel_dia;
      }

}

2.3.35.4. Hooking a Reacting Channel Solver UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_REACTING_CHANNEL_SOLVER is compiled (Compiling UDFs), the name that you specified in the DEFINE macro argument (for example, set_channel_htc) will become visible and selectable in the User-Defined Function Hooks dialog box in Ansys Fluent. See Hooking DEFINE_REACTING_CHANNEL_SOLVER UDFs for details.

2.3.36. DEFINE_RELAX_TO_EQUILIBRIUM

2.3.36.1. Description

When the Relax to Chemical Equilibrium species chemistry solver option is enabled (as described in Enabling Species Transport and Reactions and Choosing the Mixture Material in the Fluent User's Guide for details), you can use DEFINE_RELAX_TO_EQUILIBRIUM to specify the characteristic time at each cell, over which the species react toward their chemical equilibrium state. This UDF will replace Fluent internal calculations of described in The Relaxation to Chemical Equilibrium Model in the Fluent Theory Guide.

2.3.36.2. Usage

DEFINE_RELAX_TO_EQUILIBRIUM(name,c,t,pressure,temp,yi,tau)

Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index.

Thread *t

Pointer to cell thread.

real pressure

Pressure.

real temp

Temperature.

real *yi

Pointer to array containing species mass fractions.

real *tau

Pointer to characteristic time (scalar-valued).

Function returns

void

There are seven arguments to DEFINE_RELAX_TO_EQUILIBRIUM: name, c, t, pressure, temp, yi, and tau. You supply name, the name of the UDF. The variables c, t, pressure, temp, yi, and tau are passed by the Ansys Fluent solver to your UDF and have SI units. The output of the function is the characteristic time for current species with units of [s] (seconds).

DEFINE_RELAX_TO_EQUILIBRIUM is called for all reacting fluid zones whenever the UDF is hooked to Ansys Fluent in the User-Defined Function Hooks dialog box.

2.3.36.3. Example

The following UDF, named relax_tau, sets the value of tau based on the mass fraction of CH4.

/***********************************************************
 Relax to Equilibrium Example UDF
************************************************************/
#include "udf.h"

DEFINE_RELAX_TO_EQUILIBRIUM(relax_tau,c,t,pres,temp,yi,tau)
{
  /*Simple function to set tau based on mass fraction of CH4*/
  if(yi[13] > 1.e-1)
    *tau = 1.e3;
  else
    *tau = 1.e-3;
  
}

2.3.36.4. Hooking a DEFINE_RELAX_TO_EQUILIBRIUM UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_RELAX_TO_EQUILIBRIUM is interpreted or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, relax_tau) will become visible and selectable in the User-Defined Function Hooks dialog box in Ansys Fluent. See Hooking DEFINE_RELAX_TO_EQUILIBRIUM UDFs for details.

2.3.37. DEFINE_SBES_BF

2.3.37.1. Description

You can use DEFINE_SBES_BF to specify a custom blending function for the Stress-Blended Eddy Simulation (SBES) model, which is a hybrid RANS-LES turbulence model available for the following models: baseline (BSL) -, shear-stress transport (SST) -, and transition SST. Using a UDF allows you to define the blending function zonally for cases where the division between RANS and LES is clear from the geometry and the flow physics. See Stress-Blended Eddy Simulation (SBES) in the Theory Guide for details.

2.3.37.2. Usage

DEFINE_SBES_BF (name, c, t)

Argument Type

Description

symbol name

UDF name.

cell_t c

Index that identifies the cell on which the SBES blending function is to be applied.

Thread *t

Pointer to cell thread.

Function returns

real

There are three arguments to DEFINE_SBES_BF: name, c, and t. You supply name, which is the calling name of the UDF. The arguments c and t are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to return the real value of for the SBES blending function to the solver.

2.3.37.3. Example

A zonal approach is demonstrated in the following example. Depending on the x-coordinate, the blending function is 0.0 (LES mode) or 1.0 (RANS mode).

#include "udf.h" 
DEFINE_SBES_BF(user_SBES_bf, c, t)
  {
     real bf_value;
     real xc[ND_ND];
     C_CENTROID(xc,c,t);
     if (xc[0] > 2.0)
       bf_value = 0.0;
     else
       bf_value = 1.0;     
     return bf_value;
  }

2.3.37.4. Hooking an SBES Blending Function UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_SBES_BF is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the DEFINE macro argument (for example, user_SBES_bf) will become visible and selectable in the Viscous Model dialog box in Ansys Fluent. See Hooking DEFINE_SBES_BF UDFs for details.

2.3.38. DEFINE_SCAT_PHASE_FUNC

2.3.38.1. Description

You can use DEFINE_SCAT_PHASE_FUNC to specify the radiation scattering phase function for the discrete ordinates (DO) model. The function computes two values: the fraction of radiation energy scattered from direction to direction , and the forward scattering factor.

2.3.38.2. Usage

DEFINE_SCAT_PHASE_FUNC (name, cosine, f)

Argument Type

Description

symbol name

UDF name.

real cosine

Cosine of the angle between directions and .

real *f

Pointer to the location in memory where the real forward scattering factor is stored.

Function returns

real

There are three arguments to DEFINE_SCAT_PHASE_FUNC: name, cosine, and f. You supply name, the name of the UDF. cosine and f are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to compute the real fraction of radiation energy scattered from direction to direction and return it to the solver. Note that the solver computes and stores a scattering matrix for each material by calling this function for each unique pair of discrete ordinates.

2.3.38.3. Example

In the following example, a number of UDFs are concatenated in a single C source file. These UDFs implement backward and forward scattering phase functions that are cited by Jendoubi et al. [5]. The source code can be interpreted or compiled in Ansys Fluent.

/*******************************************************************
   UDFs that implement backward and forward scattering
   phase functions as cited by Jendoubi et al.
 ********************************************************************/
 
 #include "udf.h"
 
 DEFINE_SCAT_PHASE_FUNC(ScatPhiB2,c,fsf)
 {
    real phi=0;
    *fsf = 0;
    phi = 1.0 - 1.2*c + 0.25*(3*c*c-1);
    return (phi);
 }
 
 DEFINE_SCAT_PHASE_FUNC(ScatPhiB1,c,fsf)
 {
    real phi=0;
    *fsf = 0;
    phi = 1.0 - 0.56524*c + 0.29783*0.5*(3*c*c-1) +
      0.08571*0.5*(5*c*c*c-3*c) + 0.01003/8*(35*c*c*c*c-30*c*c+3) +
      0.00063/8*(63*c*c*c*c*c-70*c*c*c+15*c);
    return (phi);
 }
 
 DEFINE_SCAT_PHASE_FUNC(ScatPhiF3,c,fsf)
 {
    real phi=0;
    *fsf = 0;
    phi = 1.0 + 1.2*c + 0.25*(3*c*c-1);
    return (phi);
 }
 
 DEFINE_SCAT_PHASE_FUNC(ScatPhiF2,c,fsf)
 {
    real phi=0;
    real coeffs[9]={1,2.00917,1.56339,0.67407,0.22215,0.04725,
          0.00671,0.00068,0.00005};
    real P[9];
    int i;
    *fsf = 0;
    P[0] = 1;
    P[1] = c;
    phi = P[0]*coeffs[0] + P[1]*coeffs[1];
    for(i=1;i<7;i++)
    {
       P[i+1] = 1/(i+1.0)*((2*i+1)*c*P[i] - i*P[i-1]);
       phi += coeffs[i+1]*P[i+1];
    }
    return (phi);
 }
 
 DEFINE_SCAT_PHASE_FUNC(ScatIso,c,fsf)
 {
    *fsf=0;
    return (1.0);
 } 

2.3.38.4. Hooking a Scattering Phase UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_SCAT_PHASE_FUNCTION is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name that you specified in the DEFINE macro argument (for example, ScatPhiB) will become visible and selectable in the Create/Edit Materials dialog box in Ansys Fluent. See Hooking DEFINE_SCAT_PHASE_FUNC UDFs for details.

2.3.39. DEFINE_SOLAR_INTENSITY

2.3.39.1. Description

You can use the DEFINE_SOLAR_INTENSITY macro to define direct solar intensity or diffuse solar intensity UDFs for the solar load model. See Modeling Thermal Energy in the User’s Guide for more information on the solar load model.


Important:  Note that solar intensity UDFs are used with the Solar Model, which is available only for the 3D geometries in Ansys Fluent.


2.3.39.2. Usage

DEFINE_SOLAR_INTENSITY (name, sum_x, sun_y, sun_z, S_hour, S_minute)

Argument Type

Description

symbol name

UDF name.

real sun_x

x component of the sun direction vector.

real sun_y

y component of the sun direction vector.

real sun_z

z component of the sun direction vector.

int S_hour

Time in hours.

int S_minute

Time in minutes.

Function returns

real

There are six arguments to DEFINE_SOLAR_INTENSITY: name, sun_x, sun_y, sun_z, S_hour, and S_minute. You provide the name of your user-defined function. The variables sun_x, sun_y, sun_z, S_hour, and S_minute are passed by the Ansys Fluent solver to your UDF. Your UDF will need to compute the direct or diffuse solar irradiation and return the real value (in ) to the solver.

2.3.39.3. Example

The following source code contains two UDFs: sol_direct_intensity computes the direct solar irradiation and returns it to the Ansys Fluent solver, and sol_diffuse_intensity computes the diffuse solar irradiation.

#include "udf.h"
 
 DEFINE_SOLAR_INTENSITY(sol_direct_intensity,sun_x,sun_y,sun_z,hour,minute)
 {
    real intensity;
    intensity = 1019;
    printf("solar-time=%d intensity=%e\n", minute, intensity);
    return intensity;
 }
 
 DEFINE_SOLAR_INTENSITY(sol_diffuse_intensity,sun_x,sun_y,sun_z,hour,minute)
 {
    real intensity;
    intensity = 275;
    printf("solar-time=%d intensity-diff=%e\n", minute, intensity);
    return intensity;
 } 

2.3.39.4. Hooking a Solar Intensity UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_SOLAR_INTENSITY is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name that you specified (for example, sol_direct_intensity) in the DEFINE macro argument will become visible and selectable for Direct Solar Irradiation and Diffuse Solar Irradiation in the Radiation Model dialog box in Ansys Fluent. Note that the solar load model must be enabled. See Hooking DEFINE_SOLAR_INTENSITY UDFs for details.

2.3.40. DEFINE_SOLIDIFICATION_PARAMS

2.3.40.1. Description

You can use DEFINE_SOLIDIFICATION_PARAMS to specify user-defined mushy zone parameters and back diffusion parameters. See Modeling Solidification and Melting in the User's Guide for more information on the solidification and melting model.


Important:  The back diffusion parameter is only used if the Back Diffusion option is enabled in the Solidification and Melting dialog box.


2.3.40.2. Usage

DEFINE_SOLIDIFICATION_PARAMS (name, c, t, Amush, Gamma)

Argument Type

Description

symbol name

UDF name.

Int c

Cell Index.

Thread*

Cell thread pointer.

real*Amush

Pointer to real having mushy zone constant.

Real*Gamma

Pointer to real for back diffusion parameter.

Function returns

void

2.3.40.3. Example

The following UDF, named user_soild_params, specifies the mushy zone and uses the Clyne Kurz model for the back diffusion parameter.

#include "udf.h"
 DEFINE_SOLIDIFICATION_PARAMS(user_solid_params, c,t,Amush,Gamma)
 {
   real alpha ;
   real local_solidification_time = 1. ;
   real sec_arm_spacing = 5e-5 ;
   real solid_diff = 1e-10 ; /*solid diffusivity m2/s */
   *Amush = 1e+6 ;
   alpha = 4. * solid_diff*local_solidification_time/SQR(sec_arm_spacing);
   *Gamma = 2.*alpha/(1.+2.*alpha);
 }

2.3.40.4. Hooking a Solidification Parameter UDF in Ansys Fluent

After the UDF has been interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (eg., user_solid_params) will become visible in the Solidification and Melting dialog box in Ansys Fluent. See Hooking DEFINE_SOLIDIFICATION_PARAMS UDFs for details.

2.3.41. DEFINE_SOOT_MASS_RATES

2.3.41.1. Description

You can use DEFINE_SOOT_MASS_RATES to specify a user-defined soot nucleation, surface growth, and oxidation rates for soot mass fraction equation. The UDF is only available if the Moss-Brookes or Moss-Brookes-Hall soot model is enabled.

2.3.41.2. Usage

DEFINE_SOOT_MASS_RATES (name, c, t, Pollut, Pollut_Par, Soot, rates_linear, rates_nonlinear, index)

Argument Type

Description

symbol name

UDF name

cell_t c

Cell index

Thread *t

Pointer to cell thread on which the Soot mass rates is to be applied

Pollut_Cell *Pollut

Pointer to the data structure that contains the common data at each cell

Pollut_Parameter *Pollut_Par

Pointer to the data structure that contains auxiliary data

Soot *soot

Pointer to the data structure that contains data specific to the Soot mode.

real *rates_linear

Array to provide the linear components of soot mass rates

real *rates_nonlinear

Array to provide the nonlinear components of soot mass rates

int index

Integer value which tells whether the udf is called for nucleation, surface growth or oxidation rates

Function returns

void

There are nine arguments to DEFINE_SOOT_MASS_RATES: name, c, t, Pollut, Pollut_Par, Soot, rates_linear, rates_nonlinear, and index. You supply name, the name of the UDF. Variables c, t, Pollut, Pollut_par, Soot, rates_linear, rates_nonlinear, and index are passed by the Ansys Fluent solver to your function. A DEFINE_SOOT_MASS_RATES function does not output a value. The calculated soot nuclei rates will be stored in the arrays rates_linear and rates_nonlinear.

The soot mass rates consist of explicit and implicit parts and can be expressed as follows:

where is an explicit part of any mass rate (such as oxidation and surface growth) that can be a function of any variable(s) other than soot mass fraction and soot nuclei concentration, and is an implicit part of the nuclei rates that represents terms involving soot mass fraction and soot nuclei concentration. The term is stored in the rates_linear array, while the term is stored in the rates_nonlinear array.

The units of soot mass rate are kg/m3/s.

2.3.41.3. Example: Soot Mass Rate

The following compiled UDF, named user_soot_mass_rates, is used to provide the user-defined soot mass rate.

/*******************************************************************************
Following UDF is implementation of Fenimore-Jones soot oxidation model using UDF
*******************************************************************************/

#include "udf.h"
#include "sg_pollut.h"
#define NNORM 1.e+15
#define soot_dens 1800
#define MAXSOOT 0.01


/* user defined soot mass rates to be filled in arrays "rates_linear" and "rates_nonlinear" */
/* User defined soot mass rates have to be in following form:
	 Rate = A*B,
	 Where B is function of soot mass fraction and/or soot nuclie
	 and A is function of any variables other than soot mass fraction and nuclei.
This break is done to ensure that the soot rates can be stored in PDF tables apriori */


/* If any soot rates returned can be written in terms of only linear part (A)
and/or only non-inear part (B), then this can be done in the following manner: */

/*
	 case 1 : Only A is required
		rates_linear[index] = A
		rates_nonlinear[index] = 1.
	 case 2: Only B is required
		rates_linear[index] = 1.
		rates_nonlinear[index] = B
*/

/*
  Return from the UDF are:
	rates_linear[index] = A; Linear part
    rates_nonlinear[index] = B; Nonlinear part
*/

DEFINE_SOOT_MASS_RATES(user_soot_mass_rates,c,t,Pollut,Pollut_Par,Soot,rates_linear,rates_nonlinear,
index)
{
	switch (index)
	{
	case UDF_MASS_NUC: /*index=0 for user defined nucleation rate in soot mass fraction equation */
		break;
	case UDF_MASS_SGS: /*index=1 for user defined surface growth rate in soot mass fraction equation */
		break;
	case UDF_MASS_OXID: /*index=2 for user defined oxidation rate in soot mass fraction equation */
	{
		real term1;
		real oh_conc;
		real temp = Pollut->fluct.temp;
		real rho = POLLUT_GASDEN(Pollut);
		real onethird = 1. / 3.;
		real twothird = 2. / 3.;
		real soot_yi, nuc;
		real o_eq = 0;
		real c_omega= 105.8125, coleff= 0.04, oxid_const=1; 
		oh_conc = get_oheq(Pollut, Soot->oh_mode, o_eq)*1.e-03; /*kmol/m3*/
		term1 = sqrt(temp)*pow(M_PI*NNORM, onethird)*pow(6. / soot_dens, twothird);
		rates_linear[UDF_MASS_OXID] = -c_omega * coleff*oxid_const*oh_conc*rho*term1;
		if (NNULLP(t)) /*This check is must*/
		{
			soot_yi = C_POLLUT(c, t, EQ_SOOT);
			nuc = C_POLLUT(c, t, EQ_NUCLEI);
			rates_nonlinear[UDF_MASS_OXID] = pow(nuc, onethird)*pow(soot_yi, twothird);
		}
	}
	break;
	default:
		Error("Wrong index for user defined soot nucleation terms\n");
		break;
	}
}

2.3.41.4. Hooking a Soot Mass Rate UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_SOOT_MASS_RATES is compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_soot_mass_rates) will become visible and selectable in the User Defined Soot Mass Rates drop-down list of the Soot Model dialog box in Ansys Fluent. See Hooking DEFINE_SOOT_MASS_RATES UDFs for details.

2.3.42. DEFINE_SOOT_MOM_RATES

2.3.42.1. Description

You can use DEFINE_SOOT_MOM_RATES to specify user-defined soot nucleation, surface growth, and oxidation rates for soot moment equations. The UDF is available only for the Method of Moments soot model.

2.3.42.2. Usage

DEFINE_SOOT_MOM_RATES (name, c, t, Nnuc, Rnuc, NCnuc, Nsurf, Rsurf, Dsurf)

Argument Type

Description

symbol name

UDF name

cell_t c

Cell index

Thread *t

Pointer to cell thread on which the Method of Moments (MOM) rates is to be applied

int *Nnuc

Pointer to the number of nucleation reactions

real *Rnuc

Pointer to the nucleation rates for each nucleation reaction

real *NCnuc

Pointer to the number of carbon atoms in each nucleating species

int *Nsurf

Pointer to the number of surface reactions, including growth and oxidation

real *Rsurf

Pointer to the rates for surface growth and oxidation

real *Dsurf

Pointer to the number of carbon atoms added or removed due to surface growth or oxidation of the soot particles

Function returns

void

There are nine arguments to DEFINE_SOOT_MOM_RATES: name, c, t, Nnuc, Rnuc, NCnuc, Nsurf, Rsurf, and Dsurf. You supply name, the name of the UDF. c, t are passed by the Ansys Fluent solver to your function. Your UDF will need to specify variables Nnuc, Rnuc, NCnuc, Nsurf, Rsurf, and Dsurf. Note that for surface growth and oxidation, you need to specify the number of carbon atoms added (for surface growth) or removed (a negative value for oxidation) for each participating species in growth and oxidation. The oxidation is negative surface growth.

A DEFINE_SOOT_MOM_RATES function does not output a value. All calculated rates are stored in the arrays Rnuc and Rsurf.

The default values passed by the Ansys Fluent solver to your UDF are 0 for all the arrays. If you want to specify only user-defined nucleation rates, then you need to adjust only nucleation rates arguments, and surface growths will be modeled using the Ansys Fluent default formulation. Similarly, if you need to specify only surface growth and oxidation rates, then you need to set only the last three arguments. In this case, the nucleation will be modeled using the Ansys Fluent default formulation.

The units of nucleation rates (Rnuc) and surface growth or oxidation rates (Rsurf) are number of particles/m3/s. The source terms for the different moment transport equations will be automatically calculated by Ansys Fluent using the user-specified nucleation and growth rates.

2.3.42.3. Example: Soot MOM Rates

The following compiled UDF, named user_soot_mom_rates, is used to provide the user-defined soot MOM rates. In this example, a single nucleating species C2H2 is used to provide the user specified nucleation rates. For surface growth, HACA-based surface growth is modeled using C2H2 as growth species, and oxidation is modeled using O2 and OH.

#include "udf.h"
#define soot_eps 1e-15

DEFINE_SOOT_MOM_RATES(user_soot_mom_rates,c,t,Nnuc,Rnuc,NCnuc,Nsurf,Rsurf,Dsurf)
{
    Material *sp,*m=mixture_material(t->domain);
    int  ns,ic2h2,io2,ioh,ih,ih2,ih2o;
    double mw[MAX_PDF_SPECIES], rf[MAX_PDF_SPECIES],rr[MAX_PDF_SPECIES];
    double aa,bb,alpha,fac0,fac1;
    double xmolc2h2,xmolo2,xmolh2o,xmolh,xmolh2,xmoloh,act_soot_rad;
    double cell_temp = (double) C_T(c,t);
    double rgas_t = UNIVERSAL_GAS_CONSTANT * cell_temp;
    double mu1 = MAX(soot_eps, C_SOOT_MOM_CLIP(c, t, 1)/MAX(soot_eps, C_SOOT_MOM_CLIP(c, t, 0)));
    double m0  = MAX(soot_eps, C_SOOT_MOM_CLIP(c, t, 0));

    double rho = (double) C_R(c,t);

     mixture_species_loop (m, sp, ns)
         mw[ns] = MATERIAL_PROP(sp, PROP_mwi);
     ic2h2 = mixture_specie_index(m,"c2h2");
     io2   = mixture_specie_index(m,"o2");
     ih2   = mixture_specie_index(m,"h2");
     ih    = mixture_specie_index(m,"h");
     ioh   = mixture_specie_index(m,"oh");
     ih2o  = mixture_specie_index(m,"h2o");

     /*molar concentration of species. kmol/m3*/
     xmolc2h2 = Pdf_Yi(c,t,ic2h2)  * rho/mw[ic2h2]; 
     xmolo2   = Pdf_Yi(c,t,io2)    * rho/mw[io2]  ;
     xmolh2o  = Pdf_Yi(c,t,ih2o)   * rho/mw[ih2o] ;
     xmolh    = Pdf_Yi(c,t,ih)     * rho/mw[ih]   ;
     xmoloh   = Pdf_Yi(c,t,ioh)    * rho/mw[ioh]  ;
     xmolh2   = Pdf_Yi(c,t,ih2)    * rho/mw[ih2]  ;

    /*nucleation sources using a single step nucleation reaction of C2H2*/
     Rnuc[0]   = 54. * exp(-1.746e+8/rgas_t) * xmolc2h2 * AVOGADRO_NUMBER;   /* number/m3-s*/ 
    *Nnuc      = 1;  /*only 1 nucleation reaction. Integer quantity. No unit*/
     NCnuc[0]  = 2;  /*number of carbon atoms in PAH. No unit*/

    /*surface growth and oxidation using HACA */

    /* Parameters for Equation 14-163 of Fluent theory guide */
    aa = 12.65 - 0.00563 * cell_temp;
    bb = -1.38 + 0.00068 * cell_temp;
    alpha = MAX(0.2, MIN(1., tanh(aa / (1.e-6 + log(mu1)) + bb))); /*is unit less*/

    /*Reaction rates of HACA mechanism. Table 14.6 of Fluent Theory Guide*/

    rf[0] = 4.2e+10 * exp(-5.4392e+7 / rgas_t); /*unit is m3/kmol-s*/
    rf[1] = 1.0e+07 * pow(cell_temp, 0.734) * exp(-5.98312e+6 / rgas_t);
    rf[2] = 2.0e+10 ;
    rf[3] = 8.0e+04 * pow(cell_temp, 1.56) * exp(-1.5899e+7 / rgas_t);
    rf[4] = 2.e+09  * exp(-3.138e+7 / rgas_t);
    rf[5] = 1.3e-03 * (1.0 / (alpha * Soot_Mom->soot_site_dens/AVOGADRO_NUMBER)) * 
            sqrt(rgas_t /(2. * M_PI * 17.0));

    rr[0] = 3.9e+09  * exp(-4.6027e+07 / rgas_t);
    rr[1] = 3.68e+05 * pow(cell_temp, 1.139) * exp(-7.15464e+07 / rgas_t);
    rr[2] = 0.;
    rr[3] = 0.;

    /*Equation 14-162 of Fluent Theory Guide */

    fac0 =  MAX(SMALL_S,  rf[0] * xmolh  + rf[1] * xmoloh + rf[5] * xmoloh);
    fac1 =  MAX(SMALL_S, (rr[0] * xmolh2 + rr[1] * xmolh2o + rf[2] * xmolh + rf[3] * xmolc2h2 + 
            rf[4] * xmolo2));
    
    /*Number of active soot particles. Equation 14-163 of Fluent Theory Guide*/
    act_soot_rad = M_PI * Soot_Mom->diam_catom * Soot_Mom->diam_catom * alpha * Soot_Mom->soot_site_dens;
    act_soot_rad *=  fac0 / (fac0 + fac1); 

    /*sources due to C2H2, O2 and OH respectively*/
    *Nsurf =3 ;    /*Number of species in surface growth and oxidation  */
    Dsurf[0] =  2; /*Number of carbon atom addition/removal due to c2h2 =  2  */
    Dsurf[1] = -2; /*Number of carbon atom addition/removal due to o2   = -2. negative means removal */
    Dsurf[2] = -1; /*Number of carbon atom addition/removal due to oh   = -1  */


    /*Surface growth rate due to c2h2*/
    Rsurf[0]  =   rf[3] * act_soot_rad * xmolc2h2 *m0 ; /*unit is number/m3-s*/

    /*Oxidation rate due to o2*/
    Rsurf[1]   =  rf[4] * act_soot_rad * xmolo2 *m0 ;  /*unit is number/m3-s*/

    /*Oxidation rate due to oh*/
    Rsurf[2]   =  rf[5] * (act_soot_rad * fac1 / fac0) * xmoloh *m0 ;  /*unit is number/m3-s*/


}

2.3.42.4. Hooking a Soot MOM Rates UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_SOOT_MOM_RATES is compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_soot_mom_rates) will become visible and selectable in the User Defined Soot MOM Rates drop-down list of the Soot Model dialog box in Ansys Fluent. See Hooking DEFINE_SOOT_MOM_RATES UDFs for details.

2.3.43. DEFINE_SOOT_NUCLEATION_RATES

2.3.43.1. Description

You can use DEFINE_SOOT_NUCLEATION_RATES to specify a user-defined soot nucleation and coagulation rates. The UDF is available only if the Moss-Brookes or the Moss-Brookes-Hall soot model is enabled.

2.3.43.2. Usage

DEFINE_SOOT_NUCLEATION_RATES (name, c, t, Pollut, Pollut_Par, Soot, rates_linear, rates_nonlinear, index)

Argument Type

Description

symbol name

UDF name

cell_t c

Cell index

Thread *t

Pointer to cell thread on which the Soot nucleation rates is to be applied

Pollut_Cell *Pollut

Pointer to the data structure that contains the common data at each cell

Pollut_Parameter *Pollut_Par

Pointer to the data structure that contains auxiliary data

Soot *soot

Pointer to the data structure that contains data specific to the Soot mode.

real *rates_linear

Array to provide the linear components of soot nucleation rates

real *rates_nonlinear

Array to provide the nonlinear components of soot nucleation rates

int index

Integer value which tells whether the udf is called for nucleation or coagulation

Function returns

void

There are nine arguments to DEFINE_SOOT_NUCLEATION_RATES: name, c, t, Pollut, Pollut_Par, Soot, rates_linear, rates_nonlinear, and index. You supply name, the name of the UDF. Variables c, t, Pollut, Pollut_par, Soot, rates_linear, rates_nonlinear, and index are passed by the Ansys Fluent solver to your function. A DEFINE_SOOT_NUCLEATION_RATES function does not output a value. The calculated soot nuclei rates will be stored in the arrays rates_linear and rates_nonlinear.

The soot nucleation rates consist of explicit and implicit parts and can be expressed as follows:

where is an explicit part of the nuclei (nucleation or coagulation) that can be a function of any variable(s) other than soot mass fraction and soot nuclei concentration, and is an implicit part of the nuclei rates that represents terms involving soot mass fraction and soot nuclei concentration. The term is stored in the rates_linear array, while the term is stored in the rates_nonlinear array.

The units of nuclei rate are nuclei/m3/s.

2.3.43.3. Example: Soot Nucleation and Coagulation Rates

The following compiled UDF, named user_soot_nuc_rates, is used to provide the user-defined soot nucleation rate for cases where species-list is selected from the Precursor from dropdown list in the Soot Model dialog box.

/*********************************************************************
Following UDF is implementation of nucleation and coagulation terms of soot
nuclei transport equation for Moss Brookes soot Model using UDF
*********************************************************************/

#include "udf.h"
#include "sg_pollut.h"
#define NNORM 1.e+15
#define soot_dens 1800
#define MAXSOOT 0.01

/*User defined Soot nucleation rates have to be in following form:
 Rate = A*B, Where B is function of soot mass fraction and/or soot nuclie
 and A is function of any variables other than soot mass fraction and nuclei.
This break is done to ensure that the soot rates can be stored in PDF tables apriori.*/

/*
  Return from the UDF are:
	rates_linear[index] = A; Linear part
	rates_nonlinear[index] = B; Nonlinear part
*/

/*If any soot rates returned can be written in terms of only linear part (A)
and/or only nonlinear part (B), then this can be done in the following manner:*/

/*
   case 1 : Only A is required
	  rates_linear[index] = A
	  rates_nonlinear[index] = 1.
   case 2: Only B is required
	  rates_linear[index] = 1.
	  rates_nonlinear[index] = B
*/

DEFINE_SOOT_NUCLEATION_RATES(user_soot_nuc_rates,c,t,Pollut,Pollut_Par,Soot,rates_linear,
rates_nonlinear,index)
{
	real T = Pollut->fluct.temp;
	int ns;
	real xmolprec;
	double avgn = 6.022137e+26, nnorm = 1.e+15;

	switch (index)
	{
	case UDF_NUC: /* index = 0 for user defined nucleation term in nuclei equation*/
	{
		xmolprec = 0.;
		for (ns = PRECSP; ns < PRECSP + Soot->nprec; ns++)
		{
			xmolprec += MOLECON(Pollut, ns)*1.e-03;
		}
	   rates_linear[UDF_NUC]=(avgn/ nnorm)*Soot->calpha*xmolprec*exp(MAX(-70, -Soot->talpha / T));
	   rates_nonlinear[UDF_NUC] = 1.;
	}
	break;
	case UDF_COAG: /* index = 1 for user defined coagulation term in nuclei equation*/
	{
		real pwr4 = 1. / 6., pwr3 = 5. / 6.;
		real term1, term2;
		real rho = POLLUT_GASDEN(Pollut);
		real spsoot = MIN(MAX(Pollut->fluct.yi[IDX(SOOT)], 0.), MAXSOOT);
		real spnuclei = MAX(Pollut->fluct.yi[IDX(NUCLEI)], 0.);
		term1 = pow(24.*Pollut_Par->uni_R*1000.*T / (Soot->soot_mdens*avgn), 0.5);
		term2 = pow(6. / (M_PI*Soot->soot_mdens), pwr4);
		rates_linear[UDF_COAG] = -rho * rho*Soot->cbeta*term1*term2*pow(nnorm, pwr3);
		rates_nonlinear[UDF_COAG] = pow(spsoot, pwr4)*pow(spnuclei, (pwr3 + 1.));
	}
	break;
	default:
		Error("Wrong index for user defined soot nucleation terms\n");
		break;
	}
}

2.3.43.4. Hooking a Nucleation and Coagulation Rates UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_SOOT_NUCLEATION_RATES is compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_soot_nuc_rates) will become visible and selectable in the User Defined Soot Nuclei Rates drop-down list of the Soot Model dialog box in Ansys Fluent. See Hooking DEFINE_SOOT_NUCLEATION_RATES UDFs for details.

2.3.44. DEFINE_SOOT_OXIDATION_RATE

2.3.44.1. Description

You can use DEFINE_SOOT_OXIDATION_RATE to specify a user-defined soot oxidation rate. The UDF is available only if the Moss-Brookes or the Moss-Brookes-Hall soot model is enabled.

2.3.44.2. Usage

DEFINE_SOOT_OXIDATION_RATE (name, c, t, Pollut, Pollut_Par, Soot, soot_oxi_rate)

Argument Type

Description

symbol name

UDF name

cell_t c

Cell index

Thread *t

Pointer to cell thread on which the Soot oxidation rate is to be applied

Pollut_Cell *Pollut

Pointer to the data structure that contains the common data at each cell

Pollut_Parameter *Pollut_Par

Pointer to the data structure that contains auxiliary data

Soot *soot

Pointer to the data structure that contains data specific to the Soot model

Real soot_oxi_rate

Array to return the soot oxidation rates

Function returns

void

There are seven arguments to DEFINE_SOOT_OXIDATION_RATE: name, c, t, Pollut, Pollut_Par, Soot, and soot_oxi_rate. You supply name, the name of the UDF. Variables c, t, Pollut, Pollut_par, Soot, and soot_oxi_rate are passed by the Ansys Fluent solver to your function. A DEFINE_SOOT_OXIDATION_RATE function does not output a value. The calculated soot oxidation rates will be stored in the array soot_oxi_rate.

The soot oxidation rate consists of explicit and implicit parts and can be expressed as follows:

where A is an explicit part of the oxidation rate that can be a function of any variable(s) other than soot mass fraction and soot nuclei concentration, and B is an implicit part of the oxidation rate that represents terms involving soot mass fraction and soot nuclei concentration. The term A is stored as the first element of the soot_oxi_rate array, while the term B is stored as the second element of the array.

The units of oxidation rate are kg/m3/s

2.3.44.3. Example: Soot Oxidation Rate

The following compiled UDF, named user_soot_oxid_rate, is used to provide the user-defined oxidation rate.

/*********************************************************************
User defined Soot oxidation Rate: Fenimore-Jones soot oxidation model
*********************************************************************/

#include "udf.h"
#include "sg_pollut.h"
#define NNORM 1.e+15
#define soot_dens 1800
#define c_omega 105.8125 /*kg-m-kmol-1 K^-1./2. S^-1, oxidation model constant*/ 
#define coleff 0.04 /*collisional*/
#define oxid_const 0.015 /*oxidation rate scaling parameter*/

/*user defined soot oxidation rates to be filled in array "soot_oxi_rate"*/
/*User defined Soot oxidation rate has to be in following form:
   Rate = A*B, Where B is function of soot mass fraction and/or soot nuclie and A is function of any
   variables other than soot mass fraction and nuclei. This break is done to apriori store the soot
   formation rates in PDF tables*/

/* Store the computed soot oxidation rate inside the UDF as: */
/*  soot_oxi_rate[0] = A; */ /*Linear part*/
/*  soot_oxi_rate[1] = B; */ /*Nonlinear part*/


/*Following UDF is implementation of Fenimore-Jones soot oxidation model using UDF*/

DEFINE_SOOT_OXIDATION_RATE(user_soot_oxid_rate,c,t,Pollut,Pollut_Par,Soot,soot_oxi_rate)
{
    real term1;
    real oh_conc;
    real temp = Pollut->fluct.temp;
    real rho =  POLLUT_GASDEN(Pollut);
    real onethird = 1./3.;
    real twothird = 2./3. ;
    real soot_yi,nuc;
    real o_eq=0.;

    oh_conc = get_oheq(Pollut, Soot->oh_mode, o_eq)*1.e-03; /*kmol/m3*/
    term1 = sqrt(temp)*pow(M_PI*NNORM, onethird)*pow(6./soot_dens, twothird);
    
    soot_oxi_rate[0] = c_omega*coleff*oxid_const*oh_conc*rho*term1;

    if(NNULLP(t)) /*This check is must*/
      {
        soot_yi = C_POLLUT(c,t,EQ_SOOT);
        nuc = C_POLLUT(c,t,EQ_NUCLEI);
        soot_oxi_rate[1] = pow(nuc, onethird)*pow(soot_yi,twothird);
      }

}

2.3.44.4. Hooking a Soot Oxidation Rate UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_SOOT_OXIDATION_RATE is compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_soot_oxid_rate) will become visible and selectable in the User-Defined Oxidation Rate drop-down list of the Soot Model dialog box in Ansys Fluent. See Hooking DEFINE_SOOT_OXIDATION_RATE UDFs for details.

2.3.45. DEFINE_SOOT_PRECURSOR

2.3.45.1. Description

You can use DEFINE_SOOT_PRECURSOR to specify a user-defined concentration of soot precursor. During execution, the DEFINE_SOOT_PRECURSOR is called at the time of calculating the average soot source terms. The UDF is only available if the Moss Brookes soot model is enabled.

2.3.45.1.1. Usage

DEFINE_SOOT_PRECURSOR (name, c, t, Pollut, Pollut_Par, Soot)

Argument Type

Description

symbol name

UDF name

cell_t c

Cell index

Thread *t

Pointer to cell thread on which the Soot precursor is to be applied

Pollut_Cell *Pollut

Pointer to the data structure that contains the common data at each cell

Pollut_Parameter *Pollut_Par

Pointer to the data structure that contains auxiliary data

Soot *soot

Pointer to the data structure that contains data specific to the Soot model

Function returns

real

There are six arguments to DEFINE_SOOT_PRECURSOR: name, c, t, Pollut, Pollut_Par, and Soot. You supply name, the name of the UDF. Variables c, t, Pollut, Pollut_par, and Soot are passed by the Ansys Fluent solver to your function. A DEFINE_SOOT_PRECURSOR function returns the soot precursor concentration in kg-mol/m3.

2.3.45.1.2. Example: Soot Precursor

The following compiled UDF, named user_soot_prec is used to provide the user-defined soot precursor concentration in kg-mol/m3.

/*******************************************************
User Defined Soot precursor concentration: 
Return molar concentration of soot precursor in kg-mol/m3
C2H2 is used as precursor
*******************************************************/

DEFINE_SOOT_PRECURSOR(user_soot_prec,Pollut,Pollut_Par,Soot)
{
  real xmol_prec;
  real rho =  POLLUT_GASDEN(Pollut);
  real c2h2_mol_wt =26;

  xmol_prec = rho*MAX(0., Pollut->fluct.yi[C2H2])/c2h2_mol_wt;
  return xmol_prec; 
}
2.3.45.1.3. Hooking a SOOT_PRECURSOR UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_SOOT_PRECURSOR is compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_soot_precursor) will become visible and selectable in the Species Definition group box of the Soot Model dialog box in Ansys Fluent. See Hooking DEFINE_SOOT_PRECURSOR UDFs for details.

2.3.46. DEFINE_SOURCE

2.3.46.1. Description

You can use DEFINE_SOURCE to specify custom source terms for the different types of solved transport equations in Ansys Fluent (except the discrete ordinates radiation model) including:

  • mass

  • momentum

  • ,

  • energy (also for solid zones)

  • species mass fractions

  • P1 radiation model

  • user-defined scalar (UDS) transport

  • granular temperature (Eulerian, Mixture multiphase models)

2.3.46.2. Usage

DEFINE_SOURCE (name, c, t, dS, eqn)

Argument Type

Description

symbol name

UDF name.

cell_t c

Index that identifies cell on which the source term is to be applied.

Thread *t

Pointer to cell thread.

real dS[]

Array that contains the derivative of the source term with respect to the dependent variable of the transport equation.

int eqn

Equation number.

Function returns

real

There are five arguments to DEFINE_SOURCE: name, c, t, dS, and eqn. You supply name, the name of the UDF. c, t, dS, and eqn are variables that are passed by the Ansys Fluent solver to your UDF. Note that the source term derivatives may be used to linearize the source term if they enhance the stability of the solver. To illustrate this, note that the source term can be expressed, in general, as Equation 2–11, where is the dependent variable, is the explicit part of the source term, and is the implicit part.

(2–11)

Specifying a value for in Equation 2–11 can enhance the stability of the solution and help convergence rates due to the increase in diagonal terms on the solution matrix. Ansys Fluent automatically determines if the value of that is given by you will aid stability. If it does, then Ansys Fluent will define as , and as . If not, the source term is handled explicitly.

Your UDF will need to compute the real source term only for a single cell and return the value to the solver, but you have the choice of setting the implicit term dS[eqn] to , or forcing the explicit solution of the source term by setting it equal to .

Note that like property UDFs, source term UDFs (defined using DEFINE_SOURCE) are called by Ansys Fluent from within a loop on cell threads. The solver passes to the DEFINE_SOURCE term UDF all the necessary variables to define a custom source term, since source terms are solved on a cell basis. Consequently, your UDF will not need to loop over cells in the thread since Ansys Fluent is already doing it.

The units on all source terms are of the form generation-rate/volume. For example, a source term for the continuity equation would have units of kg/m3-s.

2.3.46.3. Example 1 - Source Term Addition

The following UDF, named xmom_source, is used to add source terms in Ansys Fluent. The source code can be interpreted or compiled. The function generates an -momentum source term that varies with position as

Suppose

where

Then

The source term returned is

and the derivative of the source term with respect to (true for both positive and negative values of ) is

/*******************************************************************
    UDF for specifying an x-momentum source term in a spatially 
   dependent porous media
 *******************************************************************/
 
 #include "udf.h"
 
 #define C2 100.0
 
 DEFINE_SOURCE(xmom_source,c,t,dS,eqn)
 {
    real x[ND_ND];
    real con, source;
    C_CENTROID(x,c,t);
    con = C2*0.5*C_R(c,t)*x[1];
    source = -con*fabs(C_U(c, t))*C_U(c,t);
    dS[eqn] = -2.*con*fabs(C_U(c,t));
    return source;
 } 

2.3.46.4. Example 2 - Degassing Boundary Condition

The following source code contains UDFs that define a degassing boundary condition for flow in a bubble column reactor (BCR) or a similar device. Typically, in a BCR, gas is sparged at the bottom of a vertical cylinder filled with water. The top surface can be modeled as a free-surface where the water level rises in proportion to the volume fraction of the incoming gas. However, to avoid modeling the extra head space at the top, sometimes the free surface is replaced by a degassing boundary where the top surface of the liquid behaves as a symmetry plane, and the gas is removed as a sink. The compressibility of gas and compressibility of liquid are ignored in this case.

Using this approach, the UDFs define the degassing source as the mass sink for the gas (secondary) phase and the momentum sources associated with the mass sources in X, Y, and Z directions for both the liquid (primary) and gas (secondary) phases. The bottom surface is defined as a standard velocity inlet for the gas phase. The UDF is applied to the top surface, where bubbles leave the liquid. The sink removes all gas phase mass in the cells next to the degassing boundary during one-time step.

/*******************************************************************
   This UDF is an implementation of the degassing boundary condition
 *******************************************************************/
 
 #include "udf.h"
 #include "sg.h"
 #include "sg_mphase.h"
 #include "flow.h"
 #include "mem.h"
 #include "metric.h"
 
 DEFINE_SOURCE(degassing_source, cell, thread, dS, eqn)
 {
    real source;
    Thread *tm = THREAD_SUPER_THREAD(thread);
    source = -C_R(cell,thread)*C_VOF(cell,thread)/CURRENT_TIMESTEP ;
    C_UDMI(cell,tm,0) = source;
    dS[eqn] = -C_R(cell,thread)/CURRENT_TIMESTEP;
    return source;
 }
 
 DEFINE_SOURCE(x_prim_recoil, cell, tp, dS, eqn)
 {
    real source;
    Thread *tm = THREAD_SUPER_THREAD(tp);
    Thread *ts;
    ts = THREAD_SUB_THREAD(tm,1);
    source = -C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP*C_U(cell,tp);  
   dS[eqn] =-C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP;
    return source;
 }
  
 DEFINE_SOURCE(x_sec_recoil, cell, ts, dS, eqn)
 {
    real source;
    Thread *tm = THREAD_SUPER_THREAD(ts);
    source = -C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP*C_U(cell,ts);
    dS[eqn] = -C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP;
    return source;
 }
 
 DEFINE_SOURCE(y_prim_recoil, cell, tp, dS, eqn)
 {
    real source;
    Thread *tm = THREAD_SUPER_THREAD(tp);
    Thread *ts;
    ts = THREAD_SUB_THREAD(tm,1);
    source = -C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP*C_V(cell,tp);
    dS[eqn] =-C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP;
    return source;
 }
 
  DEFINE_SOURCE(y_sec_recoil, cell, ts, dS, eqn)
 {
    real source;  Thread *tm = THREAD_SUPER_THREAD(ts);
    source = -C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP*C_V(cell,ts);
   dS[eqn] = -C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP;
    return source;
 }
 
 DEFINE_SOURCE(z_prim_recoil, cell, tp, dS, eqn)
 {
    real source;
    Thread *tm = THREAD_SUPER_THREAD(tp);
    Thread *ts;
    ts = THREAD_SUB_THREAD(tm,1);
    source = -C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP*C_W(cell,tp);
    dS[eqn] =-C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP;
    return source;
 }
 
  DEFINE_SOURCE(z_sec_recoil, cell, ts, dS, eqn)
 {
    real source;
    Thread *tm = THREAD_SUPER_THREAD(ts);
    source = -C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP*C_W(cell,ts);
   dS[eqn] = -C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP;
    return source;
 } 

2.3.46.5. Hooking a Source UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_SOURCE is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, xmom_source) will become visible and selectable in the Fluid or Solid cell zone condition dialog box in Ansys Fluent. See Hooking DEFINE_SOURCE UDFs for details.

2.3.47. DEFINE_SPARK_GEOM (R14.5 spark model)

The DEFINE_SPARK_GEOM is available with the R14.5 spark model only. See the R14.5 Ansys Fluent User's Guide for information about using the R14.5 spark model in Ansys Fluent.

2.3.47.1. Description

You can use DEFINE_SPARK_GEOM to define custom spark kernel volume shapes.

2.3.47.2. Usage

DEFINE_SPARK_GEOM (name,c,t)

Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index.

Thread *t

Pointer to cell thread on which the source term is to be applied.

Function returns

integer inside

There are three arguments to DEFINE_SPARK_GEOM: name, c, and t. You will supply name, the name of the UDF, and the variables c and t are passed by the Ansys Fluent solver into the UDF. The UDF will need to return an integer value that indicates whether or not the cell defined by the arguments c and t is within the spark kernel volume. A returned value of zero indicates that the cell is not within the spark kernel. All other values indicate that the cell is within the kernel.

2.3.47.3. Example

This example UDF is used to define three different custom shape types: a sphere, a cylinder, or a frustum.

#include "udf.h"
#include "sg_spark.h"

 typedef enum {
    SPHERE,
    CYLINDER,
    FRUSTUM
 } Spark_Geom;
 
 DEFINE_SPARK_GEOM(spark_geom,c,t)
 {
    int inside=0;
    Spark_Geom spark_geom=FRUSTUM; /* set to chosen shape */
    Spark_Par *spark_par = getSparkPar();
    int snum=0; /* spark index */
    switch(spark_geom) {
      case SPHERE:
        {
           real rad,rad2;
           real NV_VEC(xc);
           real NV_VEC(xdiff);
           real time = CURRENT_TIME;
           real start_time = spark_par[snum].start_time;
           real duration = spark_par[snum].duration;

           /* user sphere data */
           real r0 = 0.001;    /* initial radius */
           real rf = 0.003;    /* final radius */
           real xcen[3]={0.0,0.0,0.0}; /* sphere centre */
           real dr = ABS(rf-r0);
           C_CENTROID(xc,c,t);
           NV_VV(xdiff, =, xc,-,xcen);   /* user growth rate */
           rad = r0 + (time-start_time)*dr/duration;
           rad2 = rad*rad;

           /* flag cell if inside sphere */
           if (NV_DOT(xdiff,xdiff) < rad2)
             inside = 1;
             break;
        }
      case CYLINDER:
        {
           real rad, rad2;
           real am, NV_VEC(xa);
           real cm, NV_VEC(xc);
           real time = CURRENT_TIME;
           real start_time = spark_par[snum].start_time;
           real duration = spark_par[snum].duration;

           /* user cylinder data */
           real r0 = 0.001;    /* initial radius */
           real rf = 0.003;    /* final radius */
           real x0[3]={0.0,0.0,0.0}; /* axis start */
           real x1[3]={-0.003,0.0,0.0}; /* axis end */
           real dr = ABS(rf-r0);

           /* user growth rate */
           rad = r0 + (time-start_time)*dr/duration;
           rad2 = rad*rad;
         
           /* compute normalized axis vector */
           NV_VV(xa,=,x1,-,x0);
           am = NV_MAG(xa);
           NV_S(xa,/=,am);
           C_CENTROID(xc,c,t);
           NV_V (xc, -=, x0);
           cm = NV_DOT(xc,xa);

           /* flag cell if inside cylinder */
           if (cm >= 0 && cm <= am)
             {
               NV_VS(xc,-=,xa,*,cm);
               if (NV_MAG2(xc) <= rad2)
                 inside = 1;
             }
         break;
        }
      case FRUSTUM:
        {
           real rad, rad0, rad1, rad2;
           real am, NV_VEC(xa);
           real cm, NV_VEC(xc);
           real time = CURRENT_TIME;
           real start_time = spark_par[snum].start_time;
           real duration = spark_par[snum].duration;

           /* user frustum data */
           real r00 = 0.001, r01 = 0.002;  /* initial radii */
           real rf0 = 0.003, rf1 = 0.004;  /* final radii */
           real x0[3]={0.0,0.0,0.0};    /* axis start */
           real x1[3]={-0.003,-0.003,0.0};  /* axis end */
           real dr0 = ABS(rf0-r00);
           real dr1 = ABS(rf1-r01);

           /* user growth rate */
           rad0 = r00 + (time-start_time)*dr0/duration;
           rad1 = r01 + (time-start_time)*dr1/duration;

          /* compute normalized axis vector */
           NV_VV(xa,=,x1,-,x0);
           am = NV_MAG(xa);
           NV_S(xa,/=,am);
           C_CENTROID(xc,c,t);
           NV_V (xc, -=, x0);
           cm = NV_DOT(xc,xa);
           rad = rad0 + cm/am * (rad1-rad0);
           rad2 = rad*rad;

           /* flag cell if inside frustum */
           if (cm >= 0 && cm <= am)
             {
               NV_VS(xc,-=,xa,*,cm);
               if (NV_MAG2(xc) <= rad2)
                  inside = 1;
             }
           break;
         }
         default:
        break;
        }
    return inside;
 }

2.3.47.4. Hooking a Spark Geometry UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_SPARK_GEOM is compiled (Compiling UDFs), the name that you specified in the DEFINE macro argument will become visible and selectable in the Set Spark Ignition dialog box in Ansys Fluent. See Hooking DEFINE_SPARK_GEOM UDFs for details.

2.3.48. DEFINE_SPECIFIC_HEAT

2.3.48.1. Description

The DEFINE_SPECIFIC_HEAT macro can be used to define temperature-dependent functions for specific heat and sensible enthalpy for fluid, solid and mixture materials (this does not include DPM particles). These functions must be defined in a consistent manner, that is, the enthalpy function should be the temperature integral of the specific heat function.


Important:  This option is not available with the premixed, non-premixed and partially premixed models, and should be used as a compiled UDF only.


2.3.48.2. Usage

DEFINE_SPECIFIC_HEAT (name,T,Tref,h,yi)

Argument Type

Description

symbol name

UDF name

real T

Temperature for the calculation of the specific heat and enthalpy

real Tref

Reference temperature for the enthalpy calculation

real *h

Pointer to real

real *yi

Pointer to array of mass fractions of gas phase species

Function returns

real

There are five arguments to DEFINE_SPECIFIC_HEAT: name, T, Tref, h, and yi. You supply name, the name of the UDF. T and Tref are real variables that are passed by the Ansys Fluent solver to the UDF, and h is a pointer to real.

The UDF must return the real value of the specific heat, and set the sensible enthalpy to the value referenced by the real pointer h. Note that the entropy is not computed in the UDF, instead Ansys Fluent sets the entropy as , where is computed by the UDF at , and is the mean logarithmic average of T and Tref.

2.3.48.3. Example

/**********************************************************************
   UDF that computes specific heat and sets the sensible enthalpy
   to the referenced value
 ***********************************************************************/
 
 #include "udf.h"
 DEFINE_SPECIFIC_HEAT(my_user_cp, T, Tref, h, yi)
 {
   real cp=2000.;
   *h = cp*(T-Tref);
   return cp;
 }

2.3.48.4. Hooking a Specific Heat UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_SPECIFIC_HEAT is compiled (Compiling UDFs), the name that you specified in the DEFINE macro argument (for example, my_user_cp) will become visible and selectable in the Create/Edit Materials dialog box in Ansys Fluent. See Hooking DEFINE_SPECIFIC_HEAT UDFs for details.

2.3.49. DEFINE_SR_RATE

2.3.49.1. Description

You can use DEFINE_SR_RATE to specify a custom surface reaction rate. A custom surface reaction rate function defined using this macro will overwrite the default reaction rate (for example, finite-rate) that is specified in the Create/Edit Materials dialog box. A DEFINE_SR_RATE UDF is compatible with the laminar finite-rate model. It is not available with the stiff chemistry solver.

An example of a reaction rate that depends upon gas species mass fractions is provided below. Also provided is a reaction rate UDF that takes into account site species.


Important:  Note that the three types of surface reaction species are internally numbered with an (integer) index i in order


2.3.49.2. Usage

DEFINE_SR_RATE (name,f,t,r,my,yi,rr)

Argument Type

Description

symbol name

UDF name.

face_t f

Index that identifies a face within the given thread (or cell in the case of surface reaction in a porous zone).

Thread *t

Pointer to face thread on which the surface rate reaction is to be applied.

Reaction *r

Pointer to data structure for the reaction.

double *mw

Pointer to array of species molecular weights.

double *yi

Pointer to array of mass fractions of gas species at the surface and the coverage of site species (or site fractions).

double *rr

Pointer to reaction rate.

Function returns

void

There are seven arguments to DEFINE_SR_RATE: name, f, t, r, my, yi, and rr. You supply name, the name of the UDF. After your UDF is compiled and linked, the name that you have chosen for your function will become visible and selectable in the graphical user interface in Ansys Fluent. f, t, r, my, and yi are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to set the reaction rate to the value referenced by the real pointer rr as shown in the examples below.

2.3.49.3. Example 1 - Surface Reaction Rate Using Species Mass Fractions

The following compiled UDF, named arrhenius, defines a custom surface reaction rate using species mass fractions in Ansys Fluent.

/*******************************************************************
 Custom surface reaction rate UDF
 ********************************************************************/
 #include "udf.h"
 /* ARRHENIUS CONSTANTS */
 #define PRE_EXP 1e+15
 #define ACTIVE 1e+08
 #define BETA 0.0
 
 real arrhenius_rate(real temp)
 {
    return
    PRE_EXP*pow(temp,BETA)*exp(-ACTIVE/(UNIVERSAL_GAS_CONSTANT*temp));
 }
 
 /* Species numbers. Must match order in Ansys Fluent dialog box */
 #define HF 0
 #define WF6 1
 #define H2O 2
 #define NUM_SPECS 3
 
 /* Reaction Exponents */
 #define HF_EXP 2.0
 #define WF6_EXP 0.0
 #define H2O_EXP 0.0
 
 #define MW_H2 2.0
 #define STOIC_H2 3.0
 
 /* Reaction Rate Routine */
 
 real reaction_rate(cell_t c, Thread *cthread,real mw[],real yi[])
 
 /* Note that all arguments in the reaction_rate function call in your .c 
 source file MUST be on the same line or a compilation error will occur */ 
 {
    real concenHF = C_R(c,cthread)*yi[HF]/mw[HF];
    return arrhenius_rate(C_T(c,cthread))*pow(concenHF,HF_EXP);
 }
 
 DEFINE_SR_RATE(arrhenius,f,fthread,r,mw,yi,rr)
 {
   *rr =
   reaction_rate(F_C0(f,fthread),THREAD_T0(fthread),mw,yi);
 } 

2.3.49.4. Example 2 - Surface Reaction Rate Using Site Species

The following compiled UDF, named my_rate, defines a custom surface reaction rate that takes into account site species.

/*******************************************************************
 Custom surface reaction rate UDF
 ********************************************************************/
 #include "udf.h"
 DEFINE_SR_RATE(my_rate,f,t,r,mw,yi,rr)
 {
   Thread *t0=t->t0;
   cell_t c0=F_C0(f,t);
   double sih4 = yi[0];  /* mass fraction of sih4 at the wall */
   double si2h6 = yi[1];
   double sih2 = yi[2];
   double h2 = yi[3];
   double ar = yi[4];  /* mass fraction of ar at the wall */
   double rho_w = 1.0, site_rho = 1.0e-6, T_w = 300.0;
   double si_s = yi[6];  /* site fraction of si_s*/
   double sih_s = yi[7];  /* site fraction of sih_s*/
   T_w = F_T(f,t);
   rho_w = C_R(c0,t0)*C_T(c0,t0)/T_w;
   sih4 *= rho_w/mw[0]; /* converting of mass fractions to molar concentrations */
   si2h6 *= rho_w/mw[1];
   sih2 *= rho_w/mw[2];
   h2 *= rho_w/mw[3];
   ar *= rho_w/mw[4];
   si_s  *= site_rho;  /* converting of site fractions to site concentrations */
   sih_s *= site_rho;
   if (STREQ(r->name, "reaction-1"))
     *rr = 100.0*sih4; 
   else if (STREQ(r->name, "reaction-2"))
     *rr = 0.1*sih_s;
   else if (STREQ(r->name, "reaction-3"))
     *rr = 100*si2h6*si_s;
   else if (STREQ(r->name, "reaction-4"))
     *rr = 1.0e10*sih2;
  } 

2.3.49.5. Hooking a Surface Reaction Rate UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_SR_RATE is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, my_rate) will become visible and selectable in the User-Defined Function Hooks dialog box in Ansys Fluent. See Hooking DEFINE_SR_RATE UDFs for details.

2.3.50. DEFINE_THICKENED_FLAME_MODEL

2.3.50.1. Description

You can use DEFINE_THICKENED_FLAME_MODEL to specify the thickening factor , efficiency factor, , and dynamic thickening parameter for the thickened flame model (TFM). This UDF can be hooked only if the thickened flame model is enabled in the Species Model dialog box.

2.3.50.2. Usage

DEFINE_THICKENED_FLAME_MODEL (name,c,t,F,E,Omega)

Argument Type

Description

symbol name

UDF name.

Thread *c

Index that identifies a cell within the given thread.

Thread *t

Pointer to cell thread on which the TFM parameters (F, E, Omega) are to be applied.

F

Pointer to array of the thickening factor.

E

Pointer to array of the efficiency factor.

Omega

Pointer to array of the dynamic thickening factor.

Function returns

void

There are six arguments to DEFINE_THICKENED_FLAME_MODEL: name, c, t, F, E, and Omega. You supply name, the name of the UDF. After your UDF is compiled, the name that you have chosen for your function will become visible and selectable in the graphical user interface in Ansys Fluent. c, t, F, E, and Omega are variables that are passed by the Ansys Fluent solver to your UDF.


Note:  The default values of F, E, and Omega are calculated before the UDF is called, therefore none of these values necessarily need to be set in the UDF.


2.3.50.3. Example - Thickened Flame Model

In the simple example below, the DEFINE_THICKENED_FLAME_MODEL returns a fixed thickening factor , with a unity efficiency factor (so that the effect of thickening on the turbulent flame speed is neglected), and a unity dynamic thickening parameter (so that thickening is applied everywhere in the domain, including far from the flame front).

 #include "udf.h"
 
DEFINE_THICKENED_FLAME_MODEL(user_TFM, c, t, F, E, Omega)
{
   *F = 10.;

   *E = 1.;

   *Omega = 1.;
} 

2.3.50.4. Hooking a Thickened Flame Model UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_THICKENED_FLAME_MODEL is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the DEFINE macro argument (for example, user_TFM) will become visible and selectable in the User-Defined Function Hooks dialog box in Ansys Fluent. See Hooking DEFINE_THICKENED_FLAME_MODEL UDFs for details.

2.3.51. DEFINE_TRANS UDFs

The following DEFINE macros can be used to specify transition correlations for the Transition SST model in Ansys Fluent.

2.3.51.1. DEFINE_TRANS_ALG_REC_COR

2.3.51.1.1. Description

You can use DEFINE_TRANS_ALG_REC_COR to specify your own formulation of the critical Reynolds number correlation for the Algebraic Transition Model.

2.3.51.1.2. Usage

DEFINE_TRANS_ALG_REC_COR (name, c, t)

Argument Type

Description

symbol name

UDF name.

cell_t c

Index that identifies the cell on which the critical Reynolds number correlation is to be applied.

Thread *t

Pointer to cell thread.

Function returns

real

There are three arguments to these functions: name, c, and t. You specify the name of the UDF. c and t are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to return the real value for the critical Reynolds number correlation to the solver.

2.3.51.1.3. Example

In the following example, a zonal approach is demonstrated. Depending on the x-coordinate, the critical Reynolds number correlation is set to 10.0 or the built-in version is used.

#include "udf.h"
DEFINE_TRANS_ALG_REC_COR(user_trans_alg_rec_cor, c, t)
 {
    real rec_value;
    real xc[ND_ND];
    C_CENTROID(xc,c,t);
    if (xc[0]>2.0)
      rec_value = Get_Trans_Alg_Rec_Cor (c, t,
        C_R(c,t), C_MU_L(c,t), C_WALL_DIST(c,t),
        C_O(c,t), Strainrate_Mag(c,t), Rotationrate_Mag(c,t));
    else
      rec_value = 10.0;
    return rec_value;
 }
2.3.51.1.4. Hooking a UDF for Critical Reynolds Number to Ansys Fluent

After the UDF that you have defined using DEFINE_TRANS_ALG_REC_COR is interpreted or compiled, the name of the argument that you supplied as the DEFINE macro argument (for example, user_trans_alg_rec_cor) will become visible and selectable in the Viscous Model dialog box in the drop-down menu of the model coefficient.

2.3.51.2. DEFINE_TRANS_FLENGTH

2.3.51.3. Description

You can use DEFINE_TRANS_FLENGTH to specify the transition length for the Transition SST turbulence model.

2.3.51.4. Usage

DEFINE_TRANS_FLENGTH (name, c, t)

Argument Type

Description

symbol name

UDF name.

cell_t c

Index of cell on which the transition length function is to be applied.

Thread *t

Pointer to cell thread.

Function returns

real

There are three arguments to DEFINE_TRANS_FLENGTH: name, c, and t. You supply name, the name of the UDF. c and t are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to return the real value for the transition length function to the solver.

2.3.51.5. Example

An example of a TRANS_FLENGTH UDF is provided at the end of this section.

2.3.51.6. Hooking a Transition Correlation UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_TRANS_FLENGTH is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the DEFINE macro argument (for example, user_Flength) will become visible and selectable in the Viscous Model dialog box in Ansys Fluent. See Hooking DEFINE_TRANS UDFs for details.

2.3.51.7. DEFINE_TRANS_GEOMRGH

2.3.51.8. Description

You can use DEFINE_TRANS_GEOMRGH to specify the geometric roughness height for the Transition SST turbulence model. For more details on the model, see Transition SST and Rough Walls.

2.3.51.9. Usage

DEFINE_TRANS_GEOMRGH (name, c, t)

Argument Type

Description

symbol name

UDF name.

cell_t c

Index of cell on which the geometric roughness height is to be applied.

Thread *t

Pointer to cell thread.

Function returns

real

There are three arguments to DEFINE_TRANS_GEOMRGH: name, c, and t. You supply name, the name of the UDF. c and t are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to return the real value for the geometric roughness height to the solver.

2.3.51.10. Example

An example of a DEFINE_TRANS_GEOMRGH UDF is provided at the end of this section.

2.3.51.11. Hooking a Transition Correlation UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_TRANS_GEOMRGH is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the DEFINE macro argument (for example, user_Geomrgh) will become visible and selectable in the Viscous Model dialog box in Ansys Fluent. See Hooking DEFINE_TRANS UDFs for details.

2.3.51.12. DEFINE_TRANS_RETHETA_C

2.3.51.13. Description

You can use DEFINE_TRANS_RETHETA_C to specify the critical momentum thickness Reynolds number for the Transition SST turbulence model.

2.3.51.14. Usage

DEFINE_TRANS_RETHETA_C (name, c, t)

Argument Type

Description

symbol name

UDF name.

cell_t c

Index that identifies the cell on which the critical momentum thickness Reynolds number is to be applied.

Thread *t

Pointer to cell thread.

Function returns

real

There are three arguments to DEFINE_TRANS_RETHETA_C: name, c, and t. You supply name, the name of the UDF. c and t are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to return the real value for the critical momentum thickness Reynolds number to the solver.

2.3.51.15. Example

An example of a TRANS_RETHETA_C UDF is provided at the end of this section.

2.3.51.16. Hooking a Transition Correlation UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_TRANS_RETHETA_C is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the DEFINE macro argument (for example, user_Re_thetac) will become visible and selectable in the Viscous Model dialog box in Ansys Fluent. See Hooking DEFINE_TRANS UDFs for details.

2.3.51.17. DEFINE_TRANS_RETHETA_T

2.3.51.18. Description

You can use DEFINE_TRANS_RETHETA_T to specify the transition onset momentum thickness Reynolds number for the Transition SST turbulence model.

2.3.51.19. Usage

DEFINE_TRANS_RETHETA_T (name, c, t)

Argument Type

Description

symbol name

UDF name.

cell_t c

Index that identifies the cell on which the transition onset momentum thickness Reynolds number is to be applied.

Thread *t

Pointer to cell thread.

Function returns

real

There are three arguments to DEFINE_TRANS_RETHETA_T: name, c, and t. You supply name, the name of the UDF. c and t are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to return the real value for the transition onset momentum thickness Reynolds number to the solver.

2.3.51.20. Example

The following functions (which are concatenated into a single C source code file) demonstrate this usage.

 #include "udf.h"
 
 DEFINE_TRANS_FLENGTH(user_Flength, c, t)
 {
    real Flength = 31.468;
    return Flength;
 }

 DEFINE_TRANS_GEOMRGH(user_Geomrgh, c, t)
 {
/* Dimensional value of geometric roughness height */
    real Geomrgh = 0.001;
    return Geomrgh;
 }
 
 DEFINE_TRANS_RETHETA_C(user_Re_thetac, c, t)
 {
    real Re_thetac = 176.396;
    return Re_thetac;
 }
 
 DEFINE_TRANS_RETHETA_T(user_Re_thetat, c, t)
 {
    real Re_thetat = 210;
    return Re_thetat;
 }
 

2.3.51.21. Hooking a Transition Correlation UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_TRANS is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the DEFINE macro argument (for example, user_Re_thetat) will become visible and selectable in the Viscous Model dialog box in Ansys Fluent. See Hooking DEFINE_TRANS UDFs for details.

2.3.52. DEFINE_TRANSIENT_PROFILE

2.3.52.1. Description

You can use the DEFINE_TRANSIENT_PROFILE macro to specify cell zone conditions that vary over time (for example, the rotation rate of a fan rotor zone at machine startup). Using this macro, you can replace the default transient profile interpolation method in Ansys Fluent or provide an analytic expression for the corresponding variable.

2.3.52.2. Usage

DEFINE_TRANSIENT_PROFILE (name, current_time)

Argument Type

Description

symbol name

UDF name.

real current_time

Current time.

Function returns

real

There are two arguments to DEFINE_TRANSIENT_PROFILE: name and current_time. You supply name, and then current_time is passed by the Ansys Fluent solver to your UDF. Your UDF will need to compute the real value of the corresponding variable, to which the function is assigned.

2.3.52.3. Example

The following UDF, named rotation_rate_ramp, computes the rotation rate of a cell zone, simulating startup behavior. The angular velocity is increased linearly in time up to a flow time of 0.1 s, after which it remains constant at a rate of 250 rad/s. The source can be interpreted or compiled.

 #include "udf.h"
 
 DEFINE_TRANSIENT_PROFILE(rotation_rate_ramp,time)
 {
  real rotation_rate = 0.0;
 if (time < 0.1)
		{
 			 rotation_rate = 2500.0 * time;
		}
 else
		{
			rotation_rate = 250.0;
		}
	return rotation_rate; 
} 

2.3.52.4. Hooking a Transient Profile UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_TRANSIENT_PROFILE is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name that you specified in the DEFINE macro argument will become visible and selectable in the cell zone condition dialog boxes. See Hooking DEFINE_TRANSIENT_PROFILE UDFs for details.

2.3.53. DEFINE_TURB_PREMIX_SOURCE

2.3.53.1. Description

You can use DEFINE_TURB_PREMIX_SOURCE to customize the turbulent flame speed and source term ( in Equation 8–70 and in Equation 8–113 in the Fluent Theory Guide) in the premixed combustion model and the partially premixed combustion model.

2.3.53.2. Usage

DEFINE_TURB_PREMIX_SOURCE (name, c, t, turb_flame_speed, source)

Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index.

Thread *t

Pointer to cell thread on which the turbulent premixed source term is to be applied.

real *turb_flame_speed

Pointer to the turbulent flame speed.

real *source

Pointer to the reaction progress source term.

Function returns

void

There are five arguments to DEFINE_TURB_PREMIX_SOURCE: name, c, t, turb_flame_speed, and source. You supply name, the name of the UDF. c, t, turb_flame_speed, and source are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to set the turbulent flame speed to the value referenced by the turb_flame_speed pointer. It will also need to set the source term to the value referenced by the source pointer.

2.3.53.3. Example

The following UDF, named turb_flame_src, specifies a custom turbulent flame speed and source term in the premixed combustion model. The source code must be executed as a compiled UDF in Ansys Fluent.

In the standard premixed combustion model in Ansys Fluent, the mean reaction rate of the progress variable (that is, the source term) is modeled as

(2–12)

where is the mean reaction progress variable, is the density, and is the turbulent flame speed.

In the UDF example, the turbulent flame speed is modeled as

(2–13)

where is the laminar flame speed and is the turbulent fluctuation. Note that the partially premixed combustion model is assumed to be enabled (see Modeling Partially Premixed Combustion in the User's Guide), so that the unburned density and laminar flame speed are available as polynomials. See Additional Macros for Writing UDFs for details on the NULLP, THREAD_STORAGE, and SV_VARS macros.

/*******************************************************************
  UDF that specifies a custom turbulent flame speed and source
  for the premixed combustion model
 ********************************************************************/
 
 #include "udf.h"
 #include "sg_pdf.h" /* not included in udf.h so must include here */
 
 DEFINE_TURB_PREMIX_SOURCE(turb_flame_src,c,t,turb_flame_speed,source)
 {
    real up = TRB_VEL_SCAL(c,t);
    real ut, ul, grad_c, rho_u, Xl, DV[ND_ND];
    ul = C_LAM_FLAME_SPEED(c,t);
    Xl = THREAD_VAR(t).fluid.premix_var.tdiff_u;
    rho_u = THREAD_VAR(t).fluid.premix_var.rho_u;

    if(NNULLP(THREAD_STORAGE(t,SV_PREMIXC_G)))
      {
         NV_V(DV, =, C_STORAGE_R_NV(c,t,SV_PREMIXC_G));
         grad_c = sqrt(NV_DOT(DV,DV));
      }
    ut = ul*sqrt(1. + SQR(up/ul));
    *turb_flame_speed = ut;
    *source = rho_u*ut*grad_c;
 } 

2.3.53.4. Hooking a Turbulent Premixed Source UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_TURB_PREMIX_SOURCE is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, turb_flame_src) will become visible and selectable in the User-Defined Function Hooks dialog box in Ansys Fluent. See Hooking DEFINE_TURB_PREMIX_SOURCE UDFs for details.

2.3.54. DEFINE_TURB_SCHMIDT UDF

The DEFINE_TURB_SCHMIDT macro can be used to specify the turbulent Schmidt numbers of all transported species in Ansys Fluent, for single-phase flows.

2.3.54.1. Description

The turbulent Schmidt number, denoted , controls the turbulent diffusion of species transported in Ansys Fluent. You can use DEFINE_TURB_SCHMIDT to specify for each species solved.

2.3.54.2. Usage

DEFINE_TURB_SCHMIDT (name, c, t, i)

Argument Type

Description

symbol name

UDF name.

cell_t c

Index of cell on which the Turbulent Schmidt number function is to be applied.

Thread *t

Pointer to cell thread.

int i

Species index.

Function returns

real

There are four arguments to DEFINE_TURB_SCHMIDT: name, c, t and i. You supply name, the name of the UDF. c, 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 for the turbulent Schmidt number to the solver.

2.3.54.3. Example

The following example sets to be inversely proportional to the species index. Hence, the first species in the materials list will have the smallest turbulent diffusion, and the last species will have the largest turbulent diffusion.

#include "udf.h"
 
 DEFINE_TURB_SCHMIDT(udf_sct, c, t, i)
 {
    return 1./((real)i+1.);
 } 

2.3.54.4. Hooking a Turbulent Schmidt Number UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_TURB_SCHMIDT is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, udf_sct in the above example) will become visible and selectable in the Viscous Model dialog box in Ansys Fluent. See Hooking DEFINE_TURB_SCHMIDT UDFs for details.

2.3.55. DEFINE_TURBULENT_VISCOSITY

2.3.55.1. Description

You can use DEFINE_TURBULENT_VISCOSITY to specify a custom turbulent viscosity function for the Spalart-Allmaras, - , and - turbulence models for single-phase applications. In addition, for 3D versions of Ansys Fluent you can specify a subgrid-scale turbulent viscosity UDF for the large eddy simulation model. For Eulerian multiphase flows, turbulent viscosity UDFs can be assigned on a per-phase basis, and/or to the mixture, depending on the turbulence model. See Table 2.9: Eulerian Multiphase Model and DEFINE_TURBULENT_VISCOSITY UDF Usage for details.

Table 2.9: Eulerian Multiphase Model and DEFINE_TURBULENT_VISCOSITY UDF Usage

Turbulence Model

Phase that Turbulent Viscosity UDF Is Specified On

- Mixture

mixture, primary and secondary phases

- Dispersed

primary and secondary phases

- Per-Phase

primary and secondary phases


2.3.55.2. Usage

DEFINE_TURBULENT_VISCOSITY (name, c, t)

Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index.

Thread *t

Pointer to cell thread on which the turbulent viscosity is to be applied.

Function returns

real

There are three arguments to DEFINE_TURBULENT_VISCOSITY: name, c, and t. You supply name, the name of the UDF. c and t are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to return the real value of the turbulent viscosity to the solver.

2.3.55.3. Example 1 - Single Phase Turbulent Viscosity UDF

The following UDF, named user_mu_t, defines a custom turbulent viscosity for the standard - turbulence model. Note that the value of GVAR_TURB(coeff, ke_Cmu) in the example is defined through the graphical user interface, but made accessible to all UDFs. The source code can be interpreted or compiled in Ansys Fluent.

/********************************************************************
  UDF that specifies a custom turbulent viscosity for standard
  k-epsilon formulation
 *********************************************************************/
 
 #include "udf.h"
 
 DEFINE_TURBULENT_VISCOSITY(user_mu_t,c,t)
 {
    real mu_t;
    real rho = C_R(c,t);
    real k  = C_K(c,t);
    real d  = C_D(c,t);
    mu_t = GVAR_TURB(coeff, ke_Cmu)*rho*SQR(k)/d;
    return mu_t;
 } 

2.3.55.4. Example 2 - Multiphase Turbulent Viscosity UDF

/********************************************************************
    Custom turbulent viscosity functions for each phase and the
    mixture in a two-phase multiphase flow
 *********************************************************************/
 #include "udf.h"
 
 DEFINE_TURBULENT_VISCOSITY(mu_t_ke_mixture, c, t)
 {
    real mu_t;
    real rho = C_R(c,t);
    real k  = C_K(c,t);
    real d  = C_D(c,t);
    real cmu = GVAR_TURB(coeff, ke_Cmu);
    mu_t = rho*cmu*k*k/d;
    return mu_t;
 }
 
 DEFINE_TURBULENT_VISCOSITY(mu_t_ke_1, c, t)
 {
    Thread *tm = lookup_thread_by_id(DOMAIN_SUPER_DOMAIN(THREAD_DOMAIN(t)),t->id);
    CACHE_T_SV_R (density, t, SV_DENSITY);
    CACHE_T_SV_R (mu_t, t, SV_MU_T);
    CACHE_T_SV_R (density_m, tm, SV_DENSITY);
    CACHE_T_SV_R (mu_t_m, tm, SV_MU_T);
    return density[c]/density_m[c]*mu_t_m[c];
 }
 
 DEFINE_TURBULENT_VISCOSITY(mu_t_ke_2, c, t)
 {
    Thread *tm = lookup_thread_by_id(DOMAIN_SUPER_DOMAIN(THREAD_DOMAIN(t)),t->id);
    CACHE_T_SV_R (density, t, SV_DENSITY);
    CACHE_T_SV_R (mu_t, t, SV_MU_T);
    CACHE_T_SV_R (density_m, tm, SV_DENSITY);
    CACHE_T_SV_R (mu_t_m, tm, SV_MU_T);
    return density[c]/density_m[c]*mu_t_m[c];
 } 

2.3.55.5. Hooking a Turbulent Viscosity UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_TURBULENT_VISCOSITY is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the function name(s) that you specified in the DEFINE macro argument(s) (for example user_mu_t for single phase, or mu_t_ke_mixture, mu_t_ke_1, and mu_t_ke_2 for multiphase) will become visible and selectable in the Viscous Model dialog box in Ansys Fluent. See Hooking DEFINE_TURBULENT_VISCOSITY UDFs for details.

2.3.56. DEFINE_VR_RATE

2.3.56.1. Description

You can use DEFINE_VR_RATE to specify a custom volumetric reaction rate for a single reaction or for multiple reactions. During Ansys Fluent execution, DEFINE_VR_RATE is called for every reaction in every single cell. A DEFINE_VR_RATE UDF is compatible with the laminar finite-rate model. It is not available with the Chemkin-CFD solver.

2.3.56.2. Usage

DEFINE_VR_RATE (name,c,t,r,mw,yi,rr,rr_t)

Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index.

Thread *t

Pointer to cell thread on which the volumetric reaction rate is to be applied.

Reaction *r

Pointer to data structure that represents the current reaction.

real *mw

Pointer to array of species molecular weights.

real *yi

Pointer to array of the species mass fractions.

real *rr

Pointer to laminar reaction rate.

real *rr_t

Pointer to turbulent reaction rate.

Function returns

void

There are eight arguments to DEFINE_VR_RATE: name, c, t, r, mw, yi, rr, and rr_t. You supply name, the name of the UDF. c, t, r, mw, yi, rr, and rr_t are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to set the values referenced by the real pointers rr and rr_t to the laminar and turbulent reaction rates, respectively. Note that when using the stiff chemistry solver, Ansys Fluent does not use rr_t.

rr and rr_t (defined by the UDF) are computed, and the lower of the two values is used when the finite-rate/eddy-dissipation chemical reaction mechanism used. Note that rr and rr_t are conversion rates in kmol/-s. These rates, when multiplied by the respective stoichiometric coefficients, yield the production/consumption rates of the individual chemical components.

2.3.56.3. Example 1

The following UDF, named vol_reac_rate, specifies a volume reaction rate. The function must be executed as a compiled UDF in Ansys Fluent.

/*********************************************************************
   UDF for specifying a volume reaction rate
   The basics of Ansys Fluent’s calculation of reaction rates: only an
   Arrhenius ("finite rate") reaction rate is calculated
   from the inputs given by the user in the graphical user interface
 **********************************************************************/
 
 #include "udf.h"
 
 DEFINE_VR_RATE(vol_reac_rate,c,t,r,wk,yk,rate,rr_t)
 {
    real ci, prod;
    int i;
 
   /* Calculate Arrhenius reaction rate */
    prod = 1.;
    for(i = 0; i < r->n_reactants; i++)
      {
        ci  = C_R(c,t) * yk[r->reactant[i]] / wk[r->reactant[i]];
        prod *= pow(ci, r->exp_reactant[i]);
      }
      *rate = r->A * exp(- r->E / (UNIVERSAL_GAS_CONSTANT * C_T(c,t))) *
               pow(C_T(c,t), r->b) * prod;
      *rr_t = *rate;
      /* No "return..;" value. */
 } 

2.3.56.4. Example 2

When multiple reactions are specified, a volume reaction rate UDF is called several times in each cell. Different values are assigned to the pointer r, depending on which reaction the UDF is being called for. Therefore, you will need to determine which reaction is being called, and return the correct rates for that reaction. Reactions can be identified by their name through the r->name statement. To test whether a given reaction has the name reaction-1, for example, you can use the following C construct:

if (!strcmp(r->name, "reaction-1"))
  {
     .... /* r->name is identical to "reaction-1" ... */
  } 

Important:  Note that strcmp(r->name, "reaction-1") returns which is equal to FALSE when the two strings are identical.


It should be noted that DEFINE_VR_RATE defines only the reaction rate for a predefined stoichiometric equation (set in the Reactions dialog box) therefore providing an alternative to the Arrhenius rate model. DEFINE_VR_RATE does not directly address the particular rate of species creation or depletion; this is done by the Ansys Fluent solver using the reaction rate supplied by your UDF.

The following is a source code template that shows how to use DEFINE_VR_RATE in connection with more than one user-specified reaction. Note that Ansys Fluent always calculates the rr and rr_t reaction rates before the UDF is called. Consequently, the values that are calculated are available only in the given variables when the UDF is called.

/*********************************************************************
   Multiple reaction UDF that specifies different reaction rates
   for different volumetric chemical reactions
 **********************************************************************/
 #include "udf.h"
 
 DEFINE_VR_RATE(myrate,c,t,r,mw,yi,rr,rr_t)
 {
   /*If more than one reaction is defined, it is necessary to distinguish
   between these using the names of the reactions.     */
     if (!strcmp(r->name, "reaction-1"))
       {
          /* Reaction 1 */
       }
     else if (!strcmp(r->name, "reaction-2"))
       {
          /* Reaction 2 */
       }
     else
       {
         /*  Message("Unknown Reaction\n"); */
       }
   /* Message("Actual Reaction: %s\n",r->name); */
 
 }

2.3.56.5. Hooking a Volumetric Reaction Rate UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_VR_RATE is interpreted (Interpreting UDFs)or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, myrate) will become visible and selectable in the User-Defined Function Hooks dialog box in Ansys Fluent. See Hooking DEFINE_VR_RATE UDFs for details.

2.3.57. DEFINE_WALL_FUNCTIONS

2.3.57.1. Description

You can use DEFINE_WALL_FUNCTIONS to provide custom wall functions for applications when you want to replace the standard wall functions in Ansys Fluent. Note that this is available only for use with the - turbulence models, and cannot be combined with the Eulerian multiphase model.

2.3.57.2. Usage

DEFINE_WALL_FUNCTIONS (name, f, t, c0, t0, wf_ret, yPlus, Emod)

Argument Type

Description

symbol name

UDF name.

face_t f

face index.

Thread *t

pointer to face thread

cell_t c0

cell index.

Thread *t0

pointer to cell thread.

int wf_ret

wall function index

real yPlus

y+ value

real Emod

wall function E constant

Function returns

real

There are eight arguments to DEFINE_WALL_FUNCTIONS: name, f, t, c0, t0, wf_ret, yPlus, and Emod. You supply name, the name of the UDF. f, t, c0, t0, wf_ret, yPlus, and Emod are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to compute the real value of the wall functions U+, dU+/dy+, and d2U+/dY+2 for laminar and turbulent regions and return them to the solver.

2.3.57.3. Example

The following UDF, named user_log_law, computes U+ and dU+/dy+, and d2U+/dY+2 for laminar and turbulent regions using DEFINE_WALL_FUNCTIONS. The source code can be interpreted or compiled in Ansys Fluent.

/******************************************************************
   User-defined wall functions: separated into turbulent and laminar regimes
 /*****************************************************************/
 #include "udf.h"
 
 DEFINE_WALL_FUNCTIONS(user_log_law, f, t, c0, t0, wf_ret, yPlus, Emod)
 {
    real wf_value;
    switch (wf_ret)
      {
      case UPLUS_LAM:
         wf_value = yPlus;
         break;
      case UPLUS_TRB:
         wf_value = log(Emod*yPlus)/KAPPA;
         break;
      case DUPLUS_LAM:
         wf_value = 1.0;
         break;
      case DUPLUS_TRB:
         wf_value = 1./(KAPPA*yPlus);
         break;
      case D2UPLUS_TRB:
         wf_value = -1./(KAPPA*yPlus*yPlus);
         break;
      default:
         printf("Wall function return value unavailable\n");
      }
    return wf_value;
 } 

2.3.57.4. Hooking a Wall Function UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_WALL_FUNCTIONS is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_log_law) will become visible and selectable in the Viscous Model dialog box in Ansys Fluent. See Hooking DEFINE_WALL_FUNCTIONS UDFs for details.

2.3.58. DEFINE_WALL_NODAL_DISP

2.3.58.1. Description

You can use DEFINE_WALL_NODAL_DISP to define the displacement of nodes in a wall that is adjacent to a solid zone, as part of an intrinsic fluid-structure interaction (FSI) simulation. For details about such simulations, see Modeling Fluid-Structure Interaction (FSI) Within Fluent in the User's Guide.

2.3.58.2. Usage

DEFINE_WALL_NODAL_DISP (name, f, t, v, m)

Argument Type

Description

symbol name

UDF name.

face_t f

Face index.

Thread *t

Pointer to face thread.

Node *v

Node pointer.

int m

Index that defines the displacement component.

Function returns

real

There are five arguments to DEFINE_WALL_NODAL_DISP: name, f, t, v, and m. You supply name, the name of the UDF. f, t, v, and m are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to compute the real value of the displacement Phib for each component and return them to the solver.

2.3.58.3. Example

The following UDF, named wall_nodal_disp, sets displacement components using DEFINE_WALL_NODAL_DISP. It defines each component of nodal displacement to be equal to the corresponding wall coordinate. The source code can be interpreted or compiled in Ansys Fluent.

#include "udf.h"
 
DEFINE_WALL_NODAL_DISP(wall_nodal_disp, f, t, v, m)
{
  int n;
  real Phib;

  if (m==0)
    Phib = NODE_X(v);
  else if (m==1)
    Phib = NODE_Y(v);
  else  
    Phib = NODE_Z(v);

  return Phib;
}

2.3.59. DEFINE_WALL_NODAL_FORCE

2.3.59.1. Description

You can use DEFINE_WALL_NODAL_FORCE to define the force applied to nodes in a wall that is adjacent to a solid zone as part of an intrinsic fluid-structure interaction (FSI) simulation. For details about such simulations, see Modeling Fluid-Structure Interaction (FSI) Within Fluent in the User's Guide.

2.3.59.2. Usage

DEFINE_WALL_NODAL_FORCE (name, f, t, v, m)

Argument Type

Description

symbol name

UDF name.

face_t f

Face index.

Thread *t

Pointer to face thread.

Node *v

Node pointer.

int m

Index that defines the force component.

Function returns

real

There are five arguments to DEFINE_WALL_NODAL_FORCE: name, f, t, v, and m. You supply name, the name of the UDF. f, t, v, and m are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to compute the real value of the force Phib for each component and return them to the solver.

2.3.59.3. Example

The following UDF, named wall_nodal_force, sets force components using DEFINE_WALL_NODAL_DISP. It specifies the force for each node based on the node location. The source code can be interpreted or compiled in Ansys Fluent.

#include "udf.h"
 
DEFINE_WALL_NODAL_FORCE(wall_nodal_force, f, t, v, m)
{
  int n;
  real Phib;
  real y = NODE_Y(v);

  if (y > 10.1)
    Phib = 125;
  else if (y < 9.9)
    Phib = 125;
  else
    Phib = 250;

  return Phib;
}

2.3.60. DEFINE_SOURCE_FE

2.3.60.1. Description

You can use DEFINE_SOURCE_FE to define the volumetric structural body force, as part of an intrinsic fluid-structure interaction (FSI) simulation. For details about such simulations, see Modeling Fluid-Structure Interaction (FSI) Within Fluent in the User's Guide.

2.3.60.2. Usage

DEFINE_SOURCE_FE (name, c, t)

Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index.

Thread *t

Cell thread pointer.

Function returns

real

There are three arguments to DEFINE_SOURCE_FE: name, c, and t. You supply name, the name of the UDF. c and t are variables that are passed by the Ansys Fluent solver to your UDF. Your UDF will need to compute the real value of the force source and return it to the solver.

2.3.60.3. Example

The following UDF, named dz_force, is used to simulate the volumetric body force in the z-direction due to the stretching of a bar under its own weight using DEFINE_SOURCE_FE. It determines the volumetric force by multiplying the density C_R(c,t) by a gravitational factor gravity_z. The source code can be interpreted or compiled in Ansys Fluent.

#include "udf.h"
 
DEFINE_SOURCE_FE(dz_force,c,t)
{
   real gravity_z = -10.;
   real rho = C_R(c,t);
   real source;
  
   source = rho * gravity_z;

   return source;
} 

2.3.60.4. Hooking a Volumetric Structural Body Force UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_SOURCE_FE is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, dz_force) will become visible and selectable in the appropriate Displacement Source dialog for Solid cell zones in Ansys Fluent. See Hooking DEFINE_SOURCE_FE UDFs for details.

2.3.61. DEFINE_WSGGM_ABS_COEFF

2.3.61.1. Description

You can use DEFINE_WSGGM_ABS_COEFF to customize the absorption coefficient computed using the domain-based weighted-sum-of-gray-gases model (WSGGM) model, by either replacing the internally calculated value or by modifying the value computed by Ansys Fluent. During the execution, a DEFINE_WSGGM_ABS_COEFF function is called by Ansys Fluent for each fluid zone and also for each band (in the case of a non-gray model). If the soot model is enabled, DEFINE_WSGGM_ABS_COEFF can also be used to modify the soot absorption coefficient computed by Ansys Fluent. See Radiation in Combusting Flows in the Theory Guide for further information about how composition-dependent absorption coefficients are calculated.


Important:  The WSGGM is implemented in a gray approach. If the WSGGM is used with a non-gray model, the absorption coefficient will be the same in all bands. Use DEFINE_GRAY_BAND_ABS_COEFF to change the absorption coefficient per band or per gray gas.


2.3.61.2. Usage

DEFINE_WSGGM_ABS_COEFF (name, c, t, xi, p_t, s, soot_conc, Tcell, nb, ab_wsggm, ab_soot)

Argument Type

Description

symbol name

UDF name.

cell_t c

Cell index.

Thread *t

Pointer to cell thread on which the WSGGM absorption coefficient function is to be applied.

real xi[]

Array containing species mole fractions.

real p_t

Total pressure.

real s

Beam length based on domain size.

real soot_conc

Concentration of the soot (if the soot model is enabled).

real Tcell

Temperature of the cell.

int nb

Band number (nb=0 for gray model).

real *ab_wsggm

Absorption coefficient computed by the WSGGM in Ansys Fluent.

real *ab_soot

Absorption coefficient computed by the soot model in Ansys Fluent.

Function returns

void

There are eleven arguments to DEFINE_WSGGM_ABS_COEFF: name, c, t, xi, p_t, s, soot_conc, Tcell, nb, ab_wsggm, and ab_soot. You supply name, the name of the UDF. c, t, xi, p_t, s, soot_conc, Tcell, nb, ab_wsggm, and ab_soot are variables that are passed by the Ansys Fluent solver to your UDF.

2.3.61.3. Example

The following UDF, named user_wsggm_abs_coeff, replaces the WSGGM and soot absorption coefficients so that they are no longer the value calculated internally by Ansys Fluent. While DEFINE_WSGGM_ABS_COEFF UDFs can be interpreted or compiled in Ansys Fluent, the following example can only be compiled.

#include "udf.h"
#include "materials.h"

DEFINE_WSGGM_ABS_COEFF(user_wsggm_abs_coeff, c, t, xi, p_t, s, soot_conc, Tcell, nb, ab_wsggm, ab_soot)
{
  Material *m = THREAD_MATERIAL(t);
  int ico2 = mixture_specie_index(m, "co2");
  int ih2o = mixture_specie_index(m, "h2o");
  real CO2_molf, H2O_molf;
  real k2, k3, k4;


  CO2_molf= xi[ico2];
  H2O_molf= xi[ih2o];
  

        switch (nb)
          {
           case 0 :  /*  First gray gas*/
             {
               *ab_wsggm = 0;
             }
             break;

           case 1 :  /*  Second gray gas*/
             {
               k2   = 0.1;
               *ab_wsggm = (k2 * (H2O_molf + CO2_molf)) * p_t;
             }
             break;

           case 2 :  /*  Third gray gas*/
             {
               k3   =  7.1;
               *ab_wsggm = (k3 * (H2O_molf + CO2_molf)) * p_t;
             }
             break;

           case 3 :  /*  Fourth gray gas*/
             {
               k4   =  60.0; 
               *ab_wsggm = (k4 * (H2O_molf + CO2_molf)) * p_t;
             }
          }

       *ab_soot =  0.1;
}

2.3.61.4. Hooking a Wall Function UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_WSGGM_ABS_COEFF is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_wsggm_abs_coeff) will become visible and selectable in the Create/Edit Materials dialog box in Ansys Fluent. See Hooking DEFINE_WSGGM_ABS_COEFF UDFs for details.

2.3.62. DEFINE_ZONE_MOTION

2.3.62.1. Description

You can use DEFINE_ZONE_MOTION to specify the cell zone motion components in a moving reference frame, moving mesh, or solid motion simulation. All motion components are passed as arguments to the UDF, so that access to them is provided in a single UDF. The arguments contain the default values already, so that if a specific component (for example, the origin) is not modified by the UDF, it will retain its default value.

2.3.62.2. Usage

DEFINE_ZONE_MOTION (name, omega, axis, origin, velocity, time, dtime)

Argument Type

Description

symbol name

UDF name.

real *omega

Pointer to the rotational velocity magnitude, default 0.

real axis[3]

Rotation axis direction vector, default (0 0 1) and (1 0 0) for 2D axisymmetric cases.

real origin[3]

Rotation axis origin vector, default (0 0 0).

real velocity[3]

Translational velocity vector, default (0 0 0).

real current_time

Current time.

real dtime

Current time step.

Function returns

void

There are seven arguments to DEFINE_ZONE_MOTION: name, omega, axis, origin, velocity, time, and dtime. You supply name, the name of the UDF. The variables omega, axis, origin, velocity, time, and dtime are passed by the Ansys Fluent solver to your UDF and have SI units. Your UDF will need to compute the motion components that you want to modify. If a certain component is not modified by the UDF, it will retain its default value. The vector specified as axis does not need to be a unit vector; note that it will be normalized before it is used further inside the solver, that is, definitions such as (1 1 1) and (10 10 10) are equivalent.

All vectors are specified as 3 dimensional, even for 2D simulations. The third component of the origin and the translational velocity vectors will be ignored in 2D cases. For regular 2D cases, rotation is assumed to be around the Z axis. In a 2D axisymmetric case, the rotation is around the X axis. Hence, for 2D cases any modification to the axis vector inside the UDF will be ignored.

2.3.62.3. Example

The following UDF, named fmotion, computes the rotation rate of a cell zone, simulating start-up behavior. The angular velocity is increased linearly in time up to a flow time of 0.1 s, after which it remains constant at 250 rad/s. A constant translational velocity of 1 m/s in the X direction is assigned. The lines assigning the origin and axis vectors only repeat the default behavior, and could be omitted. The source can be interpreted or compiled.

#include "udf.h"
 DEFINE_ZONE_MOTION(fmotion,omega,axis,origin,velocity,time,dtime)
{
  if (time < 0.1) 
   {
    *omega = 2500.0 * time;
   }
	 else
   {
    *omega = 250.0;
   }
  N3V_D (velocity,=,1.0,0.0,0.0);
  N3V_S(origin,=,0.0);        /* default values, line could be omitted */
  N3V_D(axis,=,0.0,0.0,1.0);     /* default values, line could be omitted */

  return;
}

2.3.62.4. Hooking a Zone Motion UDF to Ansys Fluent

After the UDF that you have defined using DEFINE_ZONE_MOTION is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument will become visible and selectable in the cell zone condition dialog boxes.

See Hooking DEFINE_ZONE_MOTION UDFs for details.