【问题标题】:C programming for sinusoidal wave generation用于生成正弦波的 C 编程
【发布时间】:2015-11-14 08:32:19
【问题描述】:

我编写了一个代码,用作 ANSYS fluent 模拟中的用户定义函数。此代码旨在在通道壁上产生正弦变形。根据以下等式

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

我面临的问题是“我如何编写代码以便根据上面给出的方程移动二维通道墙上的每个节点”

#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);
}

【问题讨论】:

    标签: c math simulation waveform trigonometry


    【解决方案1】:

    应该是

    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));
    }
    

    现在 sign 是一个数组,您可以计算不同 x 值下许多通道的干扰,希望对您有所帮助

    (NB 表示要在 +ve x 方向移动的波浪需要 -ct ,这首先是反直觉的)

    【讨论】:

      猜你喜欢
      • 2018-10-26
      • 2012-07-11
      • 2016-02-21
      • 2015-02-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多