【发布时间】: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