fluent UDF第四章 DEFINE宏
更新时间:2023-03-10 17:40:01 阅读量: 教育文库 文档下载
- fluent流体仿真软件推荐度:
- 相关推荐
第四章 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 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 boundary condition boundary condition boundary condition boundary condition boundary condition boundary condition boundary condition Materials 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 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 Materials User-Defined Function Hooks User-Defined Function Hooks absorption coefficient DEFINE_PROPERTY scattering coefficient laminar flow speed rate of strain scattering function DEFINE_PROPERTY DEFINE_PROPERTY DEFINE_PROPERTY phase DEFINE_SCAT_PHASE_FUNC DEFINE_SR_RATE DEFINE_VR_RATE surface reaction rate volume reaction rate turbulent source scalar flux function scalar function premixed DEFINE_TURB_PREMUser-Defined Function IX_SOURCE DEFINE_UDS_FLUX Hooks User-Defined Scalars unsteady DEFINE_UDS_UNSTEUser-Defined Scalars ADY
center of motion grid motion 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 dependent solutions)
DEFINE_NOX_RATE DEFINE_DELTAT ? ? ? ? ? ? ? ? ? ? ? ? ? ?
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
=
(4.3.3)
k -1 =
k 2 =
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]);
(4.3.4)
(4.3.5)
(4.3.6)
(4.3.7)
kr2 = ARRH(NOx, K_R[1]);
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 int i Function returns: void
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.
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 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 \
#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
288 K), the viscosity follows a linear profile
kg/m-s). In the intermediate temperature range (286 K 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 real *f Function returns: real
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. 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 dependent variable, A is the explicit part of the source term, and
is the implicit part.
(4.3.9) is the
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 variable that is used to derive the
term ( dS[eqn]).
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 功能和使用方法的介绍
你可以使用DEFINE_TURB_PREMIX_SOURCE macro to customize the turbulent flame speed and source term in the premixed combustion model (see Chapter 15 of the User's Guide) and the partially premixed combustion model (see Chapter 16).
Macro: DEFINE_TURB_PREMIX_SOURCE ( name, c, t, turb_flame_speed, source) Argument types: cell_t c Thread *t real *turb_flame_speed real *source Function returns: void
There are five arguments to DEFINE_TURB_PREMIX_SOURCE: name, c, t, turb_flame_speed, and source. name is the name of the UDF, specified by you. 当你的UDF编译和连接时,你为函数所选择的名字会在FLUENT图形用户界面中变得可见,且可被选择。 c, t, turb_flame_speed, and source are variables that are passed by the FLUENT solver to your UDF.
t is a pointer to the thread on which the turbulent premixed source term is to be applied. c is an index that identifies a cell within the given thread. turb_flame_speed is a real pointer to the turbulent flame speed, and source is a real pointer to the reaction progress source term.
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. This is demonstrated in the 例子: below. 例子:
下面的UDF名字为turb_flame_src, specifies a custom turbulent flame speed and source term in the premixed combustion model. It can be executed as a compiled UDF in FLUENT.
In the standard premixed combustion model in FLUENT, the mean reaction rate of the progress variable (that is, the source term) is modeled as
(4.3.10)
where c is the mean reaction progress variable, is the density, and U t is the turbulent flame speed.
In the UDF 例子:, the turbulent flame speed is modeled as
(4.3.11)
where U l is the laminar flame speed and u' is the turbulent fluctuation. Note that the partially premixed combustion model is assumed to be enabled (see Chapter 16 of the User's Guide), so that the unburned density and laminar flame speed are available as polynomials. See Chapter 6 for details on the NULLP, THREAD_STORAGE, and SV_VARS utilities.
/*******************************************************************/ /* UDF that specifies a custom turbulent flame speed and source */
/* for the premixed combustion model */
/*******************************************************************/
#include \
#include \ */
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, DV[ND_ND];
ul = Ul_par_premix(C_FMEAN(c,t)); rho_u = rho_par_premix(C_FMEAN(c,t));
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; }
Activating a Turbulent Premixed Source UDF in FLUENT
Once you have compiled and linked the source code for a custom turbulent premixed source UDF, you can activate it in the User-Defined Function Hooks panel in FLUENT. See Section 8.2.5 for more details. 4.3.11 DEFINE_TURBULENT_VISCOSITY 功能和使用方法的介绍
你可以使用DEFINE_TURBULENT_VISOCITY macro to define a custom turbulent viscosity for the Spalart-Allmaras, k- , k- , and LES turbulence models.
Macro:
DEFINE_TURBULENT_VISCOSITY ( name, c, t)
Argument types: cell_t c
Thread *t
Function returns: real
There are three arguments to DEFINE_TURBULENT_VISCOSITY: 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. t is a pointer to the thread on which the turbulent viscosity is to be applied. c is an index that identifies a cell within the given thread. Your UDF will need to return the real value of the turbulent viscosity to the solver, as shown in the 例子: below. Note that the value of M_keCmu in the 例子: is defined through the graphical user interface, but made accessible to all UDFs. 例子:
下面的UDF名字为user_mu_t, defines a custom turbulent viscosity for the standard k- This function can be executed as an interpreted or compiled UDF in FLUENT. /********************************************************************/ /* UDF that specifies a custom turbulent viscosity for standard */
/* k-epsilon formulation using DEFINE_TURBULENT_VISCOSITY */ /********************************************************************/
#include \
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 = M_keCmu*rho*SQR(k)/d;
return mu_t;
turbulence model.
}
Activating a Turbulent Viscosity UDF in FLUENT
Once you have compiled and linked the source code for a custom turbulent viscosity UDF, you can activate it in the Viscous Model panel in FLUENT. See Section 8.2.9 for more details. 4.3.12 DEFINE_UDS_FLUX 功能和使用方法的介绍
你可以使用DEFINE_UDS_FLUX macro when you want to customize how the advective flux term is computed in your user-defined scalar (UDS) transport equation. Details on setting up and solving UDS transport equations are provided in Chapter 9.
Macro: DEFINE_UDS_FLUX ( name, f, t, i) Argument types: face_t f Thread *t int i Function returns: real
There are four arguments to DEFINE_UDS_FLUX: name, f, t, and i. name is the name of the UDF, specified by you. 当你的UDF编译和连接时,你为函数所选择的名字会在FLUENT图形用户界面中变得可见,且可被选择。 f, 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 user-defined scalar flux is to be applied. f is an index that identifies a face within the given thread. i is an index that identifies the user-defined scalar. Your UDF will need to return the real value of the mass flow rate through the given face, as shown in the 例子: below. The advection term in the differential transport equation has the following most general form:
(4.3.12)
where is the user-defined scalar conservation quantity and is a vector field. In the default advection term,
is, by default, the product of the scalar density and the velocity vector:
(4.3.13)
To define the advection term in Equation 4.3-13 using DEFINE_UDS_FLUX, your UDF needs to return the scalar value
to FLUENT, where
is the same as defined in Equation 4.3-13 and is the face normal
vector of the face.
You will need to compute in your UDF using, for 例子:, predefined macros for velocity vector and scalar
density that Fluent has provided (see Chapter 6 for more details) or using your own prescription. The first case is illustrated in the sample C source code, shown below.
!! Note that if more than one scalar is being solved, you can use a conditional if statement in your UDF to define a different flux function for each i. i = 0 is associated with scalar-0 (the first scalar equation being solved).
!! Note also that must have units of mass flow rate in SI (i.e., kg/s).
/*********************************************************************/ /* sample C source code that computes dot product of psi and A */ /* Note that this is not a complete C function */
/*********************************************************************/
real NV_VEC(psi), NV_VEC(A); /* declaring vectors psi and A */ NV_D(psi, =, F_U(f,t), F_V(f,t), F_W(f,t)); /* defining psi in */
/* terms of velocity field */ NV_S(psi, *=, F_R(f,t)) /* multiplying density to get psi vector */
F_AREA(A, f, t) /* face normal vector returned from F_AREA */ return NV_DOT(psi, A); /* dot product of the two returned */
Additionally, since most quantities in FLUENT are not allocated in memory for interior faces, only for boundary faces (e.g., wall zones), your UDF will also need to calculate interior face values from the cell values
of adjacent cells. This is most easily done using the arithmetic mean method. Vector arithmetic can be coded in C using the NV_ and ND_ macros that Fluent has provided (see Chapter 6 for more details).
Note that if you had to implement the default advection term in a UDF without the fluid density in the definition of
(see above), you could simply put the following line in your DEFINE_UDS_FLUX UDF:
return F_FLUX(f,t) / rho;
where the denominator can be determined by averaging the adjacent cell's density values C_R(F_C0(f,t),F_C0_THREAD(f,t)) and C_R(F_C1(f,t),F_C1_THREAD(f,t)). 例子:
下面的UDF名字为my_uds_flux, returns the mass flow rate through the given face. This value is usually available within FLUENT through the F_FLUX(f,t) macro. The flux is positive when it goes from cell c0 to cell c1. The face flux normal vector always points from c0 to c1. Note that the face area normal vector (returned by F_AREA also points outwards (out of the domain) for boundary faces. The UDF can be executed as a compiled UDF in FLUENT.
/**********************************************************************/ /* UDF that implements a simplified advective term in the */ /* scalar transport equation */
/**********************************************************************/
#include \
DEFINE_UDS_FLUX(my_uds_flux, f, t, i) {
Thread *t0, *t1 = NULL; cell_t c0, c1 = -1;
real NV_VEC(psi_vec), NV_VEC(A);
/* neighboring cells of face f, and their (corresponding) threads */
t0 = F_C0_THREAD(f,t); c0 = F_C0(f,t);
if (NULL != F_C1_THREAD(f,t))
/* Alternative: if (! BOUNDARY_FACE_THREAD_P(t)) */ {
t1 = F_C1_THREAD(f,t); c1 = F_C1(f,t); } else {
t1 = NULL;
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) {
/*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 */ }
else if (!strcmp(r->name, \ {
/* Reaction 2 */ } else {
/* CX_Message(\ }
/* CX_Message(\ }
Activating a Volumetric Reaction Rate UDF in FLUENT
Once you have compiled and linked the source code for a custom volumetric 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.4 Multiphase DEFINE Macros
The following DEFINE macros are used only for multiphase applications. Table 4.4.1 provides a quick reference guide to the DEFINE macros, the functions they are used to define, and the panels 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_CAVITATION_RATE (Section 4.4.1) ? DEFINE_EXCHANGE_PROPERTY (Section 4.4.2)
? DEFINE_VECTOR_EXCHANGE_PROPERTY (Section 4.4.3)
?
Table 4.4.1: Quick Reference Guide for Multiphase DEFINE Macros Function DEFINE Macro Panel Activated In cavitation rate DEFINE_CAVITATION_RATE drag coefficient DEFINE_EXCHANGE_PROPERTY lift coefficient DEFINE_EXCHANGE_PROPERTY slip velocity
User-Defined Function Hooks Phase Interaction Phase Interaction DEFINE_VECTOR_EXCHANGE_PROPERTY Phase Interaction 4.4.1 DEFINE_CAVITATION_RATE ? 4.4.2 DEFINE_EXCHANGE_PROPERTY
? 4.4.3 DEFINE_VECTOR_EXCHANGE_PROPERTY
?
4.4.1 DEFINE_CAVITATION_RATE 功能和使用方法的介绍
你可以使用DEFINE_CAVITATION_RATE macro to model the creation of vapor due to pressure tension in a multiphase flow.
Macro: DEFINE_CAVITATION_RATE ( name, c, t, p, rhoV, rhoL, vofV, p_v, n_b, m_dot) Argument types: cell_t c Thread *t real *p real *rhoV real *rhoL real *vofV real *p_v real *n_b real *m_dot Function returns: void
There are ten arguments to DEFINE_CAVITATION_RATE: name, c, t, p, rhoV, rhoL, vofV, p_v, n_b, and m_dot. name is the name of the UDF, specified by you. 当你的UDF编译和连接时,你为函数所选择的名字会在FLUENT图形用户界面中变得可见,且可被选择。 c, t, p, rhoV, rhoL, vofV, p_v, n_b, and m_dot are variables that are passed by the FLUENT solver to your UDF.
t is a pointer to the mixture-level thread. c is the index of a cell on the thread pointed to by t. The remaining arguments are real pointers to the following data: shared pressure ( p), vapor density ( rhoV), liquid density ( rhoL), vapor volume fraction ( vofV), vaporization pressure ( p_v), number of bubbles per unit volume ( n_b), and rate of vapor formation ( m_dot) Your UDF will need to set the value referenced by the real pointer m_dot, to the cavitation rate. 例子:
下面的UDF名字为cavitation_rate, is an 例子: of how to calculate the mass transfer between the liquid and vapor phases (cavitation rate) in a multiphase mixture. The function can be executed as an interpreted or compiled UDF.
/***********************************************************************/ /* UDF that computes the cavitation rate */
/***********************************************************************/
#include \
#define MIN_VOF 1.e-5
#define MAX_VOF 0.999999
DEFINE_CAVITATION_RATE(cavitation_rate, c, t, p,
rhoV, rhoL, vofV, p_v, n_b, m_dot) {
real p_vapor = *p_v; real n_bubbles = *n_b; real dp, vofM, radV;
dp = p_vapor - ABS_P( p[c], op_pres );
vofM = MIN(MAX(MIN_VOF, vofV[c]),MAX_VOF);
radV = pow(vofM/((1.-vofM)*4./3.*M_PI*n_bubbles), 1./3.);
if (dp>0.)
*m_dot = (1.-vofV[c]) * n_bubbles * 4. * M_PI *
radV * radV/(1.+n_bubbles*4./3.*M_PI*radV*radV*radV) * sqrt(2.*ABS(dp)/(3.*rhoL[c])); else {
*m_dot = - (1.-vofV[c]) * n_bubbles * 4. *M_PI *
radV*radV/(1.+n_bubbles*4./3.*M_PI*radV*radV*radV) * sqrt(2.*ABS(dp)/(3.*rhoL[c])); if (vofV[c] <= MIN_VOF) *m_dot=0.; } }
Activating a Cavitation Rate UDF in FLUENT
Once you have compiled and linked the source code for a custom cavitation rate UDF, you can activate it in the User-Defined Function Hooks panel in FLUENT. See Section 8.3.1 for more details. 4.4.2 DEFINE_EXCHANGE_PROPERTY 功能和使用方法的介绍
你可以使用DEFINE_EXCHANGE_PROPERTY macro to specify custom lift and drag coefficients for the multiphase Eulerian model.
Macro: DEFINE_EXCHANGE_PROPERTY ( name, c, mixture_thread, second_column_phase_index, first_column_phase_index) Argument types: cell_t c Thread *mixture_thread int second_column_phase_index int first_column_phase_index Function returns: real
There are five arguments to DEFINE_EXCHANGE_PROPERTY: name, c, mixture_thread, second_column_phase_index, and first_column_phase_index. name is the name of the UDF, specified by you. 当你的UDF编译和连接时,你为函数所选择的名字会在FLUENT图形用户界面中变得可见,且可被选择。 c, mixture_thread, second_column_phase_index, and first_column_phase_index are variables that are passed by the FLUENT solver to your UDF.
mixture_thread is a pointer to the mixture-level thread. c is the index of a cell on the thread pointed to by mixture_thread. first_column_phase_index and second_column_ phase_index are integer identifiers corresponding to the pair of phases in your multiphase flow that you are specifying a slip velocity for. The identifiers correspond to the phases that are selected in the Phase Interaction panel in the graphical user interface. An index of 0 corresponds to the primary phase, and is incremented by one for each secondary phase. Your UDF will need to return the real value of the lift or drag coefficient to the FLUENT solver. 例子:
下面的UDF名字为custom_drag, can be used to customize the default Syamlal drag law in FLUENT. The default drag law uses 0.8 (for void <=0.85) and 2.65 (void >0.85) for bfac. This results in a minimum fluid velocity of 25 cm/s. The UDF modifies the drag law to result in a minimum fluid velocity of 8 cm/s, using 0.28 and 9.07 for the bfac parameters.
/***************************************************************/ /* UDF for customizing the default Syamlal drag law in Fluent */
/***************************************************************/
#include \
#define pi 4.*atan(1.) #define diam2 3.e-4
DEFINE_EXCHANGE_PROPERTY(custom_drag, cell, mix_thread, s_col, f_col) {
Thread *thread_g, *thread_s;
real x_vel_g, x_vel_s, y_vel_g, y_vel_s, abs_v, slip_x, slip_y, rho_g, rho_s, mu_g, reyp, afac,
bfac, void_g, vfac, fdrgs, taup, k_g_s;
/* find the threads for the gas (primary) */ /* and solids (secondary phases) */
thread_g = THREAD_SUB_THREAD(mix_thread, s_col);/* gas phase */ thread_s = THREAD_SUB_THREAD(mix_thread, f_col);/* solid phase*/
/* find phase velocities and properties*/
x_vel_g = C_U(cell, thread_g); y_vel_g = C_V(cell, thread_g);
x_vel_s = C_U(cell, thread_s); y_vel_s = C_V(cell, thread_s);
slip_x = x_vel_g - x_vel_s; slip_y = y_vel_g - y_vel_s;
rho_g = C_R(cell, thread_g); rho_s = C_R(cell, thread_s);
mu_g = C_MU_L(cell, thread_g);
/*compute slip*/
abs_v = sqrt(slip_x*slip_x + slip_y*slip_y);
/*compute reynolds number*/
reyp = rho_g*abs_v*diam2/mu_g;
/* compute particle relaxation time */
taup = rho_s*diam2*diam2/18./mu_g;
void_g = C_VOF(cell, thread_g);/* gas vol frac*/
/*compute drag and return drag coeff, k_g_s*/
afac = pow(void_g,4.14);
if(void_g<=0.85)
bfac = 0.281632*pow(void_g, 1.28); else
bfac = pow(void_g, 9.076960);
vfac = 0.5*(afac-0.06*reyp+sqrt(0.0036*reyp*reyp+0.12*reyp*(2.*bfac- afac)+afac*afac)); fdrgs = void_g*(pow((0.63*sqrt(reyp)/
vfac+4.8*sqrt(vfac)/vfac),2))/24.0;
正在阅读:
南大物化选择题+答案07-11
美丽嘉兴我寻访作文800字06-27
9号区间盾构始发应急救援预案演练方案11-24
工程质量监理是监理工作的重点05-29
2014人大计硕士考研复试题及备考经验08-12
利用扫描仪得到文字信息的方法 - 图文05-24
汇编语言习题(2)12-10
书香伴我成长作文1000字06-15
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- 第四章
- fluent
- DEFINE
- UDF
- 药理学习题集(综合,含答案)
- 浅析书法艺术在包装设计中的应用
- 最高人民法院审理旅游纠纷案件司法解释理解与适用
- 浅谈中国传统文化对我们现实生活的指导意义
- 江西省农民专业合作社项目申报书
- 第八章 组合变形
- 焊接技术的发展
- 电机车司机安全知识考试试卷
- 《单片机原理及应用》黄友锐主编课后习题答案- 副本
- 永川区青峰小学2014-2015学年教师校本研训项目实施方案
- 财务会计天津大学作业答案
- 关于湘鄂川黔革命根据地的调查报告 - 图文
- 材料力学复习提纲
- 湛师新闻伦理学考试复习提要
- 设计心理学在可爱文化方面的研究
- 满堂支架方案(附计算书)
- 关于我省推动文旅融合发展的调研报告
- 塑料衬里施工方案 - 图文
- 2018-2019学年苏教版六年级语文下册期末试卷(含答案)
- 2004级语言学期末考试题A卷