您好,欢迎访问三七文档
当前位置:首页 > 办公文档 > 其它办公文档 > Fluent-UDF-第四章-DEFINE宏
DEFINEFluentUDFDEFINE•4.1•4.2DEFINE•4.3DEFINE•4.4DEFINE•4.5DEFINE4.1DEFINE••••(DPM)DEFINEutilities(Chapter6)FLUENTDEFINEudf.hDEFINEdpm.hAudf.hdpm.hUDFdpm.hDEFINEDEFINE4.2DEFINEDEFINEFLUENT4.2.1FLUENTDEFINEDEFINEudf.hA•DEFINE_ADJUST(4.2.1)•DEFINE_INIT(4.2.2)•DEFINE_ON_DEMAND(4.2.3)•DEFINE_RW_FILE(4.2.4)4.2.1DEFINEDEFINEDEFINE_ADJUSTUser-DefinedFunctionHooksDEFINE_INITUser-DefinedFunctionHooksDEFINE_ON_DEMANDExecuteOnDemandDEFINE_RW_FILEUser-DefinedFunctionHooksCasedata•4.2.1DEFINE_ADJUST•4.2.2DEFINE_INIT•4.2.3DEFINE_ON_DEMAND•4.2.4DEFINE_RW_FILE4.2.1DEFINE_ADJUSTDEFINE_ADJUSTFLUENTDEFINE_ADJUSTDEFINE_ADJUST3.3.13.3.2forDEFINE_ADJUSTFLUENTDEFINE_ADJUST(name,d)Domain*dvoidDEFINE_ADJUSTnamednameUDFUDFFLUENTdFLUENTUDFDDEFINE_ADJUST1UDFadjustDEFINE_ADJUSTUDFUDFFLUENT/*******************************************************************//*UDF*//********************************************************************/#includeudf.hDEFINE_ADJUST(my_adjust,d){Thread*t;/*Integratedissipation.*/realsum_diss=0.;cell_tc;thread_loop_c(t,d){begin_c_loop(c,t)sum_diss+=C_D(c,t)*C_VOLUME(c,t);end_c_loop(c,t)}printf(Volumeintegralofturbulentdissipation:%g\n,sum_diss);}2UDFadjust_fcnDEFINE_ADJUSTUDFFLUENT/********************************************************************//*UDFfordefininguser-definedscalarsandtheirgradients*//********************************************************************/#includeudf.hDEFINE_ADJUST(adjust_fcn,d){Thread*t;cell_tc;realK_EL=1.0;/*Donothingifgradientisn'tallocatedyet.*/if(!Data_Valid_P())return;thread_loop_c(t,d){if(FLUID_THREAD_P(t)){begin_c_loop_all(c,t){C_UDSI(c,t,1)+=K_EL*NV_MAG2(C_UDSI_G(c,t,0))*C_VOLUME(c,t);}end_c_loop_all(c,t)}}}ActivatinganAdjustUDFinFLUENTadjustUDFFLUENTUser-DefinedFunctionHooks8.1.14.2.2DEFINE_INITDEFINE_INITDEFINE_INITUDFDEFINE_INIT3.3.13.3.2FLUENTDEFINE_INITMacro:DEFINE_INIT(name,d)Argumenttypes:Domain*dFunctionreturns:voidDEFINE_INITnamednameUDFUDFFLUENTdFLUENTUDFdisapointertothedomainoverwhichtheinitializationfunctionistobeapplied.Thedomainargumentprovidesaccesstoallcellandfacethreadsinthemesh.Formultiphaseflows,thedomainpointerthatispassedtothefunctionbythesolveristhemixture-leveldomainpointer.ADEFINE_INITfunctiondoesnotreturnavaluetothesolver.UDFmy_init_funcUDFFLUENT/*******************************************************************//*UDFforinitializingflowfieldvariables*//***********************************************************************/#includeudf.hDEFINE_INIT(my_init_function,domain){cell_tc;Thread*t;realxc[ND_ND];/*loopoverallcellthreadsinthedomain*/thread_loop_c(t,domain){/*loopoverallcells*/begin_c_loop_all(c,t){C_CENTROID(xc,c,t);if(sqrt(ND_SUM(pow(xc[0]-0.5,2.),pow(xc[1]-0.5,2.),pow(xc[2]-0.5,2.)))0.25)C_T(c,t)=400.;elseC_T(c,t)=300.;}end_c_loop_all(c,t)}}ThemacroND_SUM(a,b,c)thatisusedintheUDFcomputesthesumofthefirsttwoarguments(2D)orallthreearguments(3D).Itisusefulforwritingfunctionsinvolvingvectoroperationssothatthesamefunctioncanbeusedfor2Dand3D.Fora2Dcase,thethirdargumentisignored.SeeChapter5foradescriptionofpredefinedsolveraccessmacros(e.g.,C_CENTROID)andChapter6forutilitymacros(e.g.,ND_SUM).ActivatinganInitializationUDFinFLUENTUDFyoucanactivatethefunctionintheUser-DefinedFunctionHookspanelinFLUENT.SeeSection8.1.2formoredetails.4.2.3DEFINE_ON_DEMANDDEFINE_ON_DEMANDmacrotodefineaUDFtoexecuteondemandinFLUENT,ratherthanhavingFLUENTcallitautomaticallyduringthecalculation.YourUDFwillbeexecutedimmediately,onceitisactivated,butitisnotaccessiblewhilethesolverisiterating.NotethatthedomainpointerdisnotexplicitlypassedasanargumenttoDEFINE_ON_DEMAND.Therefore,ifyouwanttousethedomainvariableinyouron-demandfunction,youwillneedtofirstretrieveitusingtheGet_DomainutilityprovidedbyFluent(showninbelow).SeeSection6.5.1fordetailsonGet_Domain.Macro:DEFINE_ON_DEMAND(name)Argumenttypes:noneFunctionreturns:voidThereisonlyoneargumenttoDEFINE_ON_DEMAND:name.nameisthenameoftheUDF,specifiedbyyou.UDFFLUENTADEFINE_ON_DEMANDfunctiondoesnotreturnavaluetothesolver.UDFdemand_calcItthencomputesatemperaturefunctionandstoresitinuser-definedmemorylocation0(whichisallocatedasdescribedinSection6.7).OnceyouexecutetheUDF(asdescribedinSection8.1.3),thefieldvaluesforf(T)willbeavailableinthedrop-downlistsinpostprocessingpanelsinFLUENT.Youcanselectthisfieldbychoosingudm-0intheUserDefinedMemory...category.IfyouwriteadatafileafterexecutingtheUDF,theuser-definedmemoryfieldwillbesavedtothedatafile.TheUDFcanbeexecutedasaninterpretedorcompiledUDFinFLUENT./**********************************************************************//*UDFtocalculatetemperaturefieldfunctionandstorein*//*user-definedmemory.Alsoprintmin,max,avgtemperatures.*//**********************************************************************/#includeudf.hDEFINE_ON_DEMAND(on_demand_calc)Domain*d;/*declaredomainpointersinceitisnotpasseda*//*argumenttoDEFINEmacro*/{realtavg=0.;realtmax=0.;realtmin=0.;realtemp,volume,vol_tot;Thread*t;cell_tc;d=Get_Domain(1);/*GetthedomainusingFluentutility*//*Loopoverallcellthreadsinthedomain*/thread_loop_c
本文标题:Fluent-UDF-第四章-DEFINE宏
链接地址:https://www.777doc.com/doc-7227746 .html