海基公司培訓(xùn)講義文件fluent-vudfs_第1頁
海基公司培訓(xùn)講義文件fluent-vudfs_第2頁
海基公司培訓(xùn)講義文件fluent-vudfs_第3頁
海基公司培訓(xùn)講義文件fluent-vudfs_第4頁
海基公司培訓(xùn)講義文件fluent-vudfs_第5頁
已閱讀5頁,還剩18頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論