zhangload 发表于 2007-4-17 18:05

写udf,动网格DEFINE_CG_MOTION 疑问?

(1)请问
有谁用udf做动网格
编写DEFINE_CG_MOTION(piston, dt, vel, omega, time, dtime)

成功过的??

给个例子好吗??

如有相关例子请发送到zhangload@163.com

(2)按照目前udf 做的移动移动网格问题的相关例子中的udf如下,都是帮助文件里自带的例子。见附录,估计做相关的人都看过了这2个例子。有几点疑问:

   1)他们这些力的转换思路 和理论是什么?
   2)这2个例子的力学转换关系有些不同,为什么会这样?哪个是标准的?
   3)他们中给定的常数,比如,50.0 、K_SPRING 150000 、 0.4 * 0.0254是什么含义?是如何得来? 如果要修改一般要注意哪些?




附udf例子--------------------------------------
1)#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 = v_prev;
}


+--------------------------------------------------------------------------------
2)DEFINE_CG_MOTION(valve, dt, cg_vel, cg_omega, time, dtime)
{
#if !RP_NODE
Thread *t = DT_THREAD (dt);
face_t f;
real force, loc;
#endif
real velo;

/* reset velocities */
NV_S (cg_vel, =, 0.0);
NV_S (cg_omega, =, 0.0);

if (!Data_Valid_P ())
    return;

#if !RP_NODE
/* compute force on piston wall */
force = 0.0;
begin_f_loop (f, t)
    {
      real *AA;

      AA = F_AREA_CACHE (f, t);
      force += F_P (f, t) * AA;
    }
end_f_loop (f, t)

# if RP_2D
if (rp_axi)
    force *= 2.0 * M_PI;
# endif

read_loc_velo_file (&loc, &velo);

/* add in spring force */
# define K_SPRING 150000
{
    real init_disp = 0.4 * 0.0254;
    real s_force =K_SPRING * (loc + init_disp);

    force = force - s_force;
}

/* compute change in velocity */
{
    real dv = dtime * force / 0.01;

    velo += dv;
    loc += velo * dtime;
}

Message ("\nUDF valve: time = %f, x_vel = %f, force = %f, loc(m)= %f\n",
         time, velo, force, loc);
write_loc_velo_file (loc, velo);
#endif /* !RP_NODE */

#if PARALLEL
host_to_node_real_1 (velo);
#endif

cg_vel = velo;
}

hyacinth 发表于 2007-4-19 16:06

动网格 UDF,支持多个运动,支持并行,支持信息自动保存

/* ******************************************* */
/* ******************************************* */

可以根据需要,添加更多的运动
支持多个运动,支持并行,支持信息自动保存

/* ******************************************* */
/* ******************************************* */

# include "udf.h"

/* ******************************************* */
static real G = 9.80; /* gravity */

static real valve_M = 0.1; /* mass of moving object*/
static real valve_S = 0.0; /* replacement of moving object*/
static real valve_V = 0.0; /* velocity of moving object */
static real valve_F = 0.0; /* fluid force of one component */
static int is_valve = 0; /* is the object still moving */

static real ball_M = 0.19; /* mass of moving object*/
static real ball_S = 0.0; /* replacement of moving object*/
static real ball_V = 0.0; /* velocity of moving object */
static real ball_F = 0.0; /* fluid force of one component */
static int is_ball = 0; /* is the object still moving */
/* ******************************************* */

DEFINE_CG_MOTION(valve, dt, vel, omega, time, dtime)
{
#if !RP_HOST
    Thread *t;
    Domain *d;
    real dv, CG, force, moment;

    /* Check to see if there is data */
    if (!Data_Valid_P ())
    {
      Message0("\n\nNo data->No mesh motion!!!\n\n");
      return;
    }
   
    /* Reset velocities */
    NV_S (vel, =, 0.0);
    NV_S (omega, =, 0.0);
   
    /* Calculate force*/
    d = THREAD_DOMAIN (DT_THREAD ((Dynamic_Thread *)dt));
    t = DT_THREAD(dt);
    NV_S (CG, =, 0.0);
    Compute_Force_And_Moment (d, t, CG, force, moment, FALSE);

    /* Compute change in velocity, i.e., dv=F*dt/M velocity update using explicit Euler formula */
    dv = dtime * (force - G * valve_M) / valve_M;
    if(is_valve == 0 && dv >= 0.0)
    {
      is_valve = 1;
      Message0("\n\n============================== BEGIN VALVE MOTION INFO ==============================\n");
      Message0("\n VALVE BEGIN MOVE! \n");
      Message0("\n============================== END VALVE MOTION INFO ==============================\n");
    }
    if(is_valve == 0 && dv < 0.0) {
      dv = 0.0;
    }
    valve_V += dv;
    if(valve_S >= 0.010)
    {
      valve_V = 0.0;
    }
    valve_S += valve_V * dtime;

    /* Set x-component of velocity */
    vel = valve_V;
    valve_F = force;

    Message0("\n\n============================== BEGIN VALVE MOTION INFO ==============================\n");
    Message0("\ntime=%.5e F(x)=%.4e S(x)=%.6e V(x)=%.6e move?=%d\n", time, force, valve_S, valve_V, is_valve);
    Message0("\n============================== END VALVE MOTION INFO ==============================\n");
#endif

    node_to_host_real_1(valve_S);
    node_to_host_real_1(valve_V);
    node_to_host_real_1(valve_F);
    node_to_host_int_1(is_valve);

    node_to_host_real(vel, ND_ND);
    node_to_host_real(omega, ND_ND);
}

DEFINE_CG_MOTION(ball, dt, vel, omega, time, dtime)
{
#if !RP_HOST
    Thread *t;
    Domain *d;
    real dv, CG, force, moment;

    /* Check to see if there is data */
    if (!Data_Valid_P ())
    {
      Message0("\n\nNo data->No mesh motion!!!\n\n");
      return;
    }
   
    /* Reset velocities */
    NV_S (vel, =, 0.0);
    NV_S (omega, =, 0.0);
   
    /* Calculate force*/
    d = THREAD_DOMAIN (DT_THREAD ((Dynamic_Thread *)dt));
    t = DT_THREAD(dt);
    NV_S (CG, =, 0.0);
    Compute_Force_And_Moment (d, t, CG, force, moment, FALSE);

    /* Compute change in velocity, i.e., dv=F*dt/M velocity update using explicit Euler formula */
    dv = dtime * (force - G * ball_M) / ball_M;
    if(is_ball == 0 && dv >= 0.0)
    {
      is_ball = 1;
      Message0("\n\n============================== BEGIN BALL MOTION INFO ==============================\n");
      Message0("\n BALL BEGIN MOVE! \n");
      Message0("\n============================== END BALL MOTION INFO ==============================\n");
    }
    if(is_ball == 0 && dv < 0.0) {
       dv = 0.0;
    }
    ball_V += dv;
    ball_S += ball_V * dtime;
   
    /* Set x-component of velocity */
    vel = ball_V;
    ball_F = force;

    Message0("\n\n============================== BEGIN BALL MOTION INFO ==============================\n");
    Message0("\ntime=%.5e F(x)=%.4e S(x)=%.6e V(x)=%.6e move?=%d\n", time, force, ball_S, ball_V, is_ball);
    Message0("\n============================== END BALL MOTION INFO ==============================\n\n");
#endif

    node_to_host_real_1(ball_S);
    node_to_host_real_1(ball_V);
    node_to_host_real_1(ball_F);
    node_to_host_int_1(is_ball);

    node_to_host_real(vel, ND_ND);
    node_to_host_real(omega, ND_ND);
}

static void write_data(FILE *fp)
{
    fprintf(fp, "%e ", valve_V);
    fprintf(fp, "\n");
    fprintf(fp, "%e ", valve_S);
    fprintf(fp, "\n");
    fprintf(fp, "%e ", valve_F);
    fprintf(fp, "\n");
    fprintf(fp, "%d ", is_valve);
    fprintf(fp, "\n");

    fprintf(fp, "%e ", ball_V);
    fprintf(fp, "\n");
    fprintf(fp, "%e ", ball_S);
    fprintf(fp, "\n");
    fprintf(fp, "%e ", ball_F);
    fprintf(fp, "\n");
    fprintf(fp, "%d ", is_ball);
}

static void read_data(FILE * fp)
{
    fscanf(fp, "%e", [$valve_V)]
    fscanf(fp, "%e", [$valve_S)]
    fscanf(fp, "%e", [$valve_F)]
    fscanf(fp, "%d", [$is_valve)]

    fscanf(fp, "%e", [$ball_V)]
    fscanf(fp, "%e", [$ball_S)]
    fscanf(fp, "%e", [$ball_F)]
    fscanf(fp, "%d", [$is_ball)]
}

DEFINE_RW_FILE(reader, fp)
{
    Message0("\n\n============================== BEGIN UDF INFOMATION ==============================\n");
    Message0("\nReading UDF data from data file...\n");

#if PARALLEL
#if RP_HOST
    read_data(fp);
#endif
#else
    read_data(fp);
#endif

    host_to_node_real_1(valve_V);
    host_to_node_real_1(valve_S);
    host_to_node_real_1(valve_F);
    host_to_node_int_1(is_valve);
   
    host_to_node_real_1(ball_V);
    host_to_node_real_1(ball_S);
    host_to_node_real_1(ball_F);
    host_to_node_int_1(is_ball);

    Message0("\n------------------------------ BEGIN VALVE MOTION INFO ------------------------------\n");
    Message0("\nS(x)=%.6e V(x)=%.6e F(x)=%.4e move?=%d\n", valve_S, valve_V, valve_F, is_valve);
    Message0("\n------------------------------ END VALVE MOTION INFO ------------------------------\n");
   
    Message0("\n------------------------------ BEGIN BALL MOTION INFO ------------------------------\n");
    Message0("\nS(x)=%.6e V(x)=%.6e F(x)=%.4e move?=%d\n", ball_S, ball_V, ball_F, is_ball);
    Message0("\n------------------------------- END BALL MOTION INFO -------------------------------\n");
    Message0("\n================================ END UDF INFOMATION ================================\n\n");
}

DEFINE_RW_FILE(writer, fp)
{
    Message0("\n\n============================== BEGIN UDF INFOMATION ==============================\n");
    Message0("\n\nWriting UDF data to data file...\n");

#if PARALLEL
#if RP_HOST
    write_data(fp);
#endif
#else
    write_data(fp);
#endif
    Message0("\n================================ END UDF INFOMATION ================================\n\n");
}

来自傲雪

albert 发表于 2007-6-29 15:42

我觉得我们自己做的时候不用这么麻烦把
直接做动网格的那部分就可以乐把

snow2146073 发表于 2011-4-14 16:52

学不会啊,愁啊

漂亮朋友 发表于 2011-4-20 10:43

基本理论是牛顿第二定律,50是质量,K_spring 代表弹簧刚度值,0.4(inch) * 0.0254表示长度(因为UDF采用国际单位制),关于UDF的使用方法主要靠自己好好琢磨,鉴于你用CG——motion,推荐你几个宏,1,DT_CG(dt)2.COMPUTE_FORCE_AND_MOMENT.

zczhang1989 发表于 2012-3-23 10:19

有没有谁知道那个光顺法的那个怎么让动边界的位移扩散出去。

Seventy721 发表于 2012-3-27 08:52

需要将周边的区域也设置为动网格,可以在GUI界面里Dynamic zones里面设置好参数,然后在UDF里用SET_DEFORMING_THREAD_FLAG(THREAD_T0(t));

ljxronaldo 发表于 2012-3-28 12:02

回复 5 # 漂亮朋友 的帖子

请问F_AREA_CACHE 是什么意思呢?
另外,你提供的宏是从哪儿找到的,有没有什么参考资料提供一下啊。谢谢!
190745256@qq.com
页: [1]
查看完整版本: 写udf,动网格DEFINE_CG_MOTION 疑问?