当前位置: 首页 > news >正文

Pyfluent 执行Meshing工作流

1. 部署安装pyfluent

Pyfluent支持Fluent 2022R2或更高版本,PyFluent支持Python 3.10~3.13版本,点击 此处 即可下载。
安装核心依赖需使用pip命令,如若详细了解该命令的使用,详见 此处

pip install ansys-fluent-core
pip install pyfluent
//如有需要可进一步安装
pip install ansys-fluent-parametric       //参数化求解
//如果安装失败,使用下面命令
pip install git+https://github.com/ansys/pyfluent-parametric.git
pip install ansys-fluent-visualization    //可视化后处理
//如果安装失败,使用下面命令
pip install git+https://github.com/ansys/pyfluent-visualization.git

如果出现下载异常或者速度较慢,可以更换国内pip镜像源,具体方法如下:

  • 临时更换:pip install package -i https://pypi.tuna.tsinghua.edu.cn/simple
  • 永久更换:pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

换回默认源:pip config unset global.index-url

镜像源地址有:

清华大学TUNA镜像源: https://pypi.tuna.tsinghua.edu.cn/simple
阿里云镜像源: http://mirrors.aliyun.com/pypi/simple/
中国科学技术大学镜像源: https://mirrors.ustc.edu.cn/pypi/simple/
华为云镜像源: https://repo.huaweicloud.com/repository/pypi/simple/
腾讯云镜像源:https://mirrors.cloud.tencent.com/pypi/simple/
#官方镜像源:https://pypi.org/simple

安装完成之后,可进一步验证是否安装成功

