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 Functions – Table 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.
- 2.3.1. DEFINE_ANISOTROPIC_CONDUCTIVITY
- 2.3.2. DEFINE_CAPILLARY_PRESSURE
- 2.3.3. DEFINE_CHEM_STEP
- 2.3.4. DEFINE_CPHI
- 2.3.5. DEFINE_CORNER_FLOW_CORRECTION_CCORNER
- 2.3.6. DEFINE_CURVATURE_CORRECTION_CCURV
- 2.3.7. DEFINE_DIFFUSIVITY
- 2.3.8. DEFINE_DOM_DIFFUSE_REFLECTIVITY
- 2.3.9. DEFINE_DOM_SOURCE
- 2.3.10. DEFINE_DOM_SPECULAR_REFLECTIVITY
- 2.3.11. DEFINE_EC_KINETICS_PARAMETER
- 2.3.12. DEFINE_EC_RATE
- 2.3.13. DEFINE_EDC_MDOT
- 2.3.14. DEFINE_EDC_SCALES
- 2.3.15. DEFINE_ELECTROLYSIS_ECHEM_RATE
- 2.3.16. DEFINE_ELECTROLYSIS_RELATIVE_PERMEABILITY
- 2.3.17. DEFINE_EMISSIVITY_WEIGHTING_FACTOR
- 2.3.18. DEFINE_FLAMELET_PARAMETERS
- 2.3.19. DEFINE_GAP_MODEL_SOURCE
- 2.3.20. DEFINE_GEOMETRY
- 2.3.21. DEFINE_GRAY_BAND_ABS_COEFF
- 2.3.22. DEFINE_HEAT_FLUX
- 2.3.23. DEFINE_IGNITE_SOURCE
- 2.3.24. DEFINE_KW_GEKO Coefficients and Blending Function
- 2.3.25. DEFINE_MASS_TR_PROPERTY
- 2.3.26. DEFINE_NET_REACTION_RATE
- 2.3.27. DEFINE_NOX_RATE
- 2.3.28. DEFINE_PERFORATED_CD
- 2.3.29. DEFINE_PDF_TABLE
- 2.3.30. DEFINE_PR_RATE
- 2.3.31. DEFINE_PRANDTL UDFs
- 2.3.32. DEFINE_PROFILE
- 2.3.33. DEFINE_PROPERTY UDFs
- 2.3.34. DEFINE_REACTING_CHANNEL_BC
- 2.3.35. DEFINE_REACTING_CHANNEL_SOLVER
- 2.3.36. DEFINE_RELAX_TO_EQUILIBRIUM
- 2.3.37. DEFINE_SBES_BF
- 2.3.38. DEFINE_SCAT_PHASE_FUNC
- 2.3.39. DEFINE_SOLAR_INTENSITY
- 2.3.40. DEFINE_SOLIDIFICATION_PARAMS
- 2.3.41. DEFINE_SOOT_MASS_RATES
- 2.3.42. DEFINE_SOOT_MOM_RATES
- 2.3.43. DEFINE_SOOT_NUCLEATION_RATES
- 2.3.44. DEFINE_SOOT_OXIDATION_RATE
- 2.3.45. DEFINE_SOOT_PRECURSOR
- 2.3.46. DEFINE_SOURCE
- 2.3.47. DEFINE_SPARK_GEOM (R14.5 spark model)
- 2.3.48. DEFINE_SPECIFIC_HEAT
- 2.3.49. DEFINE_SR_RATE
- 2.3.50. DEFINE_THICKENED_FLAME_MODEL
- 2.3.51. DEFINE_TRANS UDFs
- 2.3.52. DEFINE_TRANSIENT_PROFILE
- 2.3.53. DEFINE_TURB_PREMIX_SOURCE
- 2.3.54. DEFINE_TURB_SCHMIDT UDF
- 2.3.55. DEFINE_TURBULENT_VISCOSITY
- 2.3.56. DEFINE_VR_RATE
- 2.3.57. DEFINE_WALL_FUNCTIONS
- 2.3.58. DEFINE_WALL_NODAL_DISP
- 2.3.59. DEFINE_WALL_NODAL_FORCE
- 2.3.60. DEFINE_SOURCE_FE
- 2.3.61. DEFINE_WSGGM_ABS_COEFF
- 2.3.62. DEFINE_ZONE_MOTION
Table 2.2: Quick Reference Guide for Model-Specific DEFINE Functions
Function |
|
Dialog Box Activated In |
---|---|---|
anisotropic thermal conductivity |
|
Create/Edit Materials |
capillary pressure |
|
Potential/Electrochemistry |
mixing constant |
|
User-Defined Function Hooks |
homogeneous net mass reaction rate for all species, integrated over a time step |
|
User-Defined Function Hooks |
species mass or UDS diffusivity |
|
Create/Edit Materials |
diffusive reflectivity for discrete ordinates (DO) model |
|
User-Defined Function Hooks |
source for DO model |
|
User-Defined Function Hooks |
specular reflectivity for DO model |
|
User-Defined Function Hooks |
electrochemical reaction kinetics parameter |
|
Reaction |
electrochemical reaction rate |
|
User-Defined Function Hooks |
reaction rates for the EDC model |
|
Species Model |
scales for the EDC model |
|
Species Model |
transfer currents for the electrolysis model |
|
Potential/Electrochemistry |
relative permeability for the electrolysis model |
|
Potential/Electrochemistry |
relative permeability for the Electrolysis model |
|
Potential/Electrochemistry |
emissivity weighting factor for the radiative transfer equation of the non-gray P-1 model and the non-gray DO model |
|
User-Defined Function Hooks |
variation of scalar dissipation, mean mixture fraction grid, and mean progress variable grid for flamelet generation |
|
Species Model |
source terms for momentum and energy equations for the cells located in a gap region |
|
Edit Gap Region |
auxiliary geometry definition |
|
Auxiliary Geometry Definition |
gray band absorption coefficient for DO model |
|
Create/Edit Materials |
wall heat flux |
|
User-Defined Function Hooks |
ignition time 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 |
|
User-Defined Function Hooks |
homogeneous net mass reaction rate for all species |
|
User-Defined Function Hooks |
Table 2.3: Quick Reference Guide for Model-Specific DEFINE Functions–Continued
Function |
|
Dialog Box Activated In |
---|---|---|
NOx formation rates (for Thermal NOx, Prompt NOx, Fuel NOx, and O Pathways) and upper limit for temperature PDF |
|
NOx Model |
discharge coefficient in a perforated wall |
|
User-Defined Function Hooks |
PDF lookup table |
|
User-Defined Function Hooks |
particle surface reaction rate |
|
User-Defined Function Hooks |
Prandtl numbers |
|
Viscous Model |
species mass fraction |
|
boundary condition (for example, Velocity Inlet) |
velocity at a boundary |
|
boundary condition |
pressure at a boundary |
|
boundary condition |
temperature at a boundary |
|
boundary condition |
mass flux at a boundary |
|
boundary condition |
target mass flow rate for pressure outlet |
|
Pressure Outlet |
turbulence kinetic energy |
|
boundary condition (for example, Velocity Inlet) |
turbulence dissipation rate |
|
boundary condition |
specific dissipation rate |
|
boundary condition |
porosity |
|
boundary condition |
viscous resistance |
|
boundary condition |
inertial resistance |
|
boundary condition |
porous resistance direction vector |
|
boundary condition |
user-defined scalar boundary value |
|
boundary condition |
internal emissivity |
|
boundary condition |
Table 2.4: Quick Reference Guide for Model-Specific DEFINE Functions–Continued
Function |
|
Dialog Box Activated In |
---|---|---|
wall thermal conditions (heat flux, heat generation rate, temperature, heat transfer coefficient, external emissivity, external radiation and free stream temperature) |
|
boundary condition |
shell layer heat generation rate |
|
Shell Conduction Layers |
wall radiation (internal emissivity, irradiation) |
|
boundary condition |
wall momentum (shear stress x, y, z components swirl component, moving wall velocity components, roughness height, roughness constant) |
|
boundary condition |
wall species mass fractions |
|
boundary condition |
wall user-defined scalar boundary value |
|
boundary condition |
wall discrete phase boundary value |
|
boundary condition |
density (as function of temperature) |
|
Create/Edit Materials |
density (as function of pressure for compressible liquids) |
|
Create/Edit Materials |
viscosity |
|
Create/Edit Materials |
mass diffusivity |
|
Create/Edit Materials |
thermal conductivity |
|
Create/Edit Materials |
thermal diffusion coefficient |
|
Create/Edit Materials |
Table 2.5: Quick Reference Guide for Model-Specific DEFINE Functions–Continued
Function |
|
Dialog Box Activated In |
---|---|---|
absorption coefficient |
|
Create/Edit Materials |
scattering coefficient |
|
Create/Edit Materials |
laminar flame speed |
|
Create/Edit Materials |
rate of strain |
|
Create/Edit Materials |
speed of sound function |
|
Create/Edit Materials |
user-defined mixing law for mixture materials (density viscosity, thermal conductivity) |
|
Create/Edit Materials |
reacting channel inlet boundary conditions |
|
Reacting Channel Model |
reacting channel solver |
|
User-Defined Function Hooks |
species characteristic time for reaching chemical equilibrium |
|
User-Defined Function Hooks |
blending function for the Stress-Blended Eddy Simulation (SBES) model |
|
Viscous Model |
scattering phase function |
|
Create/Edit Materials |
solar intensity |
|
Radiation Model |
back diffusion |
|
Solidification and Melting |
mushy zone |
|
Solidification and Melting |
soot nucleation, surface growth, and oxidation rates for soot mass fraction equation |
|
Soot Model |
soot nucleation, surface growth, and oxidation rates for soot moment equations |
|
Soot Model |
soot nucleation and coagulation rates for soot nuclei equation |
|
Soot Model |
soot oxidation rate |
|
Soot Model |
soot precursor |
|
Soot Model |
mass source |
|
cell zone condition |
momentum source |
|
cell zone condition |
energy source |
|
cell zone condition |
turbulence kinetic energy source |
|
cell zone condition |
turbulence dissipation rate source |
|
cell zone condition |
species mass fraction source |
|
cell zone condition |
user-defined scalar source |
|
cell zone condition |
P1 radiation model source |
|
cell zone condition |
spark kernel volume shape |
|
Set Spark Ignition |
specific heat and sensible enthalpy |
|
Create/Edit Materials |
surface reaction rate |
|
User-Defined Function Hooks |
thickened flame model |
|
User-Defined Function Hooks |
transition correlation numbers |
|
Viscous Model |
time-varying profiles |
|
cell zone condition |
turbulent premixed source |
|
User-Defined Function Hooks |
turbulent Schmidt number |
|
Viscous Model |
turbulent viscosity |
|
Viscous Model |
volume reaction rate |
|
User-Defined Function Hooks |
wall function |
|
Viscous Model |
wall nodal force |
|
Wall |
wall nodal displacement |
|
Wall |
weighted-sum-of-gray-gases model (WSGGM) absorption coefficient |
|
Create/Edit Materials |
soot absorption coefficient |
|
Create/Edit Materials |
cell zone motion components in a moving reference frame, moving mesh, or solid motion simulation |
|
cell zone condition |
Table 2.6: Quick Reference Guide for Model-Specific DEFINE Functions MULTIPHASE ONLY
Function |
|
Dialog Box Activated In |
---|---|---|
volume fraction (all multiphase models) |
|
boundary condition |
contact angle (VOF) |
|
Wall boundary condition |
heat transfer coefficient (Eulerian) |
|
Phase Interaction |
surface tension coefficient (VOF) |
|
Phase Interaction |
cavitation surface tension coefficient (Mixture) |
|
Phase Interaction |
cavitation vaporization pressure (Mixture) |
|
Phase Interaction |
particle or droplet diameter (Mixture) |
|
Create/Edit Materials |
diameter (Eulerian, Mixture) |
|
Secondary Phase |
solids pressure (Eulerian, Mixture) |
|
Secondary Phase |
radial distribution (Eulerian, Mixture) |
|
Secondary Phase |
elasticity modulus (Eulerian, Mixture) |
|
Secondary Phase |
viscosity (Eulerian, Mixture) |
|
Secondary Phase |
temperature (Eulerian, Mixture) |
|
Secondary Phase |
bulk viscosity (Eulerian) |
|
Secondary Phase |
frictional viscosity (Eulerian) |
|
Secondary Phase |
frictional pressure (Eulerian) |
|
Secondary Phase |
frictional modulus (Eulerian) |
|
Secondary Phase |
granular viscosity (Eulerian) |
|
Secondary Phase |
granular bulk viscosity (Eulerian) |
|
Secondary Phase |
granular conductivity (Eulerian) |
|
Secondary Phase |
temperature source (Eulerian, Mixture) |
|
boundary condition |
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.
DEFINE_ANISOTROPIC_CONDUCTIVITY
(name
, c
, t
, dmatrix
)
Argument Type |
Description |
|
UDF name. |
|
Cell index. |
|
Pointer to the cell thread on which the anisotropic conductivity is to be applied. |
|
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.
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 }
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.
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.
DEFINE_CAPILLARY_PRESSURE
(name
,
c
, t
, cp
,
dcpdalpha
, s
)
Argument Type |
Description |
|
UDF name. |
|
Cell or face index. |
|
Pointer to the cell or face thread. |
|
Pointer to capillary pressure. |
|
Pointer to the capillary pressure gradient in the space of the volume fraction of the liquid phase. |
|
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
.
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; }
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; }
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.
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.
DEFINE_CHEM_STEP
(name
, c
, t
, p
, num_p
, n_spe
, dt
, pres
, temp
, yk
)
Argument Type |
Description |
|
UDF name. |
|
Cell index of current particle. |
|
Pointer to cell thread for particle. |
|
Pointer to |
|
Not Used. |
|
Number of volumetric species. |
|
Time step. |
|
Pointer to pressure. |
|
Pointer to temperature. |
|
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.
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; }
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.
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.
DEFINE_CPHI
(name
, c
, t
)
Argument Type |
Description |
|
UDF name. |
|
Cell index. |
|
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.
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.
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.
DEFINE_CORNER_FLOW_CORRECTION_CCORNER (name, c, t)
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 .
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; }
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.
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).
DEFINE_CURVATURE_CORRECTION_CCURV
(name
,
c
, t
)
Argument Type |
Description |
|
UDF name. |
|
Index that identifies the cell on which the curvature correction coefficient is to be applied. |
|
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 .
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; }
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.
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.
DEFINE_DIFFUSIVITY
(name
, c
, t
, i
)
Argument Type |
Description |
|
UDF name. |
|
Cell index. |
|
Pointer to cell thread on which the diffusivity function is to be applied. |
|
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.
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; }
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.
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.
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 |
---|---|
|
UDF name. |
|
Pointer to the thread on which the discrete ordinate diffusivity function is to be applied. |
|
Band number (needed for the non-gray discrete ordinates (DO) model). |
|
Refractive index of medium a. |
|
Refractive index of medium b. |
|
Diffuse reflectivity at the interface facing medium a. |
|
Diffuse transmissivity at the interface facing medium a. |
|
Diffuse reflectivity at the interface facing medium 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.
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); }
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.
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.
DEFINE_DOM_SOURCE
(name
, c
, t
, ni
, nb
, emission
, in_scattering
, abs_coeff
, scat_coeff
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Cell index. |
|
Pointer to cell thread. |
|
Direction represented by the solid angle. |
|
Band number (needed for the non-gray discrete ordinates (DO) model). |
|
Pointer to emission term in the radiative transport equation (Equation 5–98 in the Theory Guide) |
|
Pointer to scattering term in the radiative transport equation (Equation 5–99 in the Theory Guide) |
|
Pointer to absorption coefficient. |
|
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.
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; }
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.
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.
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 |
---|---|
|
UDF name. |
|
Face index. |
|
Pointer to face thread on which the specular reflectivity function is to be applied. |
|
Band number (needed for non-gray discrete ordinates (DO) model). |
|
Refractive index of medium a. |
|
Refractive index of medium b. |
|
Direction vector () defined in Equation 5–116 in the Theory Guide. |
|
Interface normal vector () defined in Equation 5–116 in the Theory Guide. |
|
Variable used to flag the code that total internal reflection has occurred. |
|
Specular reflectivity for the given direction . |
|
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.
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; } }
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.
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.
DEFINE_EC_KINETICS_PARAMETER
(name
,
f
, fthread
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Index that identifies a face within the given thread. |
|
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.
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; }
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.
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.
DEFINE_EC_RATE
(name
,
f
, t
, r
,
V
, i
, didV
,
Eeq
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Index that identifies a face within the given thread. |
|
Pointer to face thread on which the electrochemical reaction is to be applied. |
|
Pointer to data structure for the reaction. |
|
Potential difference between electrode and electrolyte . |
|
Pointer to the electric current density, . |
|
Pointer to the derivative of current density with respect to potential difference , . |
| 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
.
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")) { ... } */ }
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.
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.
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 theDEFINE
statement into several lines will result in a compilation error.DEFINE_EDC_MDOT
functions can be executed only as compiled UDFs.
Argument Type |
Description |
---|---|
|
UDF name. |
|
Cell or face index. |
|
Pointer to the cell or face thread. |
|
Pointer to parameter . |
|
Integer that indicates whether |
| 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.
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);} }
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.
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).
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 theDEFINE
statement into several lines will result in a compilation error.DEFINE_EDC_SCALES
functions can be executed only as compiled UDFs.
Argument Type |
Description |
---|---|
|
UDF name. |
|
Cell or face index. |
|
Pointer to the cell or face thread. |
|
Pointer to coefficient . |
|
Pointer to coefficient . |
|
Integer that indicates whether |
| 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.
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))); }
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.
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.
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 |
|
UDF name. |
|
Cell index. |
|
Pointer to the cell thread. |
|
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
.
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; }
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.
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.
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 |
|
UDF name. |
|
Cell index. |
|
Pointer to the cell thread. |
|
Pointer to the relative permeability. |
|
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
.
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; }
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.
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.
DEFINE_EMISSIVITY_WEIGHTING_FACTOR
(name
, c
, t
, T
, nb
, emissivity_weighting_factor
)
Argument Type |
Description |
|
UDF name. |
|
Cell index. |
|
Pointer to cell thread. |
|
Temperature. |
|
Band number. |
|
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.
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; }
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.
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.
DEFINE_FLAMELET_PARAMETERS
(name
, Nf
, Nc
, Ns
, xf
, xc
, xs
)
Argument Type |
Description |
|
UDF name. |
|
Number of mean mixture fraction grid points in flamelet. |
|
Number of mean progress variable grid points. |
|
Maximum number of flamelets. |
|
Array to provide mean mixture fraction points. |
|
Array to provide mean progress variable points. |
|
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.
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); } } }
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.
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.
DEFINE_GAP_MODEL_SOURCE
(name
,
c
, tc
, Source
,
dS
)
Argument Type |
Description |
|
UDF name. |
|
Cell index. |
|
Pointer to cell thread. |
|
Source term. |
|
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
.
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; }
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.
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.
DEFINE_GEOMETRY
(name
,
o
, x
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Pointer to the geometry object. |
|
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).
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; }
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.
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.
DEFINE_GRAY_BAND_ABS_COEFF
(name
, c
, t
, nb
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Cell index. |
|
Pointer to cell thread. |
|
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.
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; }
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.
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.
DEFINE_HEAT_FLUX
(name,f,t,c0,t0,cid,cir
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Index that identifies a wall face. |
|
Pointer to wall face thread on which heat flux function is to be applied. |
|
Cell index that identifies the cell next to the wall. |
|
Pointer to the adjacent cell’s thread. |
|
Array of fluid-side diffusive heat transfer coefficients. |
|
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.
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.
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.
You can use DEFINE_IGNITE_SOURCE
to
customize the ignition time source term in the autoignition model.
DEFINE_IGNITE_SOURCE
(name
, c
, t
, source
)
Argument Type |
Description |
---|---|
|
UDF name |
|
Cell index |
|
Pointer to cell thread on which the ignition source term is to be applied |
|
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.
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; }
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.
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.
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.
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; }
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.
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.
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 |
---|---|
|
UDF name. |
|
index of face on the thread pointed to by |
|
Pointer to mixture level face thread. |
|
Index of face on the thread pointed to by |
|
Pointer to mixture level cell thread. |
|
Index of phase from which mass is transferred. |
|
ID of species from which mass is transferred (ID= -1 if phase does not have mixture material). |
|
Index of phase to which mass is transferred. |
|
ID of species to which mass is transferred (ID= -1 if phase does not have mixture material). |
|
Index of mass transfer mechanism. |
|
Pointer to the tabular data structure such as
|
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.
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; }
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.
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.
DEFINE_NET_REACTION_RATE
(name
, c
, t
, particle
, pressure
, temp
, yi
, rr
, jac
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Cell index of current particle. |
|
Pointer to cell thread for particle. |
|
Pointer to |
|
Pointer to pressure variable. |
|
Pointer to temperature variable. |
|
Pointer to array containing species mass fractions. |
|
Pointer to array containing net molar reaction rates. |
|
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.
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.
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.
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.
DEFINE_NOX_RATE
(name
, c
, t
, Pollut
, Pollut_Par
, NOx
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Cell index. |
|
Pointer to cell thread on which the NOx rate is to be applied. |
|
Pointer to the data structure that contains the common data at each cell |
|
Pointer to the data structure that contains auxiliary data. |
|
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.
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; } }
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"); }
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.
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.
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 theDEFINE
statement into several lines will result in a compilation error.DEFINE_PERFORATED_CD
functions can be executed only as compiled UDFs.
Argument Type |
Description |
---|---|
|
UDF name. |
|
Pointer to face thread. |
|
Pointer to parameter Cd |
|
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
Index | Enumerator | Variable |
---|---|---|
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 |
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; }
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.
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 asDEFINE_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.
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 theDEFINE
statement into several lines will result in a compilation error.DEFINE_PDF_TABLE
functions can be executed only as compiled UDFs.
Argument Type |
Description |
---|---|
|
UDF name. |
|
Pointer to the mixture material pdf-mixture. |
|
Cell or face index. |
|
Pointer to the cell or face thread. |
|
Mean mixture fraction. |
|
Mixture fraction variance. |
|
Secondary mean mixture fraction. |
|
Secondary mixture fraction variance. |
|
Mean unnormalized progress variable (used with the partially premixed flamelet model). |
|
Progress variable variance (used with the partially premixed flamelet model). |
|
Mean enthalpy. |
|
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. |
|
Thermodynamic variables as follows:
|
|
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 indexThread *t
: Pointer to threadint n
: Species indexreal fmean
: Mean mixture fraction
Table 2.8: Generic Macros Get_PDF
Macro |
Returns |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
real PDF net chemical forward rate of the FGM scalar
n [1/s] as in Equation 8–119 in the Fluent Theory Guide
|
|
|
|
|
|
|
|
|
An example of the usage of these macros is shown in 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 }
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.
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.
DEFINE_PR_RATE
(name
, c
, t
, r
, mw
, ci
, tp
, sf
, dif_index
, cat_index
, rr
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Cell index of current particle. |
|
Pointer to cell thread for particle. |
|
Pointer to data structure that represents the current reaction. |
|
Pointer to array containing gaseous and surface species molecular weights |
|
Pointer to array containing gas partial pressures. |
|
Pointer to |
|
Pointer
to array containing mass fractions of the solid species in the particle |
|
Diffusion controlled species as defined in the Reactions dialog box for the current reaction. |
|
Catalyst species as defined in the Reactions dialog box for the current reaction. |
|
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.
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
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; }
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.
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.
The following DEFINE
macros can be
used to specify Prandtl numbers in Ansys Fluent, for single-phase flows.
You can use DEFINE_PRANDTL_D
to specify
Prandtl numbers for turbulent dissipation ().
DEFINE_PRANDTL_D
(name
, c
, t
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Index of cell on which the Prandtl number function is to be applied. |
|
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.
An example of a DEFINE_Prandtl_D
UDF
is provided below in the source listing for DEFINE_PRANDTL_K
.
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.
You can use DEFINE_PRANDTL_K
to specify
Prandtl numbers for turbulence kinetic energy ().
DEFINE_PRANDTL_K
(name
, c
, t
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Index that identifies the cell on which the Prandtl number function is to be applied. |
|
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.
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:
Set Cmu, C1eps, and C2eps as in the RNG model.
Calculate Prandtl numbers for and using the UDF.
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; }
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.
You can use DEFINE_PRANDTL_O
to specify
Prandtl numbers for specific dissipation ( in the - model).
DEFINE_PRANDTL_O
(name
, c
, t
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Index that identifies the cell on which the Prandtl number function is to be applied. |
|
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.
/* 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; }
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.
You can use DEFINE_PRANDTL_T
to specify
Prandtl numbers that appear in the temperature equation diffusion
term.
DEFINE_PRANDTL_T
(name
, c
, t
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Index that identifies the cell on which the Prandtl number function is to be applied. |
|
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.
/* 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; }
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.
You can use DEFINE_PRANDTL_T_WALL
to
specify Prandtl numbers for thermal wall functions.
DEFINE_PRANDTL_T_WALL
(name
, c
, t
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Index that identifies the cell on which the Prandtl number function is to be applied. |
|
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.
/************************************************************* 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; }
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.
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.
DEFINE_PROFILE
(name
,
t
, i
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Pointer to thread on which boundary condition is to be applied. |
|
Index that identifies the variable that is to be defined.
|
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*/
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.
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) }
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) }
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) }
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) }
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) }
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) }
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) } }
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); }
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.
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
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.
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
, densityPROP_mu
, viscosityPROP_ktc
, thermal conductivity
generic_property
(name
, c
, t
, prop
, id
, T
)
Argument Type | Description |
---|---|
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
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.
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; }
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; }
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; }
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.
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.
DEFINE_REACTING_CHANNEL_BC
(name
, i
, group
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
ID of the reacting channel 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
.
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); }
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.
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.
DEFINE_REACTING_CHANNEL_SOLVER
(name
, params
, inlet_state
, dist
, dt
, wall_temp
, wall_hf
, compute_htc
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Pointer to array of current channel parameters. |
|
Pointer to array of inlet species composition, temperature and pressure. |
|
Pointer to array of axial distance of discrete points from channel inlet. |
|
Pointer to array of time step of integration at discrete points. |
|
Pointer to array of channel wall temperature at discrete points. |
|
Pointer to array of channel wall heat flux at discrete points |
|
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.
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; } }
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.
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.
DEFINE_RELAX_TO_EQUILIBRIUM(name,c,t,pressure,temp,yi,tau)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Cell index. |
|
Pointer to cell thread. |
|
Pressure. |
|
Temperature. |
|
Pointer to array containing species mass fractions. |
|
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.
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; }
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.
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.
DEFINE_SBES_BF
(name
, c
, t
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Index that identifies the cell on which the SBES blending function is to be applied. |
|
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.
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; }
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.
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.
DEFINE_SCAT_PHASE_FUNC
(name
, cosine
, f
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Cosine of the angle between directions and . |
|
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.
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); }
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.
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.
DEFINE_SOLAR_INTENSITY
(name
, sum_x
, sun_y
, sun_z
, S_hour
, S_minute
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
x component of the sun direction vector. |
|
y component of the sun direction vector. |
|
z component of the sun direction vector. |
|
Time in hours. |
|
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.
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; }
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.
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.
DEFINE_SOLIDIFICATION_PARAMS
(name
, c
, t
, Amush
, Gamma
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Cell Index. |
|
Cell thread pointer. |
|
Pointer to real having mushy zone constant. |
|
Pointer to real for back diffusion parameter. |
Function returns
void
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); }
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.
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.
DEFINE_SOOT_MASS_RATES (name, c, t, Pollut, Pollut_Par,
Soot, rates_linear, rates_nonlinear, index)
Argument Type |
Description |
---|---|
|
UDF name |
|
Cell index |
|
Pointer to cell thread on which the Soot mass rates is to be applied |
|
Pointer to the data structure that contains the common data at each cell |
|
Pointer to the data structure that contains auxiliary data |
|
Pointer to the data structure that contains data specific to the Soot mode. |
|
Array to provide the linear components of soot mass rates |
|
Array to provide the nonlinear components of soot mass rates |
|
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.
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; } }
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.
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.
DEFINE_SOOT_MOM_RATES (name, c, t, Nnuc, Rnuc, NCnuc, Nsurf, Rsurf,
Dsurf)
Argument Type |
Description |
---|---|
|
UDF name |
|
Cell index |
|
Pointer to cell thread on which the Method of Moments (MOM) rates is to be applied |
|
Pointer to the number of nucleation reactions |
|
Pointer to the nucleation rates for each nucleation reaction |
|
Pointer to the number of carbon atoms in each nucleating species |
|
Pointer to the number of surface reactions, including growth and oxidation |
|
Pointer to the rates for surface growth and oxidation |
|
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.
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*/ }
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.
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.
DEFINE_SOOT_NUCLEATION_RATES (name, c, t, Pollut,
Pollut_Par, Soot, rates_linear, rates_nonlinear, index)
Argument Type |
Description |
---|---|
|
UDF name |
|
Cell index |
|
Pointer to cell thread on which the Soot nucleation rates is to be applied |
|
Pointer to the data structure that contains the common data at each cell |
|
Pointer to the data structure that contains auxiliary data |
|
Pointer to the data structure that contains data specific to the Soot mode. |
|
Array to provide the linear components of soot nucleation rates |
|
Array to provide the nonlinear components of soot nucleation rates |
|
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.
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; } }
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.
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.
DEFINE_SOOT_OXIDATION_RATE
(name
, c
, t
, Pollut
, Pollut_Par
, Soot
, soot_oxi_rate
)
Argument Type |
Description |
---|---|
|
UDF name |
|
Cell index |
|
Pointer to cell thread on which the Soot oxidation rate is to be applied |
|
Pointer to the data structure that contains the common data at each cell |
|
Pointer to the data structure that contains auxiliary data |
|
Pointer to the data structure that contains data specific to the Soot model |
|
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
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); } }
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.
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.
DEFINE_SOOT_PRECURSOR
(name
, c
, t
, Pollut
, Pollut_Par
, Soot
)
Argument Type |
Description |
---|---|
|
UDF name |
|
Cell index |
|
Pointer to cell thread on which the Soot precursor is to be applied |
|
Pointer to the data structure that contains the common data at each cell |
|
Pointer to the data structure that contains auxiliary data |
|
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.
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; }
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.
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)
DEFINE_SOURCE
(name
, c
, t
, dS
, eqn
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Index that identifies cell on which the source term is to be applied. |
|
Pointer to cell thread. |
|
Array that contains the derivative of the source term with respect to the dependent variable of the transport equation. |
|
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.
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; }
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; }
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.
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.
DEFINE_SPARK_GEOM
(name,c,t
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Cell index. |
|
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.
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; }
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.
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.
DEFINE_SPECIFIC_HEAT
(name,T,Tref,h,yi
)
Argument Type |
Description |
---|---|
|
UDF name |
|
Temperature for the calculation of the specific heat and enthalpy |
|
Reference temperature for the enthalpy calculation |
|
Pointer to |
|
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
.
/********************************************************************** 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; }
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.
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
DEFINE_SR_RATE
(name,f,t,r,my,yi,rr
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Index that identifies a face within the given thread (or cell in the case of surface reaction in a porous zone). |
|
Pointer to face thread on which the surface rate reaction is to be applied. |
|
Pointer to data structure for the reaction. |
|
Pointer to array of species molecular weights. |
|
Pointer to array of mass fractions of gas species at the surface and the coverage of site species (or site fractions). |
|
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.
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); }
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; }
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.
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.
DEFINE_THICKENED_FLAME_MODEL
(name,c,t,F,E,Omega
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Index that identifies a cell within the given thread. |
|
Pointer to cell thread on which the TFM parameters (F, E, Omega) are to be applied. |
|
Pointer to array of the thickening factor. |
|
Pointer to array of the efficiency factor. |
|
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.
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.; }
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.
The following DEFINE
macros can be
used to specify transition correlations for the Transition SST model
in Ansys Fluent.
You can use DEFINE_TRANS_ALG_REC_COR
to
specify your own formulation of the critical Reynolds number correlation for the
Algebraic Transition Model.
DEFINE_TRANS_ALG_REC_COR (name, c, t)
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.
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; }
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.
You can use DEFINE_TRANS_FLENGTH
to
specify the transition length for the Transition SST turbulence model.
DEFINE_TRANS_FLENGTH
(name
, c
, t
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Index of cell on which the transition length function is to be applied. |
|
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.
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.
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.
DEFINE_TRANS_GEOMRGH
(name
,
c
, t
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Index of cell on which the geometric roughness height is to be applied. |
|
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.
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.
You can use DEFINE_TRANS_RETHETA_C
to
specify the critical momentum thickness Reynolds number for the Transition
SST turbulence model.
DEFINE_TRANS_RETHETA_C
(name
, c
, t
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Index that identifies the cell on which the critical momentum thickness Reynolds number is to be applied. |
|
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.
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.
You can use DEFINE_TRANS_RETHETA_T
to
specify the transition onset momentum thickness Reynolds number for
the Transition SST turbulence model.
DEFINE_TRANS_RETHETA_T
(name
, c
, t
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Index that identifies the cell on which the transition onset momentum thickness Reynolds number is to be applied. |
|
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.
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; }
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.
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.
DEFINE_TRANSIENT_PROFILE
(name
, current_time
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
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.
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; }
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.
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.
DEFINE_TURB_PREMIX_SOURCE
(name
, c
, t
, turb_flame_speed
, source
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Cell index. |
|
Pointer to cell thread on which the turbulent premixed source term is to be applied. |
|
Pointer to the turbulent flame speed. |
|
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.
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; }
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.
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.
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.
DEFINE_TURB_SCHMIDT
(name
, c
, t
, i
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Index of cell on which the Turbulent Schmidt number function is to be applied. |
|
Pointer to cell thread. |
|
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.
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.); }
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.
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 |
DEFINE_TURBULENT_VISCOSITY
(name
, c
, t
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Cell index. |
|
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.
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; }
/******************************************************************** 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]; }
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.
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.
DEFINE_VR_RATE
(name,c,t,r,mw,yi,rr,rr_t
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Cell index. |
|
Pointer to cell thread on which the volumetric reaction rate is to be applied. |
|
Pointer to data structure that represents the current reaction. |
|
Pointer to array of species molecular weights. |
|
Pointer to array of the species mass fractions. |
|
Pointer to laminar reaction rate. |
|
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.
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. */ }
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); */ }
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.
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.
DEFINE_WALL_FUNCTIONS
(name
, f
, t
, c0
, t0
, wf_ret
, yPlus
, Emod
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
face index. |
|
pointer to face thread |
|
cell index. |
|
pointer to cell thread. |
|
wall function index |
|
y+ value |
|
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.
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; }
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.
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.
DEFINE_WALL_NODAL_DISP
(name
,
f
, t
, v
,
m
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Face index. |
|
Pointer to face thread. |
|
Node pointer. |
|
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.
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; }
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.
DEFINE_WALL_NODAL_FORCE
(name
,
f
, t
, v
,
m
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Face index. |
|
Pointer to face thread. |
|
Node pointer. |
|
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.
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; }
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.
DEFINE_SOURCE_FE
(name
,
c
, t
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Cell index. |
|
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.
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; }
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.
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.
DEFINE_WSGGM_ABS_COEFF
(name
, c
, t
, xi
, p_t
, s
, soot_conc
, Tcell
, nb
, ab_wsggm
, ab_soot
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Cell index. |
|
Pointer to cell thread on which the WSGGM absorption coefficient function is to be applied. |
|
Array containing species mole fractions. |
|
Total pressure. |
|
Beam length based on domain size. |
|
Concentration of the soot (if the soot model is enabled). |
|
Temperature of the cell. |
|
Band number (nb=0 for gray model). |
|
Absorption coefficient computed by the WSGGM in Ansys Fluent. |
|
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.
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; }
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.
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.
DEFINE_ZONE_MOTION
(name
,
omega
, axis
,
origin
, velocity
,
time
, dtime
)
Argument Type |
Description |
---|---|
|
UDF name. |
|
Pointer to the rotational velocity magnitude, default 0. |
|
Rotation axis direction vector, default (0 0 1) and (1 0 0) for 2D axisymmetric cases. |
|
Rotation axis origin vector, default (0 0 0). |
|
Translational velocity vector, default (0 0 0). |
|
Current time. |
|
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.
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; }
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.