FLUENT Scheme 腳本調(diào)用及其案例

2016-08-19  by:CAE仿真在線  來源:互聯(lián)網(wǎng)


FLUENT 中使用 Scheme,如果好好利用,能夠大大提高工作效率。這是自己編寫的第一個(gè) journal 文件,用來設(shè)置一些選項(xiàng)。由于經(jīng)常使用 User-defined Materials Database,在 journal 中添加曾經(jīng)遭遇錯(cuò)誤,后來才發(fā)現(xiàn)是 Material 的名稱出了問題。

[python] 
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ; Author: huys
  3. ; Description: Batch setup for segment one
  4. ; Date: 2008/06/03
  5. ; Revision:
  6. ; 1.1 Add materials from user-defined material database
  7. ; Please make sure material's name is right defiend
  8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9. ;Read in the mesh file.
  10. file read-case seg1_m.msh
  11. ;Scale it. mm -> m.
  12. grid/scale
  13. ;x scale factor [1]
  14. 0.001
  15. ;y scale factor [1]
  16. 0.001
  17. ;z scale factor [1]
  18. 0.001
  19. ;Turn on the energy equation
  20. define/models energy?
  21. ;Enable energy model? [no]
  22. yes
  23. ;Compute viscous energy dissipation? [no]
  24. no
  25. ;include pressure work in energy equation? [no]
  26. no
  27. ;include kinetic energy in energy equation? [no]
  28. no
  29. ;Include diffusion at inlets? [yes]
  30. yes
  31. ;Specify turbulence model.
  32. define/models/viscous/ke-standard
  33. ;Enable the standard k-epsilon turbulence model? [no]
  34. yes
  35. ;Select equations to solve.
  36. solve/set/equations flow
  37. ;Solve Flow equation(s)? [yes]
  38. yes
  39. solve/set/equations temperature
  40. ;Solve Energy equation(s)? [yes]
  41. yes
  42. solve/set/equations ke
  43. ;Solve Turbulence equation(s)? [yes]
  44. yes
  45. ;Select material database
  46. define/materials/data-base/database-type
  47. ;Available Types: (fluent-database user-defined)
  48. ;Database Type [fluent-database]
  49. user-defined
  50. ;Database File [""]
  51. custom.scm
  52. ;Copy your materials
  53. define/materials/copy
  54. ;Material of type []>
  55. fluid
  56. ;database-material-name>
  57. water_var
  58. ;
  59. define/materials/copy
  60. ;Material of type []>
  61. solid
  62. ;database-material-name>
  63. stainless_cnt
  64. ;Define boundary conditions
  65. ; Wall
  66. define/boundary-conditions/wall
  67. ; ...
  68. inner_wall_b
  69. ;Wall Thickness (m) [0]
  70. 0
  71. ;Use Profile for Heat Generation Rate? [no]
  72. no
  73. ;Heat Generation Rate (w/m3) [0]
  74. 0
  75. ;material-name [aluminum]: Change current value? [no]
  76. no
  77. ;Thermal BC Type [heat-flux]: Change current value? [no]
  78. yes
  79. ;Thermal BC Type [heat-flux]
  80. ;; convection
  81. ;; coupled
  82. ;; heat-flux
  83. ;; mixed
  84. ;; network
  85. ;; radiation
  86. ;; temperature
  87. temperature
  88. ;Use Profile for Temperature? [no]
  89. no
  90. ;Temperature (k) [300]
  91. 1000
  92. ;Enable shell conduction? [no]
  93. no
  94. ; Inlet
  95. define/boundary-conditions/velocity-inlet
  96. ;
  97. inlet_channel_b
  98. ;Velocity Specification Method: Magnitude and Direction [no]
  99. no
  100. ;Velocity Specification Method: Components [no]
  101. no
  102. ;Velocity Specification Method: Magnitude, Normal to Boundary [yes]
  103. yes
  104. ;Reference Frame: Absolute [yes]
  105. yes
  106. ;Use Profile for Velocity Magnitude? [no]
  107. no
  108. ;Velocity Magnitude (m/s) [0]
  109. 10
  110. ;Coordinate System: Cartesian (X, Y, Z) [yes]
  111. yes
  112. ;Use Profile for Temperature? [no]
  113. no
  114. ;Temperature (k) [300]
  115. 300
  116. ;Turbulent Specification Method: K and Epsilon [yes]
  117. no
  118. ;Turbulent Specification Method: Intensity and Length Scale [no]
  119. no
  120. ;Turbulent Specification Method: Intensity and Viscosity Ratio [no]
  121. yes
  122. ;Turbulent Intensity (%) [10]
  123. 10
  124. ;Turbulent Viscosity Ratio [10]
  125. 10
  126. ; channel
  127. define/boundary-conditions/fluid
  128. ;(channel)
  129. ;zone id/name [channel]
  130. channel
  131. ;material-name [air]: Change current value? [no]
  132. yes
  133. ;material-name [air]>
  134. water_var
  135. ;Specify source terms? [no]
  136. no
  137. ;Specify fixed values? [no]
  138. no
  139. ;Motion Type: Stationary [yes]
  140. yes
  141. ;X-Origin of Rotation-Axis (m) [0]
  142. 0
  143. ;Y-Origin of Rotation-Axis (m) [0]
  144. 0
  145. ;Z-Origin of Rotation-Axis (m) [0]
  146. 0
  147. ;X-Component of Rotation-Axis [0]
  148. 0
  149. ;Y-Component of Rotation-Axis [0]
  150. 0
  151. ;Z-Component of Rotation-Axis [1]
  152. 1
  153. ;Deactivated Thread [no]
  154. no
  155. ;Laminar zone? [no]
  156. no
  157. ;Porous zone? [no]
  158. no
  159. ; soild(wall)
  160. define/boundary-conditions/solid
  161. ;(wall)
  162. ;zone id/name [wall]
  163. wall
  164. ;material-name [aluminum]: Change current value? [no]
  165. yes
  166. ;material-name [aluminum]>
  167. stainless_cnt
  168. ;Specify source terms? [no]
  169. no
  170. ;Specify fixed values? [no]
  171. no
  172. ;Motion Type: Stationary [yes]
  173. yes
  174. ;X-Origin of Rotation-Axis (m) [0]
  175. 0
  176. ;Y-Origin of Rotation-Axis (m) [0]
  177. 0
  178. ;Z-Origin of Rotation-Axis (m) [0]
  179. 0
  180. ;X-Component of Rotation-Axis [0]
  181. 0
  182. ;Y-Component of Rotation-Axis [0]
  183. 0
  184. ;Z-Component of Rotation-Axis [1]
  185. 1
  186. ;Deactivated Thread [no]
  187. no
  188. ;Set Pressure Velocity Coupling Scheme to SIMPLEC
  189. solve/set/p-v-coupling
  190. ;Pressure Velocity Coupling Scheme [20] ?
  191. ;; 20 for SIMPLE
  192. ;; 21 for SIMPLEC
  193. ;; 22 for PISO
  194. ;; 24 for Coupled
  195. 21
  196. ;Set the discretization schemes./
  197. solve/set/discretization-scheme pressure
  198. ;Convective discretization scheme for Pressure [10]
  199. ;; 10 for Standard
  200. ;; 14 for PRESTO!
  201. ;; 11 for Linear
  202. ;; 12 for Second Order
  203. ;; 13 for Body Force Weighted
  204. 10
  205. solve/set/discretization-scheme mom
  206. ;Convective discretization scheme for Momentum [0]
  207. ;; 0 for First Order Upwind
  208. ;; 1 for Second Order Upwind
  209. ;; 2 for Power Law
  210. ;; 4 for QUICK
  211. ;; 6 for Third-Order MUSCL
  212. 1
  213. solve/set/discretization-scheme temperature
  214. ;Convective discretization scheme for Energy [0]
  215. ;; 0 for First Order Upwind
  216. ;; 1 for Second Order Upwind
  217. ;; 2 for Power Law
  218. ;; 4 for QUICK
  219. ;; 6 for Third-Order MUSCL
  220. 1
  221. solve/set/discretization-scheme k
  222. ;Convective discretization scheme for Turbulence Kinetic Energy [0]
  223. ;; 0 for First Order Upwind
  224. ;; 1 for Second Order Upwind
  225. ;; 2 for Power Law
  226. ;; 4 for QUICK
  227. ;; 6 for Third-Order MUSCL
  228. 1
  229. solve/set/discretization-scheme epsilon
  230. ;Convective discretization scheme for Turbulence Dissipation Rate [0]
  231. ;; 0 for First Order Upwind
  232. ;; 1 for Second Order Upwind
  233. ;; 2 for Power Law
  234. ;; 4 for QUICK
  235. ;; 6 for Third-Order MUSCL
  236. 1
  237. ;Set underrelaxation factors.
  238. solve/set/under-relaxation pressure
  239. ;Underrelaxation factor for Pressure [0.3]
  240. 0.9
  241. solve/set/under-relaxation mom
  242. ;Underrelaxation factor for Momentum [0.7]
  243. 0.9
  244. solve/set/under-relaxation temperature
  245. ;Underrelaxation factor for Energy [1]
  246. 0.9
  247. solve/set/under-relaxation k
  248. ;Underrelaxation factor for Turbulence Kinetic Energy [0.8]
  249. 0.9
  250. solve/set/under-relaxation epsilon
  251. ;Underrelaxation factor for Turbulence Dissipation Rate [0.8]
  252. 0.9
  253. solve/set/under-relaxation turb-viscosity
  254. ;Underrelaxation factor for Viscosity [1]
  255. 0.9
  256. solve/set/under-relaxation density
  257. ;Underrelaxation factor for Density [1]
  258. 0.9
  259. solve/set/under-relaxation body-force
  260. ;Underrelaxation factor for Body Forces [1]
  261. 0.9
  262. ;Set multigrid.
  263. solve/set/multi-grid-controls pressure
  264. ;Multigrid cycle type for Pressure [1]
  265. 1
  266. ;Termination criterion [0.1]
  267. 1e-30
  268. ;Multigrid method for Pressure [0]
  269. 0
  270. ;Multigrid stabilization for Pressure [0]
  271. 0
  272. solve/set/multi-grid-controls x-mom
  273. ;Multigrid cycle type for X-Momentum [0]
  274. 0
  275. ;Termination criterion [0.1]
  276. 1e-30
  277. ;Residual reduction tolerance for [0.7]
  278. 0.999
  279. ;Multigrid method for X-Momentum [0]
  280. 0
  281. solve/set/multi-grid-controls y-mom
  282. ;Multigrid cycle type for X-Momentum [0]
  283. 0
  284. ;Termination criterion [0.1]
  285. 1e-30
  286. ;Residual reduction tolerance for [0.7]
  287. 0.999
  288. ;Multigrid method for X-Momentum [0]
  289. 0
  290. solve/set/multi-grid-controls z-mom
  291. ;Multigrid cycle type for X-Momentum [0]
  292. 0
  293. ;Termination criterion [0.1]
  294. 1e-30
  295. ;Residual reduction tolerance for [0.7]
  296. 0.999
  297. ;Multigrid method for X-Momentum [0]
  298. 0
  299. solve/set/multi-grid-controls k
  300. ;Multigrid cycle type for Turbulent Kinetic Energy [0]
  301. 0
  302. ;Termination criterion [0.1]
  303. 1e-30
  304. ;Residual reduction tolerance for [0.7]
  305. 0.999
  306. ;Multigrid method for Turbulent Kinetic Energy [0]
  307. 0
  308. solve/set/multi-grid-controls epsilon
  309. ;Multigrid cycle type for Turbulent Dissipation Rate [0]
  310. 0
  311. ;Termination criterion [0.1]
  312. 1e-30
  313. ;Residual reduction tolerance for [0.7]
  314. 0.999
  315. ;Multigrid method for Turbulent Dissipation Rate [0]
  316. 0
  317. solve/set/multi-grid-controls temperature
  318. ;Multigrid cycle type for Energy [0]
  319. 0
  320. ;Termination criterion [0.1]
  321. 1e-30
  322. ;Residual reduction tolerance for [0.7]
  323. 0.999
  324. ;Multigrid method for Energy [0]
  325. 0
  326. ;Set the convergence criteria.
  327. solve/monitors/residual convergence-criteria
  328. ;continuity residual convergence criterion [0.001]
  329. 1e-16
  330. ;x-velocity residual convergence criterion [0.001]
  331. 1e-16
  332. ;y-velocity residual convergence criterion [0.001]
  333. 1e-16
  334. ;z-velocity residual convergence criterion [0.001]
  335. 1e-16
  336. ;energy residual convergence criterion [1e-06]
  337. 1e-16
  338. ;k residual convergence criterion [0.001]
  339. 1e-16
  340. ;epsilon residual convergence criterion [0.001]
  341. 1e-16
  342. ;Write settings to a case file.
  343. file/write-case
  344. ;case file name [""]
  345. "seg1_xx.cas"