//打开终端输入
D:\Program>python
Python 3.13.1 (tags/v3.13.1:0671451, Dec  3 2024, 19:06:28) [MSC v.1942 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ansys.fluent.core as pyfluent
>>> session=pyfluent.launch_fluent(dimension = Dimension.THREE, processor_count = 4, ui_mode = UIMode.GUI)
//此时Fluent被打开,说明安装成功。

关于进一步的描述可以参见 简明讲义 详细了解,其中有些示例命令当前已经被弃用,但执行时会提示,比如

 session=pyfluent.launch_fluent(version = '3d', processor_count = 4, show_gui = True)
C:\Python313\Lib\site-packages\deprecated\classic.py:199: PyFluentDeprecationWarning: 'version' is deprecated. Use 'dimension' instead.return wrapped_(*args_, **kwargs_)
pyfluent.general WARNING: Using 'dimension = Dimension.THREE' for 'launch_fluent()' instead of 'version = 3d'.
C:\Python313\Lib\site-packages\ansys\fluent\core\utils\deprecate.py:118: PyFluentDeprecationWarning: 'show_gui' is deprecated. Use 'ui_mode' instead.return func(*args, **kwargs)
pyfluent.general WARNING: Using 'ui_mode = UIMode.GUI' for 'launch_fluent()' instead of 'show_gui = True'.

2. 代码实现

2.1 基于pyfluent实现网格参数自定义

以下内容来自 此处 ,翻译内容如下:

2.1.1 Watertight meshing workflow

(1)导入几何模型

import ansys.fluent.core as pyfluent
from ansys.fluent.core import examplesimport_file_name = examples.download_file('mixing_elbow.pmdb', 'pyfluent/mixing_elbow')
meshing_session = pyfluent.launch_fluent(mode=pyfluent.FluentMode.MESHING, precision=pyfluent.Precision.DOUBLE, processor_count=2
)
watertight = meshing_session.watertight()
watertight.import_geometry.file_name.set_state(import_file_name)
watertight.import_geometry.length_unit.set_state('in')
watertight.import_geometry()

(2)添加局部尺寸

watertight.add_local_sizing.add_child_to_task()
watertight.add_local_sizing()

(3)生成面网格

watertight.create_surface_mesh.cfd_surface_mesh_controls.max_size.set_state(0.3)
watertight.create_surface_mesh()

(4)几何描述

watertight.describe_geometry.update_child_tasks(setup_type_changed=False)
watertight.describe_geometry.setup_type.set_state("The geometry consists of only fluid regions with no voids")
watertight.describe_geometry.update_child_tasks(setup_type_changed=True)
watertight.describe_geometry()

(5)更新边界类型

watertight.update_boundaries.boundary_label_list.set_state(["wall-inlet"])
watertight.update_boundaries.boundary_label_type_list.set_state(["wall"])
watertight.update_boundaries.old_boundary_label_list.set_state(["wall-inlet"])
watertight.update_boundaries.old_boundary_label_type_list.set_state(["velocity-inlet"])
watertight.update_boundaries()

(6)更新区域

watertight.update_regions()

(7)添加边界层

watertight.add_boundary_layer.add_child_to_task()
watertight.add_boundary_layer.bl_control_name.set_state("smooth-transition_1")
watertight.add_boundary_layer.insert_compound_child_task()
watertight.add_boundary_layer_child_1()

(8)生成体网格

watertight.create_volume_mesh.volume_fill.set_state("poly-hexcore")
watertight.create_volume_mesh.volume_fill_controls.hex_max_cell_length.set_state(0.3)
watertight.create_volume_mesh()

(9)切换至求解模式

solver_session = meshing_session.switch_to_solver()

2.1.2 Fault-tolerant meshin workflow

对于需要清理或修改的复杂CAD几何体(例如处理重叠、相交、孔洞和重复元素),请使用容错网格划分工作流程。以下示例演示了如何使用容错工作流程。
(1)导入几何模型以及零部件管理

import ansys.fluent.core as pyfluent
from ansys.fluent.core import examplesimport_file_name = examples.download_file("exhaust_system.fmd", "pyfluent/exhaust_system"
)
meshing_session = pyfluent.launch_fluent(precision=pyfluent.Precision.DOUBLE, processor_count=2, mode=pyfluent.FluentMode.MESHING)
fault_tolerant = meshing_session.fault_tolerant()
meshing_session.PartManagement.InputFileChanged(FilePath=import_file_name, IgnoreSolidNames=False, PartPerBody=False
)
meshing_session.PMFileManagement.FileManager.LoadFiles()
meshing_session.PartManagement.Node["Meshing Model"].Copy(Paths=["/dirty_manifold-for-wrapper," + "1/dirty_manifold-for-wrapper,1/main,1","/dirty_manifold-for-wrapper," + "1/dirty_manifold-for-wrapper,1/flow-pipe,1","/dirty_manifold-for-wrapper," + "1/dirty_manifold-for-wrapper,1/outpipe3,1","/dirty_manifold-for-wrapper," + "1/dirty_manifold-for-wrapper,1/object2,1","/dirty_manifold-for-wrapper," + "1/dirty_manifold-for-wrapper,1/object1,1",]
)
meshing_session.PartManagement.ObjectSetting["DefaultObjectSetting"].OneZonePer.set_state("part")
fault_tolerant.import_cad_and_part_management.context.set_state(0)
fault_tolerant.import_cad_and_part_management.create_object_per.set_state("Custom")
fault_tolerant.import_cad_and_part_management.fmd_file_name.set_state(import_file_name)
fault_tolerant.import_cad_and_part_management.file_loaded.set_state("yes")
fault_tolerant.import_cad_and_part_management.object_setting.set_state("DefaultObjectSetting")
fault_tolerant.import_cad_and_part_management()

(2)几何与流动描述

fault_tolerant.describe_geometry_and_flow.add_enclosure.set_state("No")
fault_tolerant.describe_geometry_and_flow.close_caps.set_state("Yes")
fault_tolerant.describe_geometry_and_flow.describe_geometry_and_flow_options.advanced_options.set_state(True)
fault_tolerant.describe_geometry_and_flow.describe_geometry_and_flow_options.extract_edge_features.set_state("Yes")
fault_tolerant.describe_geometry_and_flow.flow_type.set_state("Internal flow through the object")
fault_tolerant.describe_geometry_and_flow.update_child_tasks(setup_type_changed=False)
fault_tolerant.describe_geometry_and_flow()

(3)封闭流体区域

fault_tolerant.enclose_fluid_regions_fault.create_patch_preferences.show_create_patch_preferences.set_state(False)fault_tolerant.enclose_fluid_regions_fault.patch_name.set_state("inlet-1")
fault_tolerant.enclose_fluid_regions_fault.selection_type.set_state("zone")
fault_tolerant.enclose_fluid_regions_fault.zone_selection_list.set_state(["inlet.1"])
fault_tolerant.enclose_fluid_regions_fault.insert_compound_child_task()
fault_tolerant.enclose_fluid_regions_fault_child_1()fault_tolerant.enclose_fluid_regions_fault.patch_name.set_state("inlet-2")
fault_tolerant.enclose_fluid_regions_fault.selection_type.set_state("zone")
fault_tolerant.enclose_fluid_regions_fault.zone_selection_list.set_state(["inlet.2"])
fault_tolerant.enclose_fluid_regions_fault.insert_compound_child_task()
fault_tolerant.enclose_fluid_regions_fault_child_2()fault_tolerant.enclose_fluid_regions_fault.patch_name.set_state("inlet-3")
fault_tolerant.enclose_fluid_regions_fault.selection_type.set_state("zone")
fault_tolerant.enclose_fluid_regions_fault.zone_selection_list.set_state(["inlet"])
fault_tolerant.enclose_fluid_regions_fault.insert_compound_child_task()
fault_tolerant.enclose_fluid_regions_fault_child_3()fault_tolerant.enclose_fluid_regions_fault.patch_name.set_state("outlet-1")
fault_tolerant.enclose_fluid_regions_fault.selection_type.set_state("zone")
fault_tolerant.enclose_fluid_regions_fault.zone_selection_list.set_state(["outlet"])
fault_tolerant.enclose_fluid_regions_fault.zone_type.set_state("pressure-outlet")
fault_tolerant.enclose_fluid_regions_fault.insert_compound_child_task()
fault_tolerant.enclose_fluid_regions_fault_child_4()

(4)提取边缘特征

fault_tolerant.extract_edge_features.extract_edges_name.set_state("edge-group-1")
fault_tolerant.extract_edge_features.extract_method_type.set_state("Intersection Loops")
fault_tolerant.extract_edge_features.object_selection_list.set_state(["flow_pipe", "main"])
fault_tolerant.extract_edge_features.insert_compound_child_task()
fault_tolerant.extract_edge_features_child_1()

(5)识别区域

fault_tolerant.identify_regions.show_coordinates = True
fault_tolerant.identify_regions.material_points_name.set_state("fluid-region-1")
fault_tolerant.identify_regions.selection_type.set_state("zone")
fault_tolerant.identify_regions.x.set_state(377.322045740589)
fault_tolerant.identify_regions.y.set_state(-176.800676988458)
fault_tolerant.identify_regions.z.set_state(-37.0764628583475)
fault_tolerant.identify_regions.zone_selection_list.set_state(["main.1"])
fault_tolerant.identify_regions.insert_compound_child_task()
fault_tolerant.identify_regions_child_1()fault_tolerant.identify_regions.show_coordinates = True
fault_tolerant.identify_regions.material_points_name.set_state("void-region-1")
fault_tolerant.identify_regions.new_region_type.set_state("void")
fault_tolerant.identify_regions.object_selection_list.set_state(["inlet-1", "inlet-2", "inlet-3", "main"])
fault_tolerant.identify_regions.x.set_state(374.722045740589)
fault_tolerant.identify_regions.y.set_state(-278.9775145640143)
fault_tolerant.identify_regions.z.set_state(-161.1700719416913)
fault_tolerant.identify_regions.insert_compound_child_task()
fault_tolerant.identify_regions_child_2()

(6)定义泄露阈值

fault_tolerant.define_leakage_threshold.add_child.set_state("yes")
fault_tolerant.define_leakage_threshold.flip_direction.set_state(True)
fault_tolerant.define_leakage_threshold.plane_direction.set_state("X")
fault_tolerant.define_leakage_threshold.region_selection_single.set_state("void-region-1")fault_tolerant.define_leakage_threshold.arguments.set_state({'add_child': 'yes','flip_direction': True,'leakage_name': 'leakage-1','plane_direction': 'X','region_selection_single': ['void-region-1'],}
)
fault_tolerant.define_leakage_threshold.insert_compound_child_task()
fault_tolerant.define_leakage_threshold_child_1()

(7)更新区域设置

fault_tolerant.update_region_settings.all_region_filter_categories.set_state(["2"] * 5 + ["1"] * 2)
fault_tolerant.update_region_settings.all_region_leakage_size_list.set_state(["none"] * 6 + ["6.4"])
fault_tolerant.update_region_settings.all_region_linked_construction_surface_list.set_state(["n/a"] * 6 + ["no"])
fault_tolerant.update_region_settings.all_region_mesh_method_list.set_state(["none"] * 6 + ["wrap"])
fault_tolerant.update_region_settings.all_region_name_list.set_state(["main","flow_pipe","outpipe3","object2","object1","void-region-1","fluid-region-1",])
fault_tolerant.update_region_settings.all_region_overset_componen_list.set_state(["no"] * 7)
fault_tolerant.update_region_settings.all_region_source_list.set_state(["object"] * 5 + ["mpt"] * 2)
fault_tolerant.update_region_settings.all_region_type_list.set_state(["void"] * 6 + ["fluid"])
fault_tolerant.update_region_settings.all_region_volume_fill_list.set_state(["none"] * 6 + ["tet"])
fault_tolerant.update_region_settings.filter_category.set_state("Identified Regions")
fault_tolerant.update_region_settings.all_region_leakage_size_list.set_state([""])
fault_tolerant.update_region_settings.all_region_mesh_method_list.set_state(["wrap"])
fault_tolerant.update_region_settings.all_region_name_list.set_state(["fluid-region-1"])
fault_tolerant.update_region_settings.all_region_overset_componen_list.set_state(["no"])
fault_tolerant.update_region_settings.all_region_type_list.set_state(["fluid"])
fault_tolerant.update_region_settings.all_region_volume_fill_list.set_state(["hexcore"])
fault_tolerant.update_region_settings.all_region_leakage_size_list.set_state([""])
fault_tolerant.update_region_settings.all_region_mesh_method_list.set_state(["wrap"])
fault_tolerant.update_region_settings.all_region_name_list.set_state(["fluid-region-1"])
fault_tolerant.update_region_settings.all_region_overset_componen_list.set_state(["no"])
fault_tolerant.update_region_settings.all_region_type_list.set_state(["fluid"])
fault_tolerant.update_region_settings.all_region_volume_fill_list.set_state(["tet"])
fault_tolerant.update_region_settings()

(8)选择网格控制选项

fault_tolerant.choose_mesh_control_options()

(9)生成面网格

fault_tolerant.generate_surface_mesh()

(10)更新边界类型

fault_tolerant.update_boundaries_ftm()

(11)添加边界层

fault_tolerant.add_boundary_layer_ftm.bl_control_name.set_state("aspect-ratio_1")
fault_tolerant.add_boundary_layer_ftm.insert_compound_child_task()
fault_tolerant.add_boundary_layer_ftm_child_1()

(12)生成体网格

fault_tolerant.create_volume_mesh.all_region_name_list.set_state(["main","flow_pipe","outpipe3","object2","object1","void-region-1","fluid-region-1",])
fault_tolerant.create_volume_mesh.all_region_size_list.set_state(["11.33375"] * 7)
fault_tolerant.create_volume_mesh.all_region_volume_fill_list.set_state(["none"] * 6 + ["tet"])
fault_tolerant.create_volume_mesh()

(13)切换至求解模式

solver_session = meshing_session.switch_to_solver()

2.1.3 2D meshing workflow

使用二维网格划分工作流程对特定二维几何体进行网格划分。以下示例展示了如何使用二维网格划分工作流程。
(1)导入几何模型

import ansys.fluent.core as pyfluent
from ansys.fluent.core import examplesimport_file_name = examples.download_file('NACA0012.fmd', 'pyfluent/airfoils')
meshing_session = pyfluent.launch_fluent(mode=pyfluent.FluentMode.MESHING, precision=pyfluent.Precision.DOUBLE, processor_count=2
)
two_dim_mesh = meshing_session.two_dimensional_meshing()two_dim_mesh.load_cad_geometry_2d.file_name = import_file_name
two_dim_mesh.load_cad_geometry_2d.length_unit = "mm"
two_dim_mesh.load_cad_geometry_2d.refaceting.refacet = False
two_dim_mesh.load_cad_geometry_2d()

(2)设置区域和边界

two_dim_mesh.update_boundaries_2d.selection_type = "zone"
two_dim_mesh.update_boundaries_2d()

(3)定义全局网格尺寸

two_dim_mesh.define_global_sizing_2d.curvature_normal_angle = 20
two_dim_mesh.define_global_sizing_2d.max_size = 2000.0
two_dim_mesh.define_global_sizing_2d.min_size = 5.0
two_dim_mesh.define_global_sizing_2d.size_functions = "Curvature"
two_dim_mesh.define_global_sizing_2d()

(4)添加BOI

two_dim_mesh.add_local_sizing_2d.add_child = "yes"
two_dim_mesh.add_local_sizing_2d.boi_control_name = "boi_1"
two_dim_mesh.add_local_sizing_2d.boi_execution = "Body Of Influence"
two_dim_mesh.add_local_sizing_2d.boi_face_label_list = ["boi"]
two_dim_mesh.add_local_sizing_2d.boi_size = 50.0
two_dim_mesh.add_local_sizing_2d.boi_zoneor_label = "label"
two_dim_mesh.add_local_sizing_2d.draw_size_control = True
two_dim_mesh.add_local_sizing_2d.add_child_and_update(defer_update=False)

(5)设置边的尺寸

two_dim_mesh.add_local_sizing_2d.add_child = "yes"
two_dim_mesh.add_local_sizing_2d.boi_control_name = "edgesize_1"
two_dim_mesh.add_local_sizing_2d.boi_execution = "Edge Size"
two_dim_mesh.add_local_sizing_2d.boi_size = 5.0
two_dim_mesh.add_local_sizing_2d.boi_zoneor_label = "label"
two_dim_mesh.add_local_sizing_2d.draw_size_control = True
two_dim_mesh.add_local_sizing_2d.edge_label_list = ["airfoil-te"]
two_dim_mesh.add_local_sizing_2d.add_child_and_update(defer_update=False)

(6)设置曲率尺寸

two_dim_mesh.add_local_sizing_2d.add_child = "yes"
two_dim_mesh.add_local_sizing_2d.boi_control_name = "curvature_1"
two_dim_mesh.add_local_sizing_2d.boi_curvature_normal_angle = 10
two_dim_mesh.add_local_sizing_2d.boi_execution = "Curvature"
two_dim_mesh.add_local_sizing_2d.boi_max_size = 2
two_dim_mesh.add_local_sizing_2d.boi_min_size = 1.5
two_dim_mesh.add_local_sizing_2d.boi_scope_to = "edges"
two_dim_mesh.add_local_sizing_2d.boi_zoneor_label = "label"
two_dim_mesh.add_local_sizing_2d.draw_size_control = True
two_dim_mesh.add_local_sizing_2d.edge_label_list = ["airfoil"]
two_dim_mesh.add_local_sizing_2d.add_child_and_update(defer_update=False)

(7)添加边界层

two_dim_mesh.add_2d_boundary_layers.add_child = "yes"
two_dim_mesh.add_2d_boundary_layers.bl_control_name = "aspect-ratio_1"
two_dim_mesh.add_2d_boundary_layers.number_of_layers = 4
two_dim_mesh.add_2d_boundary_layers.offset_method_type = "aspect-ratio"
two_dim_mesh.add_2d_boundary_layers.add_child_and_update(defer_update=False)

(8)生成(面)网格

# NOTE: Setting `show_advanced_options = True` is required to configure advanced preferences.
# This dependency may be removed in a future release as the API evolves.
two_dim_mesh.generate_initial_surface_mesh.surface_2d_preferences.show_advanced_options = True
two_dim_mesh.generate_initial_surface_mesh.surface_2d_preferences.merge_edge_zones_based_on_labels = "no"
two_dim_mesh.generate_initial_surface_mesh.surface_2d_preferences.merge_face_zones_based_on_labels = "no"
two_dim_mesh.generate_initial_surface_mesh()two_dim_mesh.add_2d_boundary_layers_child_1.revert()
two_dim_mesh.add_2d_boundary_layers_child_1.add_child = "yes"
two_dim_mesh.add_2d_boundary_layers_child_1.bl_control_name = "uniform_1"
two_dim_mesh.add_2d_boundary_layers_child_1.first_layer_height = 2
two_dim_mesh.add_2d_boundary_layers_child_1.number_of_layers = 4
two_dim_mesh.add_2d_boundary_layers_child_1.offset_method_type = "uniform"
two_dim_mesh.add_2d_boundary_layers_child_1()# NOTE: Setting `show_advanced_options = True` is required to configure advanced preferences.
# This dependency may be removed in a future release as the API evolves.
two_dim_mesh.generate_initial_surface_mesh.surface_2d_preferences.show_advanced_options = True
two_dim_mesh.generate_initial_surface_mesh.surface_2d_preferences.merge_edge_zones_based_on_labels = "no"
two_dim_mesh.generate_initial_surface_mesh.surface_2d_preferences.merge_face_zones_based_on_labels = "no"
two_dim_mesh.generate_initial_surface_mesh()

关于meshing workflow的操作详见官方的介绍,不做描述。

2.2 基于.jou录制脚本的处理

具体操作如下,简言之,就是开始录制 → 开始你的操作 → 结束录制
image

之后使用python程序来执行jou文件 → py文件,这样就可以直接使用python执行网格生成的操作。

下面的代码使用了ttkbootstrap UI库(因为tkinter UI界面略显古老),同时可以使用pyinstaller工具将python代码打包成可执行程序,如若不想使用终端命令操作,可以下载 auto-py-to-exe 来打包,也可用批处理程序,新建run.bat

pyinstaller -F -i 图标.ico -n 名字 --noconsol --noconfirm jou2py.py

执行程序之前确保安装相关工具:

  • pip install pyinstaller
  • pip install tkpython版本在3.1以上,tkinter库其作为标准库的一部分已经内置
  • pip install ttkbootstrap

转换工具程序代码(我是菜鸡,AI生成)

import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from ttkbootstrap.dialogs import Messagebox
import os
import re
import tkinter as tk
from tkinter import filedialog, scrolledtextclass JouFileProcessor:def __init__(self, root):self.root = rootself.root.title("Jou to Py by Code_WSS")self.root.geometry("800x600")# 设置样式self.style = ttk.Style()# 显示ttkbootstrap版本信息self.show_ttk_version()# 设置中文字体支持self.style.configure(".", font=("SimHei", 10))# 创建主题切换区域self.create_theme_switcher()# 创建主界面组件self.create_widgets()def show_ttk_version(self):"""显示ttkbootstrap版本信息"""try:ttk_version = ttk.__version__print(f"ttkbootstrap版本: {ttk_version}")version_frame = ttk.Frame(self.root)version_frame.pack(fill=X, padx=10, pady=2)ttk.Label(version_frame,text=f"ttkbootstrap版本: {ttk_version}",font=("SimHei", 8)).pack(anchor=E)except Exception as e:print(f"获取ttkbootstrap版本失败: {str(e)}")def get_supported_themes(self):"""获取支持的主题"""try:return self.style.theme_names()except Exception as e:print(f"获取主题列表失败: {e}")return ["cosmo", "flatly", "darkly"]def create_theme_switcher(self):"""创建主题切换组件"""theme_frame = ttk.Frame(self.root)theme_frame.pack(pady=5, padx=10, fill=X, anchor=N)ttk.Label(theme_frame, text="主题设置:").pack(side=LEFT, padx=5)# 获取支持的主题列表self.themes = self.get_supported_themes()self.theme_var = tk.StringVar(value=self.style.theme_use())self.theme_combobox = ttk.Combobox(theme_frame,textvariable=self.theme_var,values=self.themes,state="readonly",width=20)self.theme_combobox.pack(side=LEFT, padx=5)self.theme_combobox.bind("<<ComboboxSelected>>", self.apply_theme)def apply_theme(self, event=None):"""应用选中的主题"""try:selected_theme = self.theme_var.get()if selected_theme not in self.themes:Messagebox.show_warning("警告", f"不支持的主题: {selected_theme}")returnself.style.theme_use(selected_theme)self.root.update_idletasks()self.root.update()Messagebox.show_info("操作成功", f"主题已成功切换为: {selected_theme}")except Exception as e:error_msg = f"切换主题失败: {str(e)}\n建议升级ttkbootstrap到最新版本"print(error_msg)Messagebox.show_error("切换失败", error_msg)def create_widgets(self):"""创建界面组件"""# 文件选择区域file_frame = ttk.LabelFrame(self.root, text="文件选择", padding=10)file_frame.pack(fill=X, padx=10, pady=5)self.file_path = tk.StringVar()ttk.Entry(file_frame, textvariable=self.file_path, width=50).pack(side=LEFT, padx=5, fill=X, expand=True)browse_btn = ttk.Button(file_frame, text="浏览文件", command=self.browse_file, bootstyle=SECONDARY)browse_btn.pack(side=LEFT, padx=5)process_btn = ttk.Button(file_frame, text="处理文件", command=self.process_file, bootstyle=SUCCESS)process_btn.pack(side=LEFT, padx=5)# 日志显示区域log_frame = ttk.LabelFrame(self.root, text="处理日志", padding=10)log_frame.pack(fill=BOTH, padx=10, pady=5, expand=True)self.log_text = scrolledtext.ScrolledText(log_frame,wrap=tk.WORD,height=15)self.log_text.pack(fill=BOTH, expand=True)self.log_text.config(state=tk.DISABLED)# 状态栏self.status_var = tk.StringVar(value="就绪")status_bar = ttk.Label(self.root,textvariable=self.status_var,anchor=W,padding=5,relief=SUNKEN)status_bar.pack(side=BOTTOM, fill=X)def browse_file(self):file_path = filedialog.askopenfilename(title="选择Jou文件",filetypes=[("Jou文件", "*.jou"), ("所有文件", "*.*")])if file_path:self.file_path.set(file_path)self.update_status(f"已选择文件: {os.path.basename(file_path)}")def process_file(self):file_path = self.file_path.get()if not file_path:Messagebox.show_warning("警告", "请先选择文件")returnif not os.path.exists(file_path):Messagebox.show_error("错误", "文件不存在")returntry:output_file = self.convert_jou_to_py(file_path)self.update_status(f"处理完成: {os.path.basename(output_file)}", "green")Messagebox.show_info("成功", f"文件转换成功\n保存至: {output_file}")except Exception as e:self.update_status(f"处理失败: {str(e)}", "red")Messagebox.show_error("错误", f"处理文件时出错: {str(e)}")def convert_jou_to_py(self, input_file):self.update_info(f"开始转换文件: {os.path.basename(input_file)}\n")self.update_info(f"输入文件路径: {input_file}\n")output_dir = os.path.dirname(input_file)filename = os.path.splitext(os.path.basename(input_file))[0]output_file = os.path.join(output_dir, f"{filename}_converted.py")with open(input_file, "r", encoding="utf-8") as infile:lines = infile.readlines()self.update_info(f"读取到 {len(lines)} 行内容\n")processed_lines = []output_mesh_file = Nonefor line in lines:if line.strip().startswith("/file/set-tui-version"):continueif line.strip() == "(newline)":continueif line.strip().startswith("(cx-gui-do"):continueif "(%py-exec" in line:if line.endswith('")\n'):line = line[:-3] + "\n"elif line.endswith('")'):line = line[:-2]line = re.sub(r'\(\%py-exec\s*"', "mesh.", line)if line.strip().startswith("/file/write-mesh"):match = re.search(r'"([^"]+)"', line)if match:filename = match.group(1)if filename.endswith(".gz"):filename = filename[:-3]output_mesh_file = filenameline = f'mesh.meshing.File.WriteMesh(r"{filename}")\n'if line.strip() == "/exit":line = "mesh.exit()\n"processed_lines.append(line)header_lines = ["import ansys.fluent.core as pyfluent\n",'mesh = pyfluent.launch_fluent(mode="meshing", precision="double", processor_count=2)\n\n',]footer_lines = ["\nmesh.meshing.File.WriteMesh()\n" if not output_mesh_file else "","mesh.exit()\n",]with open(output_file, "w", encoding="utf-8") as outfile:outfile.writelines(header_lines)outfile.writelines(processed_lines)outfile.writelines(footer_lines)self.update_info(f"转换成功: {os.path.basename(input_file)} → {os.path.basename(output_file)}\n")self.update_info(f"输出文件路径: {output_file}\n")self.update_info("=" * 50 + "\n\n")return output_filedef update_info(self, message):self.log_text.config(state=tk.NORMAL)self.log_text.insert(tk.END, message)self.log_text.see(tk.END)self.log_text.config(state=tk.DISABLED)def update_status(self, message, color="black"):self.status_var.set(message)self.style.configure("TLabel", foreground=color)if __name__ == "__main__":app = ttk.Window(themename="cosmo")processor = JouFileProcessor(app)app.mainloop()

软件界面如图:
image
输入.jou文件,自动生成.py文件,生成之后,在终端直接执行python test.py即可调用fluent实现你的想法。

3 参考文章

[1] Pyfluent 安装
[2] Pyfluent meshing flow
[3] 胡老师的pyfluent资料1
[4] 胡老师的pyfluent资料2
[5] Ansys github 官方

相关文章:

Pyfluent 执行Meshing工作流

1. 部署安装pyfluent Pyfluent支持Fluent 2022R2或更高版本,PyFluent支持Python 3.10~3.13版本,点击 此处 即可下载。 安装核心依赖需使用pip命令,如若详细了解该命令的使用,详见 此处 pip install ansys-fluent-core pip install pyfluent //如有需要可进一步安装 pip ins…...

EF Core 与 MySQL:日志和调试详解

本文将详细讲解EF Core与MySQL的日志和调试,分为三个部分:EF Core日志配置、MySQL日志查看以及使用调试工具分析查询性能。 1. 配置 EF Core 日志 基本日志配置// 在DbContext配置中启用日志记录 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuil…...

使用镜像源解决github拉取代码问题 - GD

命令行输入以下语句: git config --global url."https://gitclone.com/github.com/".insteadOf "https://github.com/" 取消设置: git config --global --unset url."https://gitclone.com/github.com/".insteadOf 参考:[https://www.cnblogs…...

日记

redis的运行指令 redis-server.exe redis.windows.conf 开始大创的实施...

主机连接虚拟机和hbase的命令

telnet+ip+端口号 主机hbase...

类和面向对象

概述:语言特性有二,其一为既面向过程又面向对象,其二为用类和对象表示数据和操作数据的,c++将操作和数据汇聚成类和对象何为对象?即世间的一切事物。假如一个对象为feijib,则可以说这个为类feijib,难道类是对象的别名?按下不表。类具有一些属性和方法,即feijjib是硅胶…...

PHP转Go系列 | PHP8 这些新函数让你眼前一亮

说实话,PHP8 中的这三个新函数让字符串检查,变得非常直观,就像让代码说人话一样。这对我们程序员来说是一件大好事,提升可读性,减少 Bug 量,升级到 PHP8 之后,再也不用维护类似的屎山代码了。大家好,我是码农先森。 在 PHP8 之前做字符串相关的检查操作比较麻烦,可读性…...

代码随想录算法训练营第二天 |209.长度最小的子数组,59. 螺旋矩阵 II

209.长度最小的子数组 思路:快慢指针的思想,当快指针一直移动的时候,那么数列一定是递增的,且我们要求的是连续的数组,所以我们其实可以一次性用一个for就给全部遍历完成。当我们这个区间的值大于了target,我们就可以开始移动我们的慢指针了,直到我们的慢指针到达快指针…...

mac更新or安装homebrew失败

错误信息:fatal: unable to access https://github.com/Homebrew/brew/: LibreSSL SSL_read: error:02FFF03C:system library:func(4095):Operation timed out, errno 60可以用命令:/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew…...

Typescript中闭包的原理 - 教程

Typescript中闭包的原理 - 教程pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", monospace !important; font…...

CF2048H Kevin and Strange Operation

操作的自由度很大,打表可以发现限制操作的位置只增不减也是对的。 考虑怎么判断一个串 \(t\) 是否合法。 观察到对于一个位置 \(i\) 满足 \(s_i=0\),想要通过操作使 \(s_i\) 变为 \(1\),只需要 \(>i\) 的位置删掉了 \(\ge c_i\) 个数。其中 \(c_i\) 为 \(>i\) 的第一个…...

Hadoop本地库加载问题分析与解决方案

主要问题分析 ​​本地库加载警告​​: WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable 这表明Hadoop无法正确加载本地优化库,将回退到纯Java实现,性能可能受影响 ​​栈保护警告​​…...

GO基础总结

环境搭建 基本语法 参见:https://www.cnblogs.com/vonlinee/p/19005628 工具链...

Visual Studio 离线安装0x80131509

Visual Studio 2026在本月发布了,它最大的特点是集成了GitHub Copilot,内置AI编程,空了要尝尝鲜(使用过Visual Studio Code的Copilot,还是挺有用的)。目前,VS2022很少使用,像VS2012一样被跳过,主要使用VS2019,甚至有时需要VS2010编译。分享一个离线安装Visual Studio…...

Oracle备份恢复:backup as copy保留文件名不变化,只更改路径名

我们的文章会在微信公众号IT民工的龙马人生和博客网站( www.htz.pw )同步更新 ,欢迎关注收藏,也欢迎大家转载,但是请在文章开始地方标注文章出处,谢谢! 由于博客中有大量代码,通过页面浏览效果更佳。Oracle备份恢复:backup as copy保留文件名不变化,只更改路径名 有些时…...

读书笔记:数据库中的预连接神器:位图连接索引

我们的文章会在微信公众号IT民工的龙马人生和博客网站( www.htz.pw )同步更新 ,欢迎关注收藏,也欢迎大家转载,但是请在文章开始地方标注文章出处,谢谢! 由于博客中有大量代码,通过页面浏览效果更佳。本文为个人学习《Expert Oracle Database Architecture Techniques and…...

故障处理:CRS无法随操作系统自动启动故障案例分享

我们的文章会在微信公众号IT民工的龙马人生和博客网站( www.htz.pw )同步更新 ,欢迎关注收藏,也欢迎大家转载,但是请在文章开始地方标注文章出处,谢谢! 由于博客中有大量代码,通过页面浏览效果更佳。今天分享一个前几天网友遇到的集群环境中CRS无法随操作系统自动启动,但…...

02020401 EF Core基础01-EF Core简介和开发环境搭建、实体类、配置类、继承DbContex的类、Migration包的使用

02020401 EF Core基础01-EF Core简介和开发环境搭建、实体类、配置类、继承DbContex的类、Migration包的使用 1. EF Core简介(视频3-1)本课程需要你有数据库、SQL等基础知识。关系数据库:MySql、SQL Server、Oracle等。表(字段/列),表与表之间通过外键关联。对象数据库:…...

专用通路方式

-取址周期 1.从pc取址到mar (pc)->mar 此时c0有效 2.把刚才的值交给内存 (mar)->内存 c1 3.让内存读取mar中保存的值 1->r 4.让mdr获取内存刚刚读取的mar中保存的代码值 MEM(MAR)->MDR C2 5.再让IR(指令寄存器)获取MDR中的值 (MDR)->IR C3 6.(PC)+1=PC 7.最…...

typeof()

C# 中的 typeof() 是啥?一句话讲清楚:typeof() 就是“问编译器:这个类型长啥样?”它不是运行时去查对象,而是编译时就确定你写的那个“类名、接口名、结构名”到底是谁,然后返回一个叫 Type 的对象,这个对象里装满了这个类型的“身份证信息”。举个接地气的例子: 你写:…...

【未完成】2025.9 做题记录

CF1310C CF616F CF1065G CF1536F. Omkar and Akmar *2600 题意 Alice 和 Bob 在一个 \(n\) 个格子的环上玩游戏,环上的格子编号为 \(1\sim n\)。 每一轮中,玩家可选择一个空格子填入字母 A 或 B,同时要求不能存在两个相邻的格子内的字母相同。若没有合法操作,则游戏结束,当…...

2025.8 做题记录

P4064 [JXOI2017] 加法 蓝 题意 可怜有一个长度为 \(n\) 的正整数序列 \(A\),但是她觉得 \(A\) 中的数字太小了,这让她很不开心。 于是她选择了 \(m\) 个区间 \([l_i,r_i]\) 和两个正整数 \(a,k\)。她打算从这 \(m\) 个区间里选出恰好 \(k\) 个区间,并对每个区间执行一次区间…...

关于 “Thinking Machines Lab首次发长文” 的一些知识的学习和补充

1. 前言砚上三五笔,落墨鹧鸪啼原文链接: https://thinkingmachines.ai/ 相关分析链接:https://www.gongjiyun.com/blog/2025/9/fu1xw1spci9vnokjipecs9y9nzn/最近看到一篇名为《击败 LLM 推理中的非确定性:从“玄学”到可控》的文章,这里将一些知识盲区简单记录下。 如有不…...

CF1630F 题解 | 网络流

传送门 题意 给你一个长度为 \(n\) 的序列 \(a\),构建一个无向图:若 \(a_i | a_j\),则在 \(i\) 和 \(j\) 中连边。 求最少删除多少个点,才能使得剩下的图是二分图。 思路 首先,我们知道倍数关系是一个偏序关系,即 \(a_i | a_j, a_j | a_k \rightarrow a_i | a_k\)。 所以…...

攻防世界-secret-galaxy-300 - xxx

先查壳,无壳,32位程序先运行一下这个exe程序,发现闪一下就消失了,也没有什么提示字符串可查看。打算先去od里面运行看看 打开后没看到什么,查看字符串一时间也没看出什么,不过这个task函数倒是让控制台输出一堆奇怪的东西说实话看了之后有点懵,不过没关系,既然OD没什么…...

实用指南:LeetCode 面试经典 150_哈希表_单词规律(41_290_C++_简单)

实用指南:LeetCode 面试经典 150_哈希表_单词规律(41_290_C++_简单)pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier …...

数据库

数据库操作DDL 创建 create database 数据库名查询 show databases ; show database like 数据库名;修改 alter database 数据库名 set 字段名 类型 约束;删除 drop database 数据库名;使用 use 数据库名;数据库表操作DDL 创建 create table 表名(字段 类型 索引);查看表…...

代码随想录算法训练营第二天 | leetcode 209

长度最小的子数组(没做出来) 题目要求:寻找一个数组中满足大于等于目标要求的最小子数组 解题思路:返回结果可能是不存在,所以需要定义一个合适的初始值,可以使用java的最大数Integer.MAX_VALUE,然后使用滑动窗口寻找满足条件的子数组,这时还需要对之前的数进行减去,避…...

mpv硬件解码

mpv --hwdec=yes --vo=vappi 3e559881c836c30321894b20ae102c4e.mp4...

2025.9.78——卷6-8选择

卷6选择 大O表示法 大O表示法由​​德国数学家保罗巴赫曼(Paul Bachman)提出,用于表示算法的最坏情况下时间复杂度 Θ表示法 Θ表示法通常归功于​​计算机科学家Donald Knuth​​等人,用于描述算法的平均时间复杂度 ST表 预处理时间复杂度O(NlogN),查询O(logN) AVL树 一种…...

关于pytorch的读书报告

PyTorch 读书报告 一、引言 PyTorch 是由 Facebook(现 Meta)人工智能研究实验室开发的一款开源机器学习框架,自 2016 年推出以来,凭借其动态计算图特性、简洁直观的 API 设计以及强大的生态系统,迅速成为学术界和工业界深度学习研究与应用的主流工具之一。本报告将围绕 Py…...

Emacs 折腾日记(三十)——打造C++ IDE 续

上一篇博客中,我完成了C++ IDE初步工作,包括代码的高亮、折叠、跳转以及补全等工作。但是作为IDE来说功能还有点不够,就我个人而言作为IDE来说它还需要具备一键编译运行和调试功能。这篇文章就来记录我是如何实现上述功能的 编译运行 我使用的演示项目比较简单,它的文件结构…...

数据结构 项目一

一:数据结构的基本概念 数据结构----研究数据的特性及数据之间存在的关系 算法+数据结构=程序。其中数据结构是指数据逻辑结构和物理结构,算法是对数据运算的描述。 用计算机解决一个具体问题时,首先从具体问题中抽象出一个适当的数学模型,然后设计一个能解此数学模型的算法…...

好烦

我不行了,一做初赛题就有一种莫名其妙的烦躁,根本就写不进去,一点都冷静不下来...

【STL库】哈希封装 unordered_map/unordered_set - 教程

【STL库】哈希封装 unordered_map/unordered_set - 教程pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", mon…...

用 Go 语言与 Tesseract OCR 识别英文数字验证码

一、安装与配置 安装 Tesseract OCR 你需要先安装 Tesseract OCR 引擎。具体步骤如下: Ubuntu: 更多内容访问ttocr.com或联系1436423940 sudo apt-get update sudo apt-get install tesseract-ocr macOS: brew install tesseract Windows: 可以从 Tesseract GitHub 下载并安装…...

FreeRTOS和LVGL组合使用教程

前言 关于这两者组合使用的教程,网上可以说是各种方法都有,移植的时候我也有遇到各种问题,在此处记录一下解决过程 问题 栈空间的分配问题 FreeRTOS和LVGL的栈分配都尽量多一点,不然后面的任务可能创建失败 lvgl心跳的问题 网上也有很多方法FreeRTOS钩子函数 单开一个定时器…...

Pip换源

清华大学源 比较全,但是没有torch pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple南京大学源 有torch但是很多包没有,建议用来安装torch pip3 install torch torchvision torchaudio --index-url https://mirrors.nju.edu.cn/pytorch…...

7zip压缩解压缩-测试CPU性能

前言全局说明在B站刷大佬视频的时候,看到UP在Debign linux 上用7z测试CPU性能,惊讶,7z还有这功能。 赶快打开手边的电脑,看看 Windows 上的 7z 有没有这功能,一用,果然有这个功能。 以前想知道CPU性能就只能装些 XX大师,现在有了这个小巧的工具,知道参考数值就很方便了…...

高数

1 求 \(\lim_{n\to\infty}\left(1-\frac 1n\right)^{n^2}\) 解: 首先证明 \(\lim_{n\to\infty}\left(1-\frac 1n\right)^{n}=e^{-1}\)。 \[\begin{align*} \lim_{n\to\infty}\left(1-\frac 1n\right)^{n} &=\lim_{n\to\infty}\left[\left(1-\frac 1n\right)^{(n-1)}\right…...

P5666 [CSP-S2019] 树的重心

分为 \(x \ne rt\) 和 \(x = rt\) 两种情况计算. 对于第一种情况,不难发现我们合法的裁减下来的连通块大小是在一个区间范围之内的,于是 DFS 时用一棵树状数组修改即可(因为这个大小可能是子树大小可能是子树外大小,这取决于你一条祖先链有哪些点),但子树内的 siz 可能会被记入…...

Java运行机制

Java 程序运行机制 编译型(compile) 解释型 程序运行机制 ![机制图](C:\Users\asus\Desktop\图集\屏幕截图 2025-09-18 204707.png)...

除自身以外数组的乘积-leetcode

题目描述 给你一个整数数组 nums,返回 数组 answer ,其中 answer[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积 。 题目数据 保证 数组 nums之中任意元素的全部前缀元素和后缀的乘积都在 32 位 整数范围内。 请 不要使用除法,且在 O(n) 时间复杂度内完成此题。 示例 1: …...

【2022】SDRZ夏令营游记

为什么2022的游记会在2025年发? 因为感觉洛谷博客快扛不住了,决定开始搬运。今天是夏令营最后一天了,在机房里坐不住了,写篇游记来纪念一下。 day0: 这天是gryz65级三个校区的信竞同学第一次大会师。我成功与一区同学面基,线下见面和在网络上的印象完全不一样(《关于why…...

[论文笔记/评估方法] RELIABLE AND DIVERSE EVALUATION OF LLM MEDICAL KNOWLEDGE MASTERY

RELIABLE AND DIVERSE EVALUATION OF LLM MEDICAL KNOWLEDGE MASTERY该文章于2025年发表在ICLR(CCF A),早在2024年9月发布在arxiv。 文章地址:Reliable and Diverse Evaluation of LLM Medical Knowledge Mastery arXiv:[2409.14302] Reliable and diverse evaluation of …...

本地VMware Workstation Pro的rhel-server-7.9-x86_64服务器配置本地源

1. 安装好VMware Workstation Pro以及rhel-server-7.9-x86_64-dvd.iso后 2. 先对VMware Workstation 进行虚拟机关机 3. 对虚拟机的CD/DVD(SATA) 勾选设备状态为启动时连接,以及连接中勾选使用ISO镜像文件,为本地的rhel-server-7.9-x86_64-dvd.iso路径 4. 接下来就按如下操作…...

2025年十大AI网站构建工具:专家评测与推荐!

2025年,软件开发领域迎来一个关键转折点。随着 AI 技术的飞速发展,传统的网站或应用构建障碍正逐渐消失。市场上涌现出大量功能强大的工具,每一个都号称是您所需要的最佳 AI网站构建器 或 网站生成器。 然而,对于开发者、创业者乃至普通初学者而言,面对如此多的选择可能会…...

扫描线乱谈

扫描线乱谈前置知识 离散化,线段树 扫描线 首先假设你有n个矩形。如果直接暴力求解这些矩形的覆盖面积肯定不行,这时就要用扫描线算法。 假设有一根线,从下往上扫描:把每个小矩形分成很多不同的块,高是扫过的距离,那个位置没有被覆盖高就是0。显然答案就是高宽的和。 每次…...

详细介绍:量子计算学习(第十四周周报)

详细介绍:量子计算学习(第十四周周报)pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", monospace !import…...

视频播放时切出页面视频暂停(亲测可用)

视频播放时切出页面视频暂停(亲测可用)谷歌浏览器方法:视频播放网页,右键—检查—Elements—Event Listeners—找到blur,点开小三角,remove掉所有子元素...