FLUENT udf中文资料ch4

更新时间:2024-05-31 09:03:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

第四章 DEFINE宏(未完整翻译)

本章介绍了Fluent公司所提供的预定义宏,我们需要用这些预定义宏来定义UDF。在本章中这些宏就是指DEFINE宏。

? ? ? ? ?

4.1 概述

4.2 通用解算器DEFINE宏 4.3 模型指定DEFINE宏 4.4 多相DEFINE宏 4.5 离散相模型DEFINE宏 4.1 概述

DEFINE宏一般分为如下四类: 通用解算器 ? 模型指定 ? 多相

? 离散相模型(DPM)

?

对于本章所列出的每一个DEFINE宏,本章都提供了使用该宏的源代码的例子。很多例子广泛的使用了其它章节讨论的宏,如解算器读取(第五章)和utilities (Chapter 6)。需要注意的是,并不是本章所有的例子都是可以在FLUENT中执行的完整的函数。这些例子只是演示一下如何使用宏。

除了离散相模型DEFINE宏之外的所有宏的定义都包含在udf.h文件中。离散相模型DEFINE宏的定义包含在dpm.h文件中。为了方便大家,所有的定义都列于附录A中。其实udf.h头文件已经包含了dpm.h文件,所以在你的UDF源代码中就不必包含dpm.h文件了。

注意:在你的源代码中,DEFINE宏的所有参变量必须在同一行,如果将DEFINE声明分为几行就会导致编译错误。 4.2 通用解算器DEFINE宏

本节所介绍的DEFINE宏执行了FLUENT中模型相关的通用解算器函数。表 4.2.1提供了FLUENT中DEFINE宏,以及这些宏定义的功能和激活这些宏的面板的快速参考向导。每一个DEFINE宏的定义都在udf.h头文件中,具体可以参考附录A。

DEFINE_ADJUST (4.2.1节) ? DEFINE_INIT (4.2.2节)

? DEFINE_ON_DEMAND (4.2.3节) ? DEFINE_RW_FILE (4.2.4节)

?

表4.2.1:通用解算器DEFINE宏的快速参考向导 功能 处理变量 初始化变量 异步执行 读写变量到…… DEFINE宏 DEFINE_ADJUST DEFINE_INIT DEFINE_ON_DEMAND DEFINE_RW_FILE 激活该宏的面板 User-Defined Function Hooks User-Defined Function Hooks Execute On Demand User-Defined Function Hooks Case和data文件 4.2.1 DEFINE_ADJUST ? 4.2.2 DEFINE_INIT

? 4.2.3 DEFINE_ON_DEMAND ? 4.2.4 DEFINE_RW_FILE

?

4.2.1 DEFINE_ADJUST 功能和使用方法的介绍

DEFINE_ADJUST是一个用于调节和修改FLUENT变量的通用宏。例如,你可以用DEFINE_ADJUST来修改流动变量(如:速度,压力)并计算积分。你可以用它来对某一标量在整个流场上积分,然后在该结果的基础上调节边界条件。在每一步迭代中都可以执行用DEFINE_ADJUST定义的宏,并在解输运方程之前的每一步迭代中调用它。参考图3.3.1 和3.3.2 for可以大致了解一下当DEFINE_ADJUST被调用时FLUENT解的过程

宏 DEFINE_ADJUST ( name, d) 参变量类型 Domain *d 返回的功能 void DEFINE_ADJUST有两个参变量:name和d。name是你所指定的UDF的名字。当你的UDF编译并连接时,你的FLUENT图形用户界面就会显示这个名字,此时你就可以选择它了。d是FLUENT解算器传给你的UDF的变量。 D是一个指向区域的指针,调节函数被应用于这个区域上。区域变量提供了存取网格中所有单元和表面的线程。对于多相流,由解算器传给函数的区域指针是混合层区域指针。DEFINE_ADJUST函数不返回任何值给解算器。 例子1

下面的UDF名字是adjust,它使用DEFINE_ADJUST对湍流耗散在整个区域上积分。然后这个值会打印在控制台窗口中。每一步迭代都会调用这个UDF。它可以作为解释程序或者编译后的UDF在FLUENT中执行。

/*******************************************************************/ /* 积分湍流耗散并将其打印到控制台窗口的UDF */ /********************************************************************/

#include \

