gpt4 book ai didi

正弦波生成的C编程

转载 作者:太空宇宙 更新时间:2023-11-04 03:34:27 25 4
gpt4 key购买 nike

我编写了一段代码,在 ANSYS 流畅仿真中用作用户定义函数。此代码旨在在 channel 壁上产生正弦变形。根据以下等式

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 channel 壁上的每个节点”

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

对于每个 channel - 您需要在所有时间循环所有 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 值下许多 channel 的扰动,希望这对您有所帮助

(注意波在 +ve x 方向上移动需要 -ct ,这起初是违反直觉的)

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com