FLUENT UDF 入门级代码及解释

代码源自:ANSYS Fluent Customization Manual 中 8.1. Step-By-Step UDF Example 部分:

代码如下:

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

vprofile.c

UDF for specifying steady-state velocity profile boundary condition

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

#include "udf.h"

DEFINE_PROFILE(inlet_x_velocity, thread, position)/* inlet_x_velocity为自定义功能函数名, */  

{ real x[ND_ND]; /* this will hold the position vector,记录位置坐标 */  

real y, h;

face_t f;

h = 0.016; /* inlet height in m */

begin_f_loop(f,thread)

{ F_CENTROID(x, f, thread);

y = 2.*(x[1]-0.5*h)/h; /* non-dimensional y coordinate */

F_PROFILE(f, thread, position) = 0.1*(1.0-y*y); }

end_f_loop(f, thread) }

1.The constant ND_ND is defined as 2 for RP_2D (ANSYS Fluent 2D) and 3 for RP_3D (ANSYS Fluent 3D). It can be used when you want to build a matrix in 2D and a matrix in 3D. When you use ND_ND, your UDF will work for both 2D and 3D cases, without requiring any modificatio

2.DEFINE_PROFILE:You can use DEFINE_PROFILE to define a custom boundary profile or cell zone condition that varies as a function of spatial coordinates or time. 

用法:

DEFINE_PROFILE (name, t, i)

symbol name  :UDF name

Thread *t        :Pointer to thread on which boundary condition is to be applied.  指向应用于边界条件线程的指针

int i                 :Index that identifies the variable that is to be defined. i is set when you hook the UDF with int i a variable in a boundary conditions dialog box through the graphical user interface. This index is subsequently passed to your UDF by the ANSYS Fluent solver so that your function knows which variable to operate on.i为由ANSYS Fluent定义的索引,由ANSYS Fluent定义在边界条件对话框中DEFINE_PROFILE UDF挂接到一个特定变量(例如压力、温度、速度)上,该索引由ANSYS Fluent解算器传递给UDF,以便函数知道要对哪个变量进行操作。

3.begin_f_loop:ANSYS Fluent has provided you with a face looping macro to loop over all faces in a thread (begin_f_loop...). fluent自带的面循环宏定义。

4.F_CENTROID(x,f,t)F_CENTROID finds the coordinate position of the centroid of the face f and stores the coordinates in the x array. 找到面的质心坐标并保存在x[]矩阵中

5.F_PROFILE(f, t, i):Set Boundary Condition Value用于设置边界条件值:

The arguments of F_PROFILE are f, the index of the face face_t; t, a pointer to the face’s thread t; and i, an integer index to the particular face variable that is to be set. i is defined by ANSYS Fluent when you hook a DEFINE_PROFILE UDF to a particular variable (for example, pressure, temperature, velocity) in a boundary condition dialog box. This index is passed to your UDF by the ANSYS Fluent solver so that the function knows which variable to operate on i为由ANSYS Fluent定义的索引,由ANSYS Fluent定义在边界条件对话框中DEFINE_PROFILE UDF挂接到一个特定变量(例如压力、温度、速度)上,该索引由ANSYS Fluent解算器传递给UDF,以便函数知道要对哪个变量进行操作。(同DEFINE_PROFILE (name, t, i)函数中的i)

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值