FLUENT Scheme 腳本調(diào)用及其案例
2016-08-19 by:CAE仿真在線 來源:互聯(lián)網(wǎng)
FLUENT 中使用 Scheme,如果好好利用,能夠大大提高工作效率。這是自己編寫的第一個 journal 文件,用來設置一些選項。由于經(jīng)常使用 User-defined Materials Database,在 journal 中添加曾經(jīng)遭遇錯誤,后來才發(fā)現(xiàn)是 Material 的名稱出了問題。
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Author: huys
- ; Description: Batch setup for segment one
- ; Date: 2008/06/03
- ; Revision:
- ; 1.1 Add materials from user-defined material database
- ; Please make sure material's name is right defiend
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;Read in the mesh file.
- file read-case seg1_m.msh
- ;Scale it. mm -> m.
- grid/scale
- ;x scale factor [1]
- 0.001
- ;y scale factor [1]
- 0.001
- ;z scale factor [1]
- 0.001
- ;Turn on the energy equation
- define/models energy?
- ;Enable energy model? [no]
- yes
- ;Compute viscous energy dissipation? [no]
- no
- ;include pressure work in energy equation? [no]
- no
- ;include kinetic energy in energy equation? [no]
- no
- ;Include diffusion at inlets? [yes]
- yes
- ;Specify turbulence model.
- define/models/viscous/ke-standard
- ;Enable the standard k-epsilon turbulence model? [no]
- yes
- ;Select equations to solve.
- solve/set/equations flow
- ;Solve Flow equation(s)? [yes]
- yes
- solve/set/equations temperature
- ;Solve Energy equation(s)? [yes]
- yes
- solve/set/equations ke
- ;Solve Turbulence equation(s)? [yes]
- yes
- ;Select material database
- define/materials/data-base/database-type
- ;Available Types: (fluent-database user-defined)
- ;Database Type [fluent-database]
- user-defined
- ;Database File [""]
- custom.scm
- ;Copy your materials
- define/materials/copy
- ;Material of type []>
- fluid
- ;database-material-name>
- water_var
- ;
- define/materials/copy
- ;Material of type []>
- solid
- ;database-material-name>
- stainless_cnt
- ;Define boundary conditions
- ; Wall
- define/boundary-conditions/wall
- ; ...
- inner_wall_b
- ;Wall Thickness (m) [0]
- 0
- ;Use Profile for Heat Generation Rate? [no]
- no
- ;Heat Generation Rate (w/m3) [0]
- 0
- ;material-name [aluminum]: Change current value? [no]
- no
- ;Thermal BC Type [heat-flux]: Change current value? [no]
- yes
- ;Thermal BC Type [heat-flux]
- ;; convection
- ;; coupled
- ;; heat-flux
- ;; mixed
- ;; network
- ;; radiation
- ;; temperature
- temperature
- ;Use Profile for Temperature? [no]
- no
- ;Temperature (k) [300]
- 1000
- ;Enable shell conduction? [no]
- no
- ; Inlet
- define/boundary-conditions/velocity-inlet
- ;
- inlet_channel_b
- ;Velocity Specification Method: Magnitude and Direction [no]
- no
- ;Velocity Specification Method: Components [no]
- no
- ;Velocity Specification Method: Magnitude, Normal to Boundary [yes]
- yes
- ;Reference Frame: Absolute [yes]
- yes
- ;Use Profile for Velocity Magnitude? [no]
- no
- ;Velocity Magnitude (m/s) [0]
- 10
- ;Coordinate System: Cartesian (X, Y, Z) [yes]
- yes
- ;Use Profile for Temperature? [no]
- no
- ;Temperature (k) [300]
- 300
- ;Turbulent Specification Method: K and Epsilon [yes]
- no
- ;Turbulent Specification Method: Intensity and Length Scale [no]
- no
- ;Turbulent Specification Method: Intensity and Viscosity Ratio [no]
- yes
- ;Turbulent Intensity (%) [10]
- 10
- ;Turbulent Viscosity Ratio [10]
- 10
- ; channel
- define/boundary-conditions/fluid
- ;(channel)
- ;zone id/name [channel]
- channel
- ;material-name [air]: Change current value? [no]
- yes
- ;material-name [air]>
- water_var
- ;Specify source terms? [no]
- no
- ;Specify fixed values? [no]
- no
- ;Motion Type: Stationary [yes]
- yes
- ;X-Origin of Rotation-Axis (m) [0]
- 0
- ;Y-Origin of Rotation-Axis (m) [0]
- 0
- ;Z-Origin of Rotation-Axis (m) [0]
- 0
- ;X-Component of Rotation-Axis [0]
- 0
- ;Y-Component of Rotation-Axis [0]
- 0
- ;Z-Component of Rotation-Axis [1]
- 1
- ;Deactivated Thread [no]
- no
- ;Laminar zone? [no]
- no
- ;Porous zone? [no]
- no
- ; soild(wall)
- define/boundary-conditions/solid
- ;(wall)
- ;zone id/name [wall]
- wall
- ;material-name [aluminum]: Change current value? [no]
- yes
- ;material-name [aluminum]>
- stainless_cnt
- ;Specify source terms? [no]
- no
- ;Specify fixed values? [no]
- no
- ;Motion Type: Stationary [yes]
- yes
- ;X-Origin of Rotation-Axis (m) [0]
- 0
- ;Y-Origin of Rotation-Axis (m) [0]
- 0
- ;Z-Origin of Rotation-Axis (m) [0]
- 0
- ;X-Component of Rotation-Axis [0]
- 0
- ;Y-Component of Rotation-Axis [0]
- 0
- ;Z-Component of Rotation-Axis [1]
- 1
- ;Deactivated Thread [no]
- no
- ;Set Pressure Velocity Coupling Scheme to SIMPLEC
- solve/set/p-v-coupling
- ;Pressure Velocity Coupling Scheme [20] ?
- ;; 20 for SIMPLE
- ;; 21 for SIMPLEC
- ;; 22 for PISO
- ;; 24 for Coupled
- 21
- ;Set the discretization schemes./
- solve/set/discretization-scheme pressure
- ;Convective discretization scheme for Pressure [10]
- ;; 10 for Standard
- ;; 14 for PRESTO!
- ;; 11 for Linear
- ;; 12 for Second Order
- ;; 13 for Body Force Weighted
- 10
- solve/set/discretization-scheme mom
- ;Convective discretization scheme for Momentum [0]
- ;; 0 for First Order Upwind
- ;; 1 for Second Order Upwind
- ;; 2 for Power Law
- ;; 4 for QUICK
- ;; 6 for Third-Order MUSCL
- 1
- solve/set/discretization-scheme temperature
- ;Convective discretization scheme for Energy [0]
- ;; 0 for First Order Upwind
- ;; 1 for Second Order Upwind
- ;; 2 for Power Law
- ;; 4 for QUICK
- ;; 6 for Third-Order MUSCL
- 1
- solve/set/discretization-scheme k
- ;Convective discretization scheme for Turbulence Kinetic Energy [0]
- ;; 0 for First Order Upwind
- ;; 1 for Second Order Upwind
- ;; 2 for Power Law
- ;; 4 for QUICK
- ;; 6 for Third-Order MUSCL
- 1
- solve/set/discretization-scheme epsilon
- ;Convective discretization scheme for Turbulence Dissipation Rate [0]
- ;; 0 for First Order Upwind
- ;; 1 for Second Order Upwind
- ;; 2 for Power Law
- ;; 4 for QUICK
- ;; 6 for Third-Order MUSCL
- 1
- ;Set underrelaxation factors.
- solve/set/under-relaxation pressure
- ;Underrelaxation factor for Pressure [0.3]
- 0.9
- solve/set/under-relaxation mom
- ;Underrelaxation factor for Momentum [0.7]
- 0.9
- solve/set/under-relaxation temperature
- ;Underrelaxation factor for Energy [1]
- 0.9
- solve/set/under-relaxation k
- ;Underrelaxation factor for Turbulence Kinetic Energy [0.8]
- 0.9
- solve/set/under-relaxation epsilon
- ;Underrelaxation factor for Turbulence Dissipation Rate [0.8]
- 0.9
- solve/set/under-relaxation turb-viscosity
- ;Underrelaxation factor for Viscosity [1]
- 0.9
- solve/set/under-relaxation density
- ;Underrelaxation factor for Density [1]
- 0.9
- solve/set/under-relaxation body-force
- ;Underrelaxation factor for Body Forces [1]
- 0.9
- ;Set multigrid.
- solve/set/multi-grid-controls pressure
- ;Multigrid cycle type for Pressure [1]
- 1
- ;Termination criterion [0.1]
- 1e-30
- ;Multigrid method for Pressure [0]
- 0
- ;Multigrid stabilization for Pressure [0]
- 0
- solve/set/multi-grid-controls x-mom
- ;Multigrid cycle type for X-Momentum [0]
- 0
- ;Termination criterion [0.1]
- 1e-30
- ;Residual reduction tolerance for [0.7]
- 0.999
- ;Multigrid method for X-Momentum [0]
- 0
- solve/set/multi-grid-controls y-mom
- ;Multigrid cycle type for X-Momentum [0]
- 0
- ;Termination criterion [0.1]
- 1e-30
- ;Residual reduction tolerance for [0.7]
- 0.999
- ;Multigrid method for X-Momentum [0]
- 0
- solve/set/multi-grid-controls z-mom
- ;Multigrid cycle type for X-Momentum [0]
- 0
- ;Termination criterion [0.1]
- 1e-30
- ;Residual reduction tolerance for [0.7]
- 0.999
- ;Multigrid method for X-Momentum [0]
- 0
- solve/set/multi-grid-controls k
- ;Multigrid cycle type for Turbulent Kinetic Energy [0]
- 0
- ;Termination criterion [0.1]
- 1e-30
- ;Residual reduction tolerance for [0.7]
- 0.999
- ;Multigrid method for Turbulent Kinetic Energy [0]
- 0
- solve/set/multi-grid-controls epsilon
- ;Multigrid cycle type for Turbulent Dissipation Rate [0]
- 0
- ;Termination criterion [0.1]
- 1e-30
- ;Residual reduction tolerance for [0.7]
- 0.999
- ;Multigrid method for Turbulent Dissipation Rate [0]
- 0
- solve/set/multi-grid-controls temperature
- ;Multigrid cycle type for Energy [0]
- 0
- ;Termination criterion [0.1]
- 1e-30
- ;Residual reduction tolerance for [0.7]
- 0.999
- ;Multigrid method for Energy [0]
- 0
- ;Set the convergence criteria.
- solve/monitors/residual convergence-criteria
- ;continuity residual convergence criterion [0.001]
- 1e-16
- ;x-velocity residual convergence criterion [0.001]
- 1e-16
- ;y-velocity residual convergence criterion [0.001]
- 1e-16
- ;z-velocity residual convergence criterion [0.001]
- 1e-16
- ;energy residual convergence criterion [1e-06]
- 1e-16
- ;k residual convergence criterion [0.001]
- 1e-16
- ;epsilon residual convergence criterion [0.001]
- 1e-16
- ;Write settings to a case file.
- file/write-case
- ;case file name [""]
- "seg1_xx.cas"
現(xiàn)在的計算平臺有很多是 Linux Cluster,常用的作業(yè)管理系統(tǒng)采用 PBS。如果要采用 FLUENT 進行計算就需要解決在 Text Mode 下調(diào)用 FLUENT 進行求解的問題,而且多數(shù)時候
需要執(zhí)行并行版本的 FLUENT。
Linux 調(diào)用 FLUENT 的文本界面其實很簡單,比如
- fluent 3d -g
出現(xiàn)了 FLUENT 的 console,這樣就能輸入命令并執(zhí)行了。
不想手工輸入命令的話,寫一個 journal 或 scheme 腳本文件,讓 FLUENT 啟動后自動執(zhí)行。
- fluent 3d -g -i script.scm
最好加上 I/O 重定向。
fluent 3d -g -i script.scm > out.log
遠程連接時后臺執(zhí)行就比較重要了。
fluent 3d -g -i script.scm > out.log &
以上是之前在 PC 上常用的模式,還會利用 screen 之類的進行監(jiān)視。
那么并行版本又如何呢?
本地并行的話,基本上就是
利用多個節(jié)點的話,需要做些處理
多了幾個選項,其中
-pethernet 表示各節(jié)點利用局域網(wǎng)連接進行通信,發(fā)現(xiàn)用 default 選項的話會報錯的,至少 fluent12 是這個樣子。
-cnf=myhosts 表示運行的節(jié)點信息
-ssh 表示各節(jié)點采用 ssh 進行登錄,默認的話采用 rsh,如果沒有啟用 rsh 服務的話就崩潰了。
到這里基本可以了。
如果要在 PBS 中進行調(diào)用,啟動命令可以不加 i/O 重定向和后臺運行的符號
1、添加菜單項 (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 "")
2 輸出當前的迭代次數(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 自動保存,記錄輸出信息的迭代腳本
;;
;; 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 導出 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)計算時自動保存腳本
;; 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)
)
)
)
)
相關標簽搜索:FLUENT Scheme 腳本調(diào)用及其案例 FLUENT Scheme 腳本 fluent Fluent培訓 Fluent流體培訓 Fluent軟件培訓 fluent技術教程 fluent在線視頻教程 fluent資料下載 fluent分析理論 fluent化學反應 fluent軟件下載 UDF編程代做