ansys / pyworkbench

PyWorkbench
http://workbench.docs.pyansys.com/
MIT License
2 stars 4 forks source link

Fluent UI doesn't close after exit command #20

Closed mkvani closed 1 year ago

mkvani commented 1 year ago

πŸ” Before submitting the issue

🐞 Description of the bug

On WB, Fluent cell is connected through server info file:

server_info_file = wb.start_fluent_server(system_name= "FLU")

And Fluent is launched. using PyFluent command: fluent_session = pyfluent.connect_to_fluent(server_info_filepath= server_info_file)

However, when exit command is passed, Fluent GUI does not get closed.

Following is the test script to reproduce:

################################################## from ansys.workbench.core import launch_workbench import ansys.fluent.core as pyfluent

Please change these paths

client_dir = r'D:\users\mvani\PyWB\PyWB-examples\pyfluent_mixing_elbow\client_work_dir' server_dir = r'D:\users\mvani\PyWB\PyWB-examples\pyfluent_mixing_elbow\server_work_dir'

host = 'localhost' release = '241'

wb = launch_workbench(release=release, server_workdir=server_dir, client_workdir=client_dir)

Create Fluent system on WB

wb.run_script_string('template1 = GetTemplate(TemplateName="FLUENT")') wb.run_script_string('system1 = template1.CreateSystem()')

Launch Fluent

server_info_file = wb.start_fluent_server(system_name= "FLU") fluent_session = pyfluent.connect_to_fluent(server_info_filepath= server_info_file)

fluent_session.exit()

#################################################################

βœ… Expected behavior

After exit command is passed, Fluent UI should close after appropriate WB actions are complete (like saving cas/dat files) and updating WB cell status.

πŸ“ Steps to reproduce

1) In the test script provided under "Description of the bug", change the "client_dir" and "server_dir" paths 2) Execute the script

πŸ“ƒ Relevant log output

Ansys Version: image

Following is the Python module lsit (output of pip list):

Package Version


ansys-api-fluent 0.3.17
ansys-api-platform-instancemanagement 1.0.0
ansys-api-workbench 0.1.7
ansys-fluent-core 0.17.1 ansys-platform-instancemanagement 1.1.2 ansys-pythonnet 3.1.0rc1 ansys-tools-path 0.3.1 ansys-workbench-core 0.3.dev0 asttokens 2.4.0 backcall 0.2.0 certifi 2023.7.22 cffi 1.15.1 charset-normalizer 3.2.0 clr-loader 0.2.6 colorama 0.4.6 comm 0.1.4 debugpy 1.8.0 decorator 5.1.1 docker 6.1.3 executing 1.2.0 grpcio 1.58.0 grpcio-health-checking 1.48.2 h5py 3.9.0 idna 3.4 importlib-metadata 6.8.0 ipykernel 6.25.2 ipython 8.12.2 jedi 0.19.0 jupyter-client 8.3.1 jupyter-core 5.3.1 lxml 4.9.3 matplotlib-inline 0.1.6 nest-asyncio 1.5.8 numpy 1.24.4 packaging 23.1 pandas 2.0.3 parso 0.8.3 pickleshare 0.7.5 pip 21.1.1 platformdirs 3.10.0 prompt-toolkit 3.0.39 protobuf 3.20.3 psutil 5.9.5 pure-eval 0.2.2 pycparser 2.21 Pygments 2.16.1 python-dateutil 2.8.2 pytz 2023.3.post1 pywin32 306 PyYAML 6.0.1 pyzmq 25.1.1 requests 2.31.0 setuptools 56.0.0 six 1.16.0 stack-data 0.6.2 tornado 6.3.3 tqdm 4.66.1 traitlets 5.10.0 typing-extensions 4.8.0 tzdata 2023.3 urllib3 2.0.5 wcwidth 0.2.6 websocket-client 1.6.3 WMI 1.5.1 zipp 3.17.0

mkvani commented 1 year ago

@franknli Could you please look into this issue.

franknli commented 1 year ago

Hi @mkvani

PyFluent's exit command does not necessarily close the Fluent application - it probably depends on the state when the service was brought up: the behavior might be different when the PyFluent was started out of Workbench. Ultimately this is a PyFluent behavior that PyWorkbench cannot control.

However, you can always close Fluent application using existing Workbench commands, as illustrated by the Jupyter Notebook pasted below:

{ "cells": [ { "cell_type": "markdown", "id": "558376fd-674a-424c-8885-65a872acfd95", "metadata": {}, "source": [ "# Exiting PyFluent out of PyWorkbench session" ] }, { "cell_type": "code", "execution_count": null, "id": "014c5732-9f2b-423d-81ed-8e70928b2e47", "metadata": { "tags": [] }, "outputs": [], "source": [ "import os\n", "import json\n", "from ansys.workbench.core import launch_workbench\n", "import ansys.fluent.core as pyfluent" ] }, { "cell_type": "code", "execution_count": null, "id": "705a3b24-b51d-4724-8a17-f7307873197c", "metadata": { "tags": [] }, "outputs": [], "source": [ "# launch Workbench on the local machine\n", "wb = launch_workbench(client_workdir='C:/Users/fli/manoj_demo')" ] }, { "cell_type": "code", "execution_count": null, "id": "b6af4888-7482-4c40-96da-c959b4147b3a", "metadata": {}, "outputs": [], "source": [ "# create a Fluent system and return its name\n", "fluent_sys_name = wb.run_script_string('import json\nwb_script_result=json.dumps(GetTemplate(TemplateName=\\"FLUENT\\").CreateSystem().Name)')" ] }, { "cell_type": "code", "execution_count": null, "id": "e88ab850-d840-4919-954c-eacd29a699fd", "metadata": {}, "outputs": [], "source": [ "# start PyFluent server on the system, then create a PyFluent client session\n", "server_info_file=wb.start_fluent_server(system_name=fluent_sys_name)\n", "fluent=pyfluent.connect_to_fluent(server_info_filepath=server_info_file)" ] }, { "cell_type": "code", "execution_count": null, "id": "221ad401-82d1-480d-8910-da0dd34b5a2c", "metadata": { "tags": [] }, "outputs": [], "source": [ "# check if the PyFluent server is running\n", "print('server is serving? ', fluent.health_check_service.is_serving)" ] }, { "cell_type": "code", "execution_count": null, "id": "ad742a8f-6f42-427e-adc8-f66e1458bbea", "metadata": {}, "outputs": [], "source": [ "# exit PyFluent server and make sure that the server is no longer running\n", "fluent.exit()\n", "print('server is serving? ', fluent.health_check_service.is_serving)" ] }, { "cell_type": "code", "execution_count": null, "id": "48320724-37fb-41d4-959e-d9b0437a7bff", "metadata": {}, "outputs": [], "source": [ "# The Fluent application is still up at this point\n", "# One can always use existing WB command to close it\n", "wb.run_script_string(fr'''GetSystem(Name=\"{fluent_sys_name}\").GetContainer(ComponentName=\"Setup\").Exit()''')" ] }, { "cell_type": "code", "execution_count": 19, "id": "6dfe8b49-c81b-4718-851e-e1f6f0f30a12", "metadata": { "tags": [] }, "outputs": [], "source": [ "# shutdown the Workbench service\n", "wb.exit()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.4" } }, "nbformat": 4, "nbformat_minor": 5 }