版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、User Defined FunctionsIntroductionWhat is a User Defined Function?A UDF is a routine (programmed by the user) written in C which can be dynamically linked with the solver.Standard C functionse.g., trigonometric, exponential, control blocks, do-loops, file i/o, etc.Pre-Defined MacrosAllows access to
2、field variable, material property, and cell geometry data.Why build UDFs?Standard interface cannot be programmed to anticipate all needs.Customization of boundary conditions, source terms, reaction rates, material properties, etc.Adjust functions (once per iteration)Execute on Demand functionsSoluti
3、on InitializationUser Access to Fluent SolverFLUENT is designed to allow users to access the solver at some strategic instances during the solution process:Flow Diagram of FLUENT SolversSegregated Solver Coupled SolverInitializeBegin LoopExit LoopRepeatCheck Convergence Update Properties Solve Eddy
4、DissipationSolve Turbulence Kinetic EnergySolve SpeciesSolve EnergySolve Mass Continuity;Update VelocitySolve U-MomentumSolve V-MomentumSolve W-MomentumSolve Mass Momentum & EnergyUser-defined ADJUSTSource termsSource termsSource termsUser Defined InitializeUser-Defined PropertiesUser-Defined Bounda
5、ry ConditionsUDF BasicsUDFs assigns values (e.g., boundary data, source terms) to individual cells and cell faces in fluid and boundary zones.In a UDF, zones are referred to as threads.A looping macro is used to access individualcells belonging to a thread.e.g., a face-loop macro visits 563 faces on
6、 face zone 3 (velocity-inlet).Position of each face is availableto calculate and assign spatially varying properties.Thread and variable references are automatically passed to UDF when assigned to boundary in GUI.Values returned to the solver by UDFs must be in SI units.Using UDFs in the SolversThe
7、basic steps for using UDFs in FLUENT are as follows:STEP 1: Create a file containing the UDF source codeSTEP 2: Start the solver and read in your case/data filesSTEP 3: Interpret or Compile the UDFSTEP 4: Assign the UDF to the appropriate variable and zone in BC panel.STEP 5: Set the UDF update freq
8、uency in the Iterate panelSTEP 6: Run the calculationExample: Non-Uniform Inlet VelocityA non-uniform inlet velocity is to be imposed on the 2D turbine vane shown below. The x-velocity variation is to be specified as:u(y) = 20 1 - (y/0.0745)2y = 0 Step 1: Source CodeThe DEFINE_PROFILE macro allowsth
9、e function inlet_x_velocity tobe defined.All UDFs begin with a DEFINE_ macro. inlet_x_velocity will be identifiable in solver GUI. thread and nv are dynamic references: input to the UDF toidentify the zone and variablebeing defined, respectively.The macro begin_f_loop loops over all faces, f, on thr
10、ead.The F_CENTROID macro assigns cell position vector to x. The F_PROFILE macro applies the velocity component to face f.#include udf.hDEFINE_PROFILE(inlet_x_velocity, thread, nv) float x3; /* this will hold the position vector*/ float y; face_t f; begin_f_loop(f, thread) F_CENTROID(x,f,thread); y =
11、 x1; F_PROFILE(f, thread, nv) = 20.*(1.- y*y/(.0745*.0745); end_f_loop(f, thread) Step 3: Interpreting the UDFThe UDF is saved as velprof.cDefine User Defined Functions InterpretedClick CompileThe assembly language code will scroll past window. A snapshot is shown in the right.velocity_profile: .loc
12、al.pointer thread (r0) . position (r1) 0 .local.end 0 f (r6) 8 0 10 save ..L1:132 restore 133 restore 134 ret.vStep 4: Activating the UDFAccess the boundary condition panel.Switch from constant to the UDF function in the X-Velocity dropdown list.Step 5 and 6
13、: Run the CalculationYou can change the UDF Profile update Interval in the Iterate panel (default value is 1).Run the calculation as usual.Numerical Solution of the ExampleThe figure at right shows velocity field throughout turbine blade passage.The bottom figure shows the velocity vectors at the in
14、let. Notice the imposed parabolic profile.MacrosMacros are pre-defined (Fluent) functions: DEFINE_ macros allows definitions of UDF functionality.Variable access macros allow access to field variables and cell information.Utility macros provide looping capabilities, thread identification, vector and
15、 numerous other functions.Macros are defined in header files.The udf.h header file must be included in your source code.#include “udf.h”The header files must be accessible in your path.Typically stored in Fluent.Inc/src/ directory.A list of often used macros is provided in the UDF Users Guide.Help M
16、ore Documentation DEFINE MacrosAny UDF you write must begin with a DEFINE macro:18 general purpose macros and 13 DPM and multiphase related macros (not listed):DEFINE_ADJUST(name,domain); general purpose UDF called every iterationDEFINE_INIT(name,domain); UDF used to initialize field variablesDEFINE
17、_ON_DEMAND(name); defines an execute-on-demand functionDEFINE_RW_FILE(name,fp); customize reads/writes to case/data filesDEFINE_PROFILE(name,thread,index); defines boundary profilesDEFINE_SOURCE(name,cell,thread,dS,index); defines source termsDEFINE_HEAT_FLUX(name,face,thread,c0,t0,cid,cir); defines
18、 heat fluxDEFINE_PROPERTY(name,cell,thread); defines material propertiesDEFINE_DIFFUSIVITY(name,cell,thread,index); defines UDS and species diffusivitiesDEFINE_UDS_FLUX(name,face,thread,index); defines UDS flux termsDEFINE_UDS_UNSTEADY(name,cell,thread,index,apu,su); defines UDS transient termsDEFIN
19、E_SR_RATE(name,face,thread,r,mw,yi,rr); defines surface reaction ratesDEFINE_VR_RATE(name,cell,thread,r,mw,yi,rr,rr_t); defines vol. reaction ratesDEFINE_SCAT_PHASE_FUNC(name,cell,face); defines scattering phase function for DOMDEFINE_DELTAT(name,domain); defines variable time step size for unsteady
20、 problemsDEFINE_TURBULENT_VISCOSITY(name,cell,thread); defines procedure for calculating turbulent viscosityDEFINE_TURB_PREMIX_SOURCE(name,cell,thread,turbflamespeed,source); defines turb. flame speedDEFINE_NOX_RATE(name,cell,thread,nox); defines NOx production and destruction ratesSome Thread and L
21、ooping Utility Macroscell_t c; defines a cellface_t f; defines a faceThread *t; pointer to a threadDomain *d; pointer to collection of all threadsthread_loop_c(t, d) loop that steps through all cell threads in domainthread_loop_f(t, d) loop that steps through all face threads in domainbegin_c_loop(c
22、, t) end_c_loop(c, t) loop that steps through all cells in a threadbegin_f_loop(f, t) end_f_loop(f, t) loop that steps through all faces in a threadc_face_loop(c, t, n) loop that steps through all faces of a cellThread *tf = Lookup_Thread(domain, ID); return thread pointer of integer ID of zoneTHREA
23、D_ID(tf); returns zone integer ID of thread pointerCode enclosed in is executed in loop.Specialized variable types used for referencing.Geometry and Time MacrosC_NNODES(c, t); returns nodes/cellC_NFACES(c, t); returns faces/cellF_NNODES(f, t); returns nodes/faceC_CENTROID(x, c, t); returns coordinat
24、es of cell centroid in array xF_CENTROID(x, f, t); returns coordinates of face centroid in 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 for axisymmetric domainreal flow_time(); returns actual timeint time_step; retur
25、ns time step numberRP_Get_Real(“physical-time-step”); returns time step sizeCell Field Variable MacrosC_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 KEC_D(c,t); turbulent dissipation rateC_O(c,
26、t); specific dissipation of tke 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
27、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); ef
28、fective thermal conductivityC_CP(c,t); specific heatC_RGAS(c,t); gas constantC_DIFF_L(c,t); laminar species diffusivityC_DIFF_EFF(c,t,i); effective species diffusivityFace Field Variable MacrosF_R(f,t); densityF_P(f,t); pressureF_U(f,t); u-velocityF_V(f,t); v-velocityF_W(f,t); w-velocityF_T(f,t); te
29、mperatureF_H(f,t); enthalpyF_K(f,t); turbulent KEF_D(f,t); tke dissipationF_O(f,t); specific dissipation of tke F_YI(f,t,i); species mass fractionF_UDSI(f,t,i); UDS scalarsF_UDMI(f,t,i); UDM scalarsF_FLUX(f,t); mass flux across face f, defined out of domain at boundaries.Face field variables are onl
30、y available when using the segregated solver and generally, only at exterior boundaries.Other UDF ApplicationsIn addition to defining boundary values, source terms, and material properties, UDFs can be used for:InitializationExecutes once per initialization.AdjustExecutes every iteration.Wall Heat F
31、luxdefines fluid-side diffusive and radiative wall heat fluxes in terms of heat transfer coefficientsapplies to all wallsUser Defined Surface and Volumetric ReactionsRead-Write to/from case and data filesRead order and Write order must be same.Execute-on-Demand capabilityNot accessible during solveU
32、ser Defined MemoryUser-allocated memoryDefine User-Defined Memory.Up to 500 field variables can be defined.Can be accessed by UDFs:C_UDMI(cell,thread,index);F_UDMI(face,thread,index);Can be accessed for post-processing.Information is stored in data file.User Defined Scalars FLUENT can solve (up to 5
33、0) generic transportequations for User Defined Scalars, fk:User specifies:Define Models User-Defined Scalars Number of User-Defined Scalars Flux Function, FDEFINE_UDS_FLUX(name,face,thread,index)DEFINE_UDS_UNSTEADY(name,cell,thread,index,apu,su)if statements needed to associate multiple flux and tra
34、nsient functions with each UDS.ExampleCan be used to determine magnetic and/or electric field in a fluid zone.k = 1, , NscalarsUser Defined Scalars (2)User must also specify:Source terms, Sf Diffusivity, Gfif statements needed to define UDF diffusivities for each UDS.Boundary Conditions for each UDS.Specified Flux or Specified Value.Define as constant or with UDF.Interpreted vs. Compiled UDFsFunctions can either be read in and interpreted at run time (as in the example) or compiled and grouped into a shared library that is linked with
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2027年考研英语地理专业基础冲刺卷
- 2026年民法典知识竞赛公司法高频考题卷
- 2026年法律顾问考试低保边缘家庭救助模拟卷
- 2026年教学能手评选课程与教学论真题卷
- 2026年巴中市巴州区网格员考试试题及答案
- 2026年安庆市迎江区社区网格员招录考试真题库(含答案)
- 初中物理八年级下册《定滑轮与动滑轮》作业课教学设计
- 小学四年级英语教学设计:Unit 4 Helping in the community 核心素养导向的单元整体教学设计
- 小学六年级英语教学设计:Unit 3 My School Period 1 核心素养视域下的听说课实践与思考
- 高中地理必修第二册《3.1农业区位因素及其变化》教学设计
- 2025高考语文步步高大一轮复习讲义必背二 120个常见文言实词
- T-YNZYC 0120-2024 绿色药材 天门冬产地加工规程
- 9竹节人 市赛一等奖
- MSOP(测量标准作业规范)测量SOP
- 工程量确认单范本
- 菏泽城市介绍课件
- 金蝶专业版固定资产操作流程
- A拓斯达机械手说明
- 918主题班会PPT课件《勿忘国耻砥砺前行》
- 高一家长会学校领导讲话稿(3篇)
- WS/T 346-2011网织红细胞计数的参考方法
评论
0/150
提交评论