您好,欢迎访问三七文档
当前位置:首页 > 办公文档 > 其它办公文档 > FLUENT学习udf编程实例
/**************************************************UDF:通过规定一个依赖于温度的粘性特性来模拟凝固********************************************/#includeudf.hDEFILE_PROPERTY(cell_viscosity,cell,thread){realmu_lam;realtemp=C_T(cell,thread);if(temp288.)mu_lam=5.5e-3;esleif(temp286.)mu_lam=143.2135-0.49725*temp;elsemu_lam=1.;returnmu_lam;}#includeudf.h#includemath.hDEFINE_CG_MOTION(velocity,dt,vel,omega,time,dtime){realt=RP_Get_Real(flow-time);intn;floatc;n=t/25;c=t-n*25;omega[0]=0;omega[1]=0;omega[2]=0;if(c=0&&c=10)vel[0]=0;vel[1]=0;vel[2]=0.2;elseif(c10.0&&c=15.0)vel[0]=-0.1;vel[1]=0;vel[2]=0;elsevel[0]=0;vel[1]=0;vel[2]=-0.2;}/********************************************************计算气浊率的UDF*******************************************************/#includeudf.h#defineMIN_VOF1.e-5#defineMAX_VOF0.999999DEFINE_CAVITATION_RATE(user_cavitation_rate,c,t,p,rhoV,rhoL,vofV,p_v,n_b,m_dot){realp_vapor=*p_v;realn_bubbles=*n_b;realdp,vofM,radV;dp=p_vapor-ABS_P(p[c],op_pres);vofM=MIX(MAX(MIN_VOF,vofV[c],MAX_VOF));radV=pow(vofM/((1.-vofM)*4./3.*M_PI*N_Bbubbles),1./3.);if(dp0)*m_dot=(1.-vofV[c])*n_bubbles84.*M_PI*radV*radV/(1.*n_bubbles*4./3.*M_PI*radV*radV*radV)*sqrt(2.*ABS(dp)/(3.*rhoL[c]));else{*m_dot=-(1.vofV[c])*n_bubbles*4.M_PI*radV*radV/(1.*n_bubbles*4./3.M_PI*radV*radV*radV)*sqrt(2.*ABS(dp)/(3.*rhoL[c]));if(vofV[c]=MIN_VOF)*m_dot=0.;}}/******************************************************关于演示DEFINE_CHEM_STEP的UDF的例子*******************************************************/#includeudf.hDEFINE_CHEM_STEP(user_chem_step,ifail,n,dt,p,temp,yk){inti;realc=1./n_spe,decay=exp(-dt);for(i=0;ispe;i++)yk[i]=(yk[i]-c)*decay+c;}/*************************************************************************运动方程的一个自由度(X方向)*汇编的UDF***********************************************************************/#includeudf.hstaticrealv_prev=0.0;DEFINE_CG_MOTION(piston,dt,vel,omega,time,dtime){Thread*t;face_t=f;realNV_VEC(A);realforce,dv;/*重新设置速度*/NV_S(vel,=,0.0);NV_s(omega,=,0.0);if(!Data_Valid_p())return;/*获得脉络指示器,这个运动关于这个指示器而被定义*/t=DT_THREAD(dt);/*通过循环所有的面计算压力*/force=0.0;begin_f_loop(f,t){F_AREA(A,f,t);Force+=F_P(f,t)*NV_MAG(A);}end_f_loop(f,t)/*计算速度中的变化,如dv=F*dt/mass,使用显得的Euler公式更新速度*/dv=dtime*force/50.0;v_prev+=dv;message(time=%f,x_vel=%f,force=%f\ntime,v_prev,Force);/*设置速度分量*/vel[0]=v_prev;}/*********************************************************改变关于一个依赖于时间的解的时间步长的UDF*********************************************************/#includeudf.hDEFINE_DELTAT(mydeltat,domain){realtime_step;realflow_time=CURRENT_TIME;if(flow_time0.5)time_step=0.1;elsetime_step=0.2;returntime_step;}/*********************************************************使用一个自定义标量计算空气平均龄的UDF*******************************************************/#includeudf.hDEFINE_DIFFUSIVITY(mean_age_diff,c,t,i){returnC_R(c,t)*2.88e-05+C_MU_EFF(c,t)/0.7;}/*UDF,改变DO模型中的散发项*/#includeduf.hDEFINE_DOM_SOURCE(user_dom_source,c,t,ni,nb,emission,in_scattering,abs_coeff,scat_coeff){/*散发增加5%*/*emission*=1.05;}/*UDF,输出半透明壁面上的扩散的反射率和扩散的传播率*/#includeudf.hDEFINE_DOM_DEFFUSE_REFLECTIVITY(user_dom_diff_refl,t,nband,n_a,n_b,diff_ref_a,diff_tran_a,diff_ref_b,diff_tran_b){/*ArgumenttypesThread*tintnbandintn_aintn_breal*diff_ref_a//边a上得扩散的反射率real*diff_tran_a//边a上得扩散的传播率real*diff_ref_b//边b上得扩散的反射率real*diff_tran_b//边b上得扩散的传播率*/printf(diff_ref_a=%fdiff_tran_a=%f\n,*diff_ref_a,*diff_tran_a);printf(diff_ref_b=%fdiff_tran_b=%f\n,*diff_ref_b,*diff_tran_b);}#includeudf.hDEFINE_EXECUTE_AT_END(execute_at_end){Domain*d;Thread*t;/*对耗散进行积分。*/realsum_diss=0;cell_tc;d=Get_Domain(1);/*若是多相,则是混合域*/thread_loop_c(t,d){if(FLUID_THREAD_P(t)){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);fflush(stdout);}/*UDF,在半透明的壁面上,沿面f的方向改变镜子的反射率和传播率*/#includeudf.hDEFINE_DOM_SPECULAR_REFLECTIVITY(user_dom_spec_refl,f,t,nband,n_a,n_b,ray_direction,en,internal_reflection,specular_reflectivity,specular_transmissivity){/*Argumenttypesface_tfThread*dintnbandintn_aintn_brealray_directionrealray_directionrealenint*internal_reflectionreal*specular_reflectivityreal*specular_transmissivity*/realangle,cos_theta;realPI=3.141592;cos_theta=Nv_DOT(ray_direction,en)if(angle45&&angle60){*specular_reflectivity=0.3;*specular_transmissivity=0.7;}}/**************************************************************UDF:在FLUENT中,用户化缺省的Syamlal阻力法则**************************************************************/#includeudf.h#definePi4.*atan(1.)#definediam23.e-4DEFINE_EXCHANGE_PROPERTY(custom_drag,cell,mix_thread,s_col,f_col){Thread*thread_g,*thread_s;realx_vel_g,x_vel_s,y_vel_g,y_vel_s,abs_v,slip_x,slip_y,rho_g,rho_s,mu_g,reyp,afac,bfac,void,vfac,fdrgs,taup,k_g_s;/*寻找关于气体的脉络(初步)*//*寻找关于固体的脉络(第二相)*/thread_g=THREAD_SUB_THREAD(mix_thread,s_col);/*气体相*/thread_s=THREAD_SUB_THREAD(mix_thread,f_col);/*固体相*//*寻找相速度和特性*/x_vel_g=C_U(cell,thread_g);y_vel_g=C_V(cell,thread_g);x_vel_s=C_U(cell,thread_s);y_vel_s=C_V(cell,thread_s);slip_x=x_vel_g-x_vel_s;slip_y=y_vel_g-y_vel_s;rho_g=C_R(cell,thread_g);rho_s=C_R(cell,thread_s);mu_g=C_R(ce
本文标题:FLUENT学习udf编程实例
链接地址:https://www.777doc.com/doc-2714959 .html