DEFINE_ADJUST(my_adjust, d) {

Thread *t;

/* Integrate dissipation. */ real sum_diss=0.; cell_t c;

thread_loop_c (t,d) {

begin_c_loop (c,t)

sum_diss += C_D(c,t)* C_VOLUME(c,t); end_c_loop (c,t) }

printf(\}

例子: 2

下面UDF的名字是adjust_fcn,它用DEFINE_ADJUST指定了某一自定义标量是另一自定义标量的梯度的函数。该函数在每一次迭代中都会被调用。它可以作为编译后的UDF在FLUENT中执行。

/********************************************************************/ /* UDF for defining user-defined scalars and their gradients */

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

#include \

DEFINE_ADJUST(adjust_fcn, d) {

Thread *t; cell_t c;

real K_EL = 1.0;

/* Do nothing if gradient isn't allocated yet. */ if (! Data_Valid_P()) return;

thread_loop_c (t, d) {

if (FLUID_THREAD_P(t)) {

begin_c_loop_all (c,t) { C_UDSI(c,t,1)

K_EL*NV_MAG2(C_UDSI_G(c,t,0))*C_VOLUME(c,t); } end_c_loop_all (c, t) } } }

Activating an Adjust UDF in FLUENT

+=

在为adjust UDF的源代码进行编译和连接之后,你可以在FLUENT中的User-Defined Function Hooks 面板激活这个函数。更详细的内容请参阅8.1.1节。 4.2.2 DEFINE_INIT 功能和使用方法的介绍

你可以用DEFINE_INIT宏来定义一组解的初始值。DEFINE_INIT 完成和修补一样的功能,只是它以另一种方式——UDF来完成。每一次初始化时DEFINE_INIT函数都会被执行一次,并在解算器完成默认的初始化之后立即被调用。因为它是在流场初始化之后被调用的,所以它最常用于设定流动变量的初值。参考图3.3.1和3.3.2关于FLUENT解过程的介绍可以看出什么时候调用DEFINE_INIT函数。

Macro: DEFINE_INIT ( name, d) Argument types: Domain *d Function returns: void DEFINE_INIT有两个参变量:name和d。name是你所指定的UDF的名字。当你的UDF编译并连接时,你的FLUENT图形用户界面就会显示这个名字,此时你就可以选择它了。d是FLUENT解算器传给你的UDF的变量。

d is a pointer to the domain over which the initialization function is to be applied. The domain argument provides access to all cell and face threads in the mesh. For multiphase flows, the domain pointer that is passed to the function by the solver is the mixture-level domain pointer. A DEFINE_INIT function does not return a value to the solver. 例子

下面的UDF名字是my_init_func,它在某一个解中初始化了流动变量。在解过程开始时它被执行了一次。它可以作为解释程序或者编译后的UDF在FLUENT中执行。

/*******************************************************************/ /* UDF for initializing flow field variables */

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

#include \

DEFINE_INIT(my_init_function, domain) {

cell_t c; Thread *t;

real xc[ND_ND];

/* loop over all cell threads in the domain */ thread_loop_c (t,domain) {

/* loop over all cells */ begin_c_loop_all (c,t) {

C_CENTROID(xc,c,t);

if (sqrt(ND_SUM(pow(xc[0] - 0.5,2.), pow(xc[1] - 0.5,2.),

pow(xc[2] - 0.5,2.))) < 0.25) C_T(c,t) = 400.; else

C_T(c,t) = 300.; }

end_c_loop_all (c,t) } }

The macro ND_SUM(a, b, c) that is used in the UDF computes the sum of the first two arguments (2D) or all three arguments (3D). It is useful for writing functions involving vector operations so that the same function can be used for 2D and 3D. For a 2D case, the third argument is ignored. See Chapter 5 for a description of predefined solver access macros (e.g., C_CENTROID) and Chapter 6 for utility macros (e.g., ND_SUM).

Activating an Initialization UDF in FLUENT

编译并连接UDF源代码之后。you can activate the function in the User-Defined Function Hooks panel in FLUENT. See Section 8.1.2 for more details. 4.2.3 DEFINE_ON_DEMAND 功能和使用方法的介绍

你可以使用DEFINE_ON_DEMAND macro to define a UDF to execute on demand in FLUENT, rather than having FLUENT call it automatically during the calculation. Your UDF will be executed immediately, once it is activated, but it is not accessible while the solver is iterating. Note that the domain pointer d is not explicitly passed as an argument to DEFINE_ON_DEMAND. Therefore, if you want to use the domain variable in your on-demand function, you will need to first retrieve it using the Get_Domain utility provided by Fluent (shown in 例子: below). See Section 6.5.1 for details on Get_Domain.

Macro: DEFINE_ON_DEMAND ( name) Argument types: none Function returns: void

There is only one argument to DEFINE_ON_DEMAND: name. name is the name of the UDF, specified by you. 当你的UDF编译和连接时,你为函数所选择的名字会在FLUENT图形用户界面中变得可见,且可被选择。 A DEFINE_ON_DEMAND function does not return a value to the solver. 例子:

下面的UDF名字为demand_calc,计算并打印出当前数据场的最小、最大和平均温度。It then computes a temperature function

and stores it in user-defined memory location 0 (which is allocated as described in Section 6.7). Once you execute the UDF (as described in Section 8.1.3), the field values for f( T) will be available in the drop-down lists in postprocessing panels in FLUENT. You can select this field by choosing udm-0 in the User Defined Memory... category. If you write a data file after executing the UDF, the user-defined memory field will be saved to the data file. The UDF can be executed as an interpreted or compiled UDF in FLUENT.

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

/* UDF to calculate temperature field function and store in */

/* user-defined memory. Also print min, max, avg temperatures. */ /**********************************************************************/

#include \

DEFINE_ON_DEMAND(on_demand_calc)

Domain *d; /* declare domain pointer since it is not passed a */

/* argument to DEFINE macro */ {

real tavg = 0.; real tmax = 0.; real tmin = 0.;

real temp,volume,vol_tot; Thread *t; cell_t c;

d = Get_Domain(1); /* Get the domain using Fluent utility */

/* Loop over all cell threads in the domain */ thread_loop_c(t,d) {

/* Compute max, min, volume-averaged temperature */

/* Loop over all cells */ begin_c_loop(c,t) {

volume = C_VOLUME(c,t); /* get cell volume */ temp = C_T(c,t); /* get cell temperature */

if (temp < tmin || tmin == 0.) tmin = temp; if (temp > tmax || tmax == 0.) tmax = temp;

vol_tot += volume; tavg += temp*volume;

}

end_c_loop(c,t)

tavg /= vol_tot;

printf(\ Tmax = %g Tavg = %g\\n\

/* Compute temperature function and store in user-defined memory*/

/*(location index 0) */

begin_c_loop(c,t) {

temp = C_T(c,t);

C_UDMI(c,t,0) = (temp-tmin)/(tmax-tmin); }

end_c_loop(c,t)

} }

Get_Domain is a macro that retrieves the pointer to a domain. It is necessary to get the domain pointer using this macro since it is not explicitly passed as an argument to DEFINE_ON_DEMAND. The function, named on_demand_calc, does not take any explicit arguments. Within the function body, the variables that are to be used by the function are defined and initialized first. Following the variable declarations, a looping macro is used to loop over each cell thread in the domain. Within that loop another loop is used to loop over all the cells. Within the inner loop, the total volume and the minimum, maximum, and volume-averaged temperature are computed. These computed values are printed to the FLUENT console. Then a second loop over each cell is used to compute the function f( T) and store it in user-defined memory location 0. Refer to Chapter 5 for a description of predefined solver access macros (e.g., C_T) and Chapter 6 for utility macros (e.g., begin_c_loop). Activating an On-Demand UDF in FLUENT

After you have compiled and linked the source code for your on-demand UDF, you can activate the function in the Execute On Demand panel in FLUENT. See Section 8.1.3 for more details.

4.2.4 DEFINE_RW_FILE 功能和使用方法的介绍

你可以使用DEFINE_RW_FILE macro to define customized information that you want to be written to a case or data file, or read from a case or data file. You can save and restore custom variables of any data types (e.g., integer, real, Boolean, structure) using DEFINE_RW_FILE. It is often useful to save dynamic information (e.g., number of occurrences in conditional sampling) while your solution is being calculated, which is another use of this function. Note that the read order and the write order must be the same when you use this function.

Macro: DEFINE_RW_FILE ( name, fp) Argument types: FILE *fp Function returns: void

There are two arguments to DEFINE_RW_FILE: name and fp. name is the name of the UDF, specified by you. 当你的UDF编译和连接时,你为函数所选择的名字会在FLUENT图形用户界面中变得可见,且可被选择。 fp is a variable that is passed by the FLUENT solver to your UDF.

fp is a pointer to the file to or from which you are writing or reading. A DEFINE_RW_FILE function does not return a value to the solver.

!! Do not use the fwrite macro in DEFINE_RW_FILE functions that are running on Windows platforms. Use fprintf instead. 例子:

The following C source code contains 例子:s of functions that write information to a data file and read it back. These functions are concatenated into a single file that can be executed as interpreted or compiled in FLUENT.

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

/* UDFs that increment a variable, write it to a data file */

/* and read it back in */ /***********************************************************************/

#include \

int kount = 0; /* define global variable kount */

DEFINE_ADJUST(demo_calc, domain) {

kount++;

printf(\}

DEFINE_RW_FILE(writer, fp) {

printf(\

fprintf(fp, \}

DEFINE_RW_FILE(reader, fp) {

printf(\

fscanf(fp, \}

At the top of the listing, the integer kount is defined and initialized to zero. The first function ( demo_calc)ltindexdemo_calc is an ADJUST function that increments the value of kount at each iteration, since the ADJUST function is called once per iteration. (See Section 4.2.1 for more information about ADJUST functions.) The second function ( writer) instructs FLUENT to write the current value of kount to the data file, when the data file is saved. The third function ( reader) instructs FLUENT to read the value of kount from the data file, when the data file is read.

The functions work together as follows. If you run your calculation for, say, 10 iterations ( kount has been incremented to a value of 10) and save the data file, then the current value of kount (10) will be written to your data file. If you read the data back into FLUENT and continue the calculation, kount will start at a value of 10 and will be incremented at each iteration. Note that you can save as many static variables as you want, but you must be sure to read them in the same order in which they are written.

Activating a Read/Write Case or Data File UDF in FLUENT

After you have compiled and linked the source code for your read/write UDF, you can activate the function in the User-Defined Function Hooks panel in FLUENT. See Section 8.1.4 for more details. 4.3 模型指定DEFINE宏

本节所介绍的DEFINE宏用于set parameters for a particular model in FLUENT. Table 4.3.1 provides a quick reference guide to the DEFINE macros, the functions

they are used to define, and the panel where they are activated in FLUENT. Definitions of each DEFINE macro are listed in the udf.h header file. For your convenience, the definitions are also provided in Appendix A.

? ? ? ? ? ? ? ? ? ? ? ? ? ?

DEFINE_DELTAT (Section 4.3.1)

DEFINE_DIFFUSIVITY (Section 4.3.2) DEFINE_HEAT_FLUX (Section 4.3.3) DEFINE_NOX_RATE (Section 4.3.4) DEFINE_PROFILE (Section 4.3.5) DEFINE_PROPERTY(Section 4.3.6)

DEFINE_SCAT_PHASE_FUNC (Section 4.3.7) DEFINE_SOURCE (Section 4.3.8) DEFINE_SR_RATE (Section 4.3.9)

DEFINE_TURB_PREMIX_SOURCE (Section 4.3.10) DEFINE_TURBULENT_VISCOSITY (Section 4.3.11) DEFINE_UDS_FLUX (Section 4.3.12)

DEFINE_UDS_UNSTEADY (Section 4.3.13) DEFINE_VR_RATE (Section 4.3.14)

Table 4.3.1: Quick Reference Guide for Model-Specific DEFINE Macros Variable DEFINE Macro Panel Activated In boundary condition (e.g., Velocity Inlet) boundary condition boundary condition boundary condition boundary condition boundary condition boundary condition boundary condition boundary condition boundary condition boundary condition species mass fraction DEFINE_PROFILE velocity at a boundary DEFINE_PROFILE pressure at a boundary DEFINE_PROFILE boundary temperature DEFINE_PROFILE turbulent energy kinetic DEFINE_PROFILE turbulent dissipation DEFINE_PROFILE rate mass source momentum source energy source turbulent k.e. source DEFINE_SOURCE DEFINE_SOURCE DEFINE_SOURCE DEFINE_SOURCE turb. dissipation rate DEFINE_SOURCE source UDS or species mass DEFINE_DIFFUSIVITdiffusivity Y turbulent viscosity heat flux density viscosity mass diffusivity thermal conductivity Materials DEFINE_TURBULENTViscous Model _VISCOSITY DEFINE_HEAT_FLUX boundary condition DEFINE_PROPERTY DEFINE_PROPERTY DEFINE_PROPERTY DEFINE_PROPERTY Materials Materials Materials Materials Materials Materials Materials Materials absorption coefficient DEFINE_PROPERTY scattering coefficient laminar flow speed rate of strain scattering function DEFINE_PROPERTY DEFINE_PROPERTY DEFINE_PROPERTY phase DEFINE_SCAT_PHASMaterials E_FUNC DEFINE_SR_RATE DEFINE_VR_RATE User-Defined Function Hooks User-Defined Function Hooks surface reaction rate volume reaction rate turbulent source scalar flux function scalar function center of motion grid motion premixed DEFINE_TURB_PREMUser-Defined Function IX_SOURCE DEFINE_UDS_FLUX Hooks User-Defined Scalars unsteady DEFINE_UDS_UNSTEUser-Defined Scalars ADY gravity DEFINE_CG_MOTION Dynamic Zones DEFINE_GRID_MOTION Dynamic Zones Dynamic Zones NOx Model Iterate geometry deformation DEFINE_GEOM NOx formation rate time step (for time DEFINE_NOX_RATE DEFINE_DELTAT dependent solutions)

? ? ? ? ? ? ? ? ? ? ? ? ? ?

4.3.1 DEFINE_DELTAT

4.3.2 DEFINE_DIFFUSIVITY 4.3.3 DEFINE_HEAT_FLUX 4.3.4 DEFINE_NOX_RATE 4.3.5 DEFINE_PROFILE 4.3.6 DEFINE_PROPERTY

4.3.7 DEFINE_SCAT_PHASE_FUNC 4.3.8 DEFINE_SOURCE 4.3.9 DEFINE_SR_RATE

4.3.10 DEFINE_TURB_PREMIX_SOURCE 4.3.11 DEFINE_TURBULENT_VISCOSITY 4.3.12 DEFINE_UDS_FLUX

4.3.13 DEFINE_UDS_UNSTEADY 4.3.14 DEFINE_VR_RATE

4.3.1 DEFINE_DELTAT 功能和使用方法的介绍

你可以使用DEFINE_DELTAT宏来控制时间相关问题解的时间步长。This macro can only be used if the adaptive time-stepping method option has been activated in the Iterate panel in FLUENT.

Macro: DEFINE_DELTAT ( name, domain) Argument types: Domain *domain Function returns: real

There are two arguments to DEFINE_DELTAT: name and domain. name is the name of the UDF, specified by you. 当你的UDF编译和连接时,你为函数所选择的名字会在FLUENT图形用户界面中变得可见,且可被选择。 domain is passed by the FLUENT solver to your UDF. Your UDF will need to return the real value of the physical time step to the solver.

例子:

下面的UDF名字为mydeltat, is a simple function that shows how you can use DEFINE_DELTAT to change the value of the time step in a simulation. First, RP_Get_Real is used to get the value of the current simulation time ( flow_time). Then, for the first 0.5 seconds of the calculation, a time step of 0.1 is set. A time step of 0.2 is set for the remainder of the simulation. The time step variable is then returned to the solver. See Section 6.9 for details on RP_Get_Real.

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

/* UDF that changes the time step value for a time-dependent solution */

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

#include \

DEFINE_DELTAT(mydeltat, domain) {

real time_step;

real flow_time = RP_Get_Real(\ if (flow_time < 0.5) time_step = 0.1; else

time_step = 0.2; return time_step; }

Activating an Adaptive Time Step UDF in FLUENT

Once you have compiled and linked the source code for an adaptive time step UDF, you can activate it in the Iterate panel in FLUENT. See Section 8.2.8 for more details.

4.3.2 DEFINE_DIFFUSIVITY 功能和使用方法的介绍

你可以使用DEFINE_DIFFUSIVITY macro to specify the diffusivity for the species transport equations or user-defined scalar (UDS) transport equations.

Macro: DEFINE_DIFFUSIVITY ( name, c, t, i) Argument types: cell_t c Thread *t int i Function returns: real

There are four arguments to DEFINE_DIFFUSIVITY: name, c, and t, and i. 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.

c is an index that identifies a cell within the given thread. t is a pointer to the thread on which the diffusivity function is to be applied. i is an index that identifies the species or user-defined scalar. Your UDF will need to return the real value of diffusivity to the solver.

Note that diffusivity UDFs (defined using DEFINE_DIFFUSIVITY) are called by FLUENT from within a loop on cell threads. Consequently, your UDF will not need to loop over cells in a thread since FLUENT is doing it outside of the function call. Your UDF will be required to compute the diffusivity only for a single cell and return the real value to the solver. 例子:

下面的UDF名字为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 = 0.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 \

DEFINE_DIFFUSIVITY(mean_age_diff, c, t, i) {

return C_R(c,t) * 2.88e-05 + C_MU_EFF(c,t) / 0.7; }

Activating a Diffusivity UDF in FLUENT

Once you have compiled and linked your diffusivity UDF, you can activate it by selecting it as the mass or UDS diffusivity in the Materials panel in FLUENT. See Section 8.2.4 for more details. 4.3.3 DEFINE_HEAT_FLUX 功能和使用方法的介绍

In spite of its name, the DEFINE_HEAT_FLUX macro is not to be used to explicitly set the heat flux along a wall. FLUENT computes the heat flux along a wall based on currently selected models to account for the diffusive and radiative energy fluxes (if any). You must only use a DEFINE_HEAT_FLUX UDF when you want to employ some other heat transfer mechanism that is not currently being modeled. The total heat flux at the wall will be the sum of the currently computed heat flux (based on the activated models) and the heat flux defined by the UDF.

Macro: DEFINE_HEAT_FLUX ( name, f, t, c0, t0, cid, cir) Argument types: face_t f Thread *t cell_t c0 Thread *t0 real cid[] real cir[] Function returns: void

There are seven arguments to DEFINE_HEAT_FLUX: name, f, t, c0, t0, cid, and cir. name is the name of the UDF, specified by you. 当你的UDF编译和连接时,你为函数所选择的名字会在FLUENT图形用户界面中变得可见,且可被选择。 f, t, c0, t0, cir[], and cid[] are variables that are passed by the FLUENT solver to your UDF. f is an index that identifies a wall face within the given thread. t is a pointer to the thread on which the heat flux function is to be applied. c0 is an index that identifies the cell next to the wall, and t0 is a pointer to the adjacent cell's thread.

cid[] and cir[] are real arrays that need to be computed by your UDF. Array cid[] stores the fluid-side diffusive heat transfer coefficients, while array cir[] stores radiative heat transfer coefficients. With these inputs provided to the function, the

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

qid = cid[0] + 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)

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 FLUENT from within a loop over wall faces.

!! 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. 例子:

Section 10.5.2 provides an 例子: of the P-1 radiation model implementation through a user-defined scalar. An 例子: of the usage of the DEFINE_HEAT_FLUX macro is included in that implementation. Activating a Heat Flux UDF in FLUENT

Once you have compiled and linked your heat flux UDF, you can activate it by selecting it in the User-Defined Function Hooks panel in FLUENT. See Section 8.2.2 for more details. 4.3.4 DEFINE_NOX_RATE 功能和使用方法的介绍

你可以使用DEFINE_NOX_RATE macro to calculate NOx production and reduction rates in FLUENT. The UDF rate that you specify is independent of the standard NOx model options. You can deselect the standard NOx options in your simulation, and choose the UDF rate instead.

Macro: DEFINE_NOX_RATE ( name, c, t, NOx) Argument types: cell_t c Thread *t NOx_Parameter *NOx Function returns: void

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

c is an index that identifies a cell within the given thread. t is a pointer to the thread on which the NOx rate is to be applied. NOx is a pointer to the NOx structure. A DEFINE_NOX_RATE function does not return a value. The calculated NOx rates are returned through the NOx structure.

Note that, although the data structure is called NOx, the DEFINE_NOX_RATE macro can be used to calculate the rates of any of the pollutant species (i.e., NO, HCN, and NH 3), depending on which of the pollutant species equations is being solved. 例子:

下面编译的UDF名字为user_nox, computes NOx production and reduction rates based on the forward and reverse rates of NO defined as

(4.3.1)

and

(4.3.2)

where the rate coefficients, which have units of m 3/mol-s, are defined as k 1

=

k -1

=

k 2

=

(4.3.5) (4.3.4) (4.3.3)

k -2 =

O concentration is given by

=

All concentrations in the rate expressions have units of mol/mol 3. /************************************************************/ /* UDF 例子: of User-Defined NOx Rate */ /************************************************************/

#include \

#define SMALL_S 1.e-29

DEFINE_NOX_RATE(user_nox, c, t, NOx) {

real kf1, kr1, kf2, kr2; real o_eq;

real s1, s2, s3, rf, rr;

Rate_Const K_F[2] = {{1.80e8, 0.0, 38370.0}, {1.80e4, 1.0, 4680.0}};

Rate_Const K_R[2] = {{3.80e7, 0.0, 425.0}, {3.80e3, 1.0, 20820.0}};

Rate_Const K_O = {3.664e1, 0.5, 27123.0};

if (NOX_EQN(NOx) != EQ_NO) return;

kf1 = ARRH(NOx, K_F[0]); kr1 = ARRH(NOx, K_R[0]); kf2 = ARRH(NOx, K_F[1]); kr2 = ARRH(NOx, K_R[1]);

(4.3.6)

(4.3.7)

s1 = kf2*MOLECON(NOx, O2);

s3 = s1 + kr1*MOLECON(NOx, NO);

/* determine O concentration (partial equilibrium)*/

o_eq = ARRH(NOx, K_O)*sqrt(MOLECON(NOx, O2));

/* calculate NO rate */ s2 = 2.*o_eq;

/* forward rate... */

rf = s2*(kf1*MOLECON(NOx, N2))*s1/s3; /* reverse rate... */

rr = -s2*kr1*kr2*pow(MOLECON(NOx, NO), 2.0)/s3; /* rates have units mole/m^3/s */ NOX_FRATE(NOx) = rf; NOX_RRATE(NOx) = rr; }

A number of Fluent-provided macros can be used in the calculation of pollutant rate using user-defined functions. The macros listed below are defined in the header file sg_nox.h which is included in the udf.h file. The variable NOx indicates a pointer to the NOx_Parameter structure.

NOX_EQN(NOx) returns the index of the pollutant equation currently being solved. The indices are EQ_NO for NO, EQ_HCN for HCN, and EQ_NH3 for NH 3.

? MOLECON(NOx, SPE) returns the molar concentration of a species specified by SPE, which must be replaced by one of the following identifiers: FUEL, O 2, O, OH, H 2O, N 2, N, CH, CH 2, CH 3, NO, HCN, NH 3. Identifier FUEL represents the fuel species as specified in the Fuel Species drop-down list under Prompt NO Parameters in the NOx Model panel.

? NULLIDX(NOx, SPE) returns TRUE if the species specified by SPE does not exist in the FLUENT case (i.e., in the Species panel).

? ARRH(NOx, K) returns the Arrhenius rate calculated from the constants specified by K. K is defined using the Rate_Const data type and has three elements - A, B, and C. The Arrhenius rate is given in the form of

?

where T is the temperature.

?

NOX_FRATE(NOx) is used to return the production rate of the pollutant species being solved.

?

NOX_RRATE(NOx) is used to return the reduction rate of the pollutant species being solved.

Activating a NOx Rate UDF in FLUENT

Once you have compiled and linked your NOx rate UDF, you can activate it by selecting it in the NOx Model panel in FLUENT. See Section 8.2.3 for more details. 4.3.5 DEFINE_PROFILE 功能和使用方法的介绍

你可以使用DEFINE_PROFILE macro to define a custom boundary profile that varies as a function of spatial coordinates or time. Some of the variables you can customize at a boundary are

? ? ? ? ?

velocity, pressure, temperature, turbulent kinetic energy, turbulent dissipation rate

volume fraction (multiphase)

species mass fraction (species transport) wall thermal conditions wall stress conditions

Macro: DEFINE_PROFILE ( name, t, i) Argument types: Thread *t

There are three arguments to DEFINE_PROFILE: name, t, and i. name is the name of the UDF, specified by you. 当你的UDF编译和连接时,你为函数所选择的名字会在FLUENT图形用户界面中变得可见,且可被选择。 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 boundary condition is to be applied. i is an index that identifies the variable that is to be defined. i is set when you associate (hook) the UDF with a variable in a boundary condition panel through the graphical user interface. This index is subsequently passed to your UDF by the FLUENT solver, so that your function knows which variable to operate on.

int i Function returns: void 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 Section 6.26 of the User's Guide for more information on fixing values in a cell zone boundary condition. The arguments of the macro will change accordingly. There are three arguments to DEFINE_PROFILE for a cell zone: name, thread, and np. name is the name of the UDF, specified by you. thread and np are variables that are passed by the FLUENT solver to your UDF.

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

F_PROFILE is typically used along with DEFINE_PROFILE, and is a predefined macro provided by Fluent. F_PROFILE stores a boundary condition in memory for a given face and index and is nested within the face loop in the 例子:s 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 Section 6.4 for a description of F_PROFILE. 例子: 1

下面的UDF名字为pressure_profile, generates a parabolic pressure profile according to the equation

Note that this UDF assumes that the grid is generated such that the origin is at the geometric center of the boundary zone to which the UDF is to be applied. y is 0.0 at the center of the inlet and extends to at the top and bottom of the inlet. This function can be executed as an interpreted or compiled UDF in FLUENT. /***********************************************************************/

/* UDF for specifying steady-state parabolic pressure profile boundary */

/* profile for a turbine vane */ /***********************************************************************/

#include \

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 y 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 panel) to set the pressure face value in memory. 例子: 2

在下面的例子中,:, DEFINE_PROFILE is used to generate profiles for the x 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 which can be executed as interpreted or compiled in FLUENT. The 1/7th power law is used to specify the x velocity component:

A fully-developed profile occurs when is one-half the duct height. In this 例子:, the mean x 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 Karman constant = 0.41.)

The friction velocity and wall shear take the forms

and 0.085 . ( is the von

The friction factor is estimated from the Blasius equation:

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

/* Concatenated UDFs for fully-developed turbulent inlet profiles */

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

#include \

#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) }

例子: 3

在下面的例子中:, 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. See Section 6.26 of the User's Guide for more information on fixing variables.

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

/* Concatenated UDFs for simulating an impeller using fixed velocity */

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

#include \

#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, thread, np) {

cell_t c;

real x[ND_ND]; real r;

begin_c_loop (c,thread) {

/* centroid is defined to specify position dependent profiles*/

C_CENTROID(x,c,thread); r =x[1];

F_PROFILE(c,thread,np) =

ua1+(ua2*r)+(ua3*r*r)+(ua4*r*r*r)+(ua5*r*r*r*r); }

end_c_loop (c,thread) }

DEFINE_PROFILE(fixed_v, thread, np) {

cell_t c;

real x[ND_ND]; real r;

begin_c_loop (c,thread) {

/* centroid is defined to specify position dependent profiles*/

C_CENTROID(x,c,thread); r =x[1];

F_PROFILE(c,thread,np) =

va1+(va2*r)+(va3*r*r)+(va4*r*r*r)+(va5*r*r*r*r); }

end_c_loop (c,thread) }

DEFINE_PROFILE(fixed_ke, thread, np) {

cell_t c;

real x[ND_ND]; real r;

begin_c_loop (c,thread) {

/* centroid is defined to specify position dependent profiles*/

C_CENTROID(x,c,thread); r =x[1];

F_PROFILE(c,thread,np) =

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,thread) }

Activating a Profile UDF in FLUENT

Once you have compiled and linked your profile UDF, you can activate it by selecting it in the appropriate boundary condition panel in FLUENT (e.g., the Velocity Inlet panel). See Section 8.2.1 for more details.

4.3.6 DEFINE_PROPERTY 功能和使用方法的介绍

你可以使用DEFINE_PROPERTY macro to specify a custom material property in FLUENT. Some of the properties you can customize are

? ? ? ? ? ? ? ?

density (as a function of temperature only) viscosity

thermal conductivity mass diffusivity

absorption and scattering coefficients laminar flow speed rate of strain

particle or droplet diameter (multiphase mixture model)

!! UDFs cannot be used to define specific heat properties; specific heat data can only be accessed, not modified in FLUENT.

Macro: DEFINE_PROPERTY ( name, c, t) Argument types: cell_t c Thread *t Function returns: real

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

c is an index that identifies a cell within the given thread. t is a pointer to the thread on which the material property definition is to be applied.

Note that like source term UDFs, property UDFs (defined using DEFINE_PROPERTY) are called by FLUENT from within a loop on cell threads. The solver passes to a DEFINE_PROPERTY UDF all of the necessary variables it needs 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 FLUENT is already doing it. Your UDF will only be required to compute the property for a single cell and return the real value to the solver, as shown in the 例子: below. 例子:

下面的UDF名字为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 ( T > 288 K) fluid has a molecular value for the liquid (5.5 kg/m-s), while the viscosity for the cooler region ( T < 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:

(4.3.8)

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 UDF can be executed as interpreted or compiled in FLUENT.

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

/* UDF that simulates solidification by specifying a temperature- */

/* dependent viscosity property */ /*********************************************************************/

#include \

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. Activating a Material Property UDF in FLUENT

Once you have compiled and linked your property UDF, you can activate it by selecting it in the Materials panel in FLUENT. See Section 8.2.4 for more details. 4.3.7 DEFINE_SCAT_PHASE_FUNC 功能和使用方法的介绍

你可以使用DEFINE_SCAT_PHASE_FUNC macro to define the radiation scattering phase function for the discrete ordinates model. The function computes two values: the fraction of radiation energy scattered from direction i to direction j, and the forward scattering factor.

Macro: DEFINE_SCAT_PHASE_FUNC ( name, cosine, f ) Argument types: real cosine

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

real *f Function returns: real cosine is a real variable that is the cosine of the angle between the two directions. f is a real pointer that points to the location in memory where the real forward scattering factor is stored. The solver computes and stores a scattering matrix for each material by calling this function for each unique pair of discrete ordinates. Your UDF will need to return the fraction of radiation energy scattered from direction i to direction j to the solver, as shown in the 例子: below. The forward scattering factor is stored in the real variable that is referenced by the pointer f. 例子:

在下面的例子中,:, 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. [ 1]. The source code can be executed as interpreted or compiled in FLUENT.

/*******************************************************************/ /* UDFs that implement backward and forward scattering */ /* phase functions as cited by Jendoubi et. al. */

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

#include \

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); }

Activating a Radiation Scattering Phase UDF in FLUENT

Once you have compiled and linked your scattering phase UDF, you can activate it by selecting it in the Materials panel in FLUENT. See Section 8.2.4 for more details. 4.3.8 DEFINE_SOURCE 功能和使用方法的介绍

你可以使用DEFINE_SOURCE macro to define custom source terms for the different types of solved transport equations in FLUENT (except the discrete ordinates radiation model) including:

? ? ? ? ?

continuity momentum k,

energy (also for solid zones) species mass fractions

?

user-defined scalar (UDS) transport

Macro: DEFINE_SOURCE ( name, c, t, dS, eqn) Argument types: cell_t c Thread *t real dS[] int eqn Function returns: real

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

c is the index of a cell on the thread pointed to by t. This is the cell in which the source term is to be applied. Array dS specifies the derivative of the source term with respect to the dependent variable of the transport equation. These derivatives may be used to linearize the source term if they enhance the stability of the solver. To see this, note that the source term can be expressed, in general, as Equation 4.3-10, where is the dependent variable, A is the explicit part of the source term, and implicit part.

is the

(4.3.9)

Specifying a value for B in Equation 4.3-10 can enhance the stability of the solution and help convergence rates due to the increase in diagonal terms on the solution matrix. FLUENT automatically determines if the value of B that is given by the user will aid stability. If it does, then FLUENT will define A as

, and

B as . If not, the source term is handled explicitly. Your UDF will need to return the real value of the total source term 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 0.0. See Section 1.5.1 for a list of the transport

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 功能和使用方法的介绍

本文来源:https://www.bwwdw.com/article/l406.html

Top