|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
这是帮助里面的一个例子,程序中定义的这些量如何能和网格中的相对应起来,也就是说,如果有了网格,如何在程序中对它进行操作,下面这个例子希望您能讲解一下:
例如:考察一下例子,从简单x方向力平衡来计算线速度。
V是速度,F是力,m是物体质量,用explicit欧拉公式计算t时刻的速度
/************************************************************
*
* 1-degree of freedom equation of motion (x-direction)
* compiled UDF
*
************************************************************/
#include "udf.h"
static real v_prev = 0.0;
DEFINE_CG_MOTION(piston, dt, vel, omega, time, dtime)
{
Thread *t;
face_t f;
real NV_VEC (A);
real force, dv;
/* reset velocities */
NV_S (vel, =, 0.0);
NV_S (omega, =, 0.0);
if (!Data_Valid_P ())
return;
/* get the thread pointer for which this motion is defined */
t = DT_THREAD (dt);
/* compute pressure force on body by looping through all faces */
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)
/* compute change in velocity, i.e., dv = F * dt / mass
velocity update using explicit Euler formula */
dv = dtime * force / 50.0;
v_prev += dv;
Message ("time = %f, x_vel = %f, force = %f\n", time, v_prev,
force);
/* set x-component of velocity */
vel[0] = v_prev;
}
|
|