Fluent動網格【3】:DEFINE_CG_MOTION宏


除了利用Profile進行運動指定之外,Fluent中還可以使用UDF宏來指定部件的運動。其中用於運動指定的宏主要有三個:

  • DEFINE_CG_MOTION
  • DEFINE_GEOM
  • DEFINE_GRID_MOTION

今天主要看第一個UDF宏DEFINE_CG_MOTION。

用途

DEFINE_CG_MOTION宏主要用於描述剛體的運動。所謂“剛體”,指的是在運動過程中部件幾何形狀不會發生任何改變,只是其質心位置發生改變。

在定義剛體的運動時,通常以速度方式進行顯式定義。

形式

DEFINE_CG_MOTION宏的結構很簡單。

DEFINE_CG_MOTION(name,dt,vel,omega,time,dtime)

其中:

name:為宏的名稱,可以隨意定義

dt:一個指針Dynamic_Thread *dt,存儲動網格屬性,通常不需要用戶干預。

vel:平動速度,為一個數組,其中vel[0]為x方向速度,vel[1]為y方向速度,vel[2]為z方向速度。

omega:轉動速度,omega[0]為x方向角速度,omega[1]為y方向角速度,omega[2]為z方向角速度。

time:當前時間。

dtime:時間步長。

DEFINE_CG_MOTION宏實際上是要返回數據vel或omega。__

實例

實例1:利用DEFINE_CG_MOTION宏定義速度:

\[u_x = 2 sin(3t) \]

可以寫成:

#include "udf.h"
DEFINE_CG_MOTION(velocity,dt,vel,omega,time,dtime)
{
  vel[0] = 2* sin(3*time); 
}

很簡單,對不對?

再來個復雜點的例子。

實例2:已知作用在部件上的力F,計算部件在力F作用下的運動。

可以采用牛頓第二定律:

\[\int_{t_0}^{t}{dv}=\int_{t_0}^{t}{(F/m)}dt \]

則速度可寫為:

\[v_t = v_{t-\Delta t}+(F/m)\Delta t \]

可寫UDF宏為:

/************************************************************
* 1-degree of freedom equation of motion (x-direction)
* compiled UDF
************************************************************/
#include "udf.h"
 
static real v_prev = 0.0;
static real time_prev = 0.0;
 
DEFINE_CG_MOTION(piston,dt,vel,omega,time,dtime)
{
  Thread *t;
  face_t f;
  real NV_VEC(A);
  real force_x, 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_x = 0.0;
  begin_f_loop(f,t)
    {
      F_AREA(A,f,t);
      force_x += F_P(f,t) * A[0];
    }
  end_f_loop(f,t)
  /* compute change in velocity, dv = F*dt/mass */
  dv = dtime * force_x / 50.0;
  /* motion UDFs can be called multiple times and should not cause
     false velocity updates */
  if (time > (time_prev + EPSILON))
    {
      v_prev += dv;
      time_prev = time;
    }
  Message("time = %f, x_vel = %f, x_force = %f\n", time, v_prev, force_x);
  /* set x-component of velocity */
  vel[0] = v_prev;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM