鲁仁 发表于 2013-7-7 13:57:40

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:28

附件可以下载了

高永川 发表于 2013-7-8 18:15:30

测试了下,确实是这样,但没找到原因,估计跟DEFINE_CG_MOTION本身的调用方式有关。。建议在每个源文件下加一个DEFINE_EXECUTE_AT_END这样保证不会出歧义。#include "udf.h"#include<stdio.h>#define jidou2_mass 10700//the mass of the jidou2static real jidou2_inertial={83896.92,1199.83,85096.75}; //moments of inertia in 3D, here you can change the initial valuestatic real jidou2_vel_prev={0,0,0};//velocity of the jidou2, here you can change the initial valuestatic real jidou2_omega_prev={0,0,0};//angular velocity of the jidou2, here you can change the initial valuestatic real jidou2_dis_prev={0,0,0};//displacement of the jidou2, here you can change the initial valuestatic real jidou2_theta_prev={0,0,0};//angular displacement of the jidou2, here you can change the initial valuestatic real jidou2_acc={0,0,0};static real jidou2_rotacc={0,0,0};static real jidou2_centroid={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("flow-time");   fp2=fopen("ca1","a");   fp1=fopen("count0","a");fprintf(fp2,"%.6e%.8f%.8f%.8f%.8f%.8f%.8f
",time,jidou2_dis_prev,jidou2_theta_prev,jidou2_vel_prev,jidou2_omega_prev,jidou2_acc,jidou2_rotacc);fprintf(fp1,"%.6e%6i
",time,i);i=i+1;Message("this is the firt time
");fclose(fp2);    fclose(fp1); }DEFINE_CG_MOTION(JiDou2,dt,vel,omega,time,dtime){Thread *tread;Domain *domin;face_t f;real force;//the total force on the jidou2.real moment;//the total momentum on the jidou2real d_vel;real d_omega;real jidou2_k1;real jidou2_k2;real h=4.85; //h定义为箕斗高度的一半real L=440; //暂取井道深度mreal jidou2_s=0; // jidou2_s定义为箕斗的提升行程real s20=195.75; // s20定义为t=0时箕斗距罐道绳顶部的距离, s10=220-19.4-4.85=195.75real 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("ca3","a");   fp1=fopen("count1","a");fprintf(fp2,"%.6e%.8f%.8f%.8f%.8f%.8f%.8f
",time,jidou2_dis_prev,jidou2_theta_prev,jidou2_vel_prev,jidou2_omega_prev,jidou2_acc,jidou2_rotacc);fprintf(fp1,"%.6e%6i
",time,i);i=i+1;Message("this is the firt time
");fclose(fp2);    fclose(fp1);tread=DT_THREAD(dt); //get the thread pointer for which this motion is defineddomin=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=-time*9.7;    jidou2_s=-vel*time/2;   }else{    vel=-9.7;    jidou2_s=-vel*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=jidou2_dis_prev+jidou2_vel_prev*dtime;   jidou2_theta_prev=jidou2_theta_prev+jidou2_omega_prev*dtime;   jidou2_acc=(force-jidou2_k1*(jidou2_dis_prev-h*jidou2_theta_prev)-jidou2_k2*(jidou2_dis_prev+h*jidou2_theta_prev))/jidou2_mass;   d_vel=jidou2_acc*dtime;   //get the accelaration of the jidou2 with Newton’s second 1aw.   jidou2_vel_prev=jidou2_vel_prev+d_vel;//v+dv get the new translational velocity   vel=jidou2_vel_prev;   jidou2_rotacc=(moment+jidou2_k1*(jidou2_dis_prev-h* jidou2_theta_prev)*h-jidou2_k2*(jidou2_dis_prev+h*jidou2_theta_prev)*h)/jidou2_inertial;   d_omega=jidou2_rotacc*dtime;   //get the accelaration of the jidou2 with Newton’s second law.   jidou2_omega_prev=jidou2_omega_prev+d_omega;//ω+dωget the new rotational velocity   omega=jidou2_omega_prev;   Message("%.6e%.8f%.8f%.8f%.8f%.8f%.8f
",time,jidou2_dis_prev,jidou2_theta_prev,jidou2_vel_prev,jidou2_omega_prev,jidou2_acc,jidou2_rotacc);}

鲁仁 发表于 2013-7-8 18:27:42

谢谢你啊!是不是跟模型有关啊?
页: [1]
查看完整版本: Fluent 14.0计算两车交会的udf咨询