admin 管理员组

文章数量: 1086019


2024年4月16日发(作者:phonegap培训)

word格式-可编辑-感谢下载支持

第一章 介绍

本章简要地介绍了用户自定义函数(UDF)及其在Fluent中的用法。在1.1到1.6节中我们会介绍一下

什么是UDF;如何使用UDF,以及为什么要使用UDF,在1.7中将一步步的演示一个UDF例子。

1.1 什么是UDF?

1.2 为什么要使用UDF?

1.3 UDF的局限

1.4 Fluent5到Fluent6 UDF的变化

1.5 UDF基础

1.6 解释和编译UDF的比较

1.7一个step-by-stepUDF例子

1.1什么是UDF?

用户自定义函数,或UDF,是用户自编的程序,它可以动态的连接到Fluent求解器上来提高求解器

性能。用户自定义函数用C语言编写。使用DEFINE宏来定义。UDF中可使用标准C语言的库函数,也

可使用Fluent Inc.提供的预定义宏,通过这些预定义宏,可以获得Fluent求解器得到的数据。

UDF使用时可以被当作解释函数或编译函数。解释函数在运行时读入并解释。而编译UDF则在编

译时被嵌入共享库中并与Fluent连接。解释UDF用起来简单,但是有源代码和速度方面的限制不足。编

译UDF执行起来较快,也没有源代码限制,但设置和使用较为麻烦。

1.2为什么要使用UDF?

一般说来,任何一种软件都不可能满足每一个人的要求,FLUENT也一样,其标准界面及功能并不

能满足每个用户的需要。UDF正是为解决这种问题而来,使用它我们可以编写FLUENT代码来满足不同

用户的特殊需要。当然,FLUENT的UDF并不是什么问题都可以解决的,在下面的章节中我们就会具体

介绍一下FLUENT UDF的具体功能。现在先简要介绍一下UDF的一些功能:

 定制边界条件,定义材料属性,定义表面和体积反应率,定义FLUENT输运方程中的源项,用

户自定义标量输运方程(UDS)中的源项扩散率函数等等。

 在每次迭代的基础上调节计算值

 方案的初始化

 (需要时)UDF的异步执行

 后处理功能的改善

 FLUENT模型的改进(例如离散项模型,多项混合物模型,离散发射辐射模型)

由上可以看出FLUENT UDF并不涉及到各种算法的改善,这不能不说是一个遗憾。当然为了源代码

的保密我们还是可以理解这样的做法的。其实,如果这些代码能够部分开放,哪怕就一点点,我想FLUENT

会像LINUX一样发展更为迅速,使用更为广泛。遗憾的是,从目前来看,这只是一种幻想。什么时候中

国人可以出自己的精品?

1.3 UDF的局限

尽管UDF在FLUENT中有着广泛的用途,但是并非所有的情况都可以使用UDF。UDF并不能访问

所有的变量和FLUENT模型。例如,它不能调节比热值;调节该值需要使用求解器的其它功能。如果您

不知道是否可以用UDF解决某个特定的问题,您可以求助您的技术支持。

word格式-可编辑-感谢下载支持

1.4 Fluent5到Fluent6UDF的变化

如果你有FLUENT5的UDF编程经验,请注意在FLUENT6种的下列变化:

FLUENT6中加入了大量的通用多相模型。When one of these general multiphase models is enabled,

storage must be set aside for the mixture as well as the individual phases. This functionality is

manifested in the code through the use of additional thread and domain data structures. Consequently,

some predefined macros have been added that allow access to data contained within mixture-level and

phase-level domain and thread structures. See Section 3.11 for details on writing UDF for multiphase

applications.

If you have a FLUENT 5 UDF with an external domain declaration that you want to use in FLUENT 6,

then the extern statement must be replaced by a call to the Get_Domain utility and assignment to a

Domain pointer as shown below. The Fluent-provided utility, Get_Domain(1), returns the pointer to the

mixture-level domain. See Section for more details on Get_Domain.

Example

extern Domain *domain;

DEFINE_ON_DEMAND(my_udf)

{

...

}

is to be replaced by

DEFINE_ON_DEMAND(my_udf)

{

Domain *domain;

domain = Get_Domain(1);

...

}

The macro C_VOF accesses volume fraction values from the FLUENT solver. C_VOF(c, pt[i]) has

two arguments, c and pt[i]. c is the cell identifier. pt[i] is the pointer to the corresponding phase-level

thread for the ith phase, where i is the phase_domain_index. For example, C_VOF(c,pt[i]) can be used

to return the volume fraction of the ith phase fluid at cell c. The pointer pt[i] can also be retrieved using

THREAD_SUB_THREAD, discussed in Section , using i as an argument.

For compiled UDF, the makefile called

that was provided in previous FLUENT releases

has been renamed to

2

. See Section for more details.

For multiphase flow problems, you will need to supply your own user-defined scalar flux function


本文标签: 函数 模型 使用 定义 求解