Fluent的网格生成引导工作流程旨在简化从CAD几何到体网格生成的过程。用户可以使用PyFluent访问引导的工作流程。
工作流程被划分为新的网格生成工作流程和经典网格生成工作流程,它们与日志语法对齐。
可以使用PyFluent来访问与日志语法一致的经典网格工作流程。
使用 Watertight Geometry 工作流来处理不需要大量清理或修改的封闭CAD几何体。以下示例展示了如何使用Watertight Geometry工作流。
import ansys.fluent.core as pyfluent
from ansys.fluent.core import examples
import_file_name = examples.download_file('mixing_elbow.pmdb', 'pyfluent/mixing_elbow')
meshing = pyfluent.launch_fluent(
mode="meshing", precision='double', processor_count=2
)
meshing.workflow.InitializeWorkflow(WorkflowType='Watertight Geometry')
meshing.workflow.TaskObject['Import Geometry'].Arguments = {
'FileName': import_file_name, 'LengthUnit': 'in'
}
meshing.workflow.TaskObject['Import Geometry'].Execute()
meshing.workflow.TaskObject['Add Local Sizing'].AddChildToTask()
meshing.workflow.TaskObject['Add Local Sizing'].Execute()
meshing.workflow.TaskObject['Generate the Surface Mesh'].Arguments = {
'CFDSurfaceMeshControls': {'MaxSize': 0.3}
}
meshing.workflow.TaskObject['Generate the Surface Mesh'].Execute()
meshing.workflow.TaskObject["Describe Geometry"].UpdateChildTasks(
SetupTypeChanged=False
)
meshing.workflow.TaskObject["Describe Geometry"].Arguments = {
SetupType: "The geometry consists of only fluid regions with no voids"
}
meshing.workflow.TaskObject["Describe Geometry"].UpdateChildTasks(SetupTypeChanged=True)
meshing.workflow.TaskObject["Describe Geometry"].Execute()
meshing.workflow.TaskObject["Update Boundaries"].Arguments = {
"BoundaryLabelList": ["wall-inlet"],
"BoundaryLabelTypeList": ["wall"],
"OldBoundaryLabelList": ["wall-inlet"],
"OldBoundaryLabelTypeList": ["velocity-inlet"],
}
meshing.workflow.TaskObject["Update Boundaries"].Execute()
meshing.workflow.TaskObject["Update Regions"].Execute()
meshing.workflow.TaskObject["Add Boundary Layers"].AddChildToTask()
meshing.workflow.TaskObject["Add Boundary Layers"].InsertCompoundChildTask()
meshing.workflow.TaskObject["smooth-transition_1"].Arguments = {
"BLControlName": "smooth-transition_1",
}
meshing.workflow.TaskObject["Add Boundary Layers"].Arguments = {}
meshing.workflow.TaskObject["smooth-transition_1"].Execute()
meshing.workflow.TaskObject["Generate the Volume Mesh"].Arguments = {
"VolumeFill": "poly-hexcore",
"VolumeFillControls": {
"HexMaxCellLength": 0.3,
},
}
meshing.workflow.TaskObject["Generate the Volume Mesh"].Execute()
solver = meshing.switch_to_solver()
使用Fault-tolerant网格划分工作流程可处理更复杂的非水密 CAD 几何图形,这些几何图形可能需要某种形式的清理或修改(例如,重叠、交叉、孔洞、重复等缺陷)。下面的示例展示了如何使用Fault-tolerant工作流程。
import ansys.fluent.core as pyfluent
from ansys.fluent.core import examples
import_file_name = examples.download_file(
"exhaust_system.fmd", "pyfluent/exhaust_system"
)
meshing = pyfluent.launch_fluent(precision="double", processor_count=2, mode="meshing")
meshing.workflow.InitializeWorkflow(WorkflowType="Fault-tolerant Meshing")
meshing.PartManagement.InputFileChanged(
FilePath=import_file_name, IgnoreSolidNames=False, PartPerBody=False
)
meshing.PMFileManagement.FileManager.LoadFiles()
meshing.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.PartManagement.ObjectSetting["DefaultObjectSetting"].OneZonePer.set_state("part")
meshing.workflow.TaskObject["Import CAD and Part Management"].Arguments.set_state(
{
"Context": 0,
"CreateObjectPer": "Custom",
"FMDFileName": import_file_name,
"FileLoaded": "yes",
"ObjectSetting": "DefaultObjectSetting",
"Options": {
"Line": False,
"Solid": False,
"Surface": False,
},
}
)
meshing.workflow.TaskObject["Import CAD and Part Management"].Execute()
meshing.workflow.TaskObject["Describe Geometry and Flow"].Arguments.set_state(
{
"AddEnclosure": "No",
"CloseCaps": "Yes",
"FlowType": "Internal flow through the object",
}
)
meshing.workflow.TaskObject["Describe Geometry and Flow"].UpdateChildTasks(
SetupTypeChanged=False
)
meshing.workflow.TaskObject["Describe Geometry and Flow"].Arguments.set_state(
{
"AddEnclosure": "No",
"CloseCaps": "Yes",
"DescribeGeometryAndFlowOptions": {
"AdvancedOptions": True,
"ExtractEdgeFeatures": "Yes",
},
"FlowType": "Internal flow through the object",
}
)
meshing.workflow.TaskObject["Describe Geometry and Flow"].UpdateChildTasks(
SetupTypeChanged=False
)
meshing.workflow.TaskObject["Describe Geometry and Flow"].Execute()
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].Arguments.set_state(
{
"CreatePatchPreferences": {
"ShowCreatePatchPreferences": False,
},
"PatchName": "inlet-1",
"SelectionType": "zone",
"ZoneSelectionList": ["inlet.1"],
}
)
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].Arguments.set_state(
{
"CreatePatchPreferences": {
"ShowCreatePatchPreferences": False,
},
"PatchName": "inlet-1",
"SelectionType": "zone",
"ZoneLocation": [
"1",
"351.68205",
"-361.34322",
"-301.88668",
"396.96205",
"-332.84759",
"-266.69751",
"inlet.1",
],
"ZoneSelectionList": ["inlet.1"],
}
)
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].AddChildToTask()
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].InsertCompoundChildTask()
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].Arguments.set_state({})
meshing.workflow.TaskObject["inlet-1"].Execute()
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].Arguments.set_state(
{
"PatchName": "inlet-2",
"SelectionType": "zone",
"ZoneSelectionList": ["inlet.2"],
}
)
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].Arguments.set_state(
{
"PatchName": "inlet-2",
"SelectionType": "zone",
"ZoneLocation": [
"1",
"441.68205",
"-361.34322",
"-301.88668",
"486.96205",
"-332.84759",
"-266.69751",
"inlet.2",
],
"ZoneSelectionList": ["inlet.2"],
}
)
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].AddChildToTask()
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].InsertCompoundChildTask()
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].Arguments.set_state({})
meshing.workflow.TaskObject["inlet-2"].Execute()
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].Arguments.set_state(
{
"PatchName": "inlet-3",
"SelectionType": "zone",
"ZoneSelectionList": ["inlet"],
}
)
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].Arguments.set_state(
{
"PatchName": "inlet-3",
"SelectionType": "zone",
"ZoneLocation": [
"1",
"261.68205",
"-361.34322",
"-301.88668",
"306.96205",
"-332.84759",
"-266.69751",
"inlet",
],
"ZoneSelectionList": ["inlet"],
}
)
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].AddChildToTask()
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].InsertCompoundChildTask()
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].Arguments.set_state({})
meshing.workflow.TaskObject["inlet-3"].Execute()
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].Arguments.set_state(
{
"PatchName": "outlet-1",
"SelectionType": "zone",
"ZoneSelectionList": ["outlet"],
"ZoneType": "pressure-outlet",
}
)
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].Arguments.set_state(
{
"PatchName": "outlet-1",
"SelectionType": "zone",
"ZoneLocation": [
"1",
"352.22702",
"-197.8957",
"84.102381",
"394.41707",
"-155.70565",
"84.102381",
"outlet",
],
"ZoneSelectionList": ["outlet"],
"ZoneType": "pressure-outlet",
}
)
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].AddChildToTask()
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].InsertCompoundChildTask()
meshing.workflow.TaskObject["Enclose Fluid Regions (Capping)"].Arguments.set_state({})
meshing.workflow.TaskObject["outlet-1"].Execute()
meshing.workflow.TaskObject["Extract Edge Features"].Arguments.set_state(
{
"ExtractMethodType": "Intersection Loops",
"ObjectSelectionList": ["flow_pipe", "main"],
}
)
meshing.workflow.TaskObject["Extract Edge Features"].AddChildToTask()
meshing.workflow.TaskObject["Extract Edge Features"].InsertCompoundChildTask()
meshing.workflow.TaskObject["edge-group-1"].Arguments.set_state(
{
"ExtractEdgesName": "edge-group-1",
"ExtractMethodType": "Intersection Loops",
"ObjectSelectionList": ["flow_pipe", "main"],
}
)
meshing.workflow.TaskObject["Extract Edge Features"].Arguments.set_state({})
meshing.workflow.TaskObject["edge-group-1"].Execute()
meshing.workflow.TaskObject["Identify Regions"].Arguments.set_state(
{
"SelectionType": "zone",
"X": 377.322045740589,
"Y": -176.800676988458,
"Z": -37.0764628583475,
"ZoneSelectionList": ["main.1"],
}
)
meshing.workflow.TaskObject["Identify Regions"].Arguments.set_state(
{
"SelectionType": "zone",
"X": 377.322045740589,
"Y": -176.800676988458,
"Z": -37.0764628583475,
"ZoneLocation": [
"1",
"213.32205",
"-225.28068",
"-158.25531",
"541.32205",
"-128.32068",
"84.102381",
"main.1",
],
"ZoneSelectionList": ["main.1"],
}
)
meshing.workflow.TaskObject["Identify Regions"].AddChildToTask()
meshing.workflow.TaskObject["Identify Regions"].InsertCompoundChildTask()
meshing.workflow.TaskObject["fluid-region-1"].Arguments.set_state(
{
"MaterialPointsName": "fluid-region-1",
"SelectionType": "zone",
"X": 377.322045740589,
"Y": -176.800676988458,
"Z": -37.0764628583475,
"ZoneLocation": [
"1",
"213.32205",
"-225.28068",
"-158.25531",
"541.32205",
"-128.32068",
"84.102381",
"main.1",
],
"ZoneSelectionList": ["main.1"],
}
)
meshing.workflow.TaskObject["Identify Regions"].Arguments.set_state({})
meshing.workflow.TaskObject["fluid-region-1"].Execute()
meshing.workflow.TaskObject["Identify Regions"].Arguments.set_state(
{
"MaterialPointsName": "void-region-1",
"NewRegionType": "void",
"ObjectSelectionList": ["inlet-1", "inlet-2", "inlet-3", "main"],
"X": 374.722045740589,
"Y": -278.9775145640143,
"Z": -161.1700719416913,
}
)
meshing.workflow.TaskObject["Identify Regions"].AddChildToTask()
meshing.workflow.TaskObject["Identify Regions"].InsertCompoundChildTask()
meshing.workflow.TaskObject["Identify Regions"].Arguments.set_state({})
meshing.workflow.TaskObject["void-region-1"].Execute()
meshing.workflow.TaskObject["Define Leakage Threshold"].Arguments.set_state(
{
"AddChild": "yes",
"FlipDirection": True,
"PlaneDirection": "X",
"RegionSelectionSingle": "void-region-1",
}
)
meshing.workflow.TaskObject["Define Leakage Threshold"].AddChildToTask()
meshing.workflow.TaskObject["Define Leakage Threshold"].InsertCompoundChildTask()
meshing.workflow.TaskObject["leakage-1"].Arguments.set_state(
{
"AddChild": "yes",
"FlipDirection": True,
"LeakageName": "leakage-1",
"PlaneDirection": "X",
"RegionSelectionSingle": "void-region-1",
}
)
meshing.workflow.TaskObject["Define Leakage Threshold"].Arguments.set_state(
{
"AddChild": "yes",
}
)
meshing.workflow.TaskObject["leakage-1"].Execute()
meshing.workflow.TaskObject["Update Region Settings"].Arguments.set_state(
{
"AllRegionFilterCategories": ["2"] * 5 + ["1"] * 2,
"AllRegionLeakageSizeList": ["none"] * 6 + ["6.4"],
"AllRegionLinkedConstructionSurfaceList": ["n/a"] * 6 + ["no"],
"AllRegionMeshMethodList": ["none"] * 6 + ["wrap"],
"AllRegionNameList": [
"main",
"flow_pipe",
"outpipe3",
"object2",
"object1",
"void-region-1",
"fluid-region-1",
],
"AllRegionOversetComponenList": ["no"] * 7,
"AllRegionSourceList": ["object"] * 5 + ["mpt"] * 2,
"AllRegionTypeList": ["void"] * 6 + ["fluid"],
"AllRegionVolumeFillList": ["none"] * 6 + ["tet"],
"FilterCategory": "Identified Regions",
"OldRegionLeakageSizeList": [""],
"OldRegionMeshMethodList": ["wrap"],
"OldRegionNameList": ["fluid-region-1"],
"OldRegionOversetComponenList": ["no"],
"OldRegionTypeList": ["fluid"],
"OldRegionVolumeFillList": ["hexcore"],
"RegionLeakageSizeList": [""],
"RegionMeshMethodList": ["wrap"],
"RegionNameList": ["fluid-region-1"],
"RegionOversetComponenList": ["no"],
"RegionTypeList": ["fluid"],
"RegionVolumeFillList": ["tet"],
}
)
meshing.workflow.TaskObject["Update Region Settings"].Execute()
meshing.workflow.TaskObject["Choose Mesh Control Options"].Execute()
meshing.workflow.TaskObject["Generate the Surface Mesh"].Execute()
meshing.workflow.TaskObject["Update Boundaries"].Execute()
meshing.workflow.TaskObject["Add Boundary Layers"].AddChildToTask()
meshing.workflow.TaskObject["Add Boundary Layers"].InsertCompoundChildTask()
meshing.workflow.TaskObject["aspect-ratio_1"].Arguments.set_state(
{
"BLControlName": "aspect-ratio_1",
}
)
meshing.workflow.TaskObject["Add Boundary Layers"].Arguments.set_state({})
meshing.workflow.TaskObject["aspect-ratio_1"].Execute()
meshing.workflow.TaskObject["Generate the Volume Mesh"].Arguments.set_state(
{
"AllRegionNameList": [
"main",
"flow_pipe",
"outpipe3",
"object2",
"object1",
"void-region-1",
"fluid-region-1",
],
"AllRegionSizeList": ["11.33375"] * 7,
"AllRegionVolumeFillList": ["none"] * 6 + ["tet"],
"EnableParallel": True,
}
)
meshing.workflow.TaskObject["Generate the Volume Mesh"].Execute()
solver = meshing.switch_to_solver()
这个简单的例子展示了如何在一个Watertight Geometry工作流中使用CommandArgument
属性和显式属性访问方法。
注意:CommandArgument
属性为只读属性。
import ansys.fluent.core as pyfluent
from ansys.fluent.core import examples
import_file_name = examples.download_file("mixing_elbow.pmdb", "pyfluent/mixing_elbow")
meshing = pyfluent.launch_fluent(mode="meshing", precision="double", processor_count=2)
w = meshing.workflow
w.InitializeWorkflow(WorkflowType="Watertight Geometry")
w.TaskObject["Import Geometry"].CommandArguments()
w.TaskObject["Import Geometry"].CommandArguments.FileName.is_read_only()
w.TaskObject["Import Geometry"].CommandArguments.LengthUnit.is_active()
w.TaskObject["Import Geometry"].CommandArguments.LengthUnit.allowed_values()
w.TaskObject["Import Geometry"].CommandArguments.LengthUnit.default_value()
w.TaskObject["Import Geometry"].CommandArguments.LengthUnit()
w.TaskObject["Import Geometry"].CommandArguments.CadImportOptions.OneZonePer()
w.TaskObject["Import Geometry"].CommandArguments.CadImportOptions.FeatureAngle.min()
可以调用TaskObject
来获取其状态:
meshing.workflow.TaskObject()
TaskObject
中的项目现在可以通过设置字典风格来访问:
for name, object in meshing.workflow.TaskObject.items():
...
注:本文内容取自PyFluent UserGuide。
”