除了利用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:為宏的名稱(chēng)吩谦,可以隨意定義
dt:一個(gè)指針Dynamic_Thread *dt,存儲(chǔ)動(dòng)網(wǎng)格屬性膝藕,通常不需要用戶(hù)干預(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)醇疼。