我已经编写了一个代码,在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);
}

最佳答案

应该是

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值下多个通道的干扰,希望这有助于
(注意:波向+ve x方向移动需要-ct,这首先是反直觉的)

关于c - 正弦波生成的C编程,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33706582/

10-11 15:24