资源预览内容
第1页 / 共33页
第2页 / 共33页
第3页 / 共33页
第4页 / 共33页
第5页 / 共33页
第6页 / 共33页
第7页 / 共33页
第8页 / 共33页
第9页 / 共33页
第10页 / 共33页
亲,该文档总共33页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
计算流体力学软件Fluent培训 UDF基础,概要,FLUENT UDF简介 FLUENT 数据结构和宏 两个例子 UDF 支持,简介,什么是UDF? UDF 是用户自己用C语言写的一个函数,可以和FLUENT动态链接 标准C 函数 三角函数,指数,控制块,Do循环,文件读入/输出等 预定义宏 允许获得流场变量,材料属性,单元几何信息及其他 为什么使用 UDFs? 标准的界面不能编程模拟所有需求: 定制边界条件,源项,反应速率,材料属性等 定制物理模型 用户提供的模型方程 调整函数 执行和需求函数 初始化,可以使用UDF的位置,UDF 数据结构 (1),在UDF中,体域和面域通过Thread数据类型获得 Thread 是 FLUENT 定义的数据类型 为了在thread (zone)中获得数据,我们需要提供正确的指针,并使用循环宏获得thread中的每个成员(cell or face),Fluid (cell thread or zone),Boundary (face thread or zone),Domain,Cell,UDF 数据结构(2),cell_t 声明了识别单元的整型数据类型 face_t声明了识别面的整型数据类型,TypeVariableMeaning of the declaration Domain*d;d is a pointer to domain thread Thread *t; t is a pointer to thread cell_t c; c is cell thread variable face_t f; f is a face thread variable Node *node;node is a pointer to a node.,UDF中的循环宏,几个经常用到的循环宏为: 对域d中所有单元thread循环:thread_loop_c(ct,d) 对域d中所有面thread循环:thread_loop_f(ft,d) 对thread t中所有单元循环:begin_c_loop(c, t) end_c_loop (c,t) 对面thread中所有面循环begin_f_loop(f, f_thread) end_f_loop(f, f_thread),d: a domain pointer ct, t: a cell thread pointer ft,f_thread: a face thread pointer c: a cell thread variable f: a face thread variable,例子 抛物线分布的速度入口,在二维弯管入口施加抛物线分布的速度 x 方向的速度定义为 需要通过宏获得入口的中心点, 通过另外一个宏赋予速度条件,第1步 准备源代码,DEFINE_PROFILE 宏允许定义x_velocity函数 所有的UDFs 以 DEFINE_ 宏开始 x_velocity 将在 GUI中出现 thread 和 nv DEFINE_PROFILE 宏的参数,分别用来识别域和变量 begin_f_loop宏通过thread指针,对所有的面f循环 F_CENTROID宏赋单元位置向量给 x F_PROFILE 宏在面 f上施加速度分量 代码以文本文件保存inlet_bc.c,#include udf.h DEFINE_PROFILE(x_velocity,thread,nv) float x3; /* an array for the coordinates */ float y; face_t f; /* f is a face thread index */ begin_f_loop(f, thread) F_CENTROID(x,f,thread); y = x1; F_PROFILE(f, thread, nv) = 20.*(1.- y*y/(.0745*.0745); end_f_loop(f, thread) ,Header file “udf.h” must be included at the top of the program by the #include command,第 2 步 解释或编译 UDF,编译UDF 把 UDF 源码加入到源文件列表中 点击 Build进行编译和链接 如果没有错误,点击Load读入库文件 如需要,也可以卸载库文件/define/user-defined/functions/manage,解释UDF 把 UDF 源码加入到源文件列表中 点击 Interpret FLUENT 窗口会出现语言 如果没有错误,点击 Close,Define,User-Defined,Functions,Compiled,Define,User-Defined,Functions,Interpreted,解释 vs. 编译,用户函数可以在运行时读入并解释,也可以编译形成共享库文件并和FLUENT链接 解释 vs. 编译 解释 解释器是占用内存的一个大型程序 通过逐行即时执行代码 优势 不需要第三方编译器 劣势 解释过程慢,且占用内存 编译 UDF 代码一次转换为机器语言 运行效率高. 创建共享库,和其他求解器链接 克服解释器的缺陷 只有在没安装C编译器时使用解释方式,第3 步 在 FLUENT GUI中hook UDF,打开边界条件面板,选择你要施加UDF的边界 把 Constant 改为 udf x_velocity 宏的名字为 DEFINE_PROFILE 中第一个参数,第4步 运行,可以在运行窗口中改变速度分布的更新间隔(默认为1) 这个设置控制了流场多久(迭代或时间步)更新一次 运行 calculation,结果,左图为速度矢量图 右图为入口的速度矢量图,注意速度分布是抛物线型的,其他 UDF Hooks,除了边界条件、源项、材料属性外,UDF 还可用于 初始化 每次初始化执行一次 求解调整 每次迭代执行一次 壁面热流量 以传热系数方式定义流体侧的扩散和辐射热流量 应用于所有壁面 用户定义表面反应或体积反应 Case/ data 文件的读写 读入顺序必须和写出顺序一致 Execute-on-Demand 功能 不参与求解迭代,Define,User-Defined,Function Hooks,例 2 定制初始化,在球内设定初始温度600 K 球中心点位于 (0.5, 0.5, 0.5), 半径为 0.25, 其余区域为300 K 域指针通过变量传递到UDF thread_loop_c 宏用来获得所有单元threads (zones), begin_c_loop 宏获得每个单元thread中的单元,#include udf.h“ DEFINE_INIT(my_init_function, domain) cell_t c; Thread *ct; real xcND_ND; thread_loop_c(ct,domain) begin_c_loop (c,ct) C_CENTROID(xc,c,ct); if (sqrt(ND_SUM(pow(xc0-0.5,2.), pow(xc1 - 0.5,2.), pow(xc2 - 0.5,2.) 0.25) C_T(c,ct) = 600.; else C_T(c,ct) = 300.; end_c_loop (c,ct) ,DEFINE 宏,DEFINE 宏的例子,DEFINE_ADJUST(name,domain); general purpose UDF called every iteration DEFINE_INIT(name,domain); UDF used to initialize field variables DEFINE_ON_DEMAND(name); an execute-on-demand function DEFINE_RW_FILE(name,fp); customize reads/writes to case/data files DEFINE_PROFILE(name,thread,index); boundary profiles DEFINE_SOURCE(name,cell,thread,dS,index); equation source terms DEFINE_HEAT_FLUX(name,face,thread,c0,t0,cid,cir); heat flux DEFINE_PROPERTY(name,cell,thread); material properties DEFINE_DIFFUSIVITY(name,cell,thread,index); UDS and species diffusivities DEFINE_UDS_FLUX(name,face,thread,index); defines UDS flux terms DEFINE_UDS_UNSTEADY(name,cell,thread,index,apu,su); UDS transient terms DEFINE_SR_RATE(name,face,thread,r,mw,yi,rr); surface reaction rates DEFINE_VR_RATE(name,cell,thread,r,mw,yi,rr,rr_t); volumetric reaction rates DEFINE_SCAT_PHASE_FUNC(name,cell,face); scattering phase function for DOM DEFINE_DELTAT(name,domain); variable time step size for unsteady problems DEFINE_TURBULENT_VISCOSITY(name,cell,thread); calculates turbulent viscosity DEFINE_TURB_PREMIX_SOURCE(name,cell,thread,turbflamespeed,source); turbulent flame speed DEFINE_NOX_RATE(name,cell,thread,nox); NOx production and destruction rates,几何和时间宏,C_NNODES(c,t); Returns nodes/cell C_NFACES(c,t); Returns faces/cell F_NNODES(f,t);Returns nodes/face C_CENTROID(x,c,t);Returns coordinates of cell centroidin array x F_CENTROID(x,f,t); Returns coordinates of face centroidin array x F_AREA(A,f,t); Returns area vector in array A C_VOLUME(c,t); Returns cell volume C_VOLUME_2D(c,t); Returns cell volume (axisymmetric domain) real flow_time(); Returns actual time int time_step; Returns time step number RP_Get_Real(“physical-time-step”); Returns time step size,流场变量宏,C_R(c,t);Density C_P(c,t);Pressure C_U(c,t);U-veloc
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号