fluent UDF第四章 DEFINE宏(9)

2019-08-02 00:21

c1 = -1; }

/* If Face lies at domain boundary, use face values; */

/* If Face lies IN the domain, use average of adjacent cells. */

if (NULL == t1)

/* Alternative: if (BOUNDARY_FACE_THREAD_P(t)) */ {

NV_D(psi_vec, =, F_U(f,t), F_V(f,t), F_W(f,t)); NV_S(psi_vec, *=, F_R(f,t)); } else {

NV_D(psi_vec, =, C_U(c0,t0), C_V(c0,t0), C_W(c0,t0)); NV_D(psi_vec, +=, C_U(c1,t1), C_V(c1,t1), C_W(c1,t1)); NV_S(psi_vec, /=, 2.); /* averaging. */

NV_S(psi_vec, *=, (((C_R(c0,t0) + C_R(c1,t1)) / 2.))); }

/* Now psi_vec contains our \ /* Next, get the face normal vector: */

F_AREA(A, f, t);

/* Finally, return the dot product of both. */ /* Fluent will multiply the returned value */ /* by phi_f (the scalar's value at the face) */ /* to get the \ */

return NV_DOT(psi_vec, A); }

Activating a User-Defined Scalar Flux UDF in FLUENT

Once you have compiled and linked the source code for a UDS flux UDF, you can activate it in FLUENT in the User-Defined Scalars panel. See Section 8.2.10 for more details. 4.3.13 DEFINE_UDS_UNSTEADY 功能和使用方法的介绍

你可以使用DEFINE_UDS_UNSTEADY macro when you want to customize unsteady terms in your user-defined scalar (UDS) transport equations. Details on setting up and solving UDS transport equations are provided in Chapter 9.

Macro: DEFINE_UDS_UNSTEADY ( name, c, t, i, apu, su) Argument types: cell_t c Thread *t int i real *apu real *su Function returns: void

There are six arguments to DEFINE_UDS_UNSTEADY: name, c, t, i, apu, and su. name is the name of the UDF, specified by you. 当你的UDF编译和连接时,你为函数所选择的名字会在FLUENT图形用户界面中变得可见,且可被选择。 c, t, and i are variables that are passed by the FLUENT solver to your UDF. t is a pointer to the thread on which the unsteady term for the UDS transport equation is to be applied. c is an index that identifies a cell within the given thread. i is an index that identifies the user-defined scalar for which the unsteady term is to be set.

Your UDF will need to set the values of the unsteady terms referenced by the real pointers apu and su to the central coefficient and source term, respectively. Note that if more than one scalar is being solved, a conditional if statement can be used to define a different unsteady term for each i. i = 0 is associated with scalar-0 (the first scalar equation being solved).

The FLUENT solver expects that the transient term will be decomposed into a source term, su, and a central coefficient term, apu. These terms are included in the equation set in a similar manner to the way the explicit and implicit components of a source term might be handled. Hence, the unsteady term is moved to the RHS and discretized as follows:

=

=

(4.3.14)

Note that Equation 4.3-15 shows how su and apu are defined. 例子:

下面的UDF名字为uns_time, modifies user-defined scalar time derivatives using DEFINE_UDS_UNSTEADY. This function can be executed as an interpreted or compiled UDF in FLUENT. /***********************************************************************/ /* UDF for specifying user-defined scalar time derivatives */

/***********************************************************************/

#include \

DEFINE_UDS_UNSTEADY(uns_time, c, t, i, apu, su) {

real physical_dt, vol, rho, phi_old;

physical_dt = RP_Get_Real(\ vol = C_VOLUME(c,t);

rho = C_R_M1(c,t);

*apu = -rho*vol / physical_dt;/*implicit part*/ phi_old = C_STORAGE_R(c,t,SV_UDSI_M1(i)); *su = rho*vol*phi_old/physical_dt;/*explicit part*/ }

Activating an Unsteady UDS Term in FLUENT

Once you have compiled and linked the source code for an unsteady UDS term UDF, you can activate it in the User-Defined Scalar panel in FLUENT. See Section 8.2.11 for more details. 4.3.14 DEFINE_VR_RATE 功能和使用方法的介绍

你可以使用DEFINE_VR_RATE macro when you want to define a custom volumetric reaction rate for a single reaction or for multiple reactions. During FLUENT execution, the same UDF is called sequentially for all reactions.

Macro:

DEFINE_VR_RATE ( name, c, t, r, mw, yi, rr, rr_t)

Argument types: cell_t c

Thread *t

Reaction *r real *mw real *yi real *rr real *rr_t

Function returns: void

There are eight arguments to DEFINE_VR_RATE: name, c, t, r, mw, yi, rr, and rr_t. name is the name of the UDF, specified by you. 当你的UDF编译和连接时,你为函数所选择的名字会在FLUENT图形用户界面中变得可见,且可被选择。 c, t, r, mw, yi, rr, and rr_t are variables that are passed by the FLUENT solver to your UDF.

t is a pointer to the thread on which the volumetric reaction rate is to be applied. c is an index that identifies a cell within the given thread. r is a pointer to the data structure that represents the current reaction. mw is a real pointer array of the species molecular weights, and yi is a real pointer array of the species mass fractions. 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. 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 kgmol/m 3-s. These rates, when multiplied by the respective stoichiometric coefficients, yield the production/consumption rates of the individual chemical components. DEFINE_VR_RATE is called by FLUENT for every reaction in every single cell. 例子: 1

下面的UDF名字为vol_reac_rate, specifies a volume reaction rate. The function can be executed as a compiled UDF in FLUENT.

/*********************************************************************/ /* UDF for specifying a volume reaction rate */ /* The basics of Fluent's calculation of reaction rates: only an */ /* Arrhenius (\ */ /* from the inputs given by the user in the graphical user interface */

/*********************************************************************/

#include \

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_rate = *rate;

/* No \}

例子: 2

When multiple reactions are specified, the 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 例子:, 你可以使用following C constuct: if (!strcmp(r->name, \ {

.... /* r->name is identical to \ }

(Note that strcmp(r->name, \ It should be noted that DEFINE_VR_RATE only defines the reaction rate for a predefined stoichiometric equation (set in the Reactions panel) thus 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 FLUENT solver using the reaction rate provided by your UDF.

The following is a simple template that shows how to use DEFINE_VR_RATE in connection with more than one user-specified reaction. Note that 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 \

DEFINE_VR_RATE(myrate, c, t, r, mw, yi, rr, rr_t) {


fluent UDF第四章 DEFINE宏(9).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:OMT中使用的缩略词

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: