Open
Description
The computational speed of the exact same workflow in Fluent GUI and using the Python API is approximately 50 times slower, despite yielding the same results. The entire workflow consists of both mesh generation and solution computation.
All the single steps, including:
- geometry import
- Mesh surface generation
- Mesh volume generation
- Boundary layers addition
- Local refinement regions
- Application of the solution settings to the mesh
- Solution computation
The problem we are considering is a simple single fluid in laminar flow moving around a sphere inside a cylinder.
Fluent: 2025R1 (Student Version),
PyFluent: 0.33.0
Python3.11.9
Are we doing something wrong?
# %%
import os
import ansys.fluent.core as pyfluent
import yaml
# --- CARICAMENTO CONFIGURAZIONE DA FILE ---
try:
with open('config.yaml', 'r') as file:
config = yaml.safe_load(file)
except FileNotFoundError:
print("Errore: il file 'config.yaml' non è stato trovato.")
exit()
except yaml.YAMLError as e:
print(f"Errore durante la lettura del file YAML: {e}")
exit()
# --- CONFIGURAZIONE E AVVIO ---
if not os.getenv('FLUENT_PROD_DIR'):
workflow = pyfluent.launch_fluent(
mode="meshing",
dimension=3,
precision="double",
processor_count=2,
show_gui=True
)
workflow.watertight()
# %%
workflow.workflow.TaskObject['Import Geometry'].Arguments.set_state({r'FileName': r'C:/Users/testd/Documents/toy cfd/Disegno1_sfera.pmdb',r'ImportCadPreferences': {r'MaxFacetLength': 0,},r'LengthUnit': r'mm',})
workflow.workflow.TaskObject['Import Geometry'].Execute()
workflow.workflow.TaskObject['Add Local Sizing'].Arguments.set_state({r'AddChild': r'yes',r'BOICellsPerGap': 1,r'BOIControlName': r'facesize_sfera',r'BOICurvatureNormalAngle': 18,r'BOIExecution': r'Face Size',r'BOIGrowthRate': 1.2,r'BOISize': 20,r'BOIZoneorLabel': r'label',})
workflow.workflow.TaskObject['Add Local Sizing'].Arguments.set_state({r'AddChild': r'yes',r'AssignSizeUsing': r'Size',r'BOICellsPerGap': 1,r'BOIControlName': r'facesize_sfera',r'BOICurvatureNormalAngle': 18,r'BOIExecution': r'Face Size',r'BOIFaceLabelList': [r'sfera'],r'BOIGrowthRate': 1.2,r'BOIMaxSize': 548.3043334960937,r'BOIMinSize': 2.141813802719116,r'BOIPatchingtoggle': False,r'BOIScopeTo': r'faces',r'BOISize': 20,r'BOIZoneorLabel': r'label',r'BiasFactor': 4,r'DrawSizeControl': True,r'GrowthMethod': r'Growth Rate',r'GrowthPattern': r'_____ _____ _____ _____ _____',r'IgnoreOrientation': r'Yes',r'NumberofLayers': 3,r'ReverseEdgeZoneOrientation': False,r'SmallestHeight': 21.41813802719116,})
workflow.workflow.TaskObject['Add Local Sizing'].AddChildAndUpdate(DeferUpdate=False)
workflow.workflow.TaskObject['Add Local Sizing'].InsertNextTask(CommandName=r'CreateLocalRefinementRegions')
workflow.workflow.TaskObject['Create Local Refinement Regions'].Arguments.set_state({r'Axis': {r'X-Comp': 0,r'Y-Comp': 0,r'Z-Comp': 1,},r'BOIMaxSize': 320,r'BOISizeName': r'boi_1',r'BoundingBoxObject': {r'SizeRelativeLength': r'Directly specify coordinates',r'Xmax': 4000,r'XmaxRatio': 4,r'Xmin': -1000,r'XminRatio': -2,r'Ymax': 1000,r'YmaxRatio': 1,r'Ymin': -1000,r'YminRatio': -2,r'Zmax': 1000,r'ZmaxRatio': 1,r'Zmin': -1000,r'ZminRatio': -2,},r'CreationMethod': r'Box',r'CylinderLength': 5483,r'CylinderMethod': r'Vector and Length',r'CylinderObject': {r'HeightBackInc': 0,r'HeightFrontInc': 0,r'Radius1': 274.15,r'Radius2': 1096.6,r'X-Offset': 0,r'X1': 0,r'X2': 5483,r'Y-Offset': 0,r'Y1': 0,r'Y2': 0,r'Z-Offset': 0,r'Z1': 0,r'Z2': 0,},r'LabelSelectionList': [r'sfera'],r'OffsetObject': {r'AspectRatio': 5,r'BoundaryLayerHeight': 1280,r'BoundaryLayerLevels': 1,r'CrossWakeGrowthFactor': 1.1,r'DefeaturingSize': 80,r'FirstHeight': 0.01,r'FlipDirection': False,r'FlowDirection': r'X',r'LastRatioPercentage': 20,r'MptMethodType': r'Automatic',r'NumberOfLayers': 4,r'OffsetMethodType': r'uniform',r'Rate': 1.2,r'ShowCoordinates': True,r'WakeGrowthFactor': 2,r'WakeLevels': 1,r'X': 0,r'Y': 0,r'Z': 0,},r'RefinementRegionsName': r'local-refinement-1',r'SelectionType': r'label',r'VolumeFill': r'hexcore',})
workflow.workflow.TaskObject['Create Local Refinement Regions'].AddChildAndUpdate(DeferUpdate=False)
#workflow.workflow.TaskObject['Generate the Surface Mesh'].Arguments.set_state({r'CFDSurfaceMeshControls': {r'GrowthRate': 1.3,r'MaxSize': 500,r'MinSize': 20,r'ScopeProximityTo': r'faces-and-edges',},})
workflow.workflow.TaskObject['Generate the Surface Mesh'].Execute()
workflow.workflow.TaskObject['Describe Geometry'].UpdateChildTasks(Arguments={r'v1': True,}, SetupTypeChanged=False)
workflow.workflow.TaskObject['Describe Geometry'].UpdateChildTasks(Arguments={r'v1': True,}, SetupTypeChanged=True)
# %%
describe_geometry = workflow.workflow.TaskObject["Describe Geometry"]
describe_geometry.UpdateChildTasks(
SetupTypeChanged=False
)
describe_geometry.Arguments = {
'SetupType': "The geometry consists of both fluid and solid regions and/or voids"
}
describe_geometry.UpdateChildTasks(SetupTypeChanged=True)
# %%
describe_geometry.Execute()
# %%
workflow.workflow.TaskObject['Describe Geometry'].Execute()
workflow.workflow.TaskObject['Update Boundaries'].Execute()
workflow.workflow.TaskObject['Create Regions'].Arguments.set_state({r'RetainDeadRegionName': r'no',})
workflow.workflow.TaskObject['Create Regions'].Execute()
workflow.workflow.TaskObject['Update Regions'].Execute()
workflow.workflow.TaskObject['Add Boundary Layers'].Arguments.set_state({r'BLControlName': r'last-ratio_1',r'BlLabelList': [r'sfera'],r'FaceScope': {r'GrowOn': r'selected-labels',r'RegionsType': r'fluid-regions',},r'FirstHeight': 5,r'LocalPrismPreferences': {r'Continuous': r'Continuous',},r'OffsetMethodType': r'last-ratio',})
workflow.workflow.TaskObject['Add Boundary Layers'].AddChildAndUpdate(DeferUpdate=False)
workflow.workflow.TaskObject['Generate the Volume Mesh'].Arguments.set_state({r'VolumeFill': r'polyhedra',})
workflow.workflow.TaskObject['Generate the Volume Mesh'].Execute()
# %%
solver = workflow.switch_to_solver()
solver.settings.file.read_settings(file_name = "setting_solver")
# solver.exit()
# %%
num_iterations = 10
solver.solution.run_calculation.iterate(iter_count=num_iterations)
solver.settings.results.plot()
Metadata
Metadata
Assignees
Labels
No labels