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–74 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.-DPM_CHAR_FRACTION(tp)-DPM_VOLATILE_FRACTION(tp));
real one_minus_conv =
MAX(0.,(TP_MASS(tp) -ash_mass) / TP_INIT_MASS(tp)/ DPM_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–69 and Equation 7–72 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.-DPM_CHAR_FRACTION(tp)-DPM_VOLATILE_FRACTION(tp));
real one_minus_conv =
MAX(0.,(TP_MASS(tp) -ash_mass) / TP_INIT_MASS(tp)/ DPM_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.