FLUENT流体模拟UDF讲解_第1页
FLUENT流体模拟UDF讲解_第2页
FLUENT流体模拟UDF讲解_第3页
FLUENT流体模拟UDF讲解_第4页
FLUENT流体模拟UDF讲解_第5页
已阅读5页,还剩28页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、计算流体力学软件计算流体力学软件Fluent培训培训UDF基础基础A Pera Global Company PERA China概要nFLUENT UDF简介nFLUENT 数据结构和宏n两个例子nUDF 支持A Pera Global Company PERA China简介n什么是UDF? UDF 是用户自己用C语言写的一个函数,可以和FLUENT动态链接 标准C 函数 三角函数,指数,控制块,Do循环,文件读入/输出等 预定义宏 允许获得流场变量,材料属性,单元几何信息及其他n为什么使用 UDFs? 标准的界面不能编程模拟所有需求: 定制边界条件,源项,反应速率,材料属性等 定制物理模

2、型 用户提供的模型方程 调整函数 执行和需求函数 初始化A Pera Global Company PERA China可以使用UDF的位置User-Defined PropertiesUser-Defined BCsUser Defined INITIALIZESegregatedPBCSExit LoopRepeatCheck Convergence Update Properties Solve Turbulence Equation(s)Solve SpeciesSolve EnergyInitializeBegin LoopDBCSSolve Other Transport Equa

3、tions as requiredSolver?Solve Mass Continuity;Update VelocitySolve U-MomentumSolve V-MomentumSolve W-MomentumSolve Mass& MomentumSolve Mass,Momentum,Energy,SpeciesUser-defined ADJUSTSource termsSource termsSource termsSourcetermsA Pera Global Company PERA ChinaUDF 数据结构 (1)在UDF中,体域和面域通过Thread数据类型

4、获得Thread 是 FLUENT 定义的数据类型为了在thread (zone)中获得数据,我们需要提供正确的指针,并使用循环宏获得thread中的每个成员(cell or face)Fluid (cell thread or zone)Boundary (face thread or zone)DomainCellDomainCellsCell Threadface ThreadFacesA Pera Global Company PERA ChinaUDF 数据结构(2)ncell_t 声明了识别单元的整型数据类型nface_t声明了识别面的整型数据类型Domain*d;d is a p

5、ointer to domain threadThread *t; t is a pointer to thread cell_t c; c is cell thread variableface_t f; f is a face thread variableNode *node;node is a pointer to a node.Boundary face-thread(boundary-face ensemble)Fluid cell-thread(control-volume ensemble)Internal face-thread(internal-face ensemble)

6、associated with cell-threadsNodesA Pera Global Company PERA ChinaUDF中的循环宏n几个经常用到的循环宏为: 对域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,

7、t: a cell thread pointerft,f_thread: a face thread pointerc: a cell thread variablef: a face thread variableA Pera Global Company PERA China例子 抛物线分布的速度入口n在二维弯管入口施加抛物线分布的速度nx 方向的速度定义为n需要通过宏获得入口的中心点, 通过另外一个宏赋予速度条件A Pera Global Company PERA China 第1步 准备源代码nDEFINE_PROFILE 宏允许定义x_velocity函数 所有的UDFs 以 DEF

8、INE_ 宏开始 x_velocity 将在 GUI中出现 thread 和 nv DEFINE_PROFILE 宏的参数,分别用来识别域和变量 begin_f_loop宏通过thread指针,对所有的面f循环n F_CENTROID宏赋单元位置向量给 xn F_PROFILE 宏在面 f上施加速度分量n代码以文本文件保存inlet_bc.c#include udf.hDEFINE_PROFILE(x_velocity,thread,nv) float x3; /* an array for the coordinates */ float y; face_t f; /* f is a fac

9、e 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 topof the program by the #include commandA Pera Global Company PERA China第 2 步 解释或编译 UDFn编译UDFn把 UDF 源码加入到

