FLUENT udf中文资料ch4(2)

2019-04-17 15:28

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


FLUENT udf中文资料ch4(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:反洗钱2017多选题

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

马上注册会员

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