首页 UDF总结

UDF总结

举报
开通vip

UDF总结UDF使用技巧1、查找相应的函数的时候,可以现在word里面找到相应的函数名字,然后依次去中文帮助文档、英文帮助文档和网页帮助文档,看看详细解释并找找是否有相应的例子。2、打个比方来说,thread就是公路,连接的cell和face,cell和face就相当于公路上汽车停靠的站点,cell_t这个面向的是单元,而face_t面向的是边或者面(二维或三维)在fluent循环过程中,一般是用thread作线程检索,而cell或者face作检索过程中位置(相当于指示位置的参数)参数的指示3、对于UDF来说,积分就是做加法...

UDF总结
UDF使用技巧1、查找相应的函数的时候,可以现在word里面找到相应的函数名字,然后依次去中文帮助文档、英文帮助文档和网页帮助文档,看看详细解释并找找是否有相应的例子。2、打个比方来说,thread就是公路,连接的cell和face,cell和face就相当于公路上汽车停靠的站点,cell_t这个面向的是 单元 初级会计实务单元训练题天津单元检测卷六年级下册数学单元教学设计框架单元教学设计的基本步骤主题单元教学设计 ,而face_t面向的是边或者面(二维或三维)在fluent循环过程中,一般是用thread作线程检索,而cell或者face作检索过程中位置(相当于指示位置的参数)参数的指示3、对于UDF来说,积分就是做加法,把通过面上每个网格的质量流量相加4、cell和face的区别,什么时候用cell,什么时候用face?5、1.begin,end_c_loopmacroisusedforloopingoverallthecellsinparticularthreadforserialprocessing.2.Forparallelprocessing,thecellsinsideapartitioncanbecategorizedasinteriorandexteriorcells.3.Themacrosbegin,end_c_loop_int;begin,end_c_loop_extandbegin,end_c_loop_allareusedforloopingoverinterior,exteriorandallthecells(inapartition)respectively.4.Inparallelsimulations,bothbegin,end_c_loopandbegin,end_c_loop_allmacroswilldothesamejob.5.Forfacestheloopingmacroinparallelarebegin,end_f_loop_int;begin,end_f_loop_extandbegin,end_f_loopforloopingoverinterior,boundaryandallfacesrespectively.Forallpracticalpurpose,theuserneednotseparatetheinteriorandboundaryfacesofapartition.Hence,begin,end_f_loop_intandbegin,end_f_loop_extmacrosarerarelyused.实际问题1、DEFINE_UDS_UNSTEADY中的apu包括的函数是不是不包括当前时刻的变量,而su包含前一时刻的变量,所以用了C_STORAGE_R存储前一时刻的变量。2、等于零是因为计算源项的时候温度还没有更新,所以两个温度值是相等的。这个时候其实是需要两个UDM,分别保存上一步和再上一步的温度。而且可以考虑全部在源项里完成,不用Adjust宏:source=(C_UDMI(c,t,1)-C_UDMI(c,t,0))/TIME_STEP;C_UDMI(c,t,0)=C_UDMI(c,t,1);C_UDMI(c,t,1)=C_T(c,t);returnsource;当然,在刚开始计算的时候要注意下UDM的初始问题,防止出错。从第三个时间步开始,就是正常的了。这个方法挺好的,只要一开始的用DEFINE_INIT,对C_UDMI(c,t,0)=0.;C_UDMI(c,t,1)=0.;一、数据类型cell_tc单元格标识符face_tf面标识符Thread*t指向线程的指针Thread**pt象限矩阵线程的指针Node*node指向节点的指针Domain*d指向定义域的指针二、node宏函数NODE_X(node)节点在x方向上的坐标(real)NODE_Y(node)节点在y方向上的坐标(real)NODE_Z(node)节点在z方向上的坐标(real)F_NNODES(f,t)面上节点的数目(int)三、cell宏函数1、C_CENTROID(x,c,t)realx[ND_ND]单元格的重心坐标x[]注意:这句话直接使用,结果会输出到求解器中,需要使用的时候,调用x[];其中,x[0]代表x方向坐标,x[1]代表y方向坐标,x[2]代表z方向坐标。2、C_VOLUME(c,t)单元格的体积(real)C_NNODES(c,t)单元格的节点的数目(int)C_NFACES(c,t)单元格的面的数目(int)3、返回给定单元cell_tc和Thread*t的面face_tf;C_FACE(c,t,i)注意:索引号i可以被传递给c_face_loop。返回面face_tf(由C_FACE返回)的Thread*t;C_FACE_THREAD(c,t,i)注意:索引号i可以被传递给c_face_loop。4、C_R(c,t)返回线程t的单元c上的密度C_P(c,t)压力C_U(c,t)速度分量uC_V(c,t)速度分量vC_W(c,t)速度分量wC_T(c,t)温度C_H(c,t)焓C_K(c,t)湍流动能kC_NUT(c,t)Spalart-Allmaras模型中的湍流密度C_D(c,t)湍流动能耗散率(和ε像,看小木虫)C_O(c,t)比耗散率wC_YI(c,t,i)组分质量分数5、C_R_G(c,t)返回线程t的单元c上的密度梯度C_P_G(c,t)压力梯度C_U_G(c,t)速度分量u梯度C_V_G(c,t)速度分量v梯度C_W_G(c,t)速度分量w梯度C_T_G(c,t)温度梯度C_H_G(c,t)焓梯度C_K_G(c,t)湍流动能k梯度C_NUT_G(c,t)Spalart-Allmaras模型中的湍流密度梯度C_D_G(c,t)湍流动能耗散率梯度(和ε像,看小木虫)C_O_G(c,t)比耗散率w梯度C_YI_G(c,t,i)组分质量分数梯度注意:①C_T_G(c,t)[0]:温度梯度x方向的分量;[1]:y方向;[2]:z方向②C_R_G(c,t)只能用于密度基求解器,C_P_G(c,t)只能用于压力基求解器③C_YI_G(c,t,i)只能用于密度基求解器,用于压力基求解器要设置,一切设置好后,输入rpsetvar’species/save-gradients?#t④只有当已经求解出包含这个变量的方程时才能得到梯度变量,需要如下设置solve/set/expert回车然后两个yes。输入q可以返回上级目录6、C_R_RG(c,t)返回线程t的单元c上的密度改造梯度C_P_RG(c,t)压力改造梯度C_U_RG(c,t)速度分量u改造梯度C_V_RG(c,t)速度分量v改造梯度C_W_RG(c,t)速度分量w改造梯度C_T_RG(c,t)温度改造梯度C_H_RG(c,t)焓改造梯度C_K_RG(c,t)湍流动能k改造梯度C_NUT_RG(c,t)Spalart-Allmaras模型中的湍流密度改造梯度C_D_RG(c,t)湍流动能耗散率改造梯度(和ε像,看小木虫)C_O_RG(c,t)比耗散率w改造梯度C_YI_RG(c,t,i)组分质量分数改造梯度注意:①C_T_RG(c,t)[0]:温度梯度x方向的分量;[1]:y方向;[2]:z方向②C_R_RG(c,t)只用于密度基求解器,C_P_RG(c,t)只用于压力基求解器③C_YI_RG(c,t,i)只能用于密度基求解器④只有当已经求解出包含这个变量的方程时才能得到梯度变量,需要如下设置solve/set/expert回车然后两个yes。输入q可以返回上级目录7、C_R_M1(c,t)返回上一个时刻(t-Δt)的密度C_P_M1(c,t)返回上一个时刻(t-Δt)的压力C_U_M1(c,t)返回上一个时刻(t-Δt)的速度分量uC_V_M1(c,t)返回上一个时刻(t-Δt)的速度分量vC_W_M1(c,t)返回上一个时刻(t-Δt)的速度分量wC_T_M1(c,t)返回上一个时刻(t-Δt)的温度C_YI_M1(c,t,i)返回上一个时刻(t-Δt)的组分质量分数注意:①datafromC_T_M1isavailableonlyifuser-definedscalarsaredefined.②详细可以看宏DEFINE_UDS_UNSTEADY(name,c,t,i,apu,su)。8、C_R_M2(c,t)返回上两个时刻(t-2Δt)的密度C_P_M2(c,t)返回上两个时刻(t-2Δt)的压力C_U_M2(c,t)返回上两个时刻(t-2Δt)的速度分量uC_V_M2(c,t)返回上两个时刻(t-2Δt)的速度分量vC_W_M2(c,t)返回上两个时刻(t-2Δt)的速度分量wC_T_M2(c,t)返回上两个时刻(t-2Δt)的温度C_YI_M2(c,t,i)返回上两个时刻(t-2Δt)的组分质量分数注意:①datafromC_T_M2isavailableonlyifuser-definedscalarsaredefined.9、C_MU_L(c,t)层流粘度C_MU_T(c,t)湍流粘度C_MU_EFF(c,t)有效粘度C_K_L(c,t)导热系数C_K_T(c,t,prt)湍流热导率C_K_EFF(c,t,prt)有效热导率C_DIFF_L(c,t,i,j)层流组分扩散率C_DIFF_EFF(c,t,i)有效组分扩散率注意:prt是湍流普朗特常数。10、C_CP(c,t)比热容C_RGAS(c,t)气体常数/相对分子质量C_NUT(c,t)Spalart-Allmaras湍流粘度11、C_FMEAN(c,t)primarymeanmixturefractionC_FMEAN2(c,t)secondarymeanmixturefractionC_FVAR(c,t)primarymixturefractionvarianceC_FVAR2(c,t)secondarymixturefractionvarianceC_PREMIXC(c,t)reactionprogressvariableC_LAM_FLAME_SPEED(c,t)层流火焰速度C_SCAT_COEFF(c,t)散射系数C_ABS_COEFF(c,t)吸收系数C_CRITICAL_STRAIN_RATE(c,t)临界应变率C_LIQF(c,t)cell中的液体分数C_POLLUT(c,t,i)污染物的质量分数注意:①C_LIQFisavailableonlyinfluidcellsandonlyifsolidificationisturnedON②C_POLLUT(c,t,i):0-MassFractionofNO;1-MassFractionofHCN;2-MassFractionofNH3;3-MassFractionofN2O;4-SootMassFraction;5-NormalizedRadicalNuclei③Concentrationinparticles(颗粒浓度)*10(-15次方)/kg,具体公式需要看fluent中的介绍。12、C_RUU(c,t)uu雷诺应力C_RVV(c,t)vv雷诺应力C_RWW(c,t)ww雷诺应力C_RUV(c,t)uv雷诺应力C_RVW(c,t)vw雷诺应力C_RUW(c,t)uw雷诺应力13、C_VOF(c,t)volumefractionforthephasecorrespondingtophasethreadt注意:多相流VOF模型,只适用于压力基求解器四、Face宏函数(只能用于压力基求解器)1、F_CENTROID(x,f,t)realx[ND_ND]面的重心坐标x[]注意:这句话直接使用,结果会输出到求解器中,需要使用的时候,调用x[];其中,x[0]代表x方向坐标,x[1]代表y方向坐标,x[2]代表z方向坐标。2、F_AREA(A,f,t)realA[ND_ND]返回A向量(面的法向量)3、F_U(f,t)速度分量uF_V(f,t)速度分量vF_W(f,t)速度分量wF_T(f,t)温度F_H(f,t)焓F_K(ft)湍流动能kF_D(f,t)湍流动能耗散率(和ε像,看小木虫)F_YI(f,t,i)组分质量分数4、F_P(f,t)压力F_FLUX(f,t)返回通过一个面的质量流速注意:①如果流动方向是离开domain的话,F_FLUX的结果为正值,否则为负值。②thesignofthefluxthatiscomputedbythesolverisoppositetothatwhichisreportedintheFLUENTuser-interface(e.g.,ReportsFluxes...).五、Connectivity宏函数一个面两边的cell可能不是属于同一个thread下的,如果这个面在domain的外表面上,则只存在C0,如果这个面在domain内部,则存在C0和C1。1、AdjacentCellIndex(相邻cell的索引)F_C0(f,t)返回一个面相邻的C0(cell_tc)F_C1(f,t)返回一个面相邻的C1(cell_tc)注意:一个domain外表面相邻的只有C0,没有C1;内部面相邻的有C0和C12、AdjacentCellThreadTHREAD_T0(t)返回一个面相邻的C0对应的threadTHREAD_T1(t)返回一个面相邻的C1对应的thread3、INTERIOR_FACE_GEOMETRY(需要增加#include“sg.h”)INTERIOR_FACE_GEOMETRY(f,t,A,ds,es,A_by_es,dr0,dr1);/这样可以单独使用。注意:使用之前需定义下面的变量:(用法和C_CENTROID(x,c,t)类似,调用该函数后相应的值会存放在求解器中,需要哪个值自己再调用)realA[ND_ND];theareanormalvector面的法向量realds;distancebetweenthecellcentroidsreales[ND_ND];theunitnormalvectorinthedirectionfromcellc0toc1realA_by_es;thevaluerealdr0[ND_ND];vectorthatconnectsthecentroidofcellc0tothefacecentroidrealdr1[ND_ND];thevectorthatconnectsthecentroidofcellc1tothefacecentroid4、BOUNDARY_FACE_GEOMETRY(需要增加#include“sg.h”)BOUNDARY_FACE_GEOMETRY(f,t,A,ds,es,A_by_es,dr0);/这样可以单独使用。注意:使用之前需定义下面的变量:(用法和C_CENTROID(x,c,t)类似,调用该函数后相应的值会存放在求解器中,需要哪个值自己再调用)realA[ND_ND];theareanormalvector面的法向量realds;distancebetweenthecellcentroidandthefacecentroidreales[ND_ND];unitnormalvectorinthedirectionfromcentroidofcellc0tofacecentroidrealA_by_es;thevaluerealdr0[ND_ND];vectorthatconnectsthecentroidofcellc0tothefacecentroid5、如果t是边界面上的thread,则返回BOUNDARY_FACE_THREAD_P(t)TRUE注意:具体可以看帮助文件,有相关例题。6、BOUNDARY_SECONDARY_GRADIENT_SOURCE(需要增加#include“sg.h”)BOUNDARY_SECONDARY_GRADIENT_SOURCE(source,n,dphi,dx,A_by_es,k)注意:使用它之前一般会使用BOUNDARY_FACE_GEOMETRY其他注意事项看看中英文帮助文档六、Special宏函数1、ThreadPointerforZoneID(Lookup_Thread)//可以用于边界条件的设置如果你想对某个边界区域进行操作,你可以使用Lookup_Thread找到你需要的区域对应的指针t,然后进行相应操作。使用方法如下:intzone_ID=2;//ID是边界区域的编号,可以右击网格就可以查到Thread*t=Lookup_Thread(domain,zone_ID);注意:多相流情况下使用会有点麻烦,具体看看帮助2、ZoneID(THREAD_ID)使用方法如下:intzone_ID=THREAD_ID(t);可以得到t对应的zone的ID整数值。3、DomainPointer(Get_Domain)Get_Domain(domain_id);注意:domain_id是整数,对于混合相是1,对于某一个相,可以查看define-phases找到相应的ID。Get_Domain(domain_id)经常用在宏DEFINE_ON_DEMAND中,DEFINE_ON_DEMAND这个宏一般用于初始化或迭代后数据进行处理(取平均,最大值,最小值等),不能使用在迭代过程当中。例:DEFINE_ON_DEMAND(my_udf){Domain*mixture_domain;mixture_domain=Get_Domain(1);}4、SetBoundaryConditionValue(F_PROFILE)F_PROFILE(f,t,i)=…….;注意:①F_PROFILE是对面进行操作,一般用于边界条件的设定,改变边界条件上各种参数(压力,速度,组分参数)的值。②i不需要提前定义或赋值,一般配合DEFINE_PROFILE(pressure_profile,t,i)使用,而这里已经定义了i。具体可以参照DEFINE_PROFILE提供的例子。5、THREAD_SHADOW(t)if(!NULLP(ts=THREAD_SHADOW(t))){/*Dothingshereusingtheshadowwallthread(ts)*/t是薄壁的一部分,对t进行操作}如果边界不是薄壁的一部分,THREAD_SHADOW(t)返回NULLNULLP()括号里面的如果没有分配内存返回TRUE七、Time-SampledData(C_STORAGE_R)时间取样数据。八、Model-SpecificMacros用于特定模型的宏1、DPM宏2、NOx宏3、SOx宏4、动网格宏DT_THREAD(dt)Dynamic_Thread*dtpointertofacethreadDT_CG(dt)Dynamic_Thread*dtcenterofgravityvectorDT_VEL_CG(dt)Dynamic_Thread*dtcgvelocityvectorDT_OMEGA_CG(t)Dynamic_Thread*dtangularvelocityvectorDT_THETA(dt)Dynamic_Thread*dtorientationofbody-fixedaxisvectorDYNAMESH_CURRENT_TN/AcurrentdynamicmeshtimeIMETIME_TO_ABSOLUTE_CRabsolutevalueofthecrankrealtimeANK_ANGLE(time)angle九、User-DefinedScalar(UDS)TransportEquationMacros用户自定义标量输运方程宏在使用和本节UDS有关的宏的之前,必须先去fluent面板中进行设置标量的个数。Define—User-Defined—Scalars1、Set_User_Scalar_Name当你在fluent面板中设置了UDS个数后,系统会给分配的变量相应的名字,例如,分配了2个标量,则两个标量的名字为UserScalar0和UserScalar1。但你可以使用下面的函数对名字进行修改,i代表对第几个标量进行修改,name是字符串格式,可用”……”表示。Set_User_Scalar_Name(inti,char*name);注意:上述修改只能修改一次,要改一下改完;最好使用EXECUTE_ON_LOADING宏2、F_UDSI返回使用用户自定义标F_UDSI(f,t,i)i为标量的序号量输运方程的面变量注意:F_UDSI只能用于wall和flowboundaryfaces3、C_UDSIC_UDSI(c,t,i)UDScellvariablesC_UDSI_G(c,t,i)UDSgradientC_UDSI_M1(c,t,i)UDSprevioustimestepC_UDSI_M2(c,t,i)UDSsecondprevioustimestepC_UDSI_DIFF(c,t,i)UDSdiffusivity4、Reserve_User_Scalar_Vars为避免UDF和UDS冲突,使用这个宏,具体用法如下:offset=Reserve_User_Scalar_Vars(intnum);这样,UDFlibrary就可以使用C_UDSI(c,t,offset)到C_UDSI(c,t,offset+num-1),其他宏也是这样;它经常用在EXECUTE_ON_LOADING、INIT和ON_DEMAND宏中5、N_UDS可以直接使用它,不需要参数,返回FLUENT中已经 规定 关于下班后关闭电源的规定党章中关于入党时间的规定公务员考核规定下载规定办法文件下载宁波关于闷顶的规定 的UDS输运方程的数目。十、User-DefinedMemory(UDM)Macros用户自定义存储器宏本章的宏包括UDM和User-DefinedNodeMemory(UDNM)宏在使用本节中提供的宏之前,必须先去fluent界面设置变量个数,方法如下:Define—User-Defined—Memory1、当你定义了变量个数后,系统会默认给相应变量初始的名字,例:UDM:UserMemory0,UserMemory1UDNM:UserNodeMemory0,UserNodeMemory1如果你要修改相应的名字,需要使用宏Set_User_Memory_Name和宏Set_User_Node_Memory_Name。2、Set_User_Memory_NameSet_User_Memory_Name(inti,char*name);注意:这个宏只能修改一次,要改几个,一下子改完,最好在EXECUTE_ON_LOADING宏中使用。3、Set_User_Node_Memory_NameSet_User_Node_Memory_Name(inti,char*name);注意:这个宏只能修改一次,要改几个,一下子改完,最好在EXECUTE_ON_LOADING宏中使用。4、F_UDMIF_UDMI(f,t,i)i为标量的序号存储UDM的面变量注意:F_UDMI只能用于wall和flowboundaryfaces5、C_UDMIC_UDMI(c,t,i)i为标量的序号存储UDM的cell变量6、N_UDMIN_UDMI(v,i)Node*v,inti存储UDM的node变量7、Reserve_User_Memory_Vars为避免UDF和UDM冲突,使用这个宏,具体用法如下:offset=Reserve_User_Memory_Vars(intnum);这样,UDF就可以使用C_UDMI(c,t,offset)到C_UDMI(c,t,offset+num-1),其他宏也是这样;它经常用在EXECUTE_ON_LOADING、INIT和ON_DEMAND宏中十一、LoopingMacros循环宏LoopingOverCellThreadsinaDomain(thread_loop_c)LoopingOverFaceThreadsinaDomain(thread_loop_f)LoopingOverCellsinaCellThread(begin_c_loop/end_c_loop)LoopingOverFacesinaFaceThread(begin_f_loop/end_f_loop)LoopingOverFacesofaCell(c_face_loop)LoopingOverNodesofaCell(c_node_loop)LoopingOverNodesofaFace(f_node_loop)1、LoopingOverCellThreadsinaDomain(thread_loop_c)用法如下:Domain*domain;Thread*c_thread;thread_loop_c(c_thread,domain)/*loopsoverallcellthreadsindomain*/{}2、LoopingOverFaceThreadsinaDomain(thread_loop_f)用法如下:Thread*f_thread;Domain*domain;thread_loop_f(f_thread,domain)/*loopsoverallfacethreadsinadomain*/{}3、LoopingOverCellsinaCellThread(begin_c_loop/end_c_loop)用法如下:(经常配合thread_loop_c使用)cell_tc;Thread*c_thread;begin_c_loop(c,c_thread)/*loopsovercellsinacellthread*/{}end_c_loop(c,c_thread)4、LoopingOverFacesinaFaceThread(begin_f_loop/end_f_loop)用法如下:(经常配合thread_loop_f使用)face_tf;Thread*f_thread;begin_f_loop(f,f_thread)/*loopsoverfacesinafacethread*/{}end_f_loop(f,f_thread)5、LoopingOverFacesofaCell(c_face_loop)用法如下:cell_tc;Thread*t;face_tf;Thread*tf;intn;c_face_loop(c,t,n)/*loopsoverallfacesofacell*/{.f=C_FACE(c,t,n);tf=C_FACE_THREAD(c,t,n);.}n是thelocalfaceindexnumber,C_FACE宏可以获得面,C_FACE_THREAD宏可以获得面thread,还有一些宏能用于c_face_loop,在帮助文件里找到6、LoopingOverNodesofaCell(c_node_loop)用法如下:cell_tc;Thread*t;intn;Node*node;c_node_loop(c,t,n){.node=C_NODE(c,t,n);.}n是thelocalnodeindexnumber怎么获得的,C_NODE宏可以获得cell结点。7、LoopingOverNodesofaFace(f_node_loop)用法如下:face_tf;Thread*t;intn;Node*node;f_node_loop(f,t,n){.node=F_NODE(f,t,n);..}n是thelocalnodeindexnumber怎么获得的,F_NODE宏可以获得cell结点。十二、MultiphaseLoopingMacros本节中介绍的宏只能用在多相UDF中1、LoopingOverPhaseDomainsinMixture(sub_domain_loop)sub_domain_loop在每个单相域(子域)循环loopsoverallphasedomains,这个宏提供每个单相的指针和phase_domain_index(用来区别不同的相的线,第一相的线为0,第二相的线为1)。intphase_domain_index;/*indexofsubdomainpointers*/Domain*mixture_domain;Domain*subdomain;sub_domain_loop(subdomain,mixture_domain,phase_domain_index)subdomain是指向子域的指针,mixture_domain是指向超级域的指针,phase_domain_index子域第一相为0,第二相为1(注意:它和domain_id不同,domain_id超级域mixturedomain为1,第一相为2,第二相为3)如果sub_domain_loop宏用在DEFINE函数中并且他的参数还有domain变量,则mixture_domain会被求解器自动使用;如果不能使用,你可以在DEFINE函数里使用sub_domain_loop宏之前用get_domain(1)subdomainandphase_domain_indexaresetwithinthesub_domain_loopmacro.2、LoopingOverPhaseThreadsinMixture(sub_thread_loop)sub_thread_loop在每个单相线循环loopsoverallphase-levelthreadswithamixture-levelthreadintphase_domain_index;Thread*subthread;Thread*mixture_thread;sub_thread_loop(subthread,mixture_thread,phase_domain_index)subthreadisapointertothephasethread,andmixture_threadisapointertothemixture-levelthread,phase_domain_indexisanindexofsubdomainpointersthatcanberetrievedusingthePHASE_DOMAIN_INDEXmacro.注意:subthreadandphase_domain_indexareinitializedwithinthesub_thread_loopmacrodefinition.3、LoopingOverPhaseCellThreadsinMixture(mp_thread_loop_c)Themp_thread_loop_cmacroloopsthroughallcellthreads(atthemixturelevel)withinthemixturedomainandprovidesthepointersofthephase-level(cell)threadsassociatedwitheachmixture-levelthread.Thread**pt;Thread*cell_threads;Domain*mixture_domain;mp_thread_loop_c(cell_threads,mixture_domain,pt)themacroalsoreturnsapointerarray(pt)thatidentifiesthecorrespondingphase-levelthreads.Thepointertothecellthreadforthethphaseispt[i],whereiisthephase_domain_index.pt[i]canbeusedasanargumenttomacrosrequiringthephase-levelthreadpointer.cell_threadsisapointertothecellthreads,andmixture_domainisapointertothemixture-leveldomain.ptisanarraypointerwhoseelementscontainpointerstophase-levelthreads.如果mp_thread_loop_c宏用在DEFINE函数中并且他的参数还有domain变量,则mixture_domain会被求解器自动使用;如果不能使用,你可以在DEFINE函数里使用mp_thread_loop_c宏之前用get_domain(1)mp_thread_loop_c经常配合begin_c_loop使用,begin_c_loop嵌在mp_thread_loop_c中Whenbegin_c_loopisnestedwithinmp_thread_loop_c,youcanloopoverallcellsinallphasecellthreadswithinamixture.4、LoopingOverPhaseFaceThreadsinMixture(mp_thread_loop_f)Themp_thread_loop_fmacroloopsthroughallfacethreads(atthemixturelevel)withinthemixturedomainandprovidesthepointersofthephase-level(face)threadsassociatedwitheachmixture-levelthread.themacroalsoreturnsapointerarray(pt)thatidentifiesthecorrespondingphase-levelthreads.Thepointertothefacethreadforthethphaseispt[i],whereiisthephase_domain_index.pt[i]canbeusedasanargumenttomacrosrequiringthephase-levelthreadpointer.Thread**pt;Thread*face_threads;Domain*mixture_domain;mp_thread_loop_f(face_threads,mixture_domain,pt)face_threadsisapointertothefacethreads,andmixture_domainisapointertothemixture-leveldomain.ptisanarraypointerwhoseelementscontainpointerstophase-levelthreads.mp_thread_loop_f经常配合begin_f_loop使用,begin_f_loop嵌在mp_thread_loop_f中Whenbegin_f_loopisnestedwithinmp_thread_loop_f,youcanloopoverallfacesinallphasefacethreadswithinamixture.十三、AdvancedMultiphaseMacros多相流的定义会有不同1、DEFINE_ADJUST和DEFINE_INIT针对的domain只能用于超级域arepassedmixturedomainvariablesonly,而像ON_DEMAND宏中参数不传递任何变量,所以我们需要相关的宏来表示我们目前针对的对象具体是什么。编写多相模型的UDF时,要牢记多相模型的数据结构,注意函数获得的参数和函数hook在什么域上,同时还要注意你使用的多相模型的类型。2、PhaseDomainPointer(DOMAIN_SUB_DOMAIN)如果你想获得某一个单相的指针,有两种方法:第一,使用Get_Domain;第二,使用DOMAIN_SUB_DOMAIN。intphase_domain_index=0;/*primaryphaseindexis0*/Domain*mixture_domain;Domain*subdomain=DOMAIN_SUB_DOMAIN(mixture_domain,phase_domain_index);当你使用DEFINE宏并且含有aphasedomainindexargument(DEFINE_EXCHANGE_PROPERTY,DEFINE_VECTOR_EXCHANGE_PROPERTY),phase_domain_index不需要设置,否则你要指定phase_domain_index的值。3、Phase-LevelThreadPointer(THREAD_SUB_THREAD)THREAD_SUB_THREAD可以得到thephase-levelthread(subthread)pointer。intphase_domain_index=0;/*primaryphaseindexis0*/Thread*mixture_thread;/*mixture-levelthreadpointer*/Thread*subthread=THREAD_SUB_THREAD(mixture_thread,phase_domain_index);mixture_threadisapointertoamixture-levelthread。如果用DEFINE宏(例如DEFINE_PROFILE),系统会自动调用mixture_thread,如果不能自动调用,要用宏Lookup_Thread。当你使用DEFINE宏containsaphasedomainindexargument,例如(DEFINE_EXCHANGE_PROPERTY,DEFINE_VECTOR_EXCHANGE_PROPERTY),UDF会自动调用某个相,否则你要指定phase_domain_index的值。4、PhaseThreadPointerArray(THREAD_SUB_THREADS)Thread*mixture_thread;Thread**pt;/*initializept*/pt=THREAD_SUB_THREADS(mixture_thread);mixture_threadisapointertoamixture-levelthreadwhichcanrepresentacellthreadorafacethread.ItisautomaticallypassedtoyourUDFbytheFLUENTsolverwhenyouuseaDEFINEmacrothatcontainsavariablethreadargument(e.g.,DEFINE_PROFILE),andthefunctionishookedtothemixture.Otherwise,ifthemixturethreadpointerisnotexplicitlypassedtoyourUDF,thenyouwillneedtouseanothermethodtoretrieveit.ForexampleyoucanusetheLookup_Threadutilitymacro.pt[i],anelementinthearray,isapointertothecorrespondingphase-levelthreadforthethphase,whereiisthephase_domain_index.Youcanusept[i]asanargumenttosomecellvariablemacroswhenyouwanttoretrievespecificphaseinformationatacell.Forexample,C_R(c,pt[i])canbeusedtoreturnthedensityofthethphasefluidatcellc.5、MixtureDomainPointer(DOMAIN_SUPER_DOMAIN)通过这个宏,你可以通过aparticularphase-leveldomain(subdomain)pointer获得themixture-leveldomainpointer.。Domain*subdomain;Domain*mixture_domain=DOMAIN_SUPER_DOMAIN(subdomain);ItisautomaticallypassedtoyourUDFbytheFLUENTsolverwhenyouuseaDEFINEmacrothatcontainsadomainvariableargument(e.g.,DEFINE_ADJUST)在上面的例子中,要事先获得子域(即相域)的指针。如果UDF勾在某一相域上,相域的指针也可以由求解器自动传递给UDF。在当前版本FLUENT中,DOMAIN_SUPER_DOMAIN与Get_Domain(1)返回的指针是一样的。但是还是建议在UDF中,尽可能使用DOMAIN_SUPER_DOMAIN,考虑到FLUENT版本的更新,未来可能处理多个超级域。6、MixtureThreadPointer(THREAD_SUPER_THREAD)YoucanusetheTHREAD_SUPER_THREADmacrowhenyourUDFhasaccesstoaparticularphase-levelthread(subthread)pointer,andyouwanttoretrievethemixture-levelthreadpointer.Thread*subthread;Thread*mixture_thread=THREAD_SUPER_THREAD(subthread);subthreadisapointertoaparticularphase-levelthreadwithinthemultiphasemixture.ItisautomaticallypassedtoyourUDFbytheFLUENTsolverwhenyouuseaDEFINEmacrothatcontainsathreadvariableargument(e.g.,DEFINE_PROFILE),andthefunctionishookedtoaprimaryorsecondaryphaseinthemixture.7、DomainID(DOMAIN_ID)Domain*subdomain;intdomain_id=DOMAIN_ID(subdomain);8、PhaseDomainIndex(PHASE_DOMAIN_INDEX)Domain*subdomain;intphase_domain_index=PHASE_DOMAIN_INDEX(subdomain);十四、VectorandDimensionMacros1、Vdenotesavector,Sdenotesascalar,andDdenotesasequenceofthreevectorcomponentsofwhichthethirdisalwaysignoredforatwo-dimensionalcalculation.2、MacrosforDealingwithTwoandThreeDimensionsRP_2DandRP_3D3、TheNDMacros(1)ND_ND二维的时候ND_ND为2,三维的时候ND_ND为3,但如果用在数组中,都是从0开始使用,一直到n-1。realA[ND_ND][ND_ND];for(i=0;i
本文档为【UDF总结】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_270070
暂无简介~
格式:pdf
大小:597KB
软件:PDF阅读器
页数:26
分类:
上传时间:2019-07-18
浏览量:12