10、源文件列表中n点击 Build进行编译和链接n如果没有错误,点击Load读入库文件n如需要,也可以卸载库文件/define/user-defined/functions/managen解释UDFn把 UDF 源码加入到源文件列表中n点击 InterpretnFLUENT 窗口会出现语言n如果没有错误,点击 CloseDefineUser-DefinedFunctionsCompiledDefineUser-DefinedFunctionsInterpretedA Pera Global Company PERA China解释 vs. 编译n用户函数可以在运行时读入并解释,也可以编译形成共享库

11、文件并和FLUENT链接n解释 vs. 编译 解释 解释器是占用内存的一个大型程序 通过逐行即时执行代码 优势 不需要第三方编译器 劣势 解释过程慢,且占用内存 编译 UDF 代码一次转换为机器语言 运行效率高. 创建共享库,和其他求解器链接 克服解释器的缺陷n只有在没安装C编译器时使用解释方式A Pera Global Company PERA China第3 步 在 FLUENT GUI中hook UDFn打开边界条件面板,选择你要施加UDF的边界n把 Constant 改为 udf x_velocityn宏的名字为 DEFINE_PROFILE 中第一个参数A Pera Global C

12、ompany PERA China第4步 运行n可以在运行窗口中改变速度分布的更新间隔(默认为1) 这个设置控制了流场多久(迭代或时间步)更新一次n运行 calculation A Pera Global Company PERA China结果n左图为速度矢量图n右图为入口的速度矢量图,注意速度分布是抛物线型的A Pera Global Company PERA China其他 UDF Hooksn除了边界条件、源项、材料属性外,UDF 还可用于 初始化 每次初始化执行一次 求解调整 每次迭代执行一次 壁面热流量 以传热系数方式定义流体侧的扩散和辐射热流量 应用于所有壁面 用户定义表面反应或

13、体积反应 Case/ data 文件的读写 读入顺序必须和写出顺序一致 Execute-on-Demand 功能 不参与求解迭代DefineUser-DefinedFunction HooksA Pera Global Company PERA China例 2 定制初始化n在球内设定初始温度600 K 球中心点位于 (0.5, 0.5, 0.5), 半径为 0.25, 其余区域为300 Kn域指针通过变量传递到UDFnthread_loop_c 宏用来获得所有单元threads (zones), begin_c_loop 宏获得每个单元thread中的单元 #include udf.h“ D

14、EFINE_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) A Pera Global Company PERA

15、 China DEFINE 宏nDEFINE 宏的例子 DEFINE_ADJUST(name,domain); general purpose UDF called every iterationDEFINE_INIT(name,domain); UDF used to initialize field variablesDEFINE_ON_DEMAND(name); an execute-on-demand functionDEFINE_RW_FILE(name,fp); customize reads/writes to case/data filesDEFINE_PROFILE(name

16、,thread,index); boundary profilesDEFINE_SOURCE(name,cell,thread,dS,index); equation source termsDEFINE_HEAT_FLUX(name,face,thread,c0,t0,cid,cir); heat fluxDEFINE_PROPERTY(name,cell,thread); material propertiesDEFINE_DIFFUSIVITY(name,cell,thread,index); UDS and species diffusivitiesDEFINE_UDS_FLUX(na

17、me,face,thread,index); defines UDS flux termsDEFINE_UDS_UNSTEADY(name,cell,thread,index,apu,su); UDS transient termsDEFINE_SR_RATE(name,face,thread,r,mw,yi,rr); surface reaction ratesDEFINE_VR_RATE(name,cell,thread,r,mw,yi,rr,rr_t); volumetric reaction ratesDEFINE_SCAT_PHASE_FUNC(name,cell,face); sc

18、attering phase function for DOMDEFINE_DELTAT(name,domain); variable time step size for unsteady problemsDEFINE_TURBULENT_VISCOSITY(name,cell,thread); calculates turbulent viscosityDEFINE_TURB_PREMIX_SOURCE(name,cell,thread,turbflamespeed,source); turbulent flame speedDEFINE_NOX_RATE(name,cell,thread

19、,nox); NOx production and destruction ratesA Pera Global Company PERA China几何和时间宏 C_NNODES(c,t); Returns nodes/cellC_NFACES(c,t); Returns faces/cellF_NNODES(f,t);Returns nodes/faceC_CENTROID(x,c,t);Returns coordinates of cell centroidin array xF_CENTROID(x,f,t); Returns coordinates of face centroidi

20、n array xF_AREA(A,f,t); Returns area vector in array AC_VOLUME(c,t); Returns cell volume C_VOLUME_2D(c,t); Returns cell volume (axisymmetric domain)real flow_time(); Returns actual timeint time_step; Returns time step numberRP_Get_Real(“physical-time-step”); Returns time step sizeA Pera Global Compa

21、ny PERA China流场变量宏C_R(c,t); DensityC_P(c,t); PressureC_U(c,t); U-velocityC_V(c,t); V-velocityC_W(c,t); W-velocityC_T(c,t); TemperatureC_H(c,t); EnthalpyC_K(c,t); Turbulent kinetic energy (k)C_D(c,t); Turbulent dissipation rate ()C_O(c,t); Specific dissipation of k () C_YI(c,t,i);Species mass fractio

22、nC_UDSI(c,t,i); UDS scalarsC_UDMI(c,t,i); UDM scalarsC_DUDX(c,t);Velocity derivativeC_DUDY(c,t);Velocity derivativeC_DUDZ(c,t);Velocity derivativeC_DVDX(c,t); Velocity derivativeC_DVDY(c,t); Velocity derivativeC_DVDZ(c,t); Velocity derivativeC_DWDX(c,t); Velocity derivativeC_DWDY(c,t); Velocity deri

23、vativeC_DWDZ(c,t); Velocity derivativeC_MU_L(c,t); Laminar viscosityC_MU_T(c,t); Turbulent viscosityC_MU_EFF(c,t); Effective viscosityC_K_L(c,t); Laminar thermal conductivityC_K_T(c,t); Turbulent thermal conductivityC_K_EFF(c,t); Effective thermal conductivityC_CP(c,t); Specific heatC_RGAS(c,t); Gas

24、 constantA Pera Global Company PERA China流场变量宏C_R(c,t); DensityC_P(c,t); PressureC_U(c,t); U-velocityC_V(c,t); V-velocityC_W(c,t); W-velocityC_T(c,t); TemperatureC_H(c,t); EnthalpyC_K(c,t); Turbulent kinetic energy (k)C_D(c,t); Turbulent dissipation rate ()C_O(c,t); Specific dissipation of k () C_YI

25、(c,t,i);Species mass fractionC_UDSI(c,t,i); UDS scalarsC_UDMI(c,t,i); UDM scalarsC_DUDX(c,t);Velocity derivativeC_DUDY(c,t);Velocity derivativeC_DUDZ(c,t);Velocity derivativeC_DVDX(c,t); Velocity derivativeC_DVDY(c,t); Velocity derivativeC_DVDZ(c,t); Velocity derivativeC_DWDX(c,t); Velocity derivati

26、veC_DWDY(c,t); Velocity derivativeC_DWDZ(c,t); Velocity derivativeC_MU_L(c,t); Laminar viscosityC_MU_T(c,t); Turbulent viscosityC_MU_EFF(c,t); Effective viscosityC_K_L(c,t); Laminar thermalconductivityC_K_T(c,t); Turbulent thermalconductivityC_K_EFF(c,t); Effective thermalconductivityC_CP(c,t); Spec

27、ific heatC_RGAS(c,t); Gas constantC_DIFF_L(c,t); Laminar speciesdiffusivityC_DIFF_EFF(c,t,i); Effective species diffusivityA Pera Global Company PERA ChinaUDMn对每个单元由用户分配内存 定义多达500个变量 可以通过 UDFs获得: C_UDMI(cell,thread,index); F_UDMI(face,thread,index); 数据信息存在 FLUENT data 文件中DefineUser-DefinedMemoryA Pera Global Company PERA ChinaUDSnFLUENT 可以求解多达50个用户 定义标量的输运方程 UDS 变量的数量 UDS 在哪个域内求解 通量函数 DEFINE_UDS_FLUX(name,face

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论