资源预览内容
第1页 / 共25页
第2页 / 共25页
第3页 / 共25页
第4页 / 共25页
第5页 / 共25页
第6页 / 共25页
第7页 / 共25页
第8页 / 共25页
第9页 / 共25页
第10页 / 共25页
亲,该文档总共25页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
A Pera Global Company PERA ChinaANSYS 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?标准的界面不能编程模拟所有需求:定制边界条件,源项,反应速率,材料属性等定制物理模型用户提供的模型方程调整函数执行和需求函数初始化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 Equations 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数据类型获得Thread 是 FLUENT 定义的数据类型为了在thread (zone)中获得数据,我们需要提供正确的指针,并使用循环宏获得thread中的每个成员(cell or face)Fluid (cell thread or zone)Boundary (face thread or zone)DomainCellDomainCellsCell Threadface face ThreadThreadFacesA Pera Global Company PERA ChinaUDF 数据结构(2)ncell_t 声明了识别单元的整型数据类型nface_t声明了识别面的整型数据类型TypeTypeVariableVariableMeaning of the declarationMeaning of the declarationDomain*d;d is a pointer 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)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, 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 以 DEFINE_ 宏开始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 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 topof the program by the #include commandA Pera Global Company PERA China第 2 步 解释或编译 UDFn编译UDFn把 UDF 源码加入到源文件列表中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用户函数可以在运行时读入并解释,也可以编译形成共享库文件并和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 Company PERA China第4步 运行n可以在运行窗口中改变速度分布的更新间隔(默认为1)这个设置控制了流场多久(迭代或时间步)更新一次n运行 calculation A Pera Global Company PERA China结果n左图为速度矢量图n右图为入口的速度矢量图,注意速度分布是抛物线型的A Pera Global Company PERA China其他 UDF Hooksn除了边界条件、源项、材料属性外,UDF 还可用于初始化每次初始化执行一次求解调整每次迭代执行一次壁面热流量以传热系数方式定义流体侧的扩散和辐射热流量应用于所有壁面用户定义表面反应或体积反应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“ 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) A Pera Global Company PERA 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,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(name,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); scattering 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,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 centroidin 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 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(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 derivativeC_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 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 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(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 derivativeC_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); Specific 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,thread,index)非稳态函数DEFINE_UDS_UNSTEADY(name,cell,thread,index,apu,su)n例子能用来求解磁流体方程DefineUser-DefinedScalarsA Pera Global Company PERA China其他宏n还有许多其他宏:湍流模型多相流模型化学反应流动网格输入/输出A Pera Global Company PERA ChinaUDF 技术支持n由于 UDFs 可能非常复杂, ANSYS 不对用户的UDFs精度及求解稳定性负责n支持限于UDFs 和 FLUENT 求解器间的通讯谢谢A Pera Global Company PERA China
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号