中科大FLUENT讲稿 第七章 自定义函数(10)
return (drag_force);
}
else if (Re < 20.0) {
w = log10(Re);
drag_force = 18.0 + 2.367*pow(Re,0.82-0.05*w) ; return (drag_force); } else
/* Note: suggested valid range 20 < Re < 260 */ {
drag_force = 18.0 + 3.483*pow(Re,0.6305) ; return (drag_force); } }
7.5.5 计算初始化
初始化函数DEFINE_INIT在FLUENT默认的初始化之后调用。有些流场变量无法在FLUENT默认的初始化中实现,则可以通过初始化函数实现。
/***********************************************************************/ /* UDF for initializing flow field variables */
/***********************************************************************/ #include \
DEFINE_INIT(my_init_function, domain) {
cell_t c;
Thread *thread; real xc[ND_ND];
thread_loop_c (thread,domain) {
begin_c_loop_all (c,thread) {
C_CENTROID(xc,c,thread);
if (sqrt(ND_SUM(pow(xc[0] - 0.5,2.), pow(xc[1] - 0.5,2.),
pow(xc[2] - 0.5,2.))) < 0.25) C_T(c,thread) = 400.; else
C_T(c,thread) = 300.; }
end_c_loop_all (c,thread) } }
函数ND_SUM(a,b,c)用于求解函数参数列表中前面两参数(2D),或三参数(3D)之和。两嵌套的loop循环,能够扫描全场,给全场赋初始值。
7.5.6 壁面热流量
宏DEFINE_HEAT_FLUX能够定义壁面与邻近网格之间的热流量。热流量是按照下面两式计算,本例只求解qid 。
qid=cid[0]+cid[1]×C_T(c0, t0)-cid[2]×F_T(f, t)-cid[3]×pow(F_T(f,t), 4) qir=cir[0]+cir[1]×C_T(c0, t0)-cir[2]×F_T(f, t)-cir[3]×pow(F_T(f,t), 4) C语言源程序为:
/***********************************************************************/ /* UDF for specifying the diffusive heat flux between a wall and neighboring cells */
/***********************************************************************/ #include \
static real h = 0.; /* heat transfer coefficient (W/m^2 C) */ DEFINE_ADJUST(htc_adjust, domain) {
/* Define the heat transfer coefficient. */ h = 120; }
DEFINE_HEAT_FLUX(heat_flux, f, t, c0, t0, cid, cir) {
cid[0] = 0.; cid[1] = h; cid[2] = h; cid[3] = 0.; }
7.5.7 使用用户自定义标量进行后处理
宏DEFINE_ADJUST在每一步迭代执行前调用,所以可以在其中求解标量的微积分,更新与计算结果有关的流场变量等。下例中计算求解温度四次方的导数,并将值存于用户自定义标量之中,以用于后处理。
/***********************************************************************/ /* UDF for computing the magnitude of the gradient of T^4 */
/***********************************************************************/ #include \
/* Define which user-defined scalars to use. */ enum { T4,
MAG_GRAD_T4, N_REQUIRED_UDS
};
DEFINE_ADJUST(adjust_fcn, domain) {
Thread *t; cell_t c; face_t f;
/* Make sure there are enough user-defined scalars. */ if (n_uds < N_REQUIRED_UDS)
Internal_Error(\/* Fill first UDS with temperature raised to fourth power. */ thread_loop_c (t,domain) {
if (NULL != THREAD_STORAGE(t,SV_UDS_I(T4))) {
begin_c_loop (c,t) {
real T = C_T(c,t);
C_UDSI(c,t,T4) = pow(T,4.); }
end_c_loop (c,t) } }
thread_loop_f (t,domain) {
if (NULL != THREAD_STORAGE(t,SV_UDS_I(T4))) {
begin_f_loop (f,t) {
real T = 0.;
if (NULL != THREAD_STORAGE(t,SV_T)) T = F_T(f,t);
else if (NULL != THREAD_STORAGE(t->t0,SV_T)) T = C_T(F_C0(f,t),t->t0); F_UDSI(f,t,T4) = pow(T,4.); }
end_f_loop (f,t) } }
/* Fill second UDS with magnitude of gradient. */ thread_loop_c (t,domain) {
if (NULL != THREAD_STORAGE(t,SV_UDS_I(T4)) &&
NULL != T_STORAGE_R_NV(t,SV_UDSI_G(T4))) {
begin_c_loop (c,t) {
C_UDSI(c,t,MAG_GRAD_T4) = NV_MAG(C_UDSI_G(c,t,T4)); }
end_c_loop (c,t) }
}
thread_loop_f (t,domain) {
if (NULL != THREAD_STORAGE(t,SV_UDS_I(T4)) && NULL != T_STORAGE_R_NV(t->t0,SV_UDSI_G(T4))) {
begin_f_loop (f,t) {
F_UDSI(f,t,MAG_GRAD_T4) = C_UDSI(F_C0(f,t),t->t0,MAG_GRAD_T4); }
end_f_loop (f,t) } } }
条件语句if (NULL != THREAD_STORAGE(t,SV_UDS_I(T4)))检测用户自定义标量中是否已存贮温度的四次方;条件语句NULL != T_STORAGE_R_ NV (t,SV_UDSI_G(T4))检测温度四次方的梯度是否已存入用户自定义标量之中。本例使用了用户自定义标量,所以首先要激活两个用户自定义标量输运方程。
7.5.8 可执行UDFs
本例名为demo_calc的UDF,计算打印当前数据库中的最低温度,最高温度和平均温度,并计算下面的函数,存于用户定义的内存变量中。
f?T??
T?Tmin
Tmax?Tmin/**********************************************************************/ /* demand.c */
/* UDF to calculate temperature field function and store in */
/* user-defined memory. Also print min, max, avg temperatures. */
/**********************************************************************/ #include \
extern Domain* domain;
DEFINE_ON_DEMAND(demo_calc) {
float tavg = 0.;
float tmax = 0.; float tmin = 0.;
float temp,volume,vol_tot; Thread *t; cell_t c;
/* Loop over all cells in the domain */ thread_loop_c(t,domain) {
/* Compute max, min, volume-averaged temperature */
begin_c_loop(c,t) {
volume = C_VOLUME(c,t); /* get cell volume */ temp = C_T(c,t); /* get cell temperature */ if (temp < tmin || tmin == 0.) tmin = temp; if (temp > tmax || tmax == 0.) tmax = temp; vol_tot += volume; tavg += temp*volume; }
end_c_loop(c,t) tavg /= vol_tot;
printf(\/* Compute temperature function and store in user-defined memory */ /* (location index 0) */
begin_c_loop(c,t) {
temp = C_T(c,t);
C_UDMI(c,t,0) = (temp-tmin)/(tmax-tmin); }
end_c_loop(c,t) } }
函数中使用了嵌套的loop循环,循环内部的函数体实现温度最值,平均值和函数f(T)值的求解。由于函数中用到了用户自定义内存变量,所以需要事先激活用户自定义内存变量,内存变量个数不应小于所使用的内存变量个数。
…… 此处隐藏:2679字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [政务民生]2013年公共基础知识热点问题(七)
- [政务民生]检验检测机构资质认定评审准则及释义20
- [政务民生]关于印发重庆市房屋建筑和市政基础设施
- [政务民生]1、隧道洞身开挖支护施工技术交底书
- [政务民生]2015年山东省17地市中考语文试题分类汇
- [政务民生]2-高级会计师资格考试和评审流程图
- [政务民生]2018版中国清分机行业发展分析及前景策
- [政务民生]新课改高中政治探究
- [政务民生]2018-2024年中国新型组合房屋行业投资
- [政务民生]2015年上海市春季高考数学模拟试卷五
- [政务民生]灌砂法及环刀法测压实度(带计算过程)
- [政务民生]运筹学实验2求解非线性规划
- [政务民生]劝学、逍遥游默写(教师卷)
- [政务民生]《运筹学》 - 期末考试 - 试卷A - 答案
- [政务民生]八年级英语下册 Module 6 Hobbies测试
- [政务民生]2019年宪法知识竞赛试题库100题(含答
- [政务民生]自动化英文文献翻译
- [政务民生]公文格式实施细则
- [政务民生]高一地理上册课堂跟踪练习题6
- [政务民生]会计继续教育习题及答案
- 第三章 无约束最优化方法
- 泛读教程第三册答案
- 魏晋南北朝文学
- 幂的运算复习题
- 城市环境问题的成因与治理策略_以社会
- 钢结构行业产业链及竞争分析研究
- 新型热塑性弹性体增韧聚丙烯的研究
- 中国旅游地理B卷试题及答案
- (苏教版)五年级数学上册第三单元测试卷
- 不稳定性心绞痛诊断与治疗
- 俞氏国际后勤职能部门绩效考核办法
- GB7258-2017新标准考试题含答案
- 小学生汉字听写比赛活动方案
- 1.3《平抛运动》学案 教科版必修2
- 2011香港特别行政区公务员考试复习资料
- 考虑水力条件变化的城市给水管网可靠性
- 表面活性剂在油田开发和生产中的应用
- ITT内部培训资料-FI端吸泵的介绍
- 文明守纪,从我做起学生发言稿
- 初中读《聊斋志异》心得体会800字范文




