ansys / pymapdl-reader

Legacy binary interface to MAPDL binary files.
https://reader.docs.pyansys.com
MIT License
47 stars 23 forks source link

how to read all elements information from .dat file by PyMapdl_reader #401

Open planestress opened 6 months ago

planestress commented 6 months ago

πŸ” Before submitting the issue

🐞 Description of the bug

My geometry cotains two solids,so elements information in .dat file is divided into two parts(both are same material).I awnt to use PyMapdl reader to read all elements information from .dat file but it just read the first part elements information.How should I do? image image image

πŸ“ Steps to reproduce

like my discription of the bug

πŸ’» Which operating system are you using?

Windows

πŸ“€ Which ANSYS version are you using?

19.2

🐍 Which Python version are you using?

3.11

πŸ“¦ 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.65.1
ansys-mapdl-reader==0.52.20
ansys-math-core==0.1.1
ansys-mechanical-core==0.8.0
ansys-meshing-prime==0.4.1
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.2
appdirs==1.4.4
asgiref==3.7.2
build==1.0.3
cachetools==5.3.1
certifi==2023.7.22
cffi==1.16.0
charset-normalizer==3.3.0
click==8.1.7
clr-loader==0.2.6
colorama==0.4.6
contourpy==1.1.1
cryptography==41.0.4
cycler==0.12.1
Django==4.2.6
docutils==0.20.1
filelock==3.12.4
fonttools==4.43.1
geomdl==5.3.1
google-api-core==2.12.0
google-api-python-client==2.104.0
google-auth==2.23.3
google-auth-httplib2==0.1.1
googleapis-common-protos==1.61.0
grpcio==1.59.0
grpcio-status==1.48.2
h5py==3.10.0
httplib2==0.22.0
idna==3.4
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.24.3
packaging==23.2
pandas==2.1.1
Pillow==10.1.0
pkginfo==1.9.6
platformdirs==3.11.0
plumbum==1.8.2
pooch==1.7.0
protobuf==3.20.3
psutil==5.9.6
pyaedt==0.6.76
pyansys==2023.2.11
pyansys-docker==5.0.4
pyansys-tools-versioning==0.5.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.10.2
python-dateutil==2.8.2
pythonnet==3.0.1
pytwin==0.3.0
pytz==2023.3.post1
pyvista==0.40.4
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.6.0
rpyc==5.3.1
rsa==4.9
scipy==1.11.3
scooby==0.9.2
six==1.16.0
sqlparse==0.4.4
sspilib==0.1.0
tqdm==4.66.1
twine==4.0.2
typing==3.7.4.3
typing_extensions==4.8.0
tzdata==2023.3
uritemplate==4.1.1
urllib3==1.26.18
vtk==9.2.6
websocket-client==1.6.4
zipp==3.17.0
RobPasMue commented 6 months ago

@germa89 @mikerife could you help this user out?

mikerife commented 6 months ago

Hi @planstress Well, this may depend on what you want to do with the input file. Some choices are:

1 Define a Named Selection in WB Mechanical of Part1. This will be a element 'component' in the input file (MAPDL component). The PyMAPDL Reader then often has an option to specify a component when performing some function like creating a result plot.

2 Use PyMAPDL and you can use its select logic as needed to work with a sub-set of the model.

3 Use PyDPF which has Scoping based on MAPDL element attributes like material ID. A unique material ID is used by each Part in WB Mechanical even if the actual material is the same between parts.

Mike

planestress commented 6 months ago

Hi @mikerife Thank you for replying.Honestly,I don't quite understand the methods you offered because I am rookie at this. In this example,I want to read all elements information from dat file and then extract element type as well as nodes of every elements,so I issue thepymapdl_reader.Archive('ds.dst')to read elements information.In my opinion,it should read all elements information but it only read the first part elements actually. I wonder why is that and how can I do to my purpose?

mikerife commented 6 months ago

@planstress Ok I read your description backwards! I see now that you are reporting that PyMAPDL Reader has elements missing compared to the ds.dat file. Can you share the ds.dat file? There is not much to go on just from a screen shot.

planestress commented 6 months ago

@mikerife of course,here it is.Thank you. [Uploading ds.zip…]()

mikerife commented 6 months ago

Doesn't seem like the file attachment worked.

planestress commented 6 months ago

@mikerife sorry about that,I upload it again. ds.zip

germa89 commented 6 months ago

@planestress

PyMAPDL-Reader development is quite stale at the moment. I'm not quite sure why not all the elements are read in to be honest.

If I were you, I would probably switch to PyMAPDL where you can do:

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

mapdl.prep7()
mapdl.input("ds.dat")

mapdl.cmsel("s", "CRACK_TIP")
# Then you have selected the named selection called "CRACK_TIP".
...
# perform operations

This can be done, because in the ds.dat file you have attached the named selections (which are just components) are defined as:

/com,*********** Send Named Selection as Node Component ***********
CMBLOCK,CRACK_TIP,NODE,       41
(8i10)
       138       182       183       184       185       186       187       188
       189       190       191       192       193       194       195       196
       197       198       199       200       201     20501     20792     20800
     20808     20817     20826     20836     20846     20854     20862     20871
     20880     20891     20902     20913     20922     20930     20940     20949
     20958

PyMAPDL should create the proper model from the dat file, and then it should be able to read the components.

planestress commented 6 months ago

@germa89 Thank you for your reply.In fact,I want to caculate stress of some point in every element base on element shape function,so I have to get all elements information of this model include element type,nodes belong to the elements and so on. Besides,I tried your code

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

and then occured this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\31142\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\ansys\mapdl\core\launcher.py", line 1634, in launch_mapdl
    raise exception
  File "C:\Users\31142\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\ansys\mapdl\core\launcher.py", line 1590, in launch_mapdl
    from ansys.mapdl.core.mapdl_corba import MapdlCorba
  File "C:\Users\31142\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\ansys\mapdl\core\mapdl_corba.py", line 16, in <module>
    raise ImportError(
ImportError: The CORBA interface is only supported for Python 3.8 and earlier

My python version is 3.11 and my ansys version is 19.2.

mikerife commented 6 months ago

@planestress well that error is pretty evident. Try installing Python 3.8 and trying this again. Or update to a newer release of MAPDL (why are you using v19.2???).

planestress commented 6 months ago

@mikerife I pay little attention to the ansys versions,I think they are all pretty much the same.Can I achieve my purpose if I follow German's strategy?

@planestress

PyMAPDL-Reader development is quite stale at the moment. I'm not quite sure why not all the elements are read in to be honest.

If I were you, I would probably switch to PyMAPDL where you can do:

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

mapdl.prep7()
mapdl.input("ds.dat")

mapdl.cmsel("s", "CRACK_TIP")
# Then you have selected the named selection called "CRACK_TIP".
...
# perform operations

This can be done, because in the ds.dat file you have attached the named selections (which are just components) are defined as:

/com,*********** Send Named Selection as Node Component ***********
CMBLOCK,CRACK_TIP,NODE,       41
(8i10)
       138       182       183       184       185       186       187       188
       189       190       191       192       193       194       195       196
       197       198       199       200       201     20501     20792     20800
     20808     20817     20826     20836     20846     20854     20862     20871
     20880     20891     20902     20913     20922     20930     20940     20949
     20958

PyMAPDL should create the proper model from the dat file, and then it should be able to read the components.

mikerife commented 6 months ago

@planestress "I pay little attention to the ansys versions, I think they are all pretty much the same." Depending on what feature/function you are using this could be a very dangerous/wrong statement, or not. Let's assum now not and see what happens.

"Can I achieve my purpose if I follow German's strategy?" Install Python 3.8 and test and see what happens.

planestress commented 6 months ago

@mikerife I install Python 3.8.10 and reinstall PyMAPDL version 0.67, 0.68 doesn't support Python 3.8.Oh my god,why there are so many versions???Then I do as German's method but there is a new error.(I am devastated T_T)

CRITICAL - pymapdl_global -  logging - handle_exception - Uncaught exception
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Program Files (x86)\python3.8.10\lib\site-packages\ansys\mapdl\core\launcher.py", line 1634, in launch_mapdl
    raise exception
  File "D:\Program Files (x86)\python3.8.10\lib\site-packages\ansys\mapdl\core\launcher.py", line 1597, in launch_mapdl
    mapdl = MapdlCorba(
  File "D:\Program Files (x86)\python3.8.10\lib\site-packages\ansys\mapdl\core\mapdl_corba.py", line 191, in __init__
    super().__init__(
  File "D:\Program Files (x86)\python3.8.10\lib\site-packages\ansys\mapdl\core\mapdl.py", line 265, in __init__
    _sanitize_start_parm(start_parm)
  File "D:\Program Files (x86)\python3.8.10\lib\site-packages\ansys\mapdl\core\mapdl.py", line 203, in _sanitize_start_parm
    raise ValueError(f"The argument '{each_key}' is not recognaised.")
ValueError: The argument 'log_broadcast' is not recognaised.

Besides,I cannot install pyansys directly because some Python packages in pyansys are incompatible with Python 3.8,so I only installed PyMAPDL 0.67.

germa89 commented 2 months ago

@planestress the errors you are getting are because PyMAPDL is trying to connect using the CORBA interface which is the one recommended for v19.2. See Compatibility between MAPDL and interfaces

While it is true that most of the MAPDL commands remain fairly stable between versions, PyMAPDL interface does not. In 2021R1, the gRPC interface was introduced and since then, it has been the recommended PyMAPDL interface. CORBA has been deprecated recently, and it was never fully covered by testing.

My advice is to install the latest MAPDL version (at least 2022R2), and update PyMAPDL, the experience should be way better.