空气动力学研究生,没有代码基础,学习写了一个fluent中控制颗粒沉积的udf,但是不知道哪里有问题,请各位批评指导!
#include "udf.h"
#include "dpm.h"
// 定义常量
#define CRITICAL_VISCOSITY 1.0e-3 // 临界粘度 (Pa·s)
#define CRITICAL_VELOCITY 0.5 // 临界速度 (m/s)
#define ADHESION_WORK 0.0389 // 粘附功 (J/m²)
#define SURFACE_ROUGHNESS 1.0e-6 // 初始表面粗糙度 (m)
// 计算颗粒的粘附概率
real deposition_probability(real mu_p, real v_n) {
real P_s = 0.0;
if (mu_p <= CRITICAL_VISCOSITY && v_n <= CRITICAL_VELOCITY) {
P_s = 1.0; // 满足条件时粘附概率为1
}
return P_s;
}
// 计算颗粒的剥离条件(未沉积壁面)
real undeposited_detachment(real F_D, real D_p, real F_ps, real a) {
return F_D * (D_p / 2) - F_ps * a;
}
// 计算颗粒的剥离条件(沉积壁面)
real deposited_detachment(real F_p, real Y, real S, real F_i) {
return F_p * Y * S - F_i;
}
// 主函数:颗粒沉积与剥离逻辑
DEFINE_DPM_EROSION(particle_deposition_detachment, cell, thread, position, normal, velocity, temperature, mass_flow_rate, diameter, time, dt, dpm_thread) {
real mu_p = P_VISC(p); // 颗粒粘度
real v_n = NV_MAG(P_VEL(p)); // 颗粒法向速度
// 计算粘附概率
real P_s = deposition_probability(mu_p, v_n);
// 判断是否发生沉积
if (P_s > 0.5) {
// 沉积逻辑:更新表面粗糙度
real deposition_thickness = C_R(cell, thread) + (mass_flow_rate * dt) / (C_VOLUME(cell, thread) * SURFACE_ROUGHNESS);
C_R(cell, thread) = deposition_thickness; // 更新表面粗糙度
} else {
// 判断是否发生剥离
real F_D = 0.5 * C_R(cell, thread) * NV_MAG(velocity) * NV_MAG(velocity) * M_PI * diameter * diameter; // 拖曳力
real F_ps = (3.0 / 4.0) * M_PI * ADHESION_WORK * diameter; // 粘附力
real a = pow((3.0 * M_PI * ADHESION_WORK * diameter * diameter) / (2.0 * 1.0e9), 1.0 / 3.0); // 接触半径
// 未沉积壁面剥离
if (undeposited_detachment(F_D, diameter, F_ps, a) > 0) {
// 剥离逻辑:重置表面粗糙度
C_R(cell, thread) = SURFACE_ROUGHNESS;
}
// 沉积壁面剥离
real F_p = F_D; // 主流拖曳力
real Y = diameter / 2.0; // 法向力臂
real S = 1.0; // 校正系数
real F_i = F_ps; // 粘附力
if (deposited_detachment(F_p, Y, S, F_i) > 0) {
// 剥离逻辑:重置表面粗糙度
C_R(cell, thread) = SURFACE_ROUGHNESS;
}
}
}
// 动态网格更新函数
DEFINE_GRID_MOTION(dynamic_mesh_update, domain, dt, time, dtime) {
Thread *t;
cell_t c;
real deposition_thickness;
// 遍历所有网格单元
thread_loop_c(t, domain) {
begin_c_loop(c, t) {
deposition_thickness = C_R(c, t); // 获取当前沉积厚度
if (deposition_thickness > SURFACE_ROUGHNESS) {
// 更新网格节点位置
C_CENTROID(x, c, t);
x[2] += deposition_thickness; // 假设z方向为沉积方向
}
} end_c_loop(c, t);
}
}