ansys / pymapdl

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

Bug located in mapdl.get command #2430

Closed pvargasm closed 10 months ago

pvargasm commented 11 months ago

🤓 Before submitting the issue

🔍 Description of the bug

IndexError is triggered when mapdl.get is executed for entities (material in this case) that requires definition of item3argument.

Check mapdl.py. L2792 Assumes that when item3 is enabled, value has more than one line. So, a previous verification of value number of lines will avoid this issue.

🕵️ Steps To Reproduce

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

mapdl.prep7()

# tbopt corresponds to a particular material-law within material definition
tbopt = 1

# material definition
mapdl.tb(lab="CREE", mat=1, tbopt=tbopt)
mapdl.tbtemp(0)
mapdl.tbdata(stloc=1,c1=10,c2=20,c3=30,c4=40)

# material query and "IndexError" from mapdl.get method 
value=mapdl.get(entity="CREE", entnum="1", item1="TEMP", it1num=0, item2="CONST", it2num=3, item3=tbopt)

💻 Which Operating System are you using?

Windows

🐍 Which Python version are you using?

3.10

📝 PyMAPDL Report

Show the Report! ```text D:\src\Qt_env\lib\site-packages\pyvista\utilities\__init__.py:69: PyVistaDeprecationWarning: The `pyvista.utilities` module has been deprecated. `GPUInfo` is now imported as: `from pyvista.report import GPUInfo`. warnings.warn( ------------------------------------------------------------------------------- PyMAPDL Software and Environment Report Packages Requirements ********************* Core packages ------------- ansys.mapdl.core : 0.67.0 numpy : 1.26.1 platformdirs : 3.11.0 scipy : 1.11.3 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.3 pyiges : 0.3.1 tqdm : 4.66.1 Ansys Installation ****************** Version Location ------------------ 221 C:\Program Files\ANSYS Inc\v221 231 C:\Program Files\ANSYS Inc\v231 232 C:\Program Files\ANSYS Inc\v232 241 D:\ANSYSDev\ANSYS Inc\v241 Ansys Environment Variables *************************** ANSYS221_DIR C:\Program Files\ANSYS Inc\v221\ANSYS ANSYS231_DIR C:\Program Files\ANSYS Inc\v231\ANSYS ANSYS232_DIR C:\Program Files\ANSYS Inc\v232\ANSYS ANSYS241_DIR D:\ANSYSDev\ANSYS Inc\v241\ANSYS ANSYSLIC_DIR C:\Program Files\ANSYS Inc\Shared Files\Licensing ANSYSLMD_LICENSE_FILE 1055@AAPwqLw9xkRfH1A ANSYS_BUILDDEPENDENCIES D:\ANSYSDev\BuildDependencies ANSYS_CONAN_VENV_PATH D:\ANSYSDev\BuildDependencies\Conan\ConanEnv AWP_BUILDDEPENDENCIES D:\ANSYSDev\BuildDependencies AWP_GENERATED_PROPERTY_SHEETS D:\ANSYSDev\CodeDV\PropertySheets AWP_INTEL_COMPILER C:\Program Files (x86)\Intel\oneAPI\compiler\2023.1.0\windows AWP_LOCALE221 en-us AWP_LOCALE232 en-us AWP_ROOT221 C:\Program Files\ANSYS Inc\v221 AWP_ROOT231 C:\Program Files\ANSYS Inc\v231 AWP_ROOT232 C:\Program Files\ANSYS Inc\v232 AWP_ROOT241 D:\ANSYSDev\ANSYS Inc\v241 AWP_ROOTDV_DEV D:\ANSYSDev\ANSYS Inc\v241 AWP_THIRDPARTYDV_DEV D:\ANSYSDev\BuildDependencies\ThirdParty AWP_UNIT_TEST_FILES D:\ANSYSDev\UnitTestDataFiles CADOE_LIBDIR221 C:\Program Files\ANSYS Inc\v221\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 CADOE_LIBDIR241 D:\ANSYSDev\ANSYS Inc\v241\CommonFiles\Language\en-us ```

📝 Installed packages

