ansys / pymapdl

Pythonic interface to MAPDL
https://mapdl.docs.pyansys.com
MIT License
423 stars 120 forks source link

First setup: Unable to connect to APDL server #137

Closed NMDekkers closed 5 years ago

NMDekkers commented 5 years ago

Hello,

I'm trying to get pyansys working, although I'm unable run the ansys_cylinder_demo() example, however the examples.run_all() does seem to work. I'm running: Windows 10 64-bit python 3.6.8 (ansys-cobra 0.1.0, numpy 1.17.2, pyansys 0.39.1, scipy 1.3.1, vtk 8.1.2) I'm running an Ansys 19.0 academic licence through a VPN connected to my university.

By running the code in the console:

from pyansys import examples
examples.ansys_cylinder_demo()

The following output is generated:

2019-09-16 13:32:14,451 [INFO] pyansys.mapdl: Connecting to ANSYS via CORBA
Traceback (most recent call last):
  File "C:\Users\Nick\AppData\Local\Programs\Python\Python36\lib\site-packages\pyansys\mapdl.py", line 1081, in open_corba
self.mapdl.getComponentName()
  File "C:\Users\Nick\AppData\Local\Programs\Python\Python36\lib\site-packages\ansys_corba\ICoMapdlUnit_idl.py", line 185, in getComponentName
return self._obj.invoke("getComponentName", _0_AAS_CORBA.MAPDL.Solvers.ICoMapdlUnit._d_getComponentName, args)
omniORB.CORBA._omni_sys_exc: CORBA.TRANSIENT(omniORB.TRANSIENT_ConnectFailed, CORBA.COMPLETED_NO)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<input>", line 2, in <module>
  File "C:\Users\Nick\AppData\Local\Programs\Python\Python36\lib\site-packages\pyansys\examples\examples.py", line 253, in ansys_cylinder_demo
ansys = pyansys.Mapdl(exec_file=exec_file, override=True, loglevel=loglevel)
  File "C:\Users\Nick\AppData\Local\Programs\Python\Python36\lib\site-packages\pyansys\mapdl.py", line 458, in __init__
self._open(additional_switches)
  File "C:\Users\Nick\AppData\Local\Programs\Python\Python36\lib\site-packages\pyansys\mapdl.py", line 472, in _open
self.open_corba(self.nproc, self.start_timeout, additional_switches)
  File "C:\Users\Nick\AppData\Local\Programs\Python\Python36\lib\site-packages\pyansys\mapdl.py", line 1083, in open_corba
raise Exception('Unable to connect to APDL server')
Exception: Unable to connect to APDL server

A non-responding Mechanical APDL Batch program will be running after the error. While writing this, the example ran successfully twice, when I ran the example just after connecting to the vpn, but running it another time gave the same error again. When just running the GUI, I don't seem to have any licensing issues. I'm suspecting that this has something to do with licencing of some sort, but I have no clue how to fix it and I'm not all to sure why the program is "Unable to connect to APDL server".

Any clue on to what to do to solve this issue? Thanks,

Nick

natter1 commented 5 years ago

Could you try to increase the start_timeout parameter (default 120)? You have to edit the ansys_cylinder_demo()-function in examples.py by adding something like start_timeout=800 to ansys = pyansys.Mapdl(...). On a sidenote, I have similar issues, when closing and restarting ansys several times inside a script. In such cases I solve the issue by adding a time.sleep(5). Not sure if thats related to this issue.

NMDekkers commented 5 years ago

Initially, this didn't work out and it gave a similar error adding:

Exception: Unable to connect to APDL server
Exception ignored in: <bound method Mapdl.__del__ of <pyansys.mapdl.Mapdl object at 0x000001720206C390>>
Traceback (most recent call last):
  File "C:\Users\Nick\AppData\Local\Programs\Python\Python36\lib\site-packages\pyansys\mapdl.py", line 952, in __del__
  File "C:\Users\Nick\AppData\Local\Programs\Python\Python36\lib\site-packages\pyansys\mapdl.py", line 980, in exit
    Exception: 'Popen' object has no attribute 'sendline'

But after restarting my vpn, it seemed to work. Then I tried restarting it again, and it failed again.