現(xiàn)在的計(jì)算平臺(tái)有很多是 Linux Cluster,常用的作業(yè)管理系統(tǒng)采用 PBS。如果要采用 FLUENT 進(jìn)行計(jì)算就需要解決在 Text Mode 下調(diào)用 FLUENT 進(jìn)行求解的問題,而且多數(shù)時(shí)候

需要執(zhí)行并行版本的 FLUENT。


Linux 調(diào)用 FLUENT 的文本界面其實(shí)很簡單,比如

  1. fluent 3d -g

出現(xiàn)了 FLUENT 的 console,這樣就能輸入命令并執(zhí)行了。


不想手工輸入命令的話,寫一個(gè) journal 或 scheme 腳本文件,讓 FLUENT 啟動(dòng)后自動(dòng)執(zhí)行。

  1. fluent 3d -g -i script.scm

最好加上 I/O 重定向。

 

fluent 3d -g -i script.scm > out.log


遠(yuǎn)程連接時(shí)后臺(tái)執(zhí)行就比較重要了。

 

fluent 3d -g -i script.scm > out.log &


以上是之前在 PC 上常用的模式,還會(huì)利用 screen 之類的進(jìn)行監(jiān)視。


那么并行版本又如何呢?


本地并行的話,基本上就是


fluent 3d -t8 -g -i script.scm > out.log &


利用多個(gè)節(jié)點(diǎn)的話,需要做些處理


fluent 3d -pethernet -cnf=myhosts -t8 -ssh -g -i script.scm > out.log &


多了幾個(gè)選項(xiàng),其中


-pethernet 表示各節(jié)點(diǎn)利用局域網(wǎng)連接進(jìn)行通信,發(fā)現(xiàn)用 default 選項(xiàng)的話會(huì)報(bào)錯(cuò)的,至少 fluent12 是這個(gè)樣子。


-cnf=myhosts 表示運(yùn)行的節(jié)點(diǎn)信息


-ssh 表示各節(jié)點(diǎn)采用 ssh 進(jìn)行登錄,默認(rèn)的話采用 rsh,如果沒有啟用 rsh 服務(wù)的話就崩潰了。


到這里基本可以了。


如果要在 PBS 中進(jìn)行調(diào)用,啟動(dòng)命令可以不加 i/O 重定向和后臺(tái)運(yùn)行的符號(hào)



fluent 3d -pethernet -cnf=myhosts -t8 -ssh -g -i script.scm



 


1、添加菜單項(xiàng) (Text Mode)

(define ti-flab-iterate
(lambda ()
(display "Hello World!")
)
)
(define flowlab-menu
(make-menu
"flowlab"
("iterate" #t ti-flab-iterate "Iterate.")
)
)
(define add-menu
(lambda (name menu test value help)
(ti-menu-insert-item!
menu
(make-menu-item name test value help)
)
#t
)
)
(add-menu "flowlab/" main-menu #t flowlab-menu "")



addmenu


2 輸出當(dāng)前的迭代次數(shù)和參數(shù)

(define (export-niters fname parameter)

(let

(

(niter (%iterate 0))

(out-port (open-file fname "w"))

)

(if (not out-port)

(cx-error-dialog "unable to open output file for exporting niters")

)

(format out-port "$~a = ~a~%" parameter niter)

(flush-output-port out-port)

)

)


3 字符串處理

;takes any string as argument 'str', breaks it on the basis of blank-space or
;newline character into multiple strings. These multiple strings are returned
;as a list. 
(define (tokenizer str)
(let
(
(l (string->list str))
(result '())
(delimitters (list #/space #/newline #/) #/())
(started? #f)
(temp '())
)
(for-each
(lambda (c)
(if started?
(if (not (memv c delimitters))
(set! temp (append temp (list c)))
(begin
(set! result (append result (list (list->string temp))))
(set! temp '())
(set! started? #f)
)
)
(if (not (memv c delimitters))
(begin
(set! temp (append temp (list c)))
(set! started? #t)
)
)
)
)
l
)
(if started?
(set! result
(append result (list (list->string temp)))
)
)
result
)
)


4 自動(dòng)保存,記錄輸出信息的迭代腳本

;;
;; iterate.scm
;;
(define casename "coal_inj_00")
(define iternum 500)
;
(define hy-start-transcript
(lambda (filename)
(if (file-exists? filename)
(remove-file filename)
#t
)
(ti-start-transcript filename #t)
#t
)
)
;;
(define (hy-stop-transcript)
(if transcript-open?
(stop-transcript #t)
#t
)
#t
)
;;
(define (log-exec-proc exec-proc trn-file)
(begin
(hy-start-transcript trn-file)
(exec-proc)
(newline)
(hy-stop-transcript)
)
)
;;
(define my-iterate
(lambda (num)
(if (number? num)
(begin
(read-case-data casename)
(iterate num)
(write-case-data (format #f "~a-i~a" casename num))
#t
)
#f
)
)
)
;;
(log-exec-proc (lambda () (my-iterate iternum)) (string-append casename ".trn"))

5 讀取 report 文件中的數(shù)值


;;

;;

;;
(define (hy-read-rp-file filename)
(let ((p (open-input-file (format #f "~a" filename))))
(do
((x (read p) (read p)))
(
(or (number? x) (eof-object? x))
(close-input-port p)
(if (number? x) x #f)
)
)
)
)


6 讀取數(shù)據(jù)到 list 中

(define hy-read-data-to-list
(lambda (fname)
(let ((p (open-input-file (format #f "~a" fname))))
(let f ((x (read p)) (l '()))
(if (or (eof? p) (eof-object? x))
(begin
(close-input-port p)
l
)
(begin
(display x)
(newline)
(if (number? x)
(set! l (append l (list x)))
)
(f (read p) l)
)
)
)
)
)
)


7 導(dǎo)出 bc 信息

(define (hy-export-bc-names)
(for-each
(lambda (name)
(display
(format #f "{~a, /"~a/", /"~a/"},/n"
(zone-name->id name)
name
(zone-type (get-zone name))
)
)
)
(inquire-zone-names)
)
)


8 顯示 list 內(nèi)容

;;;
(define hy-display-list
(lambda (l)
(do ((i 0 (+ i 1)))
((>= i (length l)))
(display (format #f "~a --- ~a/n" i (list-ref l i)))
)
)
)


9 非穩(wěn)態(tài)計(jì)算時(shí)自動(dòng)保存腳本

;; Scheme file to autosave files at a particular time interval,

 

;;original: FLUENT Online Technical Support "Solution 656 :Autosave at specified time intervals "


;; Usage:

;; To use the scheme file to save files at a given time interval,

;; 0. Read case and data files, then read autosave.scm through File > Read > Scheme

;; 1. Open the Execute Commands panel in the GUI (Solve>Execute Commands)

;; 2. Increase the number of Defined Commands by

;; 3. Click ON next to the most recent command and select Time Step

;; next to the drop down arrow under When

;; 4. Enter the following text in the field under Command:

;; (autowrite "wcd" "autoname-" 0.2)


;; 5. Enter the compression status below. Change only the text between the quotation marks.

;; For compressed files use ".gz"

;; For uncompressed files use ""

(define g_zip "")

;;

;; The value of 0.2 should be replaced with the desired interval for the current case

;; The value of "wcd" should be replaced with

;; "wd " for data files only

;; "wcd " for case and data files

;; The value of "autoname-" should be replaced with the actual pathname+filename :

;; if it is written in current directory,pathname can be omitted.

;;default setting

(define g_filename "auto-")

(define g_wcom "wd")


(define (writefiles current-time)

(let* ((time-string) (writecommand))

(rpsetvar 'autowrite/last-file-time current-time)

(set! writecommand (string-append g_wcom " " g_filename g_zip))

(ti-menu-load-string writecommand)

)

)


(define (autowrite wcom filename interval)

(let* ( (current-time) (overlap) (last-write) (file-write-time) )

(if (not (rp-var-object 'autowrite/last-file-time))

(rp-var-define 'autowrite/last-file-time (rpgetvar 'flow-time) 'real #f)

)

(set! current-time (rpgetvar 'flow-time))

(set! last-write (rpgetvar 'autowrite/last-file-time))

(set! overlap (- last-write (* interval (truncate (/ last-write interval)))))

(set! file-write-time (+ interval (- last-write overlap)))

(if (> current-time file-write-time)

(begin

(cond

((truncate (/ last-write interval)<? 10)

(set! g_filename (string-append filename "000" (number->string (inexact->exact (truncate(/ last-write interval))))))

)

((truncate (/ last-write interval)<? 100)

(set! g_filename (string-append filename "00" (number->string (inexact->exact (truncate(/ last-write interval))))))

)

((truncate (/ last-write interval)<? 1000)

(set! g_filename (string-append filename "0" (number->string (inexact->exact (truncate(/ last-write interval))))))

)

(else

(set! g_filename (string-append filename (number->string (inexact->exact (truncate(/ last-write interval))))))

)

)

(set! g_wcom wcom)

(writefiles current-time)

)

)

)

)


開放分享:優(yōu)質(zhì)有限元技術(shù)文章,助你自學(xué)成才

相關(guān)標(biāo)簽搜索:FLUENT Scheme 腳本調(diào)用及其案例 FLUENT Scheme 腳本 fluent Fluent培訓(xùn) Fluent流體培訓(xùn) Fluent軟件培訓(xùn) fluent技術(shù)教程 fluent在線視頻教程 fluent資料下載 fluent分析理論 fluent化學(xué)反應(yīng) fluent軟件下載 UDF編程代做 

編輯
在線報(bào)名:
  • 客服在線請(qǐng)直接聯(lián)系我們的客服,您也可以通過下面的方式進(jìn)行在線報(bào)名,我們會(huì)及時(shí)給您回復(fù)電話,謝謝!
驗(yàn)證碼

全國服務(wù)熱線

1358-032-9919

廣州公司:
廣州市環(huán)市中路306號(hào)金鷹大廈3800
電話:13580329919
          135-8032-9919
培訓(xùn)QQ咨詢:點(diǎn)擊咨詢 點(diǎn)擊咨詢
項(xiàng)目QQ咨詢:點(diǎn)擊咨詢
email:kf@1cae.com