簡體   English   中英

正弦波生成的C編程

[英]C programming for sinusoidal wave generation

我編寫了一個代碼,在ANSYS流暢仿真中用作用戶定義的函數。 該規范旨在在通道壁上產生正弦形變形。 根據以下等式

H(x) = a + b*Sin (2π/λ) (x - ct)

哪里

‘a’ is the average height of the channel 
‘b’ is the amplitude of the wave 
‘c’ is the wave propagation speed 
‘λ’ is the wavelength 
‘x’ is the stream wise direction of the flow ‘
t’ is current time

我面臨的問題是“如何根據上面給出的公式編寫代碼,以便在2D通道壁上移動每個節點”

#include "udf.h"
#include "dynamesh_tools.h"
DEFINE_GRID_MOTION(peristaltic, domain, dt, time, dtime)
{

    Thread *tf= DT_THREAD(dt);
    face_t f;
    Node *v;
    real NV_VEC(omega), NV_VEC(axis), NV_VEC(dx);
    real NV_VEC(origin), NV_VEC(rvec);
    real sign;
int n;
SET_DEFORMING_THREAD_FLAG(THREAD_T0(tf));
sign = 0.5 + 2*sin(6.28 * time);
Message ("time = %f, omega = %f\n", time, sign);
NV_S(omega, =, 0.0);
NV_D(axis, =, 1.0, 0.0, 0.0);
NV_D(origin, =, 0.0, 0.0, 0.0);

begin_f_loop(f,tf)
 {
f_node_loop(f,tf,n)
{   

v = F_NODE(f,tf,n);
if (NODE_POS_NEED_UPDATE (v))
{
/* indicate that node position has been update */
/*so that it's not updated more than once */
    NODE_POS_UPDATED(v);
NV_VV(rvec, =, NODE_COORD(v), -, origin);
NV_CROSS(dx, omega, rvec);
NV_S(dx, *=, dtime);
NV_V(NODE_COORD(v), +=, dx);
    }
     }
}   
end_f_loop(f,tf);
}

應該

H(x) = a + b*Sin (2π/λ * x - wt)

要么

H(x) = a + b*Sin ((2π/λ) * (x - ct))

對於每個通道-您需要在所有時間內遍歷所有x值。

就像是

for (n=0,x=min;n<100;n++;x+=(max-min)/99) 
{
  sign[n] = 0.5 + 2*sin(2*M_PI/lambda *(x - 6.28 * time));
}

現在符號是一個數組,您可以計算x的不同值對許多通道的干擾,希望這對您有所幫助

(NB用於使波在+ ve x方向上移動需要-ct,這在第一眼是很直觀的)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM