标题: Fluent 14.0计算两车交会的udf咨询 [打印本页] 作者: 鲁仁 时间: 2013-7-7 13:57 标题: Fluent 14.0计算两车交会的udf咨询 隋博士好,我在用Fluent 14.0计算两车交会的动网格中编写了两个类似的UDF(car1.c和car2.c)(UDF中主要用到了DEFINE_CG_MOTION和Compute_Force_And_Moment)来定义两车的相向运动,同时添加到fluent 14 中编译运行,通过运行后生成“car1的位移.txt”和“car2的位移.txt”文件分析,fluent 14 将car1.c运行了一遍,car2.c运行了两遍,因为“car1的位移.txt”文件里面每个t时刻的位移数据写了一遍(参见附件中的图2),而“car2的位移.txt”文件里面每个t时刻的位移数据写了两遍(参见附件中的图1),并且第二遍的数值和第一遍的稍有不同(参见附件中的图3),car1.c并且“car1.txt”文件大小为122k,而“car2.txt”文件大小为236k。隋博士能否解答下问题可能出现在哪些方面啊?在此先行表示感谢!作者: 陈琳 时间: 2013-7-8 10:39
附件可以下载了作者: 高永川 时间: 2013-7-8 18:15
测试了下,确实是这样,但没找到原因,估计跟DEFINE_CG_MOTION本身的调用方式有关。。建议在每个源文件下加一个DEFINE_EXECUTE_AT_END这样保证不会出歧义。#include &quot;udf.h&quot;#include<stdio.h>#define jidou2_mass 10700 //the mass of the jidou2static real jidou2_inertial[3]={83896.92,1199.83,85096.75}; //moments of inertia in 3D, here you can change the initial valuestatic real jidou2_vel_prev[3]={0,0,0};//velocity of the jidou2, here you can change the initial valuestatic real jidou2_omega_prev[3]={0,0,0};//angular velocity of the jidou2, here you can change the initial valuestatic real jidou2_dis_prev[3]={0,0,0};//displacement of the jidou2, here you can change the initial valuestatic real jidou2_theta_prev[3]={0,0,0};//angular displacement of the jidou2, here you can change the initial valuestatic real jidou2_acc[3]={0,0,0};static real jidou2_rotacc[3]={0,0,0};static real jidou2_centroid[3]={0.58,4.85,0}; //centroid of the jidou2, here you can change the initia]valueint i=1;DEFINE_EXECUTE_AT_END(at_end){ real time; FILE *fp2; FILE *fp1; time = RP_Get_Real(&quot;flow-time&quot;); fp2=fopen(&quot;ca1&quot;,&quot;a&quot;); fp1=fopen(&quot;count0&quot;,&quot;a&quot;); fprintf(fp2,&quot;%.6e %.8f %.8f %.8f %.8f %.8f %.8f
&quot;,time,jidou2_dis_prev[0],jidou2_theta_prev[2],jidou2_vel_prev[0],jidou2_omega_prev[2],jidou2_acc[0],jidou2_rotacc[2]); fprintf(fp1,&quot;%.6e%6i
&quot;,time,i); i=i+1; Message(&quot;this is the firt time
&quot;); fclose(fp2); fclose(fp1); }DEFINE_CG_MOTION(JiDou2,dt,vel,omega,time,dtime){ Thread *tread; Domain *domin; face_t f; real force[3];//the total force on the jidou2. real moment[3];//the total momentum on the jidou2 real d_vel[3]; real d_omega[3]; real jidou2_k1; real jidou2_k2; real h=4.85; //h定义为箕斗高度的一半 real L=440; //暂取井道深度m real jidou2_s=0; // jidou2_s定义为箕斗的提升行程 real s20=195.75; // s20定义为t=0时箕斗距罐道绳顶部的距离, s10=220-19.4-4.85=195.75 real n2=4; // n2定义为箕斗两侧罐道绳的数量 real Q=5650; // Q为每根罐道绳底部张紧重锤的质量; real q=8.94; // q为罐道绳单位长度的重量,Φ查标准YB/T 5295-2006密封钢丝绳表 real g=9.81; // g为重力加速度; FILE *fp2; FILE *fp1; fp2=fopen(&quot;ca3&quot;,&quot;a&quot;); fp1=fopen(&quot;count1&quot;,&quot;a&quot;); fprintf(fp2,&quot;%.6e %.8f %.8f %.8f %.8f %.8f %.8f
&quot;,time,jidou2_dis_prev[0],jidou2_theta_prev[2],jidou2_vel_prev[0],jidou2_omega_prev[2],jidou2_acc[0],jidou2_rotacc[2]); fprintf(fp1,&quot;%.6e%6i
&quot;,time,i); i=i+1; Message(&quot;this is the firt time
&quot;); fclose(fp2); fclose(fp1); tread=DT_THREAD(dt); //get the thread pointer for which this motion is defined domin=THREAD_DOMAIN(tread); //DT_THREAD(t): pointer to face thread; Compute_Force_And_Moment(domin,tread,jidou2_centroid,force,moment,FALSE); //the macro for the calculation of total force and total momentum on the jidou2.if(time<=1.0) { vel[1]=-time*9.7; jidou2_s=-vel[1]*time/2; } else { vel[1]=-9.7; jidou2_s=-vel[1]*time-9.7/2; } jidou2_k1=(n2*Q*g+n2*q*(L-s20-jidou2_s+h)*g+ jidou2_mass*g)/(s20+jidou2_s-h); jidou2_k2=(n2*Q*g+n2*q*(L-s20-jidou2_s-h)*g)/(L-s20-jidou2_s-h); jidou2_dis_prev[0]=jidou2_dis_prev[0]+jidou2_vel_prev[0]*dtime; jidou2_theta_prev[2]=jidou2_theta_prev[2]+jidou2_omega_prev[2]*dtime; jidou2_acc[0]=(force[0]-jidou2_k1*(jidou2_dis_prev[0]-h*jidou2_theta_prev[2])-jidou2_k2*(jidou2_dis_prev[0]+h*jidou2_theta_prev[2]))/jidou2_mass; d_vel[0]=jidou2_acc[0]*dtime; //get the accelaration of the jidou2 with Newton’s second 1aw. jidou2_vel_prev[0]=jidou2_vel_prev[0]+d_vel[0];//v+dv get the new translational velocity vel[0]=jidou2_vel_prev[0]; jidou2_rotacc[2]=(moment[2]+jidou2_k1*(jidou2_dis_prev[0]-h* jidou2_theta_prev[2])*h-jidou2_k2*(jidou2_dis_prev[0]+h*jidou2_theta_prev[2])*h)/jidou2_inertial[2]; d_omega[2]=jidou2_rotacc[2]*dtime; //get the accelaration of the jidou2 with Newton’s second law. jidou2_omega_prev[2]=jidou2_omega_prev[2]+d_omega[2];//ω+dωget the new rotational velocity omega[2]=jidou2_omega_prev[2]; Message(&quot;%.6e %.8f %.8f %.8f %.8f %.8f %.8f
&quot;,time,jidou2_dis_prev[0],jidou2_theta_prev[2],jidou2_vel_prev[0],jidou2_omega_prev[2],jidou2_acc[0],jidou2_rotacc[2]);}作者: 鲁仁 时间: 2013-7-8 18:27
谢谢你啊!是不是跟模型有关啊?