ansys / pyfluent

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

Running external compressible flow script with gpu=True #2500

Closed lord644 closed 6 months ago

lord644 commented 8 months ago

πŸ” Before submitting the issue

🐞 Description of the bug

Hello again, I have recently update Fluent solver to 2024R1 as well as ansys-fluent-core to 0.19.2 and Python to 3.11.8. I still have an issue running External Compressible Flow script with gpu=True.

########################################################### .... Mesh is now scaled to meters.

Error: invalid command Error Object: "solve"

Error: invalid command Error Object: "solve" Warning: Pressure far-field boundary condition can only be used with ideal gas law. Please change either the boundary condition type or enable ideal gas law. Solver cannot proceed until this is fixed. Traceback (most recent call last): File "c:\Users\mathieu\Documents\Experiments\fluent\external_compressible_flow.py", line 228, in solver = meshing.switch_to_solver() ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\mathieu\miniconda3\envs\pyfluent\Lib\site-packages\ansys\fluent\core\session_meshing.py", line 33, in self.switch_to_solver = lambda: self._switch_to_solver() ^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\mathieu\miniconda3\envs\pyfluent\Lib\site-packages\ansys\fluent\core\session_meshing.py", line 37, in _switch_to_solver self.tui.switch_to_solution_mode("yes") File "C:\Users\mathieu\miniconda3\envs\pyfluent\Lib\site-packages\ansys\fluent\core\meshing\tui_241.py", line 55, in switch_to_solution_mode return PyMenu(self._service, self._version, self._mode, "/switch_to_solution_mode").execute(*args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\mathieu\miniconda3\envs\pyfluent\Lib\site-packages\ansys\fluent\core\services\datamodel_tui.py", line 243, in execute return self._service.execute_command(self._path, args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\mathieu\miniconda3\envs\pyfluent\Lib\site-packages\ansys\fluent\core\services\datamodel_tui.py", line 161, in execute_command return self._impl.execute_command(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\mathieu\miniconda3\envs\pyfluent\Lib\site-packages\ansys\fluent\core\services\error_handler.py", line 15, in func raise RuntimeError(ex.details()) from None RuntimeError: invalid command Error Object: solve

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

What can I do to fix it ?

πŸ“ Steps to reproduce

Activate gpu in python script (l.62) https://fluent.docs.pyansys.com/version/stable/_downloads/b8aa6db4291033ee466dd4c2737e1e8d/external_compressible_flow.py

i.e.

meshing = pyfluent.launch_fluent( precision="double", processor_count=4, gpu=True, mode="meshing", )

πŸ’» Which operating system are you using?

Windows

πŸ“€ Which ANSYS version are you using?

Fluent 2024R1

🐍 Which Python version are you using?

3.11

πŸ“¦ Installed packages

ansys-api-fluent==0.3.22
ansys-api-platform-instancemanagement==1.0.0
ansys-fluent-core==0.19.2
ansys-platform-instancemanagement==1.1.2
beartype==0.17.2
certifi==2024.2.2
charset-normalizer==3.3.2
docker==7.0.0
grpcio==1.62.0
grpcio-health-checking==1.48.2
idna==3.6
importlib-metadata==7.0.1
lxml==5.1.0
numpy==1.26.4
packaging==23.2
pandas==2.2.1
platformdirs==4.2.0
protobuf==3.20.3
psutil==5.9.8
python-dateutil==2.8.2
pytz==2024.1
pywin32==306
PyYAML==6.0.1
requests==2.31.0
six==1.16.0
tzdata==2024.1
urllib3==2.2.1
zipp==3.17.0
lord644 commented 8 months ago

Hello pyFluent team, do you need extra information to fix this issue or may I have missed something ?

mkundu1 commented 8 months ago

I can reproduce this error in latest Fluent/PyFluent. We need to investigate/fix this on the Fluent side. For a workaround, you can write the mesh from a CPU meshing session and read it is a GPU solver session.

lord644 commented 8 months ago

Thank you Mainak, so I ended up replacing the switch to solver call like this

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

solver = meshing.switch_to_solver()

meshing.exit() solver = pyfluent.launch_fluent( precision="double", processor_count=4, show_gui=True, gpu=True, mode="solver", ) solver.file.read(file_type="mesh", file_name="C:/Users/mathieu/AppData/Local/Ansys/ansys_fluent_core/examples/wing.msh.h5") ..... #############################################################

As you said the solver call can now make use of GPU acceleration. I still have 2 questions:

1. Regarding that specific external_compressible_flow.py example the script ends like this: ###############################################################################

Save case file

~~~~~~

Save the case file external_compressible1.cas.h5.

solver.file.write(file_name="external_compressible.cas.h5", file_type="case")

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

Solve for 25 iterations

~~~~~~~~

Solve for 25 iterations (100 iterations is recommended, however for this example 25 is sufficient).

solver.solution.run_calculation.iterate(iter_count=25)

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

Write final case file and data

~~~~~~~

Write the final case file and the data.

solver.file.write(file_name="external_compressible1.cas.h5", file_type="case") #################################################################################

As far as I understand the first call to solver.file.write saves both mesh and problem description and the second is supposed to store both the case and results. But I notice that both external_compressible.cas.h5 and external_compressible1.cas.h5 have the same size on disk, so I assume that the result isn't saved.

  1. I tried a bunch of other examples located in pyfluent-examples/examples/00-released_examples/ and all of them (excepting 'ablation' test case) have an issue even when the GPU option is turned off. Is there a repo somewhere with working examples? How can I contribute to improve them?
mkundu1 commented 8 months ago

@lord644 Right, the command for saving case and data is

solver.file.write(file_name="external_compressible1.cas.h5", file_type="case-data")

or

solver.file.write_case_data(file_name="external_compressible1.cas.h5")  # preferred

The above call will write both external_compressible1.cas.h5 and external_compressible1.dat.h5.

Feel free to fork the repo and create a PR. You can find the general contribution guidelines here.

lord644 commented 8 months ago

Is there a way to follow the state of that issue, here or on the fluent side ?

mkundu1 commented 8 months ago

Please use the current issue for tracking purpose.

mkundu1 commented 6 months ago

Fluent bug id - 1023325

mkundu1 commented 6 months ago

This will be fixed in Fluent version 2024 R2