|
|

楼主 |
发表于 2014-4-27 21:43:07
|
显示全部楼层
回复 2# milaoshu 的帖子
#include <stdio.h>
#include "udf.h"
static FILE *fp;
static real force[3];
static real M[3];
static real cg[3];
static int id1=21;
DEFINE_CG_MOTION(go_others, dt, cg_vel, cg_omega, time, dtime)
{
real a=1;
real cgvel=0.0;
real velo;
/* reset velocities */
NV_S (cg_vel, =, 0.0);
if (!Data_Valid_P ())
return;
velo =a;
Message ("\nUDF auv: time = %f, dtime = %f, y_vel = %f, ", time, dtime, velo);
cg[1]=0.0; cg[0]=0.0;
if(time==0&&time<0.1)
{
cg[0]=0;
cg[1]=0;
cg[2]=0;
}
cg_vel[0] =velo;
cg[0]=cg[0];
cg[2]=cg[2];
cg[1]=cg[1];
if(time>=0.1)
cg[0]=cg[0]+velo*(time-0.1);
cg[2]=cg[2];
cg[1]=cg[1];
Message ("M=%f cg[0]=%f cg[2]=%f\n", M[1],cg[0],cg[2]);
node_to_host_real_1(cgvel);
node_to_host_real(cg_vel,ND_ND);
}
DEFINE_CG_MOTION(go_auv, dt, cg_vel, cg_omega, time, dtime)
{
Thread *t = DT_THREAD (dt); /* pointer to a thread */
Domain *d; /* pointer to collection of all threads */
Thread *t1;
real a=1;
real cgvel=0.0;
real velo;
/* reset velocities */
NV_S (cg_vel, =, 0.0);
if (!Data_Valid_P ())
return;
velo =a;
Message ("\nUDF auv: time = %f, dtime = %f, y_vel = %f, ", time, dtime, velo);
cg[1]=0.0; cg[0]=0.0;
if(time==0&&time<0.1)
{
cg[0]=0;
cg[1]=0;
cg[2]=0;
fp=fopen("drag.txt","w");
fclose(fp);
}
fp=fopen("drag.txt","a");
cg_vel[0] =velo;
d=Get_Domain(1);
t1=Lookup_Thread(d,id1); /*Thread Pointer for Zone ID*/
Compute_Force_And_Moment(d,t1,cg,force,M,1);
cg[0]=cg[0];
cg[2]=cg[2];
cg[1]=cg[1];
if(time>=0.1)
cg[0]=cg[0]+velo*(time-0.1);
cg[2]=cg[2];
cg[1]=cg[1];
fprintf(fp,"time=%f M=%f drag=%f force-z=%f cg[0]=%f cg[2]=%f\n",time,M[1],force[0],force[2],cg[0],cg[2]);
Message ("M=%f cg[0]=%f cg[2]=%f\n", M[1],cg[0],cg[2]);
fclose(fp);
node_to_host_real_1(cgvel);
node_to_host_real(cg_vel,ND_ND);
}
定义潜艇在水中前进,力矩从-2一直增到+4 实际定常计算力矩是-3, 这是udf |
|