Show the installed packages! ```text altgraph==0.17.4 ansys-api-mapdl==0.5.1 ansys-api-platform-instancemanagement==1.0.0 ansys-dpf-core==0.9.0 ansys-dpf-gate==0.4.1 ansys-dpf-gatebin==0.4.1 ansys-grpc-dpf==0.8.1 ansys-mapdl-core==0.67.0 ansys-mapdl-reader==0.52.20 ansys-math-core==0.1.3 ansys-platform-instancemanagement==1.1.2 ansys-tools-path==0.3.1 appdirs==1.4.4 asttokens==2.4.0 backcall==0.2.0 black==23.9.1 cachetools==5.3.1 certifi==2023.7.22 charset-normalizer==3.3.0 click==8.1.7 colorama==0.4.6 comm==0.1.4 contourpy==1.1.1 coverage==7.3.2 cycler==0.12.1 debugpy==1.8.0 decorator==5.1.1 exceptiongroup==1.1.3 executing==2.0.0 flake8==6.1.0 fonttools==4.43.1 geomdl==5.3.1 google-api-core==2.12.0 google-api-python-client==2.103.0 google-auth==2.23.3 google-auth-httplib2==0.1.1 googleapis-common-protos==1.61.0 grpcio==1.59.0 httplib2==0.22.0 idna==3.4 importlib-metadata==6.8.0 iniconfig==2.0.0 ipykernel==6.25.2 ipython==8.16.1 ipython-genutils==0.2.0 isort==5.12.0 jedi==0.19.1 jupyter_client==8.4.0 jupyter_core==5.4.0 kiwisolver==1.4.5 -e git+https://github.com/ansys-internal/pymapdl-gui.git@516889cb1a67696c6c2a4abcc6a34bdc3eefb7c9#egg=mapdl_gui matplotlib==3.8.0 matplotlib-inline==0.1.6 mccabe==0.7.0 mypy-extensions==1.0.0 nest-asyncio==1.5.8 numpy==1.26.1 packaging==23.2 parso==0.8.3 pathspec==0.11.2 pefile==2023.2.7 pexpect==4.8.0 pickleshare==0.7.5 Pillow==10.1.0 platformdirs==3.11.0 pluggy==1.3.0 pooch==1.7.0 prompt-toolkit==3.0.39 protobuf==3.20.3 psutil==5.9.6 ptyprocess==0.7.0 pure-eval==0.2.2 pyansys-tools-versioning==0.5.0 pyasn1==0.5.0 pyasn1-modules==0.3.0 pycodestyle==2.11.1 pyflakes==3.1.0 Pygments==2.16.1 pyiges==0.3.1 pyinstaller==6.1.0 pyinstaller-hooks-contrib==2023.10 pyparsing==3.1.1 PyQt5==5.15.10 PyQt5-Qt5==5.15.2 PyQt5-sip==12.13.0 PyQtChart==5.15.6 PyQtChart-Qt5==5.15.2 pytest==7.4.2 pytest-cov==4.1.0 pytest-qt==4.2.0 python-dateutil==2.8.2 pyvista==0.42.3 pyvista-gui==0.1.1 pyvistaqt==0.11.0 pywin32==306 pywin32-ctypes==0.2.2 pyzmq==25.1.1 QDarkStyle==3.1 qtconsole==5.4.4 QtPy==2.4.0 requests==2.31.0 rsa==4.9 scipy==1.11.3 scooby==0.7.4 six==1.16.0 stack-data==0.6.3 tomli==2.0.1 tornado==6.3.3 tqdm==4.66.1 traitlets==5.11.2 typing_extensions==4.8.0 uritemplate==4.1.1 urllib3==2.0.6 vtk==9.2.6 wcwidth==0.2.8 zipp==3.17.0 ```

📝 Logger output file

