Fluent動(dòng)網(wǎng)格【3】:DEFINE_CG_MOTION宏

除了利用Profile進(jìn)行運(yùn)動(dòng)指定之外,F(xiàn)luent中還可以使用UDF宏來(lái)指定部件的運(yùn)動(dòng)。其中用于運(yùn)動(dòng)指定的宏主要有三個(gè):

  • DEFINE_CG_MOTION
  • DEFINE_GEOM
  • DEFINE_GRID_MOTION

今天主要看第一個(gè)UDF宏DEFINE_CG_MOTION。

用途

DEFINE_CG_MOTION宏主要用于描述剛體的運(yùn)動(dòng)。所謂“剛體”,指的是在運(yùn)動(dòng)過(guò)程中部件幾何形狀不會(huì)發(fā)生任何改變,只是其質(zhì)心位置發(fā)生改變。

在定義剛體的運(yùn)動(dòng)時(shí),通常以速度方式進(jìn)行顯式定義。

形式

DEFINE_CG_MOTION宏的結(jié)構(gòu)很簡(jiǎn)單。

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

其中:

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

dt:一個(gè)指針Dynamic_Thread *dt,存儲(chǔ)動(dòng)網(wǎng)格屬性,通常不需要用戶干預(yù)。

vel:平動(dòng)速度,為一個(gè)數(shù)組,其中vel[0]為x方向速度,vel[1]為y方向速度,vel[2]為z方向速度。

omega:轉(zhuǎn)動(dòng)速度,omega[0]為x方向角速度,omega[1]為y方向角速度,omega[2]為z方向角速度。

time:當(dāng)前時(shí)間。

dtime:時(shí)間步長(zhǎng)。

DEFINE_CG_MOTION宏實(shí)際上是要返回?cái)?shù)據(jù)vel或omega。

實(shí)例

實(shí)例1:利用DEFINE_CG_MOTION宏定義速度:


可以寫(xiě)成:

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

很簡(jiǎn)單,對(duì)不對(duì)?

再來(lái)個(gè)復(fù)雜點(diǎn)的例子。

實(shí)例2:已知作用在部件上的力F,計(jì)算部件在力F作用下的運(yùn)動(dòng)。

可以采用牛頓第二定律:



則速度可寫(xiě)為:



可寫(xiě)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;
}

更多CFD資料可微信掃描下方二維碼關(guān)注微信公眾號(hào)。


微信掃碼關(guān)注公眾號(hào)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容