Ansys Fluent workflow#

In this example, the application of PyWorkbench, a Python client scripting tool for Ansys Workbench, is demonstrated in a use case for Ansys Fluent Workflow. The Ansys Fluent TUI (Text User Interface) journal files are utilized to set up and solve the simulation. For meshing Ansys Fluent Meshing WTM (Water Tight Meshing Workflow)is employed through recorded journaling capabilites of Ansys Fluent. As aware, Workbench offers the ability to record actions performed in the user interface, also known as journaling. These recorded actions are saved as Python scripts, which allow for extending functionality, automating repetitive analyses, and running analyses in batch mode. This example demonstrates how to use such a journal file with PyWorkbench for Ansys Fluent Workflow.

This example sets up and solves a three-dimensional turbulent fluid flow and heat transfer problem in a mixing elbow, which is common in piping systems in power plants and process industries. Predicting the flow field and temperature field in the area of the mixing region is important to designing the junction properly.

Problem description#

A cold fluid at 20 deg C flows into the pipe through a large inlet. It then mixes with a warmer fluid at 40 deg C that enters through a smaller inlet located at the elbow. The pipe dimensions are in inches, and the fluid properties and boundary conditions are given in SI units. Because the Reynolds number for the flow at the larger inlet is 50,800, a turbulent flow model is required.

What this tutorial covers#

This use case that demonstrates following PyWorkbench API capabilities such as: - Initiating the Ansys Workbench server locally and establishing a connection with a local client. - Uploading the required input data from client working directory to server working directory. - Executing the Ansys Workbench journal (.wbjn) script on the server, which will execute the Fluent simulation using setup.jou and solve.jou TUI scripts. refer assets for simulation input data. - Downloading the results from the server to client. - Shutting down the server.

Performed required imports#

Performing essential imports for Ansys Workbench, pathlib to handle filesystems path.

[1]:
import pathlib
from ansys.workbench.core import launch_workbench

Setting up server Working directory and asset paths#

[2]:
workdir = pathlib.Path("__file__").parent

server_workdir = workdir / 'server_workdir'
server_workdir.mkdir(exist_ok=True)

assets = workdir / "assets"
scdoc = assets /"scdoc"
jou = assets / "jou"

Launch the workbench session with specified Ansys release version, server and client working directories#

[3]:
wb = launch_workbench(release="241", server_workdir=str(server_workdir.absolute()), client_workdir=str(workdir.absolute()))

Uploading the input data#

Upload several input files (Geometry, Ansys Fluent simulation setup and solve journal files ), which will be transferred to the host.

[4]:
wb.upload_file(str(scdoc / "mixing_elbow.scdoc"))
wb.upload_file(str(jou / "setup.jou"))
wb.upload_file(str(jou / "solve.jou"))
Uploading mixing_elbow.scdoc: 100%|██████████| 89.5k/89.5k [00:00<00:00, 5.87MB/s]
Uploading setup.jou: 100%|██████████| 2.00k/2.00k [00:00<?, ?B/s]
Uploading solve.jou: 100%|██████████| 758/758 [00:00<?, ?B/s]

Executing a workbench script#

This will configure the workbench project schematic. This file is Ansys Workbench recorded journal file (Python Script). This can be easily configured as per requirement. >Note: For a better understanding of how meshing, setup, and solve workflows are being utilized, please refer to the project.wbjn file.

[5]:
sys_name = wb.run_script_file(str((assets / "project.wbjn").absolute()))
ERROR:root:Error when running the script: CommandFailedException: The FLUENT application failed to validate the connection.

Downloading output files to the client-side working directory#

Here, only the contour saved during the simulation data post-processing is being downloaded. But one can download all the output as required.

[6]:
wb.download_file("temperature_contour.jpeg")
ERROR:root:Error during file download: Could not find file 'C:/Users/ansys/actions-runner/_work/pyworkbench-examples/pyworkbench-examples/pyworkbench-examples/doc/source/examples/ansys-fluent-workflow/server_workdir\temperature_contour.jpeg'.

Shutdown the Ansys Workbench server session#

[7]:
wb.exit()
[ ]: