|
楼主 |
发表于 2006-8-3 16:31:58
|
显示全部楼层
我把我的程序粘上,大家看看出再错误的原因,帮帮忙
#include "udf.h"
#include "mem.h"
#include "dynamesh_tools.h"
static real v_x = 0.0,v_y=0.0,omega_z=0.0;
DEFINE_CG_MOTION(piston,dt,vel,omega,time,dtime)
{
Thread *t,*tc;
face_t f;
cell_t c;
real NV_VEC(A), NV_VEC(CG);
real force_x,force_y,pressure_x,pressure_y,viscosity_x,viscosity_y,viscosity_z,moment_z,dv_x,dv_y,domega_z;
real xf[ND_ND],xc[ND_ND];
real dir_differential[3]={0,0,0};
real viscosity_coff,viscosity_stress[3],viscosity_part[3],viscosity_x_part,viscosity_y_part;
real moment_p_z,moment_v_z;
int i;
/* reset velocities */
NV_S(vel, =, 0.0);
NV_S(omega, =, 0.0);
if (!Data_Valid_P())
return;
if(time<=0.001)
{
vel[1]=34.5;
return;
}
/* get the thread pointer for which this motion is defined */
t = DT_THREAD(dt);
CG[0]=DT_CG(dt)[0],CG[1]=DT_CG(dt)[1],CG[2]=DT_CG(dt)[2];
/* compute pressure force , viscosity force and moment on body by looping through all faces */
pressure_x = 0.0,pressure_y=0.0;
moment_p_z=0.0;
viscosity_x=0.0,viscosity_y=0.0;
moment_v_z=0.0;
begin_f_loop(f,t)
{
F_AREA(A,f,t);
F_CENTROID(xf,f,t);
c=F_C0(f,t);
tc=F_C0_THREAD(f,t);
C_CENTROID(xc,c,tc);
/* pressure force*/
pressure_x += -F_P(f,t) * A[0];
pressure_y += -F_P(f,t) * A[1];
/* viscosity force*/
/*U making*/
for(i=0;i<3;i++)
dir_differential[0]+=C_U_G(c,tc)*A/NV_MAG(A)*sqrt(1-A[0]*A[0]/(NV_MAG(A)*NV_MAG(A)));
/*V making*/
for(i=0;i<3;i++)
dir_differential[1]+=C_V_G(c,tc)*A/NV_MAG(A)*sqrt(1-A[1]*A[1]/(NV_MAG(A)*NV_MAG(A)));
/*W making*/
for(i=0;i<3;i++)
dir_differential[2]+=C_W_G(c,tc)*A/NV_MAG(A)*sqrt(1-A[2]*A[2]/(NV_MAG(A)*NV_MAG(A)));
/*compute viscous stress and viscous force of cell faces*/
viscosity_coff=C_NUT(c,tc);
for(i=0;i<=3;i++)
{
viscosity_stress=dir_differential*viscosity_coff;
viscosity_part=viscosity_stress*NV_MAG(A);
}
/*compute viscous force*/
viscosity_x_part=viscosity_part[0]*sqrt(1-A[0]*A[0]/(NV_MAG(A)*NV_MAG(A)))-viscosity_part[1]*A[1]/NV_MAG(A)*sqrt(A[0]*A[0]/(A[0]*A[0]+A[2]*A[2]))-viscosity_part[2]*A[2]/NV_MAG(A)*sqrt(A[0]*A[0]/(A[1]*A[1]+A[0]*A[0]));
viscosity_y_part=viscosity_part[1]*sqrt(1-A[1]*A[1]/(NV_MAG(A)*NV_MAG(A)))-viscosity_part[0]*A[0]/NV_MAG(A)*sqrt(A[1]*A[1]/(A[1]*A[1]+A[2]*A[2]))-viscosity_part[2]*A[2]/NV_MAG(A)*sqrt(A[1]*A[1]/(A[1]*A[1]+A[0]*A[0]));
viscosity_x+=viscosity_x_part,viscosity_y+=viscosity_y_part;
/*moment*/
/* pressure force making*/
moment_p_z+=F_P(f,t) * A[0]*(xf[1]-CG[1])-F_P(f,t) * A[1]*(xf[0]-CG[0]);
/* viscosity force making*/
moment_v_z+=-viscosity_x_part*(xc[1]-CG[1])+viscosity_y_part*(xc[0]-CG[0]);
}
end_f_loop(f,t)
force_x=pressure_x+viscosity_x;
force_y=pressure_y+viscosity_y;
moment_z=moment_p_z+moment_v_z;
/* compute change in velocity and angle velocity, i.e., dv = F * dt / mass
velocity update using explicit Euler formula */
dv_x = dtime * force_x / 39400;
v_x += dv_x;
dv_y = dtime * force_y / 39400;
v_y += dv_y;
domega_z=dtime*moment_z/390000;
omega_z=domega_z;
Message ("\ntime=%f ,x=%f ,y=%f , force_x=%.1f ,force_y=%.1f ,moment_z=%.1f ,Vx=%f ,Vy=%f ,omega_z=%f\n", time,CG[0],CG[1],force_x,force_y,moment_z,v_x,v_y,omega_z);
/* set components of velocity */
vel[0] = v_x,vel[1]=v_y,omega[2]=omega_z;
}
我发现了一些问题,已将
c=F_C0(f,t);
tc=THREAD_T0(t);
两句改成
c=F_C0(f,t);
tc=F_C0_THREAD(f,t);(关于这两句,你看我上传的附件)
经多次调试,发现
程序在计算速度梯度时出错,即在有
C_U_G(c,tc)
C_V_G(c,tc)
C_V_G(c,tc)
的语句的地方可能有问题
你现看看
|
|