equations for which source terms can be applied and the corresponding that is used to derive the
term ( dS[eqn]).
variable
Note that like property UDFs, source term UDFs (defined using DEFINE_SOURCE) are called by FLUENT from within a loop on cell threads. The solver passes to the DEFINE_SOURCE term UDF all the necessary variables it needs 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 FLUENT is already doing it. Your UDF will only be required to compute the source term for a single cell and return the real value to the solver. Note that the units on all source terms are of the form generation-rate/volume. For 例子:, a source term for the continuity equation would have units of kg/m 3-s. 例子:
下面的UDF名字为xmom_source, is used to add source terms in FLUENT. It can be executed as an interpreted or compiled UDF. The function generates an x-momentum source term that varies with y position as
Suppose
where
Then
The source term returned is
and the derivative of the source term with respect to v x (true for both positive and negative values of v x) is
/*******************************************************************/ /* UDF for specifying an x-momentum source term in a spatially */
/* dependent porous media */ /*******************************************************************/
#include \
#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; }
Activating a Source Term UDF in FLUENT
Once you have compiled and linked your source term UDF, you can activate it by selecting it in the Fluid or Solid panel in FLUENT. See Section 8.2.7 for more details.
4.3.9 DEFINE_SR_RATE 功能和使用方法的介绍
你可以使用DEFINE_SR_RATE macro to customize a surface reaction rate.
Macro:
DEFINE_SR_RATE ( name, f, t, r, my, yi, rr )
Argument types: face_t f
Thread *t Reaction *r real *mw real *yi real *rr
Function returns: void
There are seven arguments to DEFINE_SR_RATE: name, f, t, r, my, yi, and rr. name is the name of the UDF, specified by you. 当你的UDF编译和连接时,你为函数所选择的名字会在FLUENT图形用户界面中变得可见,且可被选择。 f, t, r, my, and yi are variables that are passed by the FLUENT solver to your UDF.
f is an index that identifies a face within the given thread. t is a pointer to the thread on which the surface rate reaction is to be applied. r is a pointer to the data structure for the reaction. mw is a pointer to a real array containing the species molecular weights, and yi is a pointer to a real array containing the species mass fractions. Your UDF will need to set the reaction rate to the value referenced by the real pointer rr as shown in the 例子: below. 例子:
下面编译的UDF名字为arrhenius, defines a custom surface reaction rate in FLUENT.
/*******************************************************************/ /* UDF for specifying a custom surface reaction rate * /*******************************************************************/
#include \
/* 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 Fluent panel */
#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 that is used in both UDFs */ real reaction_rate(cell_t c, Thread *cthread,real mw[],real yi[]) {
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),F_C0_THREAD(f,fthread),mw,yi); }
real contact_area(cell_t c, Thread *t, int s_id, int *n) {
int i = 0;
real area = 0.0, A[ND_ND];
*n = 0;
c_face_loop(c,t,i) {
if(THREAD_ID(C_FACE_THREAD(c,t,i)) == s_id) {
(*n)++;
F_AREA(A, C_FACE(c,t,i), C_FACE_THREAD(c,t,i)); area += NV_MAG(A); } }
return area; }
Activating a Surface Reaction Rate UDF in FLUENT
Once you have compiled and linked the source code for a custom surface reaction rate UDF, you can activate it in the User-Defined Function Hooks panel in FLUENT. See Section 8.2.6 for more details.
4.3.10 DEFINE_TURB_PREMIX_SOURCE 功能和使用方法的介绍