声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 3506|回复: 7

[动网格] 求助 泵动网格的建立

[复制链接]
发表于 2010-3-12 15:15 | 显示全部楼层 |阅读模式

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

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

x
我在FLUENT v6.1动网格教程中发现的一个例子:详见附件

看样子非常像我正在做毕设的旋片泵的模型:

                               
登录/注册后可看大图

非常恳求各位大哥大姐,能告诉小弟这个例子具体的动网格设置方法
dongwangge.jpg
回复
分享到:

使用道具 举报

发表于 2011-7-2 19:33 | 显示全部楼层
这个问题温正等人的书上有。
发表于 2011-7-2 19:43 | 显示全部楼层
把udf贴给大家吧!用法自己找书看看!
  1. /**********************************************************************************************************
  2.                           UDF for vane pump application
  3.    Mesh requirements:
  4.    - Rotation must be long Z axis.
  5.    - The origin must be placed on the cylindrical axis of rotating shaft or the SMALLER circle.
  6.       - The large circle (if circle is used) must be placed to the left of the small circle
  7.         and its center must have zero y coordinate.
  8.    - Initially, one gap must be on the positive x location.
  9.       (The first three are just orientation. The last one is required because the udf assumes this initial
  10.     position for the angle alfa calculation.)
  11.    - All the pump core needs to be a single cell zone and all gaps need to be a single
  12.      cell zone.
  13.    How to use the udf:
  14.    - Modify the input file (input.txt) and place in working directory.
  15.    The input file description is as follows;
  16.    0 - Outer hape type (0=circle, 1=user-defined)
  17.    0 - Inner shape type (0=circle, 1=user-defined, 2=special)
  18.    8 - Number of vanes
  19.    6 11 - (Core ID and Gap ID)
  20.    25e-3 1.75e-3 0.1e-3 (inner circle radius, half vane width and gap size)
  21.    27.5e-3 2e-3 (outer radius and offset - if it is a circle)
  22.    - If outer profile is not a circle, then this profile must be created and stored in a file
  23.      called data_outer.txt. This file must also be placed in the working directory and has the
  24.      following format;
  25.      320 - Number of points
  26.   0.0275  0 - x and y coordinates of each point required to create the profile
  27.   0.027497851 0.0005
  28.   0.027491405 0.001
  29.   0.027480657 0.0015
  30.   0.027465603 0.002
  31.    - Build the UDF library.
  32.    - Load the mesh (The mesh has to satisfy the requirements above).
  33.    - Turn on Dynamic Mesh and In-Cylinder.
  34.    - Specify RPM under In-Cylinder tab.  Under the same tab, use 360 for Crank period and 0.25 for
  35.      Crank Angle Step Size (this determines time step size).
  36.    - Hook the UDF with fluid-pump and fluid-gap.
  37.       - Hook the initialization udf.
  38.       - Hook the reader and writer udf.
  39.    - Define one UDM.
  40.    - Define grid interfaces.
  41.    - Define other parameters for transient flow (turbulence, PISO etc.).
  42.    - Initialize the flow (you will need to intialize the flow even for just mesh motion)
  43.    Note:
  44.    - Need to read both cas/dat files even for just mesh motion
  45.    - Cannot initialize the flow in the middle of a run and then continue.
  46. Written by: Xiao Hu ([url=mailto:xh@fluent.com]xh@fluent.com[/url]), and Laz Foley ([url=mailto:lnf@fluent.com]lnf@fluent.com[/url])
  47. Last Updated: 1/20/2004
  48. **********************************************************************************************************/
  49. # include "udf.h"
  50. # include "dynamesh_tools.h"
  51. # define RPM RP_Get_Real("dynamesh/in-cyn/crank-rpm")
  52. # define noDEBUG
  53. /************************************* User inputs start **********************************************/
  54. /* extern real special_inner_radius(real z); */
  55. /* Number of vanes, core ID and gap ID */
  56. int N_VANE, CORE_ID, GAP_ID;
  57. /* Outer circle radius, inner circle radius, half vane width, gap size and offset */
  58. real R, r, HALF_VANE_WIDTH, GAP, DELTA;
  59. /* Outer contour shape */
  60. enum define_shape
  61. {
  62.   circle, user_defined, special
  63. }OUTER_SHAPE, INNER_SHAPE;
  64. /************************************* User inputs end ************************************************/
  65. enum shrink
  66. {
  67.   w_shrink, wo_shrink
  68. };
  69. struct shape
  70. {
  71. enum define_shape shape_type;
  72. enum shrink shrink_y_or_n;
  73. real center[2];
  74. real radius;
  75. real (*data)[2];
  76. int number_of_data;
  77. }pump_core_outer_shape, pump_core_inner_shape, pump_gap_outer_shape, pump_gap_inner_shape;
  78. enum UDM
  79. {
  80.   UDM_sector
  81. };

  82. static real my_atan2(real y, real x)
  83. {
  84. real result;
  85. result=atan2(y,x);
  86. if(atan2(y,x)<0)
  87.   result = atan2(y,x) + 2*M_PI;
  88. return result;
  89. }
  90. /* Find the intersection t1 and t2 for two lines (see notes pg 5)*/
  91. void find_t(real xa, real ya, real xb, real yb,
  92.                      real xc, real yc, real xd, real yd,
  93.                      real *t1, real *t2, int * flag)
  94. {
  95. real k;
  96. if((xd-xc)!=0)
  97.    {
  98.     k = (yd-yc)/(xd-xc);
  99.     if((yb-ya)-k*(xb-xa)==0)
  100.        {
  101.      (*flag) = 0;
  102.      return;
  103.        }
  104.     (*flag) = 1;
  105.     (*t1) = (-k*(xc-xa)+(yc-ya))/((yb-ya)-k*(xb-xa));
  106.     (*t2) = ((xb-xa)*(*t1)-(xc-xa))/(xd-xc);
  107.    }
  108. else
  109.    {
  110.     if((xb-xa)==0)
  111.        {
  112.      (*flag) = 0;
  113.      return;
  114.        }
  115.     if(yd==yc)
  116.       {
  117.     Message0("\nc and d are the same points-aborting!!!\n");
  118.     exit(0);
  119.    }
  120.     (*flag) = 2;
  121. (*t1) = (xc-xa)/(xb-xa);
  122. (*t2) = ((yb-ya)*(*t1)-(yc-ya))/(yd-yc);
  123.    }
  124. return;
  125. }
  126. /* Find the intersection (see notes pg5) */
  127. void find_intersection(real (*data)[2], int number_of_data, real xc, real yc, real xd, real yd,
  128.                        real *x, real *y)
  129. {
  130. int i, flag;
  131. real pt1[2], pt2[2], t1, t2;
  132. for(i=0; i<number_of_data; i++)
  133.    {
  134.     if(i<number_of_data-1)
  135.       {
  136.        pt1[0] = data[i][0];
  137.        pt1[1] = data[i][1];
  138.        pt2[0] = data[i+1][0];
  139.        pt2[1] = data[i+1][1];
  140.    }
  141.      else
  142.       {
  143.        pt1[0] = data[i][0];
  144.        pt1[1] = data[i][1];
  145.        pt2[0] = data[0][0];
  146.        pt2[1] = data[0][1];
  147.    }
  148.     find_t(pt1[0], pt1[1], pt2[0], pt2[1], xc, yc, xd, yd, &t1, &t2, &flag);
  149.     /*Message0("\n%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f flag=%3d\n",
  150.     pt1[0], pt1[1], pt2[0], pt2[1], xc, yc, xd, yd, t1, t2, flag); */
  151.     if(((flag==1)||(flag==2))&&(t1<=1)&&(t1>=0)&&(t2>=0))
  152.       {
  153.     (*x) = (1-t1)*pt1[0] + t1*pt2[0];
  154.     (*y) = (1-t1)*pt1[1] + t1*pt2[1];
  155.     /* Message0("\n%7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f \n", pt1[0], pt1[1], pt2[0], pt2[1], xc, yc, xd, yd);
  156.     Message0("\nt1=%5.2f   t2=%5.2f   x=%5.2f   y=%5.2f\n", t1, t2, *x, *y); */
  157.        return;
  158.    }
  159.    }
  160. }
  161. /* Function used to calcuate op for the gap.  Please refer to note page 4 for the definition. */
  162. static void f_Op_gap(real * xop, real * yop, real xa, real ya, real time, real sector)
  163. {
  164. real alfa, h;
  165. alfa = time*RPM*M_PI/30+sector*2*M_PI/N_VANE;
  166. h=cos(alfa)*ya-sin(alfa)*xa;
  167. if(fabs(cos(alfa))>0.1)
  168.    {
  169.    *xop = 0.5*xa;
  170.    *yop = (sin(alfa)*0.5*xa+h)/cos(alfa);
  171.    }
  172. else
  173.    {
  174.       *xop = (cos(alfa)*0.5*ya-h)/sin(alfa);
  175.    *yop = 0.5*ya;
  176.    }
  177. return;
  178. }
  179. /* Function used to calcuate op.  Please refer to note page 3 for the definition. */
  180. static void f_Op_core(real * x, real * y, real time, real sector)
  181. {
  182. real alfa;
  183. alfa = time*RPM*M_PI/30+sector*2*M_PI/N_VANE;
  184. *x = HALF_VANE_WIDTH*(cos(alfa)+cos(alfa+2*M_PI/N_VANE))/sin(2*M_PI/N_VANE);
  185. *y = HALF_VANE_WIDTH*(sin(alfa)+sin(alfa+2*M_PI/N_VANE))/sin(2*M_PI/N_VANE);
  186. return;
  187. }
  188. /* Generic function to calcualte the distance between point a and c.  Please refer to note page 2.
  189.   The inputs are points a, b, center of the circle (x0, y0), and the circle radius.  The h and H
  190.   for this application are all from this function.
  191. */
  192. static real f_h(real xa, real ya, real xb, real yb, real z_coord, struct shape * contour_shape)
  193. {
  194. if (contour_shape->shape_type==circle)
  195.    {
  196.     real t1, t2, a, b, c, t, x0, y0, radius;
  197.     x0 = contour_shape->center[0];
  198.     y0 = contour_shape->center[1];
  199.     radius = contour_shape->radius;
  200.     a=pow(xb-xa,2)+pow(yb-ya,2);
  201.     b=2*(xa-x0)*(xb-xa)+2*(ya-y0)*(yb-ya);
  202.     c=pow(xa-x0,2)+pow(ya-y0,2)-radius*radius;
  203.     t1 = (-b+sqrt(b*b-4*a*c))/(2*a);
  204.     t2 = (-b-sqrt(b*b-4*a*c))/(2*a);
  205.     if (t1>0&&t2<0)
  206.      t = t1;
  207.     else if (t2>0&&t1<0)
  208.      t = t2;
  209.     else
  210.     {
  211.      Message("\nSomething wrong with f_h. t1=%7.2f t2=%7.2f", t1, t2);
  212.      Message("\nxa=%11.3e ya=%11.3e xb=%11.3e yb=%11.3e x0=%10.3e y0=%10.3e radius=%10.3e", xa, ya, xb, yb, x0, y0, radius);
  213.      t = 1;
  214.     }
  215.     return t*sqrt((pow(yb-ya,2)+pow(xb-xa,2)));
  216.    }
  217.   else if (contour_shape->shape_type==user_defined)
  218.     {
  219.   real x, y;
  220.      find_intersection(contour_shape->data, contour_shape->number_of_data, xa, ya, xb, yb, &x, &y);
  221.      if(contour_shape->shrink_y_or_n==w_shrink)
  222.        {
  223.            return sqrt(pow(y-ya,2)+pow(x-xa,2))-GAP;
  224.     }
  225.      else
  226.        {
  227.            return sqrt(pow(y-ya,2)+pow(x-xa,2));
  228.     }
  229. }
  230.   else if (contour_shape->shape_type==special)
  231.     {
  232.      real t1, t2, a, b, c, t, x0, y0, radius;
  233.      x0 = 0;
  234.      y0 = 0;
  235.      radius = 1;
  236.      /* radius = special_inner_radius(z_coord); */
  237.      a=pow(xb-xa,2)+pow(yb-ya,2);
  238.      b=2*(xa-x0)*(xb-xa)+2*(ya-y0)*(yb-ya);
  239.      c=pow(xa-x0,2)+pow(ya-y0,2)-radius*radius;
  240.      t1 = (-b+sqrt(b*b-4*a*c))/(2*a);
  241.      t2 = (-b-sqrt(b*b-4*a*c))/(2*a);
  242.      if (t1>0&&t2<0)
  243.       t = t1;
  244.      else if (t2>0&&t1<0)
  245.       t = t2;
  246.      else
  247.      {
  248.       Message("\nSomething wrong with f_h. t1=%7.2f t2=%7.2f", t1, t2);
  249.       Message("\nxa=%11.3e ya=%11.3e xb=%11.3e yb=%11.3e x0=%10.3e y0=%10.3e radius=%10.3e", xa, ya, xb, yb, x0, y0, radius);
  250.       t = 1;
  251.      }
  252.      return t*sqrt((pow(yb-ya,2)+pow(xb-xa,2)));
  253. }
  254.   else
  255.     {
  256.   Message0("\nwrong type-aborting!!!\n");
  257.   exit(0);
  258. }
  259. }
  260. static real f_h_core(real * op, real *ap, real time)
  261. {
  262. return f_h(op[0], op[1], ap[0], ap[1], ap[2], &pump_core_inner_shape);
  263. }
  264. static real f_H_core(real * op, real *ap, real time)
  265. {
  266. real not_used_var=0;
  267. return f_h(op[0], op[1], ap[0], ap[1], not_used_var, &pump_core_outer_shape);
  268. }
  269. static real f_h_gap(real * op, real *ap, real time)
  270. {
  271. real not_used_var=0;
  272. return f_h(op[0], op[1], ap[0], ap[1], not_used_var, &pump_gap_inner_shape);
  273. }
  274. static real f_H_gap(real * op, real *ap, real time)
  275. {
  276. real not_used_var=0;
  277. return f_h(op[0], op[1], ap[0], ap[1], not_used_var, &pump_gap_outer_shape);
  278. }

  279. /* Functions used to calcuate a new position after a rigid body rotation */
  280. static void find_app_rigid(real * ap, real * app, real dtheta)
  281. {
  282. app[0]=ap[0]*cos(dtheta)-ap[1]*sin(dtheta);
  283. app[1]=ap[0]*sin(dtheta)+ap[1]*cos(dtheta);
  284. }
  285. /* For a give ap, it finds the new position appp.
  286.    According to note page 1, the inputs should be ap, op, dt, functions used to calculate h and H. time is
  287.    also given as an input in case h and H are functions of time.  But for this case, h and H are not.
  288. */
  289. static void find_appp(real * appp, real * ap, real *op, real time, real dt, real (*ff_h)(real *, real *, real), real (*ff_H)(real *, real *, real))
  290. {
  291. real H_t, H_t_dt, h_t, h_t_dt, dtheta, abs_oppappp, abs_opap;
  292. real app[3], opp[2], opap[2], temp[2];
  293. app[2] = ap[2];
  294. dtheta=RPM*M_PI/30*dt;
  295. find_app_rigid(ap, app, dtheta);   /* Find app, which is after a rigid body rotation of dtheta */
  296. find_app_rigid(op, opp, dtheta);   /* Find opp, which is after a rigid body rotation of dtheta */
  297. h_t   = ff_h(op,  ap,  time);
  298. h_t_dt= ff_h(opp, app, time+dt);
  299. H_t   = ff_H(op,  ap,  time);
  300. H_t_dt= ff_H(opp, app, time+dt);
  301. abs_opap = sqrt(pow(op[0]-ap[0],2)+pow(op[1]-ap[1],2));
  302. abs_oppappp=(abs_opap-h_t)/(H_t-h_t)*(H_t_dt-h_t_dt)+h_t_dt;
  303. opap[0]=ap[0]-op[0];
  304. opap[1]=ap[1]-op[1];
  305. temp[0]=opap[0]/abs_opap;
  306. temp[1]=opap[1]/abs_opap;
  307. appp[0]=(temp[0]*cos(dtheta)-temp[1]*sin(dtheta))*abs_oppappp+opp[0];
  308. appp[1]=(temp[0]*sin(dtheta)+temp[1]*cos(dtheta))*abs_oppappp+opp[1];
  309. }
  310. DEFINE_GRID_MOTION(vane_pump_gap, domain, dt, time, dtime)
  311. {
  312.   cell_t c;
  313.   Thread *tc = DT_THREAD ((Dynamic_Thread *)dt);
  314.   int n;
  315.   Node *v;
  316.   real ap[2], op[2], appp[2];
  317.   SET_DEFORMING_THREAD_FLAG (tc);
  318.   begin_c_loop(c, tc)
  319.     {
  320.       c_node_loop(c, tc, n)
  321.         {
  322.           v = C_NODE(c, tc, n);
  323.           if (NODE_POS_NEED_UPDATE(v))
  324.             {
  325.               NODE_POS_UPDATED(v);
  326.            ap[0]=NODE_X(v);
  327.            ap[1]=NODE_Y(v);
  328.               f_Op_gap(op, op+1, ap[0], ap[1], time-dtime, C_UDMI(c, tc, UDM_sector));
  329.               find_appp(appp, ap, op, time-dtime, dtime, f_h_gap, f_H_gap);

  330.            NODE_X(v)=appp[0];
  331.            NODE_Y(v)=appp[1];
  332.             }
  333.         }
  334.       Update_Cell_Metrics (c, tc);
  335.     }
  336.   end_c_loop (c, tc);
  337. }
  338. DEFINE_GRID_MOTION(vane_pump_core, domain, dt, time, dtime)
  339. {
  340.   cell_t c;
  341.   Thread *tc = DT_THREAD ((Dynamic_Thread *)dt);
  342.   int n;
  343.   Node *v;
  344.   real ap[3], op[2], appp[2];
  345.   /* set deforming flags */
  346.   SET_DEFORMING_THREAD_FLAG (tc);
  347.   begin_c_loop(c, tc)
  348.     {
  349.       c_node_loop(c, tc, n)
  350.         {
  351.           v = C_NODE(c, tc, n);
  352.           if (NODE_POS_NEED_UPDATE(v))
  353.             {
  354.               NODE_POS_UPDATED(v);
  355.            ap[0]=NODE_X(v);
  356.            ap[1]=NODE_Y(v);
  357.            ap[2]=NODE_Z(v);
  358.               f_Op_core(op, op+1, time-dtime, C_UDMI(c, tc, UDM_sector));
  359.               find_appp(appp, ap, op, time-dtime, dtime, f_h_core, f_H_core);
  360.            NODE_X(v)=appp[0];
  361.            NODE_Y(v)=appp[1];
  362.             }
  363.         }
  364.       Update_Cell_Metrics (c, tc);
  365.     }
  366.   end_c_loop (c, tc);
  367. }
  368. DEFINE_GRID_MOTION(walls, domain, dt, time, dtime)
  369. {
  370. }
  371. static void intialize_one_shape(struct shape * one_shape,  enum define_shape shape_type, enum shrink shrink_y_or_n, real * center, real radius, char * file_name)
  372. {
  373. one_shape->shape_type=shape_type;
  374. if (one_shape->shape_type==circle)
  375.     {
  376.   one_shape->center[0]=center[0];
  377.   one_shape->center[1]=center[1];
  378.   one_shape->radius=radius;
  379. }
  380. else if (one_shape->shape_type==user_defined)
  381.     {
  382.      FILE *fp_data;
  383.      int i, j;
  384.      one_shape->shrink_y_or_n=shrink_y_or_n;
  385.      #if PARALLEL
  386.        if(I_AM_NODE_HOST_P)
  387.      #endif
  388.         {
  389.          if(!(fp_data=fopen(file_name,"r")))
  390.           {
  391.             Message0("\nCan not open file %s -aborting!!", file_name);
  392.             exit(0);
  393.           }
  394.          fscanf(fp_data, "%d", &(one_shape->number_of_data));
  395.         }
  396.      host_to_node_int_1(one_shape->number_of_data);
  397.      if(!(one_shape->data=(real (*)[2]) calloc(one_shape->number_of_data, 2*sizeof(real))))
  398.        {
  399.      Message0("\nMemory allocatoin failure-aborting!!\n");
  400.      exit(0);
  401.     }
  402.      for(i=0; i<one_shape->number_of_data; i++)
  403.       for(j=0; j<2; j++)
  404.        {
  405.           #if PARALLEL
  406.             if(I_AM_NODE_HOST_P)
  407.           #endif
  408.              {
  409.                 #if RP_DOUBLE
  410.            fscanf(fp_data, "%le", &(one_shape->data[i][j]));
  411.                 #else
  412.            fscanf(fp_data, "%e", &(one_shape->data[i][j]));
  413.                 #endif
  414.              }
  415.     }
  416.      host_to_node_real(&(one_shape->data[0][0]), 2*one_shape->number_of_data);
  417.      #if PARALLEL
  418.        if(I_AM_NODE_HOST_P)
  419.      #endif
  420.         {
  421.          fclose(fp_data);
  422.         }
  423. }
  424. else if (one_shape->shape_type==special)
  425.     {
  426.     }
  427. else
  428.     {
  429.   Message0("\nWrong shape-aborting!!!\n");
  430.   exit(0);
  431. }
  432. }
  433. static void initialize_shape(void)
  434. {
  435. real center[2], radius;
  436. center[0]=-DELTA;
  437. center[1]=0;
  438. radius=R;
  439. intialize_one_shape(&pump_core_outer_shape, OUTER_SHAPE, wo_shrink, center, radius, "data_outer.txt");
  440. center[0]=0;
  441. center[1]=0;
  442. radius=r;
  443. intialize_one_shape(&pump_core_inner_shape, INNER_SHAPE, wo_shrink, center, radius, "data_inner.txt");
  444. center[0]=-DELTA;
  445. center[1]=0;
  446. radius=R;
  447. intialize_one_shape(&pump_gap_outer_shape, OUTER_SHAPE, wo_shrink, center, radius, "data_outer.txt");
  448. center[0]=-DELTA;
  449. center[1]=0;
  450. radius=R-GAP;
  451. intialize_one_shape(&pump_gap_inner_shape, OUTER_SHAPE, w_shrink, center, radius, "data_outer.txt");
  452. return;
  453. }
  454. /* Initialization function is used to save the inital angle alfa used in op calculation.
  455.   It is also needed to read the outer contour for user_defined shape. */
  456. DEFINE_INIT(init_sector, domain)
  457. {
  458. Thread *tc;
  459. cell_t c;
  460. Node *v;
  461. int j;
  462. real angle;
  463. /* Initialization can only be done at the beginning */
  464. Message0("\n\n**************************************************************************");
  465. Message0("\n\n Warning: you are initializing the flow.  For the vane pump application,");
  466. Message0("\n you can only do this when the mesh is at the initial position.  Otherwise,");
  467. Message0("\n initialization may cause mesh motion failure!!!\n");
  468. Message0("\n After initialization, please display the UDM-0 using cell value to verify");
  469. Message0("\n that the sector numbers are calculated correctly!\n");
  470. Message0("\n**************************************************************************\n");

  471. /* Initialize the Core sector number*/
  472. tc=Lookup_Thread(domain, CORE_ID);
  473. begin_c_loop_int(c, tc)
  474.    {
  475.       v = C_NODE(c, tc, 0);
  476.    j = my_atan2(NODE_Y(v),NODE_X(v))/(2*M_PI/N_VANE);
  477.       C_UDMI(c, tc, UDM_sector) = j;
  478.    }
  479. end_c_loop_int(c, tc)
  480. /* Initialize the Gap sector number*/
  481. if (GAP_ID != 0) {
  482.   tc=Lookup_Thread(domain, GAP_ID);
  483.   begin_c_loop_int(c, tc)
  484.     {
  485.     v = C_NODE(c, tc, 0);
  486.     angle = my_atan2(NODE_Y(v),NODE_X(v));
  487.     if (fabs(angle-2*M_PI)<2*M_PI/N_VANE*0.3)
  488.      angle = 0;
  489.     j = (angle+2*M_PI/N_VANE*0.5)/(2*M_PI/N_VANE);
  490.     C_UDMI(c, tc, UDM_sector) = j;
  491.     }
  492.   end_c_loop_int(c, tc)
  493. }
  494. }
  495. /* print the outer contour for user_defined shape_type*/
  496. static void print_one_shape(struct shape * one_shape)
  497. {
  498. Message0("%d\n", one_shape->shape_type);
  499. Message0("%d\n", one_shape->shrink_y_or_n);
  500. if (one_shape->shape_type==circle)
  501.    {
  502.      Message0("%e %e %e\n", one_shape->center[0], one_shape->center[1], one_shape->radius);
  503.    }
  504. else if(one_shape->shape_type==user_defined)
  505.    {
  506.     Message0("%d\n", one_shape->number_of_data);
  507. #ifdef DEBUG
  508.     int i, j;
  509.     for(i=0; i<one_shape->number_of_data; i++)
  510.      {
  511.       for(j=0; j<2; j++)
  512.          {
  513.        Message0("%12.4e", one_shape->data[i][j]);
  514.       }
  515.       Message0("\n");
  516.      }
  517. #endif
  518.    }
  519. else if(one_shape->shape_type==special)
  520.    {
  521.    Message0("\nSpecial Inner shape\n");
  522.    }
  523. else
  524.    {
  525.    Message0("\nWrong type-aborting!!\n"); exit(0);
  526.    }
  527. }
  528. /* Only node 0 will execute ON_DEMAND udf */
  529. DEFINE_ON_DEMAND(print_outer_contour)
  530. {
  531.    Message0("\n******************** Below is the pump core outer infor ********************\n\n");
  532.    print_one_shape(&pump_core_outer_shape);
  533.    Message0("\n******************** Below is the pump core inner infor ********************\n\n");
  534.    print_one_shape(&pump_core_inner_shape);
  535.    if(GAP_ID!=0)
  536.     {
  537.      Message0("\n******************** Below is the pump gap outer infor ********************\n\n");
  538.      print_one_shape(&pump_gap_outer_shape);
  539.      Message0("\n******************** Below is the pump gap inner infor ********************\n\n");
  540.      print_one_shape(&pump_gap_inner_shape);
  541. }
  542. }
  543. /* The input file will be read each time the UDF is loaded */
  544. DEFINE_EXECUTE_ON_LOADING(on_loading, libudf)
  545. {
  546.   FILE* fpin;
  547.   Message0("\nON_LOADING udf is executing ...\n");
  548. #if PARALLEL
  549.    if(I_AM_NODE_HOST_P)
  550. #endif
  551. {
  552.   fpin = fopen("input.txt","r");
  553.   if(fpin == NULL)
  554.      Message0("Input file does not exist!");
  555. }

  556. #if RP_DOUBLE
  557. #  define REAL_FMT "%lg"
  558. #else  /* RP_DOUBLE */
  559. #  define REAL_FMT "%g"
  560. #endif /* RP_DOUBLE */
  561. #if PARALLEL
  562.    if(I_AM_NODE_HOST_P)
  563. #endif
  564.     {
  565.    fscanf(fpin, "%d",&OUTER_SHAPE);
  566.    fscanf(fpin, "%d",&INNER_SHAPE);
  567.    fscanf(fpin, "%d",&N_VANE);
  568.    fscanf(fpin, "%d %d",&CORE_ID, &GAP_ID);
  569.    fscanf(fpin, REAL_FMT REAL_FMT REAL_FMT, &r, &HALF_VANE_WIDTH, &GAP);
  570.    fscanf(fpin, REAL_FMT REAL_FMT, &R, &DELTA);
  571.    fclose(fpin);
  572.     }
  573.   host_to_node_int_5(OUTER_SHAPE, INNER_SHAPE, N_VANE, CORE_ID, GAP_ID);
  574. host_to_node_real_5(r, HALF_VANE_WIDTH, GAP, R, DELTA);
  575. /* Read in any profile data files */
  576. initialize_shape();
  577. }
  578. static void sector_output(int flag, int sector_number)
  579. {
  580. char filename[15]="output-";
  581. char filename_1[1], filename_2[4]=".txt";
  582. real Operating_Pressure=0;
  583. real Chamber_Volume_Weighted_Pressure_Sum=0;
  584. real Chamber_Pressure=0;
  585. real Chamber_Volume=0;
  586. FILE *fp;
  587. Domain *domain;
  588. Thread *tc;
  589. cell_t c;
  590. #if PARALLEL
  591.       if(I_AM_NODE_HOST_P)
  592.     #endif
  593.     {
  594.     filename_1[0]=flag+48;
  595.     strncat(filename, filename_1, 1);
  596.     strcat(filename, ".txt");
  597.     if(N_TIME == 1) {
  598.    fp=fopen(filename,"w+");
  599.    fprintf(fp, "  time(s)    volume (cc)   pressure (Pa)  \n");
  600.    fclose(fp);
  601.     }
  602.   fp=fopen(filename, "a");
  603.     }
  604.     domain = Get_Domain(1);
  605.     tc=Lookup_Thread(domain, CORE_ID);
  606.     Operating_Pressure = RP_Get_Real ("operating-pressure");
  607.     begin_c_loop(c,tc)
  608.    {
  609.   if (C_UDMI%
复制代码
发表于 2011-7-7 13:07 | 显示全部楼层
该同学可能已经毕业了吧。
看到回帖的udf,看得真累。
其实这个动网格不难,思路理清楚之后就慢慢做就是了。
先建立物理模型,搞清楚哪些边界是运动的,是滑动还是转动。
将这些运动的部分建成六面体网格,节点编号要有规律,这样进行动网格策略会很容易操作。
另外,对于此模拟。还有一个比较关键的是高压向低压区泄漏问题,真实情况下是否有其他的密封,比如油封,泄漏速度太大也会导致计算不稳定。
其实动网格这种对软件要求较高的计算,最好用starcd,比较好做。

评分

1

查看全部评分

发表于 2011-9-3 09:39 | 显示全部楼层
看到回帖的udf,看得真累。
发表于 2011-9-9 00:33 | 显示全部楼层
UDF语言这么复杂?
发表于 2011-11-10 11:04 | 显示全部楼层
有一本书有关于螺旋桨和离心泵的流场仿真:将叶轮及其周围的区域分为一个体(可设定为动),其他区域为另外一个体,两个体之间的面设为interface
发表于 2011-11-10 11:05 | 显示全部楼层
这样应该不用编程就可以了。你试试 似乎是 FLUENT高级应用
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-11-14 13:29 , Processed in 0.077660 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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