1、第五章 使用宏存取FLUENT 解算器变量本章提供了可以存取FLUENT解算器中变量的预定义宏。5.1 介绍5.2 单元宏5.3 面宏5.4 几何图形宏5.5 节点宏5.6 多相宏5.7 DPM宏5.8 NOx宏5.1 IntroductionFluent Inc. has provided you with a set of predefined functions that you can use to access data from the FLUENT solver. These functions are primarily implemented in the code as m
2、acros. The macros listed in this chapter are defined in header files such asmem.h, metric.h, and dpm.h. The udf.h file contains definitions for DEFINE macros,as well as #include directives for most of the solver access macro header files found inthis chapter. Therefore, including udf.h in your sourc
3、e code file will also result in theinclusion of solver access .h files.Some examples of solver data you can access using predefined macros are:_ solution variables and their derivatives (e.g., velocity, temperature, turbulencequantities)_ geometry variables (e.g., coordinates, areas, volumes)_ grid
4、and node variables (e.g., node velocities)_ material property variables (e.g., density, viscosity, conductivity)_ discrete phase model variables5.1 介绍Fluent公司提供了一系列预定义函数来从求解器中读写数据。这些函数以宏的形式存放在代码中。这章的所列出的宏是被定义在扩展名为.h 文件里的。例如mem.h, metric.h, 和dpm.h。在udf.h 文件中包含了宏的定义和这章中所用到的大部分宏文件和它的说明。因此如果在你的原程序中包含了ud
5、f.h文件,那么也就包含了各种的求解器读写文件了。(.h 文件)。下面列出了一些使用预先设计的宏来读写数据类型:溶液变量及它们的组合变量(速度,温度,湍流量等)几何变量(坐标,面积,体积等)网格和节点变量(节点速度等)材料性质变量(密度,粘度,导电性等)分散相模拟变量。For all types of data except specific heat, the word access“ refers to reading and writingdata. In the case of specific heat, however, data can be read but cannot be
6、 modified.In the following sections, each macro is listed with its arguments, argument types, andreturned value. Arguments belong to the following data types:cell_t c cell identifierface_t f face identifierThread *t pointer to a threadThread *pt pointer to an array of phase threadsInt i integer inde
7、xNode *node pointer to a nodeArguments are either inputs to a function, or are outputs. Each macro returns a value,which either is output back to the solver (as an argument), or is available for assignmentin your function.对于除了指定的热量以外的所有数据而言,存取这个词还指读写数据。对于指定的的热量的数据是只能读不能改的。在下面章节中列出了每一个宏的包含的参数,参数的类型和返
8、回值。其中参数属于下面的数据类型。cell_t c 单元格标识符face_t 面积标识符Thread *t 线指示器Thread *pt 象限矩阵指示器Int I 整数Node *node 节点指示器参数既不是方程的输入也不是方程的输出。每一个宏返回一个值,这个值要么作为一个参数以输出值的形式返回求解器,要么是你方程中可用参数。For example, the macro C_Treal temp;temp = C_T(c,t);has two arguments, cell identifier c and thread pointer t. These arguments are pass
9、edfrom the FLUENT solver to the function. C T returns the real value of temperature,which can then be assigned to a variable in your UDF (temp in this example).例如宏C_Treal temp;temp = C_T(c,t);C_T有两个参数,单元标识符C和线指示器t 。这些参数从FLUENT求解器中返回到方程中。C_T返回一个温度的实数值,这个值能够分配到的你的UDF变量中去。(比如这个例子中的temp)C_CENTROID(x,c,t
10、);has three arguments: x, c, and t. In this case the cell identifier c and thread pointert are input arguments, while the array x (the cell centroid) is output to the FLUENTsolver as an argument.C_CENTROID(x,c,t)有三个参数, x,c,t。在这里单元标识符 C和线指示器是输入参数,而矩阵x(单元格的质心)是以参数形式输出到FLUENT 求解器中的。5.2 Cell MacrosThe m
11、acros listed in this section are real variables returned by the solver, and are de_nedon a cell. These cell variables are available in both the segregated and the coupled solvers.Definitions for these cell macros can be found in the referenced header files (e.g., mem.h).5.2 单元格宏这章所列出的宏是由求解器返回的实数变量,并
12、且这些变量都是定义在一个单元格中的。这些单元格变量在单独的或是联合的求解器中都能得到。(segregated and the coupled solvers.)这些单元格宏的定义在相关的扩展名为(.h)的文件中可以得到。(例如 mem.h等)5.2.1 Macros for Accessing Flow VariablesMacros for accessing flow variables in FLUENT are shown in Table 5.2.1. Note that theG, RG, M1, and M2 suffixes that are shown for the cel
13、l temperature macro (C T) canbe applied to all of the solver variable macros listed in Table 5.2.1 with the exception ofcell pressure (C P). These suffixes correspond to gradient vector, reconstruction gradientvector, previous time step, and 2nd previous time step, respectively. In the case of cellp
14、ressure, the gradient vector and components are derived using C DP instead of C P G. Adescription of each suffix and its usage is presented in the sections below.5.2.1 用来读写流体变量的宏。在FLUENT中可以用来读写流体变量的宏在表5.2.1中列出,注意加了_G ,_ RG, _M1, 和_ M2这些下标的单元格温度的宏可以应用于表5.2.1 中的所有求解器的变量中,但是除了单元格压力(C-P)。这些下标分别表示的是矢量梯度,
15、改造的矢量梯度,前一次的步长,和前两次的步长。而对于单元格压力,它的矢量梯度和相应的分量是使用C_DP 得到的而不是C_P_G。每一个下标的描述和用法在下面介绍。表 5.2.1: 在mem.h文件中的流体变量宏名称(参数) 参数类型 返回值C_T(c,t) cell t c, Thread *t 温度C_T_G(c,t) cell t c, Thread *t 温度梯度矢量C_T_G(c,t)i cell t c, Thread *t, int i 温度梯度矢量的分量C_T_RG(c,t) cell t c, Thread *t 改造后的温度梯度矢量C_T_RG(c,t)i cell t c,
16、 Thread *t, int i 改造后的温度梯度矢量的分量 C_T_M1(c,t) cell t c, Thread *t 温度的前一次步长C_T_M2(c,t) cell t c, Thread *t 温度的前二次步长C_P(c,t) cell t c, Thread *t 压力* C_DP in sg mem.hC_DP(c,t) cell t c, Thread *t 压力梯度矢量C_DP(c,t)i cell t c, Thread *t, int I 压力梯度矢量的分量C_U(c,t) cell t c, Thread *t u 方向的速度C _V(c,t) cell t c,
17、Thread *t v方向的速度C_W(c,t) cell t c, Thread *t w方向的速度C_H(c,t) cell t c, Thread *t 焓C_YI(c,t,i) cell t c, Thread *t, int i 物质质量分数C_K(c,t) cell t c, Thread *t 湍流运动能C_D(c,t) cell t c, Thread *t 湍流运动能的分散 速率C_O(c,t) cell t c, Thread *t 确定的分散速率Accessing Gradient (G) Vectors and ComponentsYou can add the the
18、 G suffix to your macro to access the gradient (G) vector of a variablequantity. For example,C_T_G(c,t); /* returns the cell temperature gradient vector. */returns the temperature gradient vector. Note that gradient variables are available onlywhen the equation for that variable is being solved. For
19、 example, if you are defininga source term for energy, your UDF can access the cell temperature gradient (usingC T G), but it cant get access to the x-velocity gradient (using C U G). Therefore, ifyou are setting up a user-defined scalar transport equation, some gradients may not beavailable. This i
20、s because the solver continually removes from memory data that it doesntneed. You can prevent the solver from freeing up memory by issuing the text commandsolve/set/expert, and then answering yes to the question, Keep temporary solvermemory from being freed?. If you do this, all of the gradient data
21、 are retained, butthe calculation requires more memory to run.读写梯度矢量和其分量你可以在你的宏中加入下标_G来得到梯度矢量和它的分量,例如:C_T_G(c,t); /* 返回单元格的温度梯度矢量. */注意只有当已经求解出包含这个变量的方程时才能得到梯度变量。例如如果你定义了一个关于能量的原程序,那么你的UDF可以读写单元格的温度梯度(使用C_ T _G)但是你却不能读写X方向的速度分量(使用C_ U _G)。而且,如果你建立了一个由使用者确定的方式转移方程,那么你就不能得到一部分的梯度了。这是因为求解器不断的移走它不需要的数据。
22、你可以使用下面的方法来阻止存储器释放记忆:发出文本命令save/set/expert ,然后对计算机提出的“是否阻止暂时的求解器记忆释放”这一提问回答“是”。按照这种做法就可以保留所有的梯度数据,但是这种计算需要更多的内存。You can access a component of a gradient vector by specifying it as an argument in thegradient vector call (0 for the x component; 1 for y; and 2 for z). For example,C_T_G(c,t)0; /* return
23、s the x-component of the cell temperature */* gradient vector */returns the x component of the temperature gradient vector. Note that in Table 5.2.1,the gradient and component macros are shown only for temperature but can be extendedto all of the variables except pressure. You must use C DP to acces
24、s the cell pressuregradient vector and components, as shown in Table 5.2.1.在调用梯度矢量时把某一分量作为参数,这样就可以得到梯度分量了,(参数0代表X方向的分量,1代表Y 方向的分量,2 代表Z 方向的分量)例如:C_T_G(c,t)0; /* 返回温度梯度X方向的分量 */注意在表5.2.1中虽然只列出了温度梯度和其分量求解的宏,但是却可以扩展到除了压力以外的所有变量中去,对于压力你只能按照表5.2.1中的方法使用C_DP来得到压力梯度和其分量。Accessing Reconstruction Gradient (R
25、G) Vectors andComponentsIn the same way as the gradient, you can add the RG su_x to your macro to access thereconstruction gradient (RG) vector and components of a variable quantity. By specify-ing the appropriate integer (0 for the x component; 1 for y; and 2 for z) as an argument,you can obtain th
26、e desired vector component. Reconstruction gradients are typicallyused when you want to implement your own interpolation scheme. Reconstruction gra-dient and component macros are shown only for temperature in Table 5.2.1, but canbe extended to all of the variables. Note that RG variables, like gradi
27、ent variables, areavailable only when the equation for that variable is being solved.读写改造过的梯度矢量和其分量和梯度一样的方式,你可以通过加RG的下标在你的宏中来得到梯度向量和其分量。通过使用恰当的整数作为参数来获得想要的矢量分量。(参数0代表X方向的分量,1代表Y方向的分量,2代表Z方向的分量)当你完成你自己的插补计划时可以使用改造过的梯度。改造过的温度梯度和其分量在表5.2.1中列出了,但是可以推广到所有的变量。注意改造过的梯度矢量和梯度矢量一样都只有在梯度方程被求解出来时才可以得到。Accessing
28、 Previous Time StepsThe M1 suffix can be generally applied to the macros in Table 5.2.1 to allow access to the value of the variable at the previous time step (i.e., t - _t). These data may be usefulin unsteady simulations. For example,C_T_M1(c,t); /* returns value of cell temperature at previous ti
29、me step*/returns the value of the cell temperature at the previous time step.The M2 suffix can be generally applied to the macros in Table 5.2.1 to allow access tothe value of the variable at the time step before the previous one (i.e., t - 2_t). Thesedata may be useful in unsteady simulations. Prev
30、ious time step macros are shown onlyfor temperature in Table 5.2.1, but can be extended to all of the variables.读写前一步长下的时间在表5.2.1里的宏中加入下标 _M1就可以得到前一次步长时间下(t-t )的变量的值。得到的这些数据可以在不稳定的模拟中使用。例如:C_T_M1(c,t); /*返回前一步时间下的单元格温度的值 */若在表5.2.1里宏的后面加上下标 M2就可以得到前两次步长下的时间(t-2t)。这些数据可用与不稳定的模拟计算中。在表5.2.1中仅列出了温度的前一次步
31、长的求法,但是可以扩展到其它的变量中去。5.2.2 Macros for Accessing DerivativesThe macros listed in Table 5.2.2 can be used to access velocity derivative variables.Table 5.2.2: Derivative Macros in mem.h5.2.2读写导数的宏在表5.2.2中列出来的宏可以用于读写由速度导数。表5.2.2 名称(参数) 参数类型 返回值C DUDX(c,t) cell t c, Thread *t velocity derivativeC DUDY(c,
32、t) cell t c, Thread *t velocity derivativeC DUDZ(c,t) cell t c, Thread *t velocity derivativeC DVDX(c,t) cell t c, Thread *t velocity derivativeC DVDY(c,t) cell t c, Thread *t velocity derivativeC DVDZ(c,t) cell t c, Thread *t velocity derivativeC DWDX(c,t) cell t c, Thread *t velocity derivativeC D
33、WDY(c,t) cell t c, Thread *t velocity derivativeC DWDZ(c,t) cell t c, Thread *t velocity derivative5.2.3 Macros for Accessing Material PropertiesThe macros listed in Table 5.2.3 can be used to access material property variables.5.2.3存取材料性质的宏在表5.2.3中列出的宏可以用于存取材料的性质。表5.2.3在mem.h中存取材料性质的宏名称(参数) 参数类型 返回
34、值C_FMEAN(c,t) cell t c, Thread *t 第一次混合分数的平均值C_FMEAN2(c,t) cell t c, Thread *t 第一次混合分数的平均值C_FVAR(c,t) cell t c, Thread *t 第一次混合分数变量C_FVAR2(c,t) cell t c, Thread *t 第二次混合分数变量C_PREMIXC(c,t) cell t c, Thread *t 反应过程变量C_LAM FLAME SPEED(c,t) cell t c, Thread *t 层流焰速度C_CRITICAL STRAIN cell t c, Thread *t
35、临界应变速度RATE(c,t)C_ POLLUT(c,t,i) cell t c, Thread *t, int i 第i个污染物质的质量分数C_R(c,t) cell t c, Thread *t 密度C_MU L(c,t) cell t c, Thread *t 层流速度C_MU T(c,t) cell t c, Thread *t 湍流速度C_MU EFF(c,t) cell t c, Thread *t 有效粘度C_K_L(c,t) cell t c, Thread *t 热传导系数C_K_T(c,t) cell t c, Thread *t 湍流热传导系数C_K_ EFF(c,t)
36、cell t c, Thread *t 有效热传导系数C_CP(c,t) cell t c, Thread *t 确定的热量C_RGAS(c,t) cell t c, Thread *t 气体常数C_DIFF L(c,t,i,j) cell t c, Thread *t, int i,int j层流物质的扩散率C_DIFF EFF(c,t,i) cell t c, Thread *t, int i 物质的有效扩散率C_ABS COEFF(c,t) cell t c, Thread *t 吸附系数C_SCAT COEFF(c,t) cell t c, Thread *t 扩散系数C_NUT(c,
37、t) cell t c, Thread *t 湍流速度for Spalart-Allmaras5.2.4 Macros for Accessing User-Defined Scalars and MemoryThe macros listed in Table 5.2.4 can be used to access user-defined scalars and memoryfor cells.Table 5.2.4: User-Defined Scalar and Memory Macros for Cells in mem.hName(Arguments) Argument Types
38、 ReturnsC _UDSI(c,t,i) cell t c, Thread *t, int i user-defined scalar (cell)user-defined scalarC_UDSI M(c,t,i) cell t c, Thread *t, int iprevious time step (cell)user-defined scalarC_UDSI_DIFF(c,t,i) cell t c, Thread *t, int idi_usivity (cell)C_UDMI(c,t,i) cell t c, Thread *t, int i user-defined mem
39、ory (cell)5.2.4用户定义的标量和存储器的宏的读写在表5.2.4中列出的宏可以为单元格读写用户定义的标量和存储器。表5.2.4在mem.h 文件中的可以为单元格读写用户定义的标量和存储器的宏名称(参数) 参数类型 返回值C _UDSI(c,t,i) cell t c, Thread *t, int i 用户定义的标量(单元格)C_UDSI M(c,t,i) cell t c, Thread *t, int i 前一次步长下用户定义的标量(单元格)C_UDSI_DIFF(c,t,i) cell t c, Thread *t, int i 用户定义的标量的分散率(单元格)C_UDMI(
40、c,t,i) cell t c, Thread *t, int i 用户定义的存储器(单元格)5.2.5 Reynolds Stress Model MacrosThe macros listed in Table 5.2.5 can be used to access variables for the Reynolds stressturbulence model.Name(Arguments) Argument Types ReturnsC RUU(c,t) cell t c, Thread *t uu Reynolds stressC RVV(c,t) cell t c, Thread
41、 *t vv Reynolds stressC RWW(c,t) cell t c, Thread *t ww Reynolds stressC RUV(c,t) cell t c, Thread *t uv Reynolds stressC RVW(c,t) cell t c, Thread *t vw Reynolds stressC RUW(c,t) cell t c, Thread *t uw Reynolds stress5.2.5雷诺兹压力模型宏在表5.2.5中列出了可以给雷诺兹压力模型读写变量的宏表5.2.2在metric.h中的RSM宏名字(参数) 参数类型 返回值C RUU(
42、c,t) cell t c, Thread *t uu 雷诺兹压力C RVV(c,t) cell t c, Thread *t vv 雷诺兹压力C RWW(c,t) cell t c, Thread *t ww 雷诺兹压力C RUV(c,t) cell t c, Thread *t uv雷诺兹压力 sC RVW(c,t) cell t c, Thread *t vw 雷诺兹压力C RUW(c,t) cell t c, Thread *t uw 雷诺兹压力5.3 Face MacrosThe macros listed in this section are defined at the bou
43、ndary face of a cell and returnreal variables from the solver. The face variables are available in the segregated solveronly. Definitions for these face macros can be found in the referenced header file (e.g.,mem.h).5.3表面宏在这节中列出的宏是在单元格的边界面上定义的并且从求解器中返回一个真值。表面宏仅可在偏析求解器中用。这些表面宏的定义可以在相关的(.h)文件中找到。(如mem
44、.h等)5.3.1 Macros for Accessing Flow VariablesThe macros listed in Table 5.3.1, access flow variables at a boundary face. Note that thedirection of the flux determined by F_FLUX points out of the domain if the face is on theboundary.Table 5.3.1: Macros for Accessing Flow Variables in mem.hName(Argume
45、nts) Argument Types ReturnsF R(f,t) face t f, Thread *t, densityF P(f,t) face t f, Thread *t, pressureF U(f,t) face t f, Thread *t, u velocityF V(f,t) face t f, Thread *t, v velocityF W(f,t) face t f, Thread *t, w velocityF T(f,t) face t f, Thread *t, temperatureF H(f,t) face t f, Thread *t, enthalp
46、yF K(f t) face t f, Thread *t, turbulent kinetic energyF D(f,t) face t f, Thread *t, turbulent kinetic energydissipation rateF YI(f,t,i) face t f, Thread *t, int i species mass fractionF FLUX(f,t) face t f, Thread *t mass ow rate througha boundary face5.3.1读写流体变量的宏在表5.3.1中列出的宏可以在边界面读写流体变量。注意如果表面在边界上
47、那么流体的方向是由F_FLUX决定的点指向外围空间的。表5.3.1在mem.h 中的流体变量读写的宏名称(参数) 参数类型 返回值F_R(f,t) face t f, Thread *t, 密度F_P(f,t) face t f, Thread *t, 压力F_U(f,t) face t f, Thread *t, u方向的速度F_V(f,t) face t f, Thread *t, v 方向的速度F_W(f,t) face t f, Thread *t, w方向的速度F_T(f,t) face t f, Thread *t, 温度F_H(f,t) face t f, Thread *t,
48、焓F_K(f t) face t f, Thread *t, 湍流运动能F_D(f,t) face t f, Thread *t, 湍流运动能的分散速率F_YI(f,t,i) face t f, Thread *t, int i 物质的质量分数F_FLUX(f,t) face t f, Thread *t 通过边界表面的质量流速5.3.2 Macros for Accessing User-Defined Scalars and MemoryThe macros listed in Table 5.3.2 can be used to access user-defined scalars a
49、nd memoryfor faces.Name(Arguments) Argument Types ReturnsF_ UDSI(f,t,i) face t f, Thread *t, int i user-de_ned scalar (face)F_UDMI(f,t,i) face t f, Thread *t, int i user-de_ned memory (face)5.3.2读写用户定义的标量和存储器的宏在表5.3.2中列出的宏可以用于给表面读写用户定义的标量和存储器的宏名称(参数) 参数类型 返回值F_UDSI(f,t,i) face t f, Thread *t, int i 用户确定的标量(表面)F_UDMI(f,t,i) face t f, Thread *t, int i 用户定义的存储器(表面)5.3.3 Miscellaneous Face Variable MacrosAdditional face variable macros are listed in Table 5.3.3.Table 5.3.3: Miscellaneous Face Variable MacrosName(Arguments) Argument Types Retu