Skip to main content

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".

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)

Yaris Static Suspension Mesh

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

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

lsdyna-mesh-reader-0.1.0.tar.gz (640.5 kB view details)

Uploaded Source

Built Distributions

lsdyna_mesh_reader-0.1.0-cp312-cp312-win_amd64.whl (707.9 kB view details)

Uploaded CPython 3.12 Windows x86-64

lsdyna_mesh_reader-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (734.9 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

lsdyna_mesh_reader-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (698.2 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

lsdyna_mesh_reader-0.1.0-cp312-cp312-macosx_10_14_x86_64.whl (703.7 kB view details)

Uploaded CPython 3.12 macOS 10.14+ x86-64

lsdyna_mesh_reader-0.1.0-cp311-cp311-win_amd64.whl (709.6 kB view details)

Uploaded CPython 3.11 Windows x86-64

lsdyna_mesh_reader-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (737.6 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

lsdyna_mesh_reader-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (700.9 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

lsdyna_mesh_reader-0.1.0-cp311-cp311-macosx_10_14_x86_64.whl (706.4 kB view details)

Uploaded CPython 3.11 macOS 10.14+ x86-64

lsdyna_mesh_reader-0.1.0-cp310-cp310-win_amd64.whl (709.8 kB view details)

Uploaded CPython 3.10 Windows x86-64

lsdyna_mesh_reader-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (737.8 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

lsdyna_mesh_reader-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (701.0 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

lsdyna_mesh_reader-0.1.0-cp310-cp310-macosx_10_14_x86_64.whl (706.6 kB view details)

Uploaded CPython 3.10 macOS 10.14+ x86-64

lsdyna_mesh_reader-0.1.0-cp39-cp39-win_amd64.whl (710.1 kB view details)

Uploaded CPython 3.9 Windows x86-64

lsdyna_mesh_reader-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (738.0 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

lsdyna_mesh_reader-0.1.0-cp39-cp39-macosx_11_0_arm64.whl (701.3 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

lsdyna_mesh_reader-0.1.0-cp39-cp39-macosx_10_14_x86_64.whl (706.8 kB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

File details

Details for the file lsdyna-mesh-reader-0.1.0.tar.gz.

File metadata

  • Download URL: lsdyna-mesh-reader-0.1.0.tar.gz
  • Upload date:
  • Size: 640.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for lsdyna-mesh-reader-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f6264dc9379c2c22e9ba2d57a885f8a06d14869d65bacc009abaa1055eca0d43
MD5 2cee609c42561e9ab30a0a40a13b910e
BLAKE2b-256 30f2bd6123712e3e6f74535f93d300438fda946f95c46c332a4fe145a9915002

See more details on using hashes here.

File details

Details for the file lsdyna_mesh_reader-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for lsdyna_mesh_reader-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8a6c8eb5d712975c37c4b9cb1b0193bf12ad1c5a7c9e0f4bbc3c274007ff985f
MD5 45b2f65793cbd68df632d5cafb55de6a
BLAKE2b-256 9536bdd0abe6c3de6be0efdfd7131d575262884232fe29f7d95958163767a2d8

See more details on using hashes here.

File details

Details for the file lsdyna_mesh_reader-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lsdyna_mesh_reader-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 131eb6fa4219833400cfd96e1cad3a58aba93ce7021fd191668afc97737dca8b
MD5 651fbaf19a862372a17e90b1429b6c85
BLAKE2b-256 902770e080e19181dc26dcbfe799f80ccc0ca8efb10da8ce170baf9d5012b968

See more details on using hashes here.

File details

Details for the file lsdyna_mesh_reader-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lsdyna_mesh_reader-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d2e7cba9f8797d0a2e51ca07522765f6953190388f440c2c4bb6fbdeb772d538
MD5 d957ed6bfe234f89c6a68c46b024eae2
BLAKE2b-256 d0f5cbcf27934eaf1a3f04eff090961b5c7fd37ad02f7f80c7c26436846ed195

See more details on using hashes here.

File details

Details for the file lsdyna_mesh_reader-0.1.0-cp312-cp312-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for lsdyna_mesh_reader-0.1.0-cp312-cp312-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 256f3036070eb9da265bc312a3ea52c0da264cd471a35ebb518c08f9796b5934
MD5 bcb84146516b5c5373ed1c3d92ccccb4
BLAKE2b-256 8941b7da52abc2ed115db9c82bbff246fedc05d27c63c1b25371aff9cadaf811

See more details on using hashes here.

File details

Details for the file lsdyna_mesh_reader-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for lsdyna_mesh_reader-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d9deff3110da6801cf907e8435738b61ab75ffcde03b07b50f301dd43a034999
MD5 47b3c03a3f2b403327b5b923e8904c9b
BLAKE2b-256 cb075e3737b93ce881864c4fad84de56c99ea29290d0946b7f6c7450676fcd57

See more details on using hashes here.

File details

Details for the file lsdyna_mesh_reader-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lsdyna_mesh_reader-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 984683e0e1f43cb6d49e7c22b295f597a9ef8feb50152aba4828fbae7b067802
MD5 ab42b5f6b40bd2fefb13e4adb3da65e1
BLAKE2b-256 77a31d135db5c2d5c86edcbfe720bb2dbd6ef44e7720228c97eb79080a7b446e

See more details on using hashes here.

File details

Details for the file lsdyna_mesh_reader-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lsdyna_mesh_reader-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 47bf24def021214f42a3e5f4165d546831cefc5bdd8bcd6331f41d529b5988fa
MD5 ebe64efcd5901d73df257b91b1d233e7
BLAKE2b-256 819ab9a0f1adc6f97ee884b828354d17921611696973ddc7473a985f783f9230

See more details on using hashes here.

File details

Details for the file lsdyna_mesh_reader-0.1.0-cp311-cp311-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for lsdyna_mesh_reader-0.1.0-cp311-cp311-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 5840e4b2cf40af698e831d09c9c2b0b638172a71427a143f5321257e6d5ae42b
MD5 a11cade48851b93ff23b9614e6445429
BLAKE2b-256 81f30bbeb715524524abd0682c555a24291bce5cca2fa9e5e09cba052579be3e

See more details on using hashes here.

File details

Details for the file lsdyna_mesh_reader-0.1.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for lsdyna_mesh_reader-0.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d2923c319aaadb0453be039b9c46ba46e6637795586a6da3f64c271a76cd00bb
MD5 0f850769e13b97a320ed309f2010c035
BLAKE2b-256 d994c03ebf9c7516dcb4cf82e03ee4c04ee77660103e1d5a0e8d6aa7958eeaa4

See more details on using hashes here.

File details

Details for the file lsdyna_mesh_reader-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lsdyna_mesh_reader-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6375a4367b053378e27c35d259e8f6f2b761052d21d94f85d3f34848d5e8079f
MD5 13d18e39bb4e07d6646b9a41eb3cc789
BLAKE2b-256 3404fd4982a3cc7d4a69089370c95c34aa922d9ee8080f65f483ba2c6a172b50

See more details on using hashes here.

File details

Details for the file lsdyna_mesh_reader-0.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lsdyna_mesh_reader-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5c2b9c5b9c0539c2ba87fedca397ea792d3e5717cefe54ad7f4878156574de98
MD5 76fa789f9b7b135563f803ff02fe8be0
BLAKE2b-256 68726e6679da936af11990d3fdc0cf5d2c83e3d5379a63abd7e8fff7b06743ef

See more details on using hashes here.

File details

Details for the file lsdyna_mesh_reader-0.1.0-cp310-cp310-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for lsdyna_mesh_reader-0.1.0-cp310-cp310-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 59635548ed67b5bcd9c4766cfac47ce517cd16e1e702a521f76cda261a4036de
MD5 a7bfe35c945455c7f2c46f600f11f7c2
BLAKE2b-256 b7d60a2f31e944c33a9829945b02d2eb90de7ff3ebdb7dc5bd0e00ea3df2c611

See more details on using hashes here.

File details

Details for the file lsdyna_mesh_reader-0.1.0-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for lsdyna_mesh_reader-0.1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 7316f871abe03cdb9ed63ed9ba4d419acc4808a67af0fe219e4dc2e8a9b6ffb4
MD5 019949c1d8be02848796aad6f2d5b38f
BLAKE2b-256 50329e7537d2698c7996b5eb2575b918069a25e7abc2e44cf688fb1b6bd0d2d1

See more details on using hashes here.

File details

Details for the file lsdyna_mesh_reader-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lsdyna_mesh_reader-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f7166cc6168465ad80376cdf396599b0c14319c252b738cfdfcb0a8e620c6e60
MD5 9ec822153ff5067927d02b35af626fd5
BLAKE2b-256 29fc6efb8697f3d8148e0ce0da441df52c0853363d1bf8276e975f97094d45f1

See more details on using hashes here.

File details

Details for the file lsdyna_mesh_reader-0.1.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lsdyna_mesh_reader-0.1.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f55c506894c6efa731b0520ab767bd0bcf6e8459394c0871a0d79e77e47b2f54
MD5 776d6b3e73c14ee1e6bf4b17136db6e4
BLAKE2b-256 ff6b1f678182a6c8a173ef1ee5def01d0abe239ade85e0df43877f21d6244a32

See more details on using hashes here.

File details

Details for the file lsdyna_mesh_reader-0.1.0-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for lsdyna_mesh_reader-0.1.0-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 556c6d2545ea1a3cf740621e0c893787476fe8992440ec23504c2fe03d761110
MD5 5187d61825f73f68495d394d4421f647
BLAKE2b-256 325d2d1a4b0e856b144c3780b3e13adbf2be888055284e4b3075c5cf125da9ff

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page