在网格划分完成或已有网格的情况下,可以进行算例的求解。
1. 切换/打开求解器
一般启动求解器前有两种情况:
- 已启动FluentMeshing并生成了网格,需要在不退出FluentMeshing的情况下直接切换至Fluent求解器。
- 已经有现成的网格文件,只需要启动Fluent求解器线程并直接读取。
针对需要直接切换的情况,在“PyFluent入门之旅(3)网格划分”的代码基础上继续编写即可,使用下述代码直接切换至求解器,并默认读取之前生成的网格
solver = meshing.switch_to_solver()
对于需要重新编写代码直接启动求解器并读取现有网格的情况。需要重新导入pyfluent库,启动求解器并使用tui读取网格文件。
import ansys.fluent.core as pyfluent
solver = pyfluent.launch_fluent(precision="double", processor_count=4, mode="solver")
solver.tui.file.read_case(case_file_name = 'mixing_elbow.msh.h5')
读取网格后可以顺便检查一下网格参数,其结果会直接输出至python界面
solver.tui.mesh.check()
2. 基本求解设置
进行求解前需要进行一些必要的设置。
首先是单位的修改,可以根据自身需求决定是否修改。例如将长度单位修改为‘in’
solver.tui.define.units("length", "in")
接着根据问题需要开启所需功能,例如该案例需要开启能量方程
solver.tui.define.models.energy("yes", ", ", ", ", ", ", ", ")
创建材料功能也十分常用,该案例我们需要创建液态水
solver.tui.define.materials.copy("fluid", "water-liquid")
将流体域材料改为液态水
solver.tui.define.boundary_conditions.fluid(
"elbow-fluid",
"yes",
"water-liquid",
"no",
"no",
"no",
"no",
"0",
"no",
"0",
"no",
"0",
"no",
"0",
"no",
"0",
"no",
"1",
"no",
"no",
"no",
"no",
"no",
)
修改完成后会输出以下结果
边界条件设置。
solver.tui.define.boundary_conditions.set.velocity_inlet(
"cold-inlet", [], "vmag", "no", 0.4, "quit"
)
solver.tui.define.boundary_conditions.set.velocity_inlet(
"cold-inlet", [], "ke-spec", "no", "no", "no", "yes", "quit"
)
solver.tui.define.boundary_conditions.set.velocity_inlet(
"cold-inlet", [], "turb-intensity", 5, "quit"
)
solver.tui.define.boundary_conditions.set.velocity_inlet(
"cold-inlet", [], "turb-hydraulic-diam", 4, "quit"
)
solver.tui.define.boundary_conditions.set.velocity_inlet(
"cold-inlet", [], "temperature", "no", 293.15, "quit"
)
# hot inlet (hot-inlet), Setting: Value:
# Velocity Specification Method: Magnitude, Normal to Boundary
solver.tui.define.boundary_conditions.set.velocity_inlet(
"hot-inlet", [], "vmag", "no", 1.2, "quit"
)
solver.tui.define.boundary_conditions.set.velocity_inlet(
"hot-inlet", [], "ke-spec", "no", "no", "no", "yes", "quit"
)
solver.tui.define.boundary_conditions.set.velocity_inlet(
"hot-inlet", [], "turb-intensity", 5, "quit"
)
solver.tui.define.boundary_conditions.set.velocity_inlet(
"hot-inlet", [], "turb-hydraulic-diam", 1, "quit"
)
solver.tui.define.boundary_conditions.set.velocity_inlet(
"hot-inlet", [], "temperature", "no", 313.15, "quit"
)
# pressure outlet (outlet), Setting: Value:
# Backflow Turbulent Intensity: 5 [%]
# Backflow Turbulent Viscosity Ratio: 4
solver.tui.define.boundary_conditions.set.pressure_outlet(
"outlet", [], "turb-intensity", 5, "quit"
)
solver.tui.define.boundary_conditions.set.pressure_outlet(
"outlet", [], "turb-viscosity-ratio", 4, "quit"
)
可以设置是否在计算中启用残差图显示,这里选择显示
solver.tui.solve.monitors.residual.plot("yes")
为方便后处理获取数据可以在所需边界创建参数报告
solver.tui.solve.report_definitions.add(
"outlet-temp-avg",
"surface-massavg",
"field",
"temperature",
"surface-names",
"outlet",
"()",
"quit",
)
3. 进行求解
完成必要的设置后,我们可以进行求解了。
首先进行初始化,使用默认的混合初始化。
solver.tui.solve.initialize.hyb_initialization()
接着保存以下算例文件
solver.tui.file.write_case("mixing_elbow1.cas.h5")
先求解100步试试看
solver.tui.solve.iterate(100)
求解完成后保存数据文件,方便后续的查看。
solver.tui.file.write_data("mixing_elbow1.dat.h5")
可以看到计算至93步时已经收敛。