声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 10676|回复: 7

[动网格] 写udf,动网格DEFINE_CG_MOTION 疑问?

[复制链接]
发表于 2007-4-17 18:05 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
(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[0] = 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[0];
    }
  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[0] = velo;
}
回复
分享到:

使用道具 举报

发表于 2007-4-19 16:06 | 显示全部楼层
动网格 UDF,支持多个运动,支持并行,支持信息自动保存

  1. /* ******************************************* */
  2. /* ******************************************* */

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

  5. /* ******************************************* */
  6. /* ******************************************* */

  7. # include "udf.h"

  8. /* ******************************************* */
  9. static real G = 9.80; /* gravity */

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

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

  21. DEFINE_CG_MOTION(valve, dt, vel, omega, time, dtime)
  22. {
  23. #if !RP_HOST
  24.     Thread *t;
  25.     Domain *d;
  26.     real dv, CG[ND_ND], force[3], moment[3];

  27.     /* Check to see if there is data */
  28.     if (!Data_Valid_P ())
  29.     {
  30.         Message0("\n\nNo data->No mesh motion!!!\n\n");
  31.         return;
  32.     }
  33.    
  34.     /* Reset velocities */
  35.     NV_S (vel, =, 0.0);
  36.     NV_S (omega, =, 0.0);
  37.    
  38.     /* Calculate force*/
  39.     d = THREAD_DOMAIN (DT_THREAD ((Dynamic_Thread *)dt));
  40.     t = DT_THREAD(dt);
  41.     NV_S (CG, =, 0.0);
  42.     Compute_Force_And_Moment (d, t, CG, force, moment, FALSE);

  43.     /* Compute change in velocity, i.e., dv=F*dt/M velocity update using explicit Euler formula */
  44.     dv = dtime * (force[0] - G * valve_M) / valve_M;
  45.     if(is_valve == 0 && dv >= 0.0)
  46.     {
  47.         is_valve = 1;
  48.         Message0("\n\n============================== BEGIN VALVE MOTION INFO ==============================\n");
  49.         Message0("\n VALVE BEGIN MOVE! \n");
  50.         Message0("\n============================== END VALVE MOTION INFO ==============================\n");
  51.     }
  52.     if(is_valve == 0 && dv < 0.0) {
  53.         dv = 0.0;
  54.     }
  55.     valve_V += dv;
  56.     if(valve_S >= 0.010)
  57.     {
  58.         valve_V = 0.0;
  59.     }
  60.     valve_S += valve_V * dtime;

  61.     /* Set x-component of velocity */
  62.     vel[0] = valve_V;
  63.     valve_F = force[0];

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

  68.     node_to_host_real_1(valve_S);
  69.     node_to_host_real_1(valve_V);
  70.     node_to_host_real_1(valve_F);
  71.     node_to_host_int_1(is_valve);

  72.     node_to_host_real(vel, ND_ND);
  73.     node_to_host_real(omega, ND_ND);
  74. }

  75. DEFINE_CG_MOTION(ball, dt, vel, omega, time, dtime)
  76. {
  77. #if !RP_HOST
  78.     Thread *t;
  79.     Domain *d;
  80.     real dv, CG[ND_ND], force[3], moment[3];

  81.     /* Check to see if there is data */
  82.     if (!Data_Valid_P ())
  83.     {
  84.         Message0("\n\nNo data->No mesh motion!!!\n\n");
  85.         return;
  86.     }
  87.    
  88.     /* Reset velocities */
  89.     NV_S (vel, =, 0.0);
  90.     NV_S (omega, =, 0.0);
  91.    
  92.     /* Calculate force*/
  93.     d = THREAD_DOMAIN (DT_THREAD ((Dynamic_Thread *)dt));
  94.     t = DT_THREAD(dt);
  95.     NV_S (CG, =, 0.0);
  96.     Compute_Force_And_Moment (d, t, CG, force, moment, FALSE);

  97.     /* Compute change in velocity, i.e., dv=F*dt/M velocity update using explicit Euler formula */
  98.     dv = dtime * (force[0] - G * ball_M) / ball_M;
  99.     if(is_ball == 0 && dv >= 0.0)
  100.     {
  101.         is_ball = 1;
  102.         Message0("\n\n============================== BEGIN BALL MOTION INFO ==============================\n");
  103.         Message0("\n BALL BEGIN MOVE! \n");
  104.         Message0("\n============================== END BALL MOTION INFO ==============================\n");
  105.     }
  106.     if(is_ball == 0 && dv < 0.0) {
  107.        dv = 0.0;
  108.     }
  109.     ball_V += dv;
  110.     ball_S += ball_V * dtime;
  111.    
  112.     /* Set x-component of velocity */
  113.     vel[0] = ball_V;
  114.     ball_F = force[0];

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

  119.     node_to_host_real_1(ball_S);
  120.     node_to_host_real_1(ball_V);
  121.     node_to_host_real_1(ball_F);
  122.     node_to_host_int_1(is_ball);

  123.     node_to_host_real(vel, ND_ND);
  124.     node_to_host_real(omega, ND_ND);
  125. }

  126. static void write_data(FILE *fp)
  127. {
  128.     fprintf(fp, "%e ", valve_V);
  129.     fprintf(fp, "\n");
  130.     fprintf(fp, "%e ", valve_S);
  131.     fprintf(fp, "\n");
  132.     fprintf(fp, "%e ", valve_F);
  133.     fprintf(fp, "\n");
  134.     fprintf(fp, "%d ", is_valve);
  135.     fprintf(fp, "\n");

  136.     fprintf(fp, "%e ", ball_V);
  137.     fprintf(fp, "\n");
  138.     fprintf(fp, "%e ", ball_S);
  139.     fprintf(fp, "\n");
  140.     fprintf(fp, "%e ", ball_F);
  141.     fprintf(fp, "\n");
  142.     fprintf(fp, "%d ", is_ball);
  143. }

  144. static void read_data(FILE * fp)
  145. {
  146.     fscanf(fp, "%e", [$valve_V)]
  147.     fscanf(fp, "%e", [$valve_S)]
  148.     fscanf(fp, "%e", [$valve_F)]
  149.     fscanf(fp, "%d", [$is_valve)]

  150.     fscanf(fp, "%e", [$ball_V)]
  151.     fscanf(fp, "%e", [$ball_S)]
  152.     fscanf(fp, "%e", [$ball_F)]
  153.     fscanf(fp, "%d", [$is_ball)]
  154. }

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

  159. #if PARALLEL
  160. #if RP_HOST
  161.     read_data(fp);
  162. #endif
  163. #else
  164.     read_data(fp);
  165. #endif

  166.     host_to_node_real_1(valve_V);
  167.     host_to_node_real_1(valve_S);
  168.     host_to_node_real_1(valve_F);
  169.     host_to_node_int_1(is_valve);
  170.    
  171.     host_to_node_real_1(ball_V);
  172.     host_to_node_real_1(ball_S);
  173.     host_to_node_real_1(ball_F);
  174.     host_to_node_int_1(is_ball);

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

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

  188. #if PARALLEL
  189. #if RP_HOST
  190.     write_data(fp);
  191. #endif
  192. #else
  193.     write_data(fp);
  194. #endif
  195.     Message0("\n================================ END UDF INFOMATION ================================\n\n");
  196. }
复制代码


来自傲雪
发表于 2007-6-29 15:42 | 显示全部楼层
我觉得我们自己做的时候不用这么麻烦把
直接做动网格的那部分就可以乐把
发表于 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.
发表于 2012-3-23 10:19 | 显示全部楼层
有没有谁知道那个光顺法的那个怎么让动边界的位移扩散出去。
发表于 2012-3-27 08:52 | 显示全部楼层
需要将周边的区域也设置为动网格,可以在GUI界面里Dynamic zones里面设置好参数,然后在UDF里用SET_DEFORMING_THREAD_FLAG(THREAD_T0(t));
发表于 2012-3-28 12:02 | 显示全部楼层
回复 5 # 漂亮朋友 的帖子

请问F_AREA_CACHE 是什么意思呢?
另外,你提供的宏是从哪儿找到的,有没有什么参考资料提供一下啊。谢谢!
190745256@qq.com
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-12-28 18:34 , Processed in 0.060640 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表