ansys / pyfluent

Pythonic interface to Ansys Fluent
https://fluent.docs.pyansys.com
MIT License
277 stars 41 forks source link

TimestepEndedEvent callback synchronous #2361

Closed baldang closed 1 month ago

baldang commented 10 months ago

🔍 Before submitting the issue

🐞 Description of the bug

I am running an unsteady simulation and I am using a callback at the end of each time step

def callback_executed_at_end_of_time_step(session_id, event_info):
        time.sleep(5)

cb_itr_id = solver.events_manager.register_callback('TimestepEndedEvent', callback_executed_at_end_of_time_step)

I would like to have a "synchronous" behavior, meaning that the next time step is computed only when the computations (above replaced with a 5s sleep) inside the callback_executed_at_end_of_time_step are terminated. Is there any chance to obtain this?

The same behavior is reproducible in Linux and Windows with python 3.11.

📝 Steps to reproduce

def callback_executed_at_end_of_time_step(session_id, event_info):
        time.sleep(5)

cb_itr_id = solver.events_manager.register_callback('TimestepEndedEvent', callback_executed_at_end_of_time_step)

💻 Which operating system are you using?

Windows

📀 Which ANSYS version are you using?

23R2

🐍 Which Python version are you using?

3.11

📦 Installed packages

ansys-api-fluent==0.3.19
ansys-api-platform-instancemanagement==1.0.0
ansys-fluent-core==0.18.2
ansys-platform-instancemanagement==1.1.2
certifi==2023.11.17
charset-normalizer==3.3.2
contourpy==1.0.6
cycler==0.11.0
docker==7.0.0
et-xmlfile==1.1.0
fonttools==4.38.0
gmsh==4.11.1
grpcio==1.60.0
grpcio-health-checking==1.48.2
idna==3.6
importlib-metadata==7.0.0
Jinja2==3.1.2
kiwisolver==1.4.4
lxml==4.9.3
markdown-it-py==3.0.0
MarkupSafe==2.1.3
matplotlib==3.6.2
mdurl==0.1.2
meshio==5.3.4
mpld3==0.5.9
numpy==1.23.4
openpyxl==3.1.2
packaging==21.3
pandas==2.1.4
Pillow==9.3.0
platformdirs==4.1.0
protobuf==3.20.3
psutil==5.9.7
Pygments==2.17.2
pygmsh==7.1.17
pyparsing==3.0.9
pytecplot==1.5.1
python-dateutil==2.8.2
pytz==2022.6
pywin32==306
PyYAML==6.0.1
pyzmq==25.0.0
requests==2.31.0
rich==13.7.0
scipy==1.11.4
six==1.16.0
style==1.1.0
tzdata==2023.3
update==0.0.1
urllib3==2.1.0
zipp==3.17.0
ajain-work commented 10 months ago

At present it is not possible.

mkundu1 commented 10 months ago

We can look into implementing this as a PyFluent feature. One option is to use the AutoPauseEvent event.

baldang commented 9 months ago

Many thanks for the support, I updated ansys-fluent-core to 0.19.2 (fluent 23R2) but I get the following error:

ansys.fluent.core.exceptions.DisallowedValuesError: AutoPauseEvent is not an allowed event-name name.
The most similar names are: AboutToReadCaseEvent.
mkundu1 commented 9 months ago

Many thanks for the support, I updated ansys-fluent-core to 0.19.2 (fluent 23R2) but I get the following error:

ansys.fluent.core.exceptions.DisallowedValuesError: AutoPauseEvent is not an allowed event-name name.
The most similar names are: AboutToReadCaseEvent.

The AutoPauseEvent is available in the main branch only. For now, the script shared above should work, we plan to release this as a feature in future.