Python自动执行fluent

TUI 命令

TUI 命令包括 Fluent 中的全部设置,见上一篇 Fluent TUI 命令。

最重要的是要包含推出程序命令,即exit ok

全部 TUI 命令如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
; 1、读取网格文件
rc fluent.msh
mesh/check
mesh/quality


display mesh-outline

; 2、勾选瞬态
/define/models/unsteady-2nd-order yes

; 3、设置重力加速度
/define/operating-conditions/gravity yes 0 -9.81 0

; 4、开启能量方程
/define/models/energy y y y

; 5、湍流模型
/define/models/viscous/spalart-allmaras y

; 6、新增混合气体
/define/models/species/species-transport y hydrogen-air
/define/materials/change-create hydrogen-air hydrogen-air y 2 h2 air 0 0 n n n n n n

; 7、管道材料及土壤材料
/define/materials/copy/solid/steel
/define/materials/change-create aluminum soil y constant 2650 y constant 789 y constant 2.9 y

; 8、设置边界条件
/define/boundary-conditions/fluid solid fluid no no no no no 0 no 0 no 0 no 0 no 0 no 0 no no no no yes no no 1 no 0 no 0 no 0 no 1 no 0 yes no 245000000000 no 245000000000 no 245000000000 no no 502000 no 502000 no 502000 0 0 no 0.43 constant 1 yes no no no

/define/boundary-conditions/zone-type inlet pressure-inlet
/define/boundary-conditions/set/pressure-inlet inlet () p0 no 400000 q
/define/boundary-conditions/set/pressure-inlet inlet () supersonic/initial-gauge-pressure no 400000 q
/define/boundary-conditions/set/pressure-inlet inlet () ke-spec no no no yes q
/define/boundary-conditions/set/pressure-inlet inlet () turb-hydraulic-diam 0.01 q
/define/boundary-conditions/set/pressure-inlet inlet () t0 no 288.15 q
/define/boundary-conditions/set/pressure-inlet inlet () species-in-mole-fractions yes q
/define/boundary-conditions/set/pressure-inlet inlet () mf no 1 q

/define/boundary-conditions/set/pressure-outlet outlet_x1 outlet_x2 outlet_y1 outlet_z1 outlet_z2 () t0 no 288.15 q

/define/boundary-conditions wall pipe 0 no 0 yes steel no no 0 no no no no no 0 no 0.5 yes no 1
/define/boundary-conditions wall ground 0 no 0 yes soil no no 0 no no no no no 0 no 0.5 yes no 1

; 9、创建并设置监测点和面
surf point-surf point-1 0 0.4 0 q
surf point-surf point-2 0 0.5 0 q
surf point-surf point-3 2 0.4 0 q

/solve/report-definitions add report1 surface-vertexavg field molef-h2 surface-names point-1 () q

/surface/plane plane1 0 0 0 0 1 0 0 0 1

; 10、初始化
/solve/initialize/set-defaults/ temperature 288.15
/solve/initialize/set-defaults/ pressure 0
/solve/initialize/set-defaults/ species-0 0

/solve/initialize initialize-flow ok
; 显示一下contour
;/display/contour molef-h2 0 1


; 11、设置保存格式及频率
; 设置数据保存内容
/file/data-file-options molef-h2 molef-air absolute-pressure air h2 velocity-magnitude mesh-x-velocity mesh-y-velocity mesh-z-velocity pressure density total-pressure total-temperature x-velocity y-velocity z-velocity viscosity-eff viscosity-lam viscosity-ratio viscosity-turb vorticity-mag q
; 保存tecplot文件
/file/transient-export/tecplot C:/Users/23984/Desktop/tui_test/tecplot1 ground inlet outlet_x1 outlet_x2 outlet_y1 outlet_z1 outlet_z2 pipe () molef-h2 molef-air absolute-pressure air h2 velocity-magnitude mesh-x-velocity mesh-y-velocity mesh-z-velocity pressure density total-pressure total-temperature x-velocity y-velocity z-velocity viscosity-eff viscosity-lam viscosity-ratio viscosity-turb vorticity-mag q tecplot1 10 time-step

; 12、创建contour并保存动画
/display/objects/create contour "contour-1" filled yes field molef-h2 surfaces-list plane1 () q
/solve/animate/objects/create "animation-1" animate-on contour-1 storage-dir C:\Users\23984\Desktop\tui_test frequency-of "Time Step" q

; 13、设置迭代参数
/solve/set/max-iterations-per-time-step 50
/solve/set/time-step 1
/solve/set/number-of-time-steps 1000
/file/write-case/setting1.cas

; 14、开始计算
/solve/dual-time-iterate 1 2

exit ok

Python 代码

含注释

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import subprocess
import time

# 获取python文件运行的目录文件夹
path, filename = os.path.split(os.path.abspath(__file__))

# 定义fluent.exe的目录
fluent_path = "D:\\ANSYS18\\ANSYS Inc\\v180\\fluent\\ntbin\\win64"

# 定义要运行的命令
command_list = []
command_list.append(f'"{fluent_path}\\fluent.exe" 3ddp -t4 -i jou1.jou')
command_list.append(f'"{fluent_path}\\fluent.exe" 3ddp -t4 -i jou2.jou')

time.sleep(1)

# 定义fluent程序循环
def run_fluent(command,path):
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=path, shell=True, universal_newlines=True)
# 持续监控输出,如果检测到程序结束就往下执行
while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
break
if output:
print(output.strip())
rc = process.poll()

count = 10
for i in range(0,count):
print(f"开始循环第{i}个")
run_fluent(command_list[i],path)
print(f"第{i}个循环结束")

print("程序结束")

这里如果想使用 python 算一些变量,然后传入程序中自动执行,这里提供一种方法,就是修改 tui 文件(.jou)内的内容。


Python自动执行fluent
http://example.com/2024/07/30/032 Python自动执行fluent/
作者
DB
发布于
2024年7月30日
许可协议