Show the logger output file. ```text >>> mapdl.prep7() DEBUG - GRPC_127.0.0.1:50052 - mesh_grpc - _reset_cache - Resetting cache INFO - GRPC_127.0.0.1:50052 - mapdl - run - *** ANSYS - ENGINEERING ANALYSIS SYSTEM RELEASE 2022 R1 22.1 *** DISTRIBUTED Ansys Mechanical Enterprise 00000000 VERSION=WINDOWS x64 10:30:48 OCT 18, 2023 CP= 0.047 ***** ANSYS ANALYSIS DEFINITION (PREP7) ***** *** ANSYS - ENGINEERING ANALYSIS SYSTEM RELEASE 2022 R1 22.1 *** DISTRIBUTED Ansys Mechanical Enterprise 00000000 VERSION=WINDOWS x64 10:30:48 OCT 18, 2023 CP= 0.047 ***** ANSYS ANALYSIS DEFINITION (PREP7) ***** >>> >>> # tbopt corresponds to a particular material-law within material definition >>> tbopt = 1 >>> >>> # material definition >>> mapdl.tb(lab="CREE", mat=1, tbopt=tbopt) DEBUG - GRPC_127.0.0.1:50052 - mesh_grpc - _reset_cache - Resetting cache INFO - GRPC_127.0.0.1:50052 - mapdl - run - DEFINE DATA TABLE CREE FOR MATERIAL 1 TBOPT = 1 OPTION FOR MATERIAL 1 DEFINE DATA TABLE CREE FOR MATERIAL 1 TBOPT = 1 OPTION FOR MATERIAL 1 >>> mapdl.tbtemp(0) DEBUG - GRPC_127.0.0.1:50052 - mesh_grpc - _reset_cache - Resetting cache INFO - GRPC_127.0.0.1:50052 - mapdl - run - TEMPERATURE TO BE USED FOR THE NEXT TBDAT COMMAND= 0.0000 TEMPERATURE SPECIFICATION= 1 TEMPERATURE TO BE USED FOR THE NEXT TBDAT COMMAND= 0.0000 TEMPERATURE SPECIFICATION= 1 >>> mapdl.tbdata(stloc=1,c1=10,c2=20,c3=30,c4=40) DEBUG - GRPC_127.0.0.1:50052 - mesh_grpc - _reset_cache - Resetting cache INFO - GRPC_127.0.0.1:50052 - mapdl - run - DATA FOR CREE TABLE FOR MATERIAL 1 AT TEMPERATURE= 0.0000 LOC= 1 1.00000e+01 2.00000e+01 3.00000e+01 4.00000e+01 DATA FOR CREE TABLE FOR MATERIAL 1 AT TEMPERATURE= 0.0000 LOC= 1 1.00000e+01 2.00000e+01 3.00000e+01 4.00000e+01 >>> >>> # material query and "IndexError" from mapdl.get method >>> value=mapdl.get(entity="CREE", entnum="1", item1="TEMP", it1num=0, item2="CONST", it2num=3, item3=tbopt) DEBUG - GRPC_127.0.0.1:50052 - mapdl - __enter__ - Entering force-output mode DEBUG - GRPC_127.0.0.1:50052 - mesh_grpc - _reset_cache - Resetting cache DEBUG - GRPC_127.0.0.1:50052 - mesh_grpc - _reset_cache - Resetting cache INFO - GRPC_127.0.0.1:50052 - mapdl - run - *GET __FLOATPARAMETER__ FROM CREE 1 ITEM=TEMP 0.00000 ITEM2=CONS 3 VALUE= 30.0000000 DEBUG - GRPC_127.0.0.1:50052 - mapdl - __exit__ - Exiting force-output mode CRITICAL - pymapdl_global - logging - handle_exception - Uncaught exception Traceback (most recent call last): File "", line 1, in File "D:\src\Qt_env\lib\site-packages\ansys\mapdl\core\mapdl.py", line 2792, in get f"The command '{command}' is showing the next message: '{value.splitlines()[1].strip()}'" IndexError: list index out of range >>> ```
pvargasm commented 11 months ago

Thanks @fanzongyue1991 for identify this issue!

mikerife commented 11 months ago

Hi @pvargasm & @fanzongyue1991 There is a slight typo in the get command: there is no get command in PyMAPDL....! The command would be get_value. This does work:

value=mapdl.get_value(entity="CREE", entnum="1", item1="TEMP", it1num=0, item2="CONST", it2num=3, item3=tbopt)

And it returns:

image

Mike

pvargasm commented 11 months ago

Hi @mikerife, thanks for your recommendation.

We will use mapdl.get_value instead of mapdl.get.

Can you confirm if, although mapdl.get continues in the documentation, it has been deprecated?

mikerife commented 11 months ago

Hi @pvargasm @fanzongyue1991 @germa89 Hey Pablo - wow I really had a brain cramp there! I'm so used to using get_value or get_array that I forgot about regular old get. "Item3" is not a field name on the *GET command with these options (i.e. getting TB material model info). But TBOPT is and when we use that it returns a different error, with same consequences, and kills the MAPDL grpc connection. So looks to be a bug.

mapdl.get(par="creepc3", entity="CREE", entnum=1, item1="TEMP", it1num=0, item2="CONST", it2num=3, tbopt=tbopt)

Mike