pyfluent code

Jinane Radi
Jinane Radi Member Posts: 5
Name Dropper First Comment
**

hello everyone , I'm new in using pyfluent ,I've created this code from a YouTube video
concerning the utilization of pyfluent .
the code works perfectly until the line when Fluent should switch to solution mode. its gives me this error

the code I have written is below

import ansys.fluent.core as pyfluent
meshing_session = pyfluent.launch_fluent(precision="double", processor_count=2, mode ="meshing" ,show_gui=True)
workflow=meshing_session.workflow
meshing=meshing_session.meshing

workflow.InitializeWorkflow(WorkflowType=r'Fault-tolerant Meshing')
workflow.InitializeWorkflow(WorkflowType=r'Watertight Geometry')
meshing.GlobalSettings.LengthUnit.set_state(r'mm')
meshing.GlobalSettings.AreaUnit.set_state(r'mm^2')
meshing.GlobalSettings.VolumeUnit.set_state(r'mm^3')
workflow.TaskObject['Import Geometry'].Arguments.set_state({r'FileName': r'C:/Users/DELL/Desktop/Fluent ANSYS/Static Mixer geometry.dsco',})
workflow.TaskObject['Import Geometry'].Execute()

workflow.TaskObject['Add Local Sizing'].AddChildAndUpdate()
workflow.TaskObject['Generate the Surface Mesh'].Execute()
workflow.TaskObject['Describe Geometry'].UpdateChildTasks(SetupTypeChanged=False)
workflow.TaskObject['Describe Geometry'].Arguments.set_state({r'SetupType': r'The geometry consists of only fluid regions with no voids',})
workflow.TaskObject['Describe Geometry'].UpdateChildTasks(SetupTypeChanged=True)
workflow.TaskObject['Describe Geometry'].Execute()
workflow.TaskObject['Update Boundaries'].Execute()
workflow.TaskObject['Update Regions'].Execute()
workflow.TaskObject['Add Boundary Layers'].AddChildAndUpdate()
workflow.TaskObject['Generate the Volume Mesh'].Execute()
meshing.excute_tui(r'''/switch-to-solution-mode''')
solver.execute_tui(r'''(newline)''')
solver.setup.models.energy = {"enabled" : True}
solver.tui.define.materials.copy('fluid', 'water-liquid')
solver.setup.cell_zone_conditions.fluid['fluid'] = {"material" : "water-liquid"}
solver.setup.boundary_conditions.velocity_inlet['velocity-inlet-1'] = {"vmag" : 0.}
solver.setup.boundary_conditions.velocity_inlet['velocity-inlet-1'] = {"vmag" : 0.}
solver.setup.boundary_conditions.velocity_inlet['velocity-inlet-2'] = {"vmag" : 1.}
solver.setup.boundary_conditions.velocity_inlet['velocity-inlet-2'] = {"vmag" : 1.}
solver.solution.initialization.hybrid_initialize()
solver.solution.run_calculation.iterate(iter_count = 20)
solver.exit()

Tagged:

Answers

  • PabloA
    PabloA Member, Employee Posts: 2
    Name Dropper First Comment First Anniversary Ansys Employee
    ✭✭✭
    edited January 31

    Hi Jinane,

    execute_tui is not available for meshing interface. As good practices, please do not use scheme or journal commands if they can be avoided. You can fix your problem by using

    solver = meshing_session.switch_to_solver()

    instead of the journal command.

    Regards

  • Jinane Radi
    Jinane Radi Member Posts: 5
    Name Dropper First Comment
    **

    Hello Mr.Pabloa , thank you so much , it works perfectly .

    Since I am a beginner in using pyfluent , what do you mean by not using scheme or journal commands ?

    by the way , Do you have any ideas on how to save this work, for example, in a folder such as a fluent file?
    sincerely