Read nodes and elements from LS-DYNA decks.
Project description
LS-DYNA Mesh Reader
This library can be used to read in LS-DYNA meshes stored within keyword
(*.k
, *.key
, *.dyn
) files, also known as keyword format "input
decks". Full documentation for this repository can be found at lsdyna-mesh-reader Documentation.
Many of these example files were obtained from the excellent documentation at LS-DYNA Examples.
Motivation
Despite its popularity, there doesn't appear to be a reader for LS-DYNA keyword files. I need a reader for a closed source project and hope that this helps someone else who also wishes to read in these files. It borrows from mapdl-archive as MAPDL also follows many of the same FORTRAN conventions when writing out FEMs.
Installation
Install the fully featured reader with visualization with:
pip install lsdyna-mesh-reader[pyvista]
If you only need the node and element arrays and not any VTK features (e.g. plotting or UnstructuredGrid representation), install the basic library with:
pip install lsdyna-mesh-reader
Examples
Before going through a basic example, let's talk about how these "decks" are organized. Each keyword file contains "keywords" that describe the start of sections of "cards". This terminology dates back to when DYNA3D was developed in 1976 where programs were written on punch cards.
To read in nodes and elements, we have to read in one or more node and element sections, each starting with *NODE
or *ELEMENT_SOLID
. This library loads in those raw sections as well as parsed sections as a higher level abstraction.
Let's start by loading the Contact Eroding I example deck.
Load the birdball deck.
>>> import lsdyna_mesh_reader
>>> from lsdyna_mesh_reader import examples
>>> deck = lsdyna_mesh_reader.Deck(examples.birdball)
LSDYNA Deck with:
Node sections: 1
Element Solid sections: 1
Element Shell sections: 1
We can now inspect one of the node sections:
>>> node_section = deck.node_sections[0]
>>> node_section
NodeSection containing 1281 nodes
| NID | X | Y | Z | tc | rc |
|-------|---------------|---------------|---------------|--------|--------|
1 -2.30940104e+00 -2.30940104e+00 -2.30940104e+00 0 0
2 -2.03960061e+00 -2.03960061e+00 -2.03960061e+00 0 0
3 -1.76980031e+00 -1.76980031e+00 -1.76980031e+00 0 0
4 -1.50000000e+00 -1.50000000e+00 -1.50000000e+00 0 0
5 -2.59364843e+00 -1.59561157e+00 -2.59364843e+00 0 0
6 -2.22909880e+00 -1.39707434e+00 -2.22909880e+00 0 0
7 -1.86454940e+00 -1.19853711e+00 -1.86454940e+00 0 0
8 -1.50000000e+00 -1.00000000e+00 -1.50000000e+00 0 0
9 -2.76911068e+00 -8.14893484e-01 -2.76911068e+00 0 0
10 -2.34607387e+00 -7.09928930e-01 -2.34607387e+00 0 0
...
We can directly access the node IDs and arrays of the node section:
Node IDs
>>> node_section.nid
array([ 1, 2, 3, ..., 1342, 1343, 1344], dtype=int32)
Node coordinates
>>> node_section.coordinates
array([[ -2.30940104, -2.30940104, -2.30940104],
[ -2.03960061, -2.03960061, -2.03960061],
[ -1.76980031, -1.76980031, -1.76980031],
...,
[ -4. , -10. , 0. ],
[ -2. , -10. , 0. ],
[ 0. , -10. , 0. ]])
The same can be done for both the solid and shell element sections.
>>> deck.element_solid_sections # or deck.element_shell_sections
[ElementSolidSection containing 816 elements
| EID | PID | N1 | N2 | N3 | N4 | N5 | N6 | N7 | N8 |
|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|
1 1 1 2 6 5 17 18 22 21
2 1 2 3 7 6 18 19 23 22
3 1 3 4 8 7 19 20 24 23
4 1 5 6 10 9 21 22 26 25
5 1 6 7 11 10 22 23 27 26
6 1 7 8 12 11 23 24 28 27
7 1 9 10 14 13 25 26 30 29
8 1 10 11 15 14 26 27 31 30
9 1 11 12 16 15 27 28 32 31
10 1 17 18 22 21 33 34 38 37
...]
Element IDs
>>> section = deck.element_solid_sections[0]
>>> section.eid
array([ 1, 2, 3, ..., 814, 815, 816], dtype=int32)
Node IDs of the elements
>>>
array([ 1, 2, 6, ..., 1256, 1267, 1266], dtype=int32)
The elements are stored as a single contiguous array for efficiency and can be split up via:
>>> import numpy as np
>>> elements = np.split(section.node_ids, section.node_id_offsets[1:-1])
[array([ 1, 2, 6, 5, 17, 18, 22, 21], dtype=int32),
array([ 2, 3, 7, 6, 18, 19, 23, 22], dtype=int32),
...
]
If you have pyvista
installed or installed the library with pip install lsdyna-mesh-reader[pyvista]
, you can convert the mesh to a single unstructured
grid:
>>> grid = deck.to_grid()
>>> grid
UnstructuredGrid (0x70d5d723bc40)
N Cells: 916
N Points: 1281
X Bounds: -2.000e+01, 2.220e-15
Y Bounds: -1.000e+01, 4.000e+00
Z Bounds: -2.000e+01, 4.441e-15
N Arrays: 2
This lets you plot, save, or perform other operations on the mesh via PyVista. For example, you could plot the resulting mesh. Here's a full example using the Yaris Static Suspension System Loading Examplew.
>>> filename = "YarisD_V2g_shock_abs_load_01.k"
>>> deck = Deck(filename)
>>> grid = deck.to_grid()
>>> grid.plot(color="w", smooth_shading=True, show_edges=True)
Caveats and Limitations
As of now, limited testing has been performed on this library and you may find that it fails to load complex or simple keyword decks.
Additionally, this reader only supports the following keywords:
*NODE
*ELEMENT_SHELL
*ELEMENT_SOLID
*ELEMENT_TSHELL
(note: sections encoded as solid sections)
The VTK UnstructuredGrid contains only the linear element conversion of the
underlying LS-DYNA elements, and only supports VTK_QUAD
, VTK_TRIANGLE
,
VTK_TETRA
, VTK_WEDGE
, and VTK_HEXAHEDRAL
.
Issues and Contributing
Feel free to open an Issue in this repository with any features you'd like me to add or bugs you need fixed.
If you'd like to contribute, please see CONTRIBUTING.md.
License
Source and content is under the MIT License, except for the LS-DYNA artifacts, which retain their original license from LS-DYNA and Ansys.
Note that the example files used here were downloaded from LS-DYNA Examples and have the following usage license as noted on the website:
The input files and several class notes are available for download. The
download is free of charge, a login is not required. All examples are
presented with a brief description. You may find an example by checking a
specific class or by using the search functionality of the site.
The content is prepared for educational purposes. Hence, material
properties and other parameters might be non-physic for simplification.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file lsdyna-mesh-reader-0.1.2.tar.gz
.
File metadata
- Download URL: lsdyna-mesh-reader-0.1.2.tar.gz
- Upload date:
- Size: 648.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 223fe8ab53948f95c0de41f4535e46775788c4fe070828a8dd38b95ecdbff104 |
|
MD5 | 46c7fca04bb9d0873bb6cf45699703ca |
|
BLAKE2b-256 | 66afdaaf477953877fc056f1fe1f541b9bb70ff6bb5c50b0d46d9ca9a2f5c3ee |
File details
Details for the file lsdyna_mesh_reader-0.1.2-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: lsdyna_mesh_reader-0.1.2-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 719.6 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82590fcd28eef63263a1f2beca7b53faececb58747e0984b68b9b16e939fbb88 |
|
MD5 | f3fede86199c1d819260128f142ac995 |
|
BLAKE2b-256 | 9a21fd52fca89a83c109736b1e3eb17d39a3825bf51fd31726e1b17cbda4f481 |
File details
Details for the file lsdyna_mesh_reader-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: lsdyna_mesh_reader-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 746.6 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70c1ab3425f91b310d7a0176be51701f1430e8a6fe8f7494446db8883985d091 |
|
MD5 | a07416547e99e14e60edb621a0e35f4a |
|
BLAKE2b-256 | a0d84a27e0e9a68e743d98f839587bd6c52e0c5e8291784456f51de6cf3df969 |
File details
Details for the file lsdyna_mesh_reader-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: lsdyna_mesh_reader-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 710.2 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11ba8fb3a2f6caa1bfe97d31412074050ce3d3d12d8943ef3deac26e3556c13f |
|
MD5 | 0f2a5ebd0d90a3aee90588300d3e1c43 |
|
BLAKE2b-256 | 7abb69ca5734d331b6fa18e7c043f822fbc574aecaebf7197f6658a5ff97d7af |
File details
Details for the file lsdyna_mesh_reader-0.1.2-cp312-cp312-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: lsdyna_mesh_reader-0.1.2-cp312-cp312-macosx_10_14_x86_64.whl
- Upload date:
- Size: 716.1 kB
- Tags: CPython 3.12, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 907fb4fab228fcf4ffe21b55f3966b3ee2cfec82d8ae21ed954e303067e67337 |
|
MD5 | 379bab30294847cf586aa6e40285ccfc |
|
BLAKE2b-256 | 3f8402e9aaae0297fcfff7fe22c49a9f936ef83e68abff6b35e2916a08ffb0f9 |
File details
Details for the file lsdyna_mesh_reader-0.1.2-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: lsdyna_mesh_reader-0.1.2-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 721.4 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b994277e9f4bcfa1f1de28d4dce41c0efc7a9b411ad67f0fac7327f03584c35 |
|
MD5 | acc1d18991f51a07f89034f3c41a52d4 |
|
BLAKE2b-256 | e2ebf789b22d4a28f166fed10fcef3e083e1682e0166ff3f6c6ab7a367b6204f |
File details
Details for the file lsdyna_mesh_reader-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: lsdyna_mesh_reader-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 749.6 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 942e09863a85bb85698e6305e7ae87821699bcf6055925a3af9f74f88f85d103 |
|
MD5 | 3e61b63d74e45dd4770aa75493c22b7e |
|
BLAKE2b-256 | 04b2c3abb4f6a146bf5150dbe5fe8c31c918cb879eebb03185b3cf587e872529 |
File details
Details for the file lsdyna_mesh_reader-0.1.2-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: lsdyna_mesh_reader-0.1.2-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 713.3 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c90abf4dfe7f8a020ce0a2373f2fe1b6051268d535e8dcebed0f396c51e518d9 |
|
MD5 | 3abbe01991333932b2c6d34eede3eb85 |
|
BLAKE2b-256 | 740f4024c5c339e332d011c0db637723a69b5f175ea2a8add304dfb5f73194cc |
File details
Details for the file lsdyna_mesh_reader-0.1.2-cp311-cp311-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: lsdyna_mesh_reader-0.1.2-cp311-cp311-macosx_10_14_x86_64.whl
- Upload date:
- Size: 719.0 kB
- Tags: CPython 3.11, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fb155e94c8125b8121a6797bfeafbac34525f6705eb8582cc98316f3641db82 |
|
MD5 | e3145f982f43ce392fb4880e1b7dba3a |
|
BLAKE2b-256 | b1c861ca0f6874f4e2cbf002a91f923ac40293929f8a664da43f1e1937cfb9f8 |
File details
Details for the file lsdyna_mesh_reader-0.1.2-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: lsdyna_mesh_reader-0.1.2-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 721.6 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1cd54df483de2e547bcb0290dcc92fb817090791ce512799015469e5fbef396 |
|
MD5 | f5062f9b97bf24fdee4eb773b8198ab9 |
|
BLAKE2b-256 | 3644d361e21221296d74582dcf3c14ab9672f5c61a593cc90281a9f5d38f3a17 |
File details
Details for the file lsdyna_mesh_reader-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: lsdyna_mesh_reader-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 749.8 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d795f130f0fe80adb93541428c28b9890193234c47ae42c282ee8143375c7334 |
|
MD5 | 47fbfc2efa9bc161beeb0236b6f4d466 |
|
BLAKE2b-256 | d14d2896c6baf0c9c7c09a6b3fc3c3899f58ecb303646a17ce6d21b936be5be1 |
File details
Details for the file lsdyna_mesh_reader-0.1.2-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: lsdyna_mesh_reader-0.1.2-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 713.4 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a69ccb0dfcacdf7982587485b2a72ee127319b93b77a98f2d057897fb12413c |
|
MD5 | 59e09b4bd3773e00e5267b5af5659b24 |
|
BLAKE2b-256 | 724ea1ef41e68126cb34de23b6f25c611af765ccc43d0fa5d21f851c84301094 |
File details
Details for the file lsdyna_mesh_reader-0.1.2-cp310-cp310-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: lsdyna_mesh_reader-0.1.2-cp310-cp310-macosx_10_14_x86_64.whl
- Upload date:
- Size: 719.2 kB
- Tags: CPython 3.10, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e612d44f0a1408802891ad913f109ae5066c4c0833e6afea91e5d1047c2002de |
|
MD5 | d1b21befe83e8ba9906b636d697bcfea |
|
BLAKE2b-256 | ef6604bf8ccab3dc0832ab14190b22f28ea8f7bb5d7b50d6b88847aff8ef1670 |
File details
Details for the file lsdyna_mesh_reader-0.1.2-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: lsdyna_mesh_reader-0.1.2-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 721.9 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3f5b3e35959ad658be5658abad1cc03a121b0144f887f86aefdd46874dcb441 |
|
MD5 | df4467ad9994bce7039e003a53a7ad35 |
|
BLAKE2b-256 | 9a1fd12bc4db65904f60a0a09b5d8e504e18bf8b713e06af23d04b654c68b153 |
File details
Details for the file lsdyna_mesh_reader-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: lsdyna_mesh_reader-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 750.1 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db15e7874c1bbb7fcadb3de0b2902de93dcc5bcf6755443d6a6177d3e510991a |
|
MD5 | 33c7b3cc6efd9a5442bfe453bcf292e7 |
|
BLAKE2b-256 | b617d18790ba7fe6742a6bff8454e5e0cf6e1c93e24892cc07e8c3ba31fd2a85 |
File details
Details for the file lsdyna_mesh_reader-0.1.2-cp39-cp39-macosx_11_0_arm64.whl
.
File metadata
- Download URL: lsdyna_mesh_reader-0.1.2-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 713.6 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22298a161619ccad4b3d8dfef16f85b1b6fd79eafc66a91d6ce5ac260f28630a |
|
MD5 | 7305d878bd18b0c31e7aa38d074a8c79 |
|
BLAKE2b-256 | 8c3773c1dd01e4d62f98158cadb174d1c5f1c86e8b62c8ed7dbee472e8775c4f |
File details
Details for the file lsdyna_mesh_reader-0.1.2-cp39-cp39-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: lsdyna_mesh_reader-0.1.2-cp39-cp39-macosx_10_14_x86_64.whl
- Upload date:
- Size: 719.5 kB
- Tags: CPython 3.9, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea5582ffe5d886b2e8a1088f9f85a7494f8426a02182b8636ff4b38fd8f302f3 |
|
MD5 | 48ae5a3d5db8a0560f34a8dfd552a6fd |
|
BLAKE2b-256 | 8996060ad3e5f3d93c390e14d38e01d77ba73735fbf1dec5cae50eca247685f0 |