FLUENT Scheme 脚本调用及其案例
2016-08-19 by:CAE仿真在线 来源:互联网
FLUENT 中使用 Scheme,如果好好利用,能够大大提高工作效率。这是自己编写的第一个 journal 文件,用来设置一些选项。由于经常使用 User-defined Materials Database,在 journal 中添加曾经遭遇错误,后来才发现是 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"
现在的计算平台有很多是 Linux Cluster,常用的作业管理系统采用 PBS。如果要采用 FLUENT 进行计算就需要解决在 Text Mode 下调用 FLUENT 进行求解的问题,而且多数时候
需要执行并行版本的 FLUENT。
Linux 调用 FLUENT 的文本界面其实很简单,比如
- fluent 3d -g
出现了 FLUENT 的 console,这样就能输入命令并执行了。
不想手工输入命令的话,写一个 journal 或 scheme 脚本文件,让 FLUENT 启动后自动执行。
- fluent 3d -g -i script.scm
最好加上 I/O 重定向。
fluent 3d -g -i script.scm > out.log
远程连接时后台执行就比较重要了。
fluent 3d -g -i script.scm > out.log &
以上是之前在 PC 上常用的模式,还会利用 screen 之类的进行监视。
那么并行版本又如何呢?
本地并行的话,基本上就是
利用多个节点的话,需要做些处理
多了几个选项,其中
-pethernet 表示各节点利用局域网连接进行通信,发现用 default 选项的话会报错的,至少 fluent12 是这个样子。
-cnf=myhosts 表示运行的节点信息
-ssh 表示各节点采用 ssh 进行登录,默认的话采用 rsh,如果没有启用 rsh 服务的话就崩溃了。
到这里基本可以了。
如果要在 PBS 中进行调用,启动命令可以不加 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 输出当前的迭代次数和参数
(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 文件中的数值
;;
;;
;;
(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 读取数据到 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 内容
;;;
(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 非稳态计算时自动保存脚本
;; 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 脚本调用及其案例 FLUENT Scheme 脚本 fluent Fluent培训 Fluent流体培训 Fluent软件培训 fluent技术教程 fluent在线视频教程 fluent资料下载 fluent分析理论 fluent化学反应 fluent软件下载 UDF编程代做