ansys / pymapdl

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

PyMAPDL exits intermittently while running in a loop when mapdl.input() command is used #2386

Open SamukhamSurya opened 9 months ago

SamukhamSurya commented 9 months ago

🤓 Before submitting the issue

🔍 Description of the bug

Hello,

I'm encountering an issue while running a PyMAPDL script in a for-loop for a large number of iterations (approximately 8000). In each iteration, I modify the node locations using an input file and then solve the problem. To change the node locations, I utilize the "mapdl.input(update_nodes.inp)" command, which executes a sequence of commands from the "update_nodes.inp" file (e.g., "n,x,y,z").

Unfortunately, after a few iterations, Mapdl terminates unexpectedly with the following error message:

File "d:\bitBucket\fcdslib_modalSensitivity\ModalSensitivity\modalSensitivity.py", line 143, in input_file self.mapdl.input(fname=inp_filename) File "D:\PythonVenvs\sensitivityAnalysis\sensitivityAnalysis\lib\site-packages\ansys\mapdl\core\errors.py", line 168, in wrapper raise MapdlExitedError("MAPDL server connection terminated") from None ansys.mapdl.core.errors.MapdlExitedError: MAPDL server connection terminated

I have identified that this issue is related to the stability of the "mapdl.input()" command.

🕵️ Steps To Reproduce

from ansys.mapdl.core import launch_mapdl
mapdl = launch_mapdl()

for i in range(5000):
    mapdl.resume('test.db')
    inputfile = 'inputfile_'+ str(i)
    mapdl.input(inputfile)
    mapdl.solve()

💻 Which Operating System are you using?

Windows

🐍 Which Python version are you using?

3.10

📝 PyMAPDL Report

PyMAPDL Software and Environment Report

Packages Requirements


Core packages

ansys.mapdl.core : 0.66.0 numpy : 1.25.2 platformdirs : 3.10.0 scipy : 1.11.2 grpc : Package not found ansys.api.mapdl.v0 : Package not found ansys.mapdl.reader : 0.52.20 google.protobuf : Package not found

Optional packages

matplotlib : 3.8.0 pyvista : 0.42.2 pyiges : 0.3.1 tqdm : 4.66.1

Ansys Installation


Version Location

222 C:\Program Files\ANSYS Inc\v222 231 C:\Program Files\ANSYS Inc\v231 232 C:\Program Files\ANSYS Inc\v232

Ansys Environment Variables


ANSYS 6855@DECEAL2.honeywell.com ANSYS222_DIR C:\Program Files\ANSYS Inc\v222\ANSYS ANSYS231_DIR C:\Program Files\ANSYS Inc\v231\ANSYS ANSYS232_DIR C:\Program Files\ANSYS Inc\v232\ANSYS ANSYSLIC_DIR C:\Program Files\ANSYS Inc\Shared Files\Licensing ANSYSLI_FLEXLM_TIMEOUT_ENV 10000000 ANSYSLI_TIMEOUT_CONNECT 90 ANSYSLI_TIMEOUT_FLEXLM 10 ANSYSLI_TIMEOUT_TCP 90 ANSYSLMD_LICENSE_FILE 6855@DECEAL2.honeywell.com AWP_LOCALE222 en-us AWP_LOCALE231 en-us AWP_LOCALE232 en-us AWP_ROOT222 C:\Program Files\ANSYS Inc\v222 AWP_ROOT231 C:\Program Files\ANSYS Inc\v231 AWP_ROOT232 C:\Program Files\ANSYS Inc\v232 CADOE_LIBDIR222 C:\Program Files\ANSYS Inc\v222\CommonFiles\Language\en-us CADOE_LIBDIR231 C:\Program Files\ANSYS Inc\v231\CommonFiles\Language\en-us CADOE_LIBDIR232 C:\Program Files\ANSYS Inc\v232\CommonFiles\Language\en-us

📝 Installed packages

ansys-api-fluent==0.3.12 ansys-api-mapdl==0.5.1 ansys-api-mechanical==0.1.0 ansys-api-meshing-prime==0.1.1 ansys-api-platform-instancemanagement==1.0.0 ansys-api-pyensight==0.3.0 ansys-api-sherlock==0.1.14 ansys-api-systemcoupling==0.1.0 ansys-dpf-composites==0.2.0 ansys-dpf-core==0.8.1 ansys-dpf-gate==0.3.1 ansys-dpf-gatebin==0.4.1 ansys-dpf-post==0.4.0 ansys-dynamicreporting-core==0.4.0 ansys-fluent-core==0.14.0 ansys-grantami-bomanalytics==1.1.3 ansys-grantami-bomanalytics-openapi==1.0.0 ansys-grantami-recordlists==1.0.0 ansys-grantami-serverapi-openapi==1.0.0 ansys-grpc-dpf==0.8.1 ansys-mapdl-core==0.66.0 ansys-mapdl-reader==0.52.20 ansys-math-core==0.1.3 ansys-mechanical-core==0.8.0 ansys-meshing-prime==0.4.0 ansys-motorcad-core==0.1.3 ansys-openapi-common==1.2.1 ansys-optislang-core==0.2.1 ansys-platform-instancemanagement==1.1.1 ansys-pyensight-core==0.5.3 ansys-pythonnet==3.1.0rc1 ansys-seascape==0.2.0 ansys-sherlock-core==0.2.0 ansys-systemcoupling-core==0.1.3 ansys-tools-path==0.3.1 appdirs==1.4.4 asgiref==3.7.2 build==1.0.3 cachetools==5.3.1 certifi==2023.7.22 cffi==1.15.1 charset-normalizer==3.2.0 click==8.1.7 clr-loader==0.2.6 colorama==0.4.6 contourpy==1.1.0 cryptography==41.0.3 cycler==0.11.0 Django==4.2.5 docutils==0.20.1 filelock==3.12.4 fonttools==4.42.1 geomdl==5.3.1 google-api-core==2.11.1 google-api-python-client==2.99.0 google-auth==2.23.0 google-auth-httplib2==0.1.1 googleapis-common-protos==1.60.0 grpcio==1.58.0 grpcio-status==1.48.2 h5py==3.9.0 httplib2==0.22.0 idna==3.4 imageio==2.31.3 importlib-metadata==6.8.0 jaraco.classes==3.3.0 keyring==24.2.0 kiwisolver==1.4.5 lxml==4.9.3 markdown-it-py==3.0.0 matplotlib==3.8.0 mdurl==0.1.2 more-itertools==10.1.0 nh3==0.2.14 numpy==1.25.2 packaging==23.1 pandas==2.1.0 Pillow==10.0.1 pkginfo==1.9.6 platformdirs==3.10.0 plumbum==1.8.2 pooch==1.7.0 protobuf==3.20.3 psutil==5.9.5 pyaedt==0.6.76 pyansys==2023.2.9 pyansys-docker==5.0.4 pyansys-tools-versioning==0.4.0 pyasn1==0.5.0 pyasn1-modules==0.3.0 pycparser==2.21 Pygments==2.16.1 pyiges==0.3.1 pyparsing==3.1.1 pypiwin32==223 pypng==0.20220715.0 pyproject_hooks==1.0.0 pyspnego==0.9.2 python-dateutil==2.8.2 pythonnet==3.0.1 pytwin==0.3.0 pytz==2023.3.post1 pyvista==0.42.2 pywin32==306 pywin32-ctypes==0.2.2 PyYAML==6.0.1 readme-renderer==42.0 requests==2.31.0 requests-negotiate-sspi==0.5.2 requests-ntlm==1.2.0 requests-toolbelt==1.0.0 rfc3986==2.0.0 rich==13.5.2 rpyc==5.3.1 rsa==4.9 scipy==1.11.2 scooby==0.7.2 six==1.16.0 sqlparse==0.4.4 tomli==2.0.1 tqdm==4.66.1 twine==4.0.2 typing==3.7.4.3 typing_extensions==4.7.1 tzdata==2023.3 uritemplate==4.1.1 urllib3==1.26.16 vtk==9.2.5 websocket-client==1.6.3 zipp==3.16.2