The "Unable to connect to APDL server" is rather instant and by default, it did not wait for 120 seconds to generate the error. I've tested a few things (for example running with no licence) and it seems that the 120 or 800 second time out only acts on the first time it is to be connected. So, once it fails to connect to the APDL server, it keeps failing even though the connection now is solid (even after opening a new python console). It sort of remembers the old failed connection, and the only way to get it working, is disconnecting to the vpn and reconnecting.

I've figured out that if I wait about 20 seconds after I've been connected to the VPN, that the ansys_cylinder_demo() seems to work and keeps working (from what I've tested in the last few minutes). If I'm too early with running the test after connecting to the vpn, the program is unable to connect.

Is there a way, that the connection is to be "re-checked" after it failed once in the past? Since, I can see the program failing to connect at some point in between several simulations and then being unable to be started again.

By the way, I'll check this again tomorrow on the university network to see how it behaves with a direct connection.

akaszynski commented 5 years ago

My guess is that the failed connection leaves MAPDL in the background and whenever it tries to connect again it's conflicting with the old failed MAPDL session. Closing that should help. I might be able to check for the failed instance and clean it up should it fail.

NMDekkers commented 5 years ago

That sounds logical, Is there a command for closing that specific instance?

No problems with the example runs on the university network by the way.

akaszynski commented 5 years ago

Found the issue and the failed process will be killed when the connection fails. Please let me know if you still have an issue with this with pyansys>=0.39.2. I'll push a new release by the end of the week.

pi314a commented 4 years ago

Hey there!

I have a similar problem. I'm trying to get pyansys working. Some weeks ago it works without problems. Yesterday I tried it again and it doesn't work anymore. By running this code for testing:

import os 
import pyansys

path = os.getcwd()
ansys = pyansys.Mapdl(run_location=path, jobname='file', override=True)

ansys.prep7()
ansys.k(1, 0, 0, 0)
ansys.save()
ansys.exit()

The following error occurs:

2020-04-16 15:16:58,956 [INFO] pyansys.mapdl: Connecting to ANSYS via CORBA
Traceback (most recent call last):
  File "C:\Users\pi\AppData\Local\Continuum\anaconda3\envs\environment_pi\lib\site-packages\pyansys\mapdl.py", line 1150, in open_corba
    self.mapdl.getComponentName()
  File "C:\Users\pi\AppData\Local\Continuum\anaconda3\envs\environment_pi\lib\site-packages\ansys_corba\ICoMapdlUnit_idl.py", line 185, in getComponentName
    return self._obj.invoke("getComponentName", _0_AAS_CORBA.MAPDL.Solvers.ICoMapdlUnit._d_getComponentName, args)
omniORB.CORBA.TRANSIENT: CORBA.TRANSIENT(omniORB.TRANSIENT_ConnectFailed, CORBA.COMPLETED_NO)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/pi/Python/Projekt/fe_model.py", line 5, in <module>
    ansys = pyansys.Mapdl(run_location=path, jobname='file', override=True)
  File "C:\Users\pi\AppData\Local\Continuum\anaconda3\envs\environment_pi\lib\site-packages\pyansys\mapdl.py", line 480, in __init__
    self._open(additional_switches)
  File "C:\Users\pi\AppData\Local\Continuum\anaconda3\envs\environment_pi\lib\site-packages\pyansys\mapdl.py", line 494, in _open
    self.open_corba(self.nproc, self.start_timeout, additional_switches)
  File "C:\Users\pi\AppData\Local\Continuum\anaconda3\envs\environment_pi\lib\site-packages\pyansys\mapdl.py", line 1152, in open_corba
    raise Exception('Unable to connect to APDL server')
Exception: Unable to connect to APDL server
2020-04-16 15:17:04,087 [ERROR] pyansys.mapdl: exit: 'Popen' object has no attribute 'sendline'
2020-04-16 15:17:04,087 [ERROR] pyansys.mapdl: kill: 'Popen' object has no attribute 'isalive'

MAPDL opens in the background. When I run MAPDL directly, there is no license problem.

I'm running: Windows 10 64-bit, ANSYS 19.1, Python 3.7 (and I tried Python 3.5) and pyansys 0.39.17. Currently I'm working with VPN.

Can someone help? Thanks