内容纲要
湖北的天气真是热啊,汗流浃背用程序代码来降温。
最近在关注Fluent的界面开发,猛补了一把Scheme语言。是时候展示一下学习成果了。这不,在酷暑中做了个太阳能手电筒:利用Fluent计算YPlus。
Y+计算通常是根据Y+值估算第一层网格高度。实现效果如下图所示。
Y+计算采用PointWise官方网页提供的计算方法。见网址 http://www.pointwise.com/yplus/ 。该方法基于 Frank M. White's Fluid Mechanics 5th edition, page 467中关于平板边界层理论计算。
具体计算方法为:
先计算雷诺数:
通过雷诺数计算摩擦系数:
计算壁面剪切力:
计算:
得到第一层网格高度:
创建sheme代码,如下所示。代码很不简洁,是因为考虑到与UDF的接口。这里计算过于简单,并没有使用UDF。
(可以滑屏查看完整代码)
;RP Variable Create Function
(define (make-new-rpvar name default type)
(if (not (rp-var-object name))
(rp-var-define name default type #f)))
;RP Variable Declarations
(make-new-rpvar 'myudf/velocity 1.0 'real) ;freestream velocity
(make-new-rpvar 'myudf/density 1.0 'real);density
(make-new-rpvar 'myudf/mu 1.0 'real) ;mu
(make-new-rpvar 'myudf/length 1.0 'real) ; Length
(make-new-rpvar 'myudf/yplus 1.0 'real) ; yplus
(make-new-rpvar 'myudf/deltas 0.0 'real) ;/deltaS
(make-new-rpvar 'myudf/re 0.0 'real) ;Re
;Dialog Box Definition
(define gui-dialog-box
;Let Statement, Local Variable Declarations
(let ((dialog-box #f)
(table)
(myudf/box1)
(myudf/box2)
(myudf/velocity)
(myudf/density)
(myudf/mu)
(myudf/length)
(myudf/yplus)
(myudf/deltas)
(myudf/re)
)
;Update-CB Function, Invoked When Dialog Box Is Opened
(define (update-cb . args)
(cx-set-real-entry myudf/velocity 1.0)
(cx-set-real-entry myudf/density 1.0)
(cx-set-real-entry myudf/mu 1.0)
(cx-set-real-entry myudf/length 1.0)
(cx-set-real-entry myudf/yplus 1.0)
(cx-set-real-entry myudf/deltas 0.0)
(cx-set-real-entry myudf/re 0.0)
)
;Apply-CB Function, Invoked When "OK" Button Is Clicked
(define (apply-cb . args)
(Cal)
)
;定义函数计算雷诺数与第一层网格高度
(define (Cal)
(rpsetvar 'myudf/velocity (cx-show-real-entry myudf/velocity))
(rpsetvar 'myudf/density (cx-show-real-entry myudf/density))
(rpsetvar 'myudf/mu (cx-show-real-entry myudf/mu))
(rpsetvar 'myudf/length (cx-show-real-entry myudf/length))
(rpsetvar 'myudf/yplus (cx-show-real-entry myudf/yplus))
(rpsetvar 'myudf/deltas (cx-show-real-entry myudf/deltas))
(rpsetvar 'myudf/re (cx-show-real-entry myudf/re))
(define re (rpgetvar 'myudf/re))
(define density (rpgetvar 'myudf/density))
(define mu (rpgetvar 'myudf/mu))
(define length (rpgetvar 'myudf/length))
(define yplus (rpgetvar 'myudf/yplus))
(define deltas (rpgetvar 'myudf/deltas))
(define velocity (rpgetvar 'myudf/velocity))
(define cf)
(define tau)
(define u_fric)
(set! re (* density (* velocity (/ length mu))))
(set! cf (/ 0.026 (expt re (/ 1 7))))
(set! tau (* cf (* density (* velocity (/ velocity 2)))))
(set! u_fric (sqrt (/ tau density)))
(set! deltas (* yplus (/ mu (* u_fric density))))
(cx-set-real-entry myudf/deltas deltas)
(cx-set-real-entry myudf/re re)
)
;Button-CB Function, Invoked When "Test Button" Is Clicked
(define (button-cb . args)
(cal)
)
;Args Function, Used For Interface Setup, Required For Apply-CB, Update-CB, and Button-CB Sections
(lambda args
(if (not dialog-box)
(let ()
(set! dialog-box (cx-create-panel "Turbulent Calculator" apply-cb update-cb))
(set! table (cx-create-table dialog-box "" 'border #f 'below 0 'right-of 0))
(set! myudf/box1 (cx-create-table table "Data Inputs" 'row 0))
(set! myudf/velocity (cx-create-real-entry myudf/box1 "Velocity[m/s]:" 'row 0))
(set! myudf/density (cx-create-real-entry myudf/box1 "Density[kg/m3]:" 'row 1))
(set! myudf/mu (cx-create-real-entry myudf/box1 "Viscosity[Pa.s]:" 'row 2))
(set! myudf/length (cx-create-real-entry myudf/box1 "Length[m]:" 'row 3))
(set! myudf/yplus (cx-create-real-entry myudf/box1 "YPlus:" 'row 4))
(cx-create-button table "Calculate" 'activate-callback button-cb 'row 1)
(set! myudf/box2 (cx-create-table table "Data Output" 'row 2))
(set! myudf/deltas (cx-create-real-entry myudf/box2 "DeltaS[m]" 'row 0))
(set! myudf/re (cx-create-real-entry myudf/box2 "Re:" 'row 1))
) ;End Of Let Statement
) ;End Of If Statement
;Call To Open Dialog Box
(cx-show-panel dialog-box)
) ;End Of Args Function
) ;End Of Let Statement
) ;End Of GUI-Dialog-Box Definition
(gui-dialog-box)
代码使用方法:
-
新建文本文件(如yplus.txt),修改文件名及扩展名为yplus.scm
-
Fluent中利用菜单File → Read → Scheme…加载文件yplus.scm即可开启对话框
程序有待改进,比如自动提取设置的边界和网格信息进行计算,此功能后面有时间再说。对于Scheme语言完全陌生的话,可看这本书《计算机程序的构造和解释》,可以找得到PDF版本。
本篇文章来源于微信公众号: CFD之道
评论前必须登录!
注册