📝 Logger output file

CRITICAL - pymapdl_global - logging - handle_exception - Uncaught exception Traceback (most recent call last): File "d:\bitBucket\fcdslib_modalSensitivity\ModalSensitivity\Main.py", line 33, in result = obj.perform_modelSensitivity(niter=None) File "d:\bitBucket\fcdslib_modalSensitivity\ModalSensitivity\modalSensitivity.py", line 73, in perform_modelSensitivity disp_pert[iter,:] = self.perturb_surf_nds(seed=0) File "d:\bitBucket\fcdslib_modalSensitivity\ModalSensitivity\modalSensitivity.py", line 168, in perturb_surf_nds surf_ndInd_to_modfy = self._extract_surf_node_ind_modfy(surf_grid) File "d:\bitBucket\fcdslib_modalSensitivity\ModalSensitivity\modalSensitivity.py", line 146, in _extract_surf_node_ind_modfy self.input_file('blade.dat.comp') File "d:\bitBucket\fcdslib_modalSensitivity\ModalSensitivity\modalSensitivity.py", line 143, in input_file self.mapdl.input(fname=inp_filename) File "D:\PythonVenvs\sensitivityAnalysis\sensitivityAnalysis\lib\site-packages\ansys\mapdl\core\errors.py", line 168, in wrapper raise MapdlExitedError("MAPDL server connection terminated") from None ansys.mapdl.core.errors.MapdlExitedError: MAPDL server connection terminated

germa89 commented 9 months ago

Hi @SamukhamSurya

Do you think you can share a minimum working example with the input files and the db file?

SamukhamSurya commented 9 months ago

Hello @germa89, Sorry, I cannot share.

germa89 commented 9 months ago

Since I'm going to need to engineer the MWE, it will take time until I find the time to do so.

germa89 commented 9 months ago

Possible duplicated of https://github.com/ansys/pymapdl/issues/1577 and/or https://github.com/ansys/pymapdl/issues/1419

iitkshail commented 4 months ago

@germa89: Do we have any quick fix/alternate here? I am also struggling with the mapdl.input() related MAPDL server interruption. I run mapdl.input() in loop with more than 100 times reading directly the old APDL script and these server interruption is very random. Currently, I can not convert the APDL scripts to pythonic way. Any suggestion is much appreciated. At the moment I can not share the related content.

germa89 commented 4 months ago

If the input file you are executing, it is always the same. I would upload it and then do something like:

mapdl.run("/input,myapdl.inp")

So you bypass having to submit the input file all time.

I didn't test this, so we might need to iterate a bit until getting it right.

yunzhiliuliu commented 4 months ago

Glad that I found this post. :) I am facing exactly the same issue of using mapdl.input() in a loop. What I am doing: export Mechanical.inp from Ansys Mechanical, then using Python to modify the .inp file regarding material properties and loads (>1000 combinations) and run them using mapdl.input(). As the .inp from Mecahnical already includes everything, the mapdl.input() will start the calculation directly. All works fine, but this error came out: raise MapdlExitedError("MAPDL server connection terminated") from None

Please guide me how to use: mapdl.run("/input,myapdl.inp") As I tried but it did not work (no calculation is carried on): image I think I need to modify the Mechanical.inp first, but I do not know what to change.

germa89 commented 4 months ago

Hi... Can you try with mapdl.input('Mechanical.inp')??

I believe running /INPUT does not work in gRPC mode.

yunzhiliuliu commented 4 months ago

@germa89 Thanks for your quick reply. mapdl.input('Mechanical.inp') works well. But the point of the discussion here is that it does not work in a loop.... Would be nice to know a workaround. That is why I am trying mapdl.run("/input,myapdl.inp") as you mentioned.

germa89 commented 4 months ago

mmhh... you could use mapdl.save and mapdl.resume instead of input again the file... that way you dont need to use mapdl.input more than once...

mapdl.input("mechanical.inp")
... # do changes
mapdl.save()
for i in range(something):
    ... # do changes
    ... # get results
    mapdl.resume() # returning to saved state.

You need to be careful to not read in results from previous steps though.