您好,欢迎访问三七文档
当前位置:首页 > 办公文档 > 其它办公文档 > Fluent-UDF-14.5-L03-Composition
©2012ANSYS,Inc.June17,20131Release14.514.5ReleaseChapter3ComposingUDFsUserDefinedFunctionsinANSYSFluent©2012ANSYS,Inc.June17,20132Release14.5UsingtheDEFINEMacrosAllUDFsaredefinedusingamacrothatstartswith“DEFINE_”ThegeneralformatofaDEFINE_macrois:DEFINE_UDF_TYPE(udf_name,0ormorevariables...)•udf_nameisthenameofthefunctionyoudefine–Itiscase-sensitive–ThisisthenameseeninthepicklistsintheGUIpanelExample:DEFINE_PROFILE(inlet_x_velocity,thread,index)•Definesboundaryprofilename“inlet_x_velocity”•threadistheboundarythreadwhichwillbechanged•indexidentifieswhichboundaryconditionvalueistobeset©2012ANSYS,Inc.June17,20133Release14.5BoundaryConditionsDEFINE_PROFILEcanbeusedonanyboundaryzonetosetconditionssuchastemperature,velocityetc.Itispossibletospecifyaconstantvalue,position-dependentortime-dependentvaluesNotethattheBCsareappliedatthefacesofboundary,nottheadjacentcells.©2012ANSYS,Inc.June17,20134Release14.5DEFINE_PROFILEThefollowingUDFsetsthevalueofx-velocityatthefaceoftheinletboundaryzoneaccordingtotheequation:Vx=Vo+Asin(wt);Vo=20m/s,A=5m/s,w=10rad/s•Loopthroughthefacesbelongingtotheinletzone•Specifythex-velocitycomponentoneachfaceusingF_PROFILE(f,ft,var)=…#includeudf.h#defineOMEGA10.0/*Userconstantscanbesetlikethis*/#defineV020.0#defineV_AMP5.0DEFINE_PROFILE(inlet_x_velocity,ft,var){realflow_time;face_tf;/*Faceindexhasitsowntype*/flow_time=CURRENT_TIME;/*SpecialFluentmacro*/begin_f_loop(f,ft)/*Fluenthasspecialfaceloopmacrostoo*/{F_PROFILE(f,ft,var)=V0+V_AMP*sin(OMEGA*flow_time);}end_f_loop(f,ft)}©2012ANSYS,Inc.June17,20135Release14.5Timehistoryoftheaveragevelocityatthepipeexitshowssinusoidaloscillationwithameanof20m/sandamplitudeof5m/sExample1:ResultsofTransientInletVelocityAverageVelocityMagnitudeFlowTime©2012ANSYS,Inc.June17,20136Release14.5ThefollowingUDFsetsthetemperatureonthefacesofawallaccordingtotheequation:Tx=300+100sin(π*x/L)Example2:SinusoidalWallTemperature#includeudf.h#defineLENGTH0.005#defineT_MIN300.0#defineT_AMP100.0DEFINE_PROFILE(wall_temp,ft,var){realtemperature;realpos[ND_ND];/*How2Dand3Dvectorsaredefined*/realomega;face_tf;omega=M_PI/LENGTH;/*M_PIisstandardCvalueforPi*/begin_f_loop(f,ft)/*Fluenthasspecialloopmacrostoo*/{F_CENTROID(pos,f,ft);/*Facecentroidsetinpos*/temperature=T_MIN+T_AMP*sin(omega*pos[0]);/*x=pos[0]*/F_PROFILE(f,ft,var)=temperature;}end_f_loop(f,ft)}©2012ANSYS,Inc.June17,20137Release14.5Example2:SinusoidalWallTemperatureWalltemperaturereachesitspeakatmidlengthofthewallStaticTemperature(K)ColdInflowHeatedWallAdiabaticWall©2012ANSYS,Inc.June17,20138Release14.5DEFINESOURCEToaddsourcetermstotheflowequationsuse:DEFINE_SOURCE(udf_name,cell,thread,dS,eqn)Sourcetermscanbeaddedtoequationsfor:•continuity•momentum•k,•Energy•MultiphaseandothersEnergysourcetermUDFsmayalsobedefinedforsolidzonesThesourcetermmacroisdifferentfromthepreviousmacrobecauseitiscalledforeachcellseparately.So,thereisnoneedtoperformacellloop!Theunitsofallsourcetermsareexpressedintermsofthevolumetricgenerationrate.(totalcellsource/m3)©2012ANSYS,Inc.June17,20139Release14.59EquationSourceTermsDEFINE_SOURCE(name,c,t,dS,eqn)providesthemechanismforaddingsourcetermstothegoverningequations.(Note:sourcetermsareaddedtoeachcellinthecontinuumzone,hencenoloopovercellsareneeded)Asourcetermcanbelinearizedasfollows:where“*”standsforthevaluebasedonthepreviousiteration.B(dS[eqn])andS*(whichisreturnedbythemacro)aresuppliedbytheuser.Thesolverwillusethelinearizationifitenhancesnumericalstability;otherwiseS*isusedexplicitly•Itishookeduptothecellzone(s)intheboundary-conditionpanel©2012ANSYS,Inc.June17,201310Release14.5Example:PositionDependentPorousMediaThefollowingUDFaddsanegativemomentumsourceintoeachcellwhichisdependentonthelocalflowspeedandyposition.xxxxvChydvdSBvvChyS22)/(2/)/(#includeudf.h#defineC2100.0#defineHEIGHT0.01DEFINE_SOURCE(mom_source_x,c,ct,dS,eqn){realNV_VEC(pos);/*Anotherwaytodefine2Dand3Dvectors*/realdS_dU;C_CENTROID(pos,c,ct);/*Cellcentroidsetinpos*//*C_R(c,ct)givesdensityofmaterialinthecell*/dS_dU=-pos[1]*C2*C_R(c,ct)*fabs(C_U(c,ct))/HEIGHT;dS[eqn]=dS_dU;/*Couldbesetto0.0ifunknownornotrequired*/returndS_dU*C_U(c,ct)/2.0;}©2012ANSYS,Inc.June17,201311Release14.5SourceTermsInDefine→BoundaryConditions→FluidActivatesourcetermsAttachtheSourceUDFtothematchingequation©2012ANSYS,Inc.June17,201312Release14.5Example:PositionDependentPorousMedia•X-momentumlossislinearinthey-position,startingfromzeroatthesymmetryplane•ThefluidflowsfasternearthemidlineofthechannelwheretheresistanceisleastVelocityVectors(m/s)PorousPlugInletOutlet©2012ANSYS,Inc.June17,201313Release14.5InitialConditionsTheinitialconditionsoftheflowcanbesetusingaUDFoftheform:DEFINE_INIT(init_sphere_temp,domain)TheUDFisexecutedonceatthebeginningofthesolutionprocessItisattachedintheUDFsHookspanelDefine→UserDefined→FunctionHooks©2012ANSYS,Inc.June17,201314Release14.5ThisUDFinitialisesthetemperaturewithinasphereofradius0.25mThemacroNV_DcanbeusedtosetavectorThemacroNV_VVcanbeusedforvectorarithmeticThemacroNV_MAGcomputesthelengthofavectorInitializationUDF(0.0,0.5,0.5)#incl
本文标题:Fluent-UDF-14.5-L03-Composition
链接地址:https://www.777doc.com/doc-4084230 .html