-
-
January 20, 2026 at 12:56 pm
24212040751
SubscriberI plan to compile the UDF code based on the content of the image and apply it to DPM. Could you please check if there are any errors in the provided code? The references are as follows.
Xu W, Dong CJ, Li DS. Numerical simulation on influences of wind speed to leaking diffusion of liquid ammonia. Advanced Materials Research. 2015 Jan 27;1073:383-7.
#include "udf.h"#include "dpm.h"#include "dpm_mem.h"/* 定义常量 */#define T_SAT 240.15 /* 蒸发温度 -33°C = 240.15 K */[cite_start]#define LATENT_HEAT 1.37e6 /* 氨气化潜热 J/kg [cite: 66] */DEFINE_DPM_HEAT_MASS(multivap, tp, Cp, hgas, hvap, cvap_surf, Z, dydt, dzdt){int ns;Material *sp;/* 变量初始化 */int nc = TP_N_COMPONENTS(tp);Thread *t0 = TP_CELL_THREAD(tp);Material *gas_mix = THREAD_MATERIAL(DPM_THREAD(t0, tp));cphase_state_t *c = &(tp->cphase[0]);real molwt[MAX_SPE_EQNS];real Tp = TP_T(tp);real mp = TP_MASS(tp);real molwt_bulk = 0.;/* 计算粒子几何属性 */real Dp = DPM_DIAM_FROM_VOL(mp / TP_RHO(tp));real Ap = DPM_AREA(Dp); [cite_start]/* [cite: 63] *//* --- 1. 热传导计算 (保持原逻辑) --- */real Pr = c->sHeat * c->mu / c->tCond;real Nu = 2.0 + 0.6 * sqrt(tp->Re) * pow(Pr, 1./3.);real h = Nu * c->tCond / Dp;/* Q = h * Ap * (T_gas - T_p) */real heat_transfer = h * (c->temp - Tp) * Ap;/* 辅助:计算气相分子量 */mixture_species_loop(gas_mix, sp, ns){molwt[ns] = MATERIAL_PROP(sp, PROP_mwi);molwt_bulk += c->yi[ns] / molwt[ns];}molwt_bulk = MAX(molwt_bulk, DPM_SMALL);/* --- 2. 核心逻辑 (修复了物理错误) --- */real evaporation_rate = 0.0;/* 情况 A: 低温显热加热 (Tp < T_SAT) */if (Tp < T_SAT){/* 仅发生热传导升温,无显著蒸发 *//* Eq (9): m * Cp * dT/dt = Q */dydt[0] += heat_transfer / (mp * Cp);evaporation_rate = 0.0;}/* 情况 B: 沸腾/气化 (Tp >= T_SAT) */else{/* 假设热量全部转化为潜热 (dm/dt * L = Q) */if (heat_transfer > 0){evaporation_rate = heat_transfer / LATENT_HEAT;}/* 能量守恒处理:显热变化 = (总热量 - 潜热消耗) *//* 理论上此处 dydt[0] 结果为 0,即温度保持在沸点 */real latent_heat_term = -evaporation_rate * LATENT_HEAT;dydt[0] += (heat_transfer + latent_heat_term) / (mp * Cp);}/* --- 3. 关键修复:源项更新 --- *//* 获取氨气在气相中的组分索引 */int gas_index = TP_COMPONENT_INDEX_I(tp, 0);if (gas_index >= 0){/* [修复1] 更新粒子质量变化率 dydt *//* 粒子质量减少,导数为负值 *//* 注意:对于多组分粒子,质量存储在 dydt[1 + component_index] *//* 对于单组分 Droplet,通常 dydt[1] 即为质量变化 */dydt[1] -= evaporation_rate;/* [修复2] 更新气相源项 dzdt *//* 气体获得质量,源项为正值 (+) */dzdt->species[gas_index] += evaporation_rate;/* 更新气相总质量源项 */dzdt->gas_mass += evaporation_rate;/* 能量源项通常由 Fluent 根据 mass source 自动处理焓流,若需显式添加显热传递给气相,可取消下行注释 *//* dzdt->energy += heat_transfer; */}} -
January 20, 2026 at 2:01 pm
Rob
Forum ModeratorStaff are unable to check UDFs. What happens when you try and compile the code?
Be aware that some of the Chinese characters in the comment might still be seen by the compiler if they trigger any of the comment close syntax.
-
Viewing 1 reply thread
- 您必须登录才能回复此主题。
Innovation Space
Trending discussions
- Application of EDC occurs flame extinguishing
- 用EDC计算发现燃料不能顺利喷出
- 热仿真计算收敛
- Must EDC model need an initial flow field?
- Compile the UDF code and apply it to the DPM.
- Please help me check if there are any issues with the UDF.
- Negative droplet growth rate in Fluent wet steam model
- Difficulty in Complex Source Term Linearization
Top Contributors
-
4934
-
1638
-
1386
-
1242
-
1021
Top Rated Tags
© 2026 Copyright ANSYS, Inc. All rights reserved.
Ansys does not support the usage of unauthorized Ansys software. Please visit www.ansys.com to obtain an official distribution.

