Skip to main content

LS-DYNA Keywords Reader Library

Project description

LS-DYNA™ Keyword Reader (dynakw)

A Python library for reading, parsing, editing, and writing LS-DYNA keyword files.

The library is designed to scale by incorporating LS-DYNA documentation and keyword examples, using prompt examples from the documentation. The maintenance and expansion of the library is automated by supplying this information to AI coding agents.

Status

Currently implemented:

  • *BOUNDARY_PRESCRIBED_MOTION
  • *ELEMENT_SHELL
  • *ELEMENT_SOLID
  • *MAT_ELASTIC
  • *NODE
  • *PART
  • *SECTION_SHELL
  • *SECTION_SOLID

The other keywords are preserved as raw text and type unknown. They can be written out unchanged, allowing any deck to be edited.

Usage

To read a file and print the keywords:

import sys
from dynakw import DynaKeywordReader, KeywordType

with DynaKeywordReader('lsdyna_exa.k') as dkr:

    # to access all keywords
    for kw in dkr.keywords():
        kw.write(sys.stdout)

    # reading a specific keyword
    for kw in dkr.find_keywords(KeywordType.NODE):
        kw.write(sys.stdout)

    # The edited file can be saved: 
    dkr.write('exa2.k')

A keywords have a type and a cards member. The values inside the cards member are dictionaries containing the data stored as numpy arrays following the LS-DYNA documentation. For example, a scale factor can be changed as follows:

if kw.type == KeywordType.BOUNDARY_PRESCRIBED_MOTION:
    kw.cards['Card 1']['SF'] = kw.cards['Card 1']['SF'] * 1.5

See also the code in the examples directory for more usage.

Example problems

The example problems demonstrate:

  • Printing the content of an LS-DYNA input deck.
  • Editing an LS-DYNA input deck.
  • Displaying the mesh using PyVista.
  • Converting LS-DYNA input to Radioss input.

More documentation

See the docs directory.

Contributing

Contributions are welcome! You can contribute either keywords examples for the QA or enhancements to the code reading the keywords.

This is easily done using AI coding agents considering the relevant LS-DYNA keyword chapter, an example keyword deck, and the existing code.

Adding a keyword using the Gemnini CLI

See .gemini/commands/*.toml for the prompts and the GEMINI.md files for an explanation of the code structure. Use the following slash commands:

\generate_instructions SECTION_SPH
\implement_keyword SECTION_SPH
\update_qa

Manually adding a new keyword

To add a keyword manually:

  1. Add the new keyword to the KeywordType enum in dynakw/core/enums.py.
  2. Create a new Python file in the dynakw/keywords/ directory named after the keyword.
  3. Implement the keyword class, inheriting from LSDynaKeyword and providing the _parse_raw_data and write methods.
  4. The unit tests should work for your new keyword (they use the enum from step 1). This requires that the keyword be present in test/full_files/*.k.

Contributing LS-DYNA keyword examples

If you have LS-DYNA input decks, please consider contributing them as examples. This helps ensure the quality and correctness of the library. A contribution can be as small as a single keyword definition. Contributing a keyword is how you ensure that it will always be read correctly by the library.

The keywords should be added to the test/full_files/ directory.

Having many keyword contributions is important because LS-DYNA has evolved to accomodate many variations of the keywords.

Testing

The code in the test directory can be exercised using 'python3 run_tests.py'. This step is essential in a new checkout because it create test data from the keyword contributions.

The '\update_qa' slash command can be used to update the tests.

Trademarks and related

LS-DYNA™ is a registered trademark of ANSYS Inc.

LS-DYNA examples can be downloaded at https://www.dynaexamples.com/ . This is currently free of charge, please see the instructions on the website, specifically the home page.

License

This project is licensed under the MIT License.

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

dynakw-1.0.0.tar.gz (33.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dynakw-1.0.0-py3-none-any.whl (42.1 kB view details)

Uploaded Python 3

File details

Details for the file dynakw-1.0.0.tar.gz.

File metadata

  • Download URL: dynakw-1.0.0.tar.gz
  • Upload date:
  • Size: 33.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for dynakw-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ff866ae1800fe09a51ed7be15f8c169d81e38442294f5bc6c6941ba2c25f7065
MD5 5278ef394c2344fa836d4d54f1871f13
BLAKE2b-256 12c9241d5db28ec6b1e10fd12fb1e46acf71e04a37bd5ff4ad774dde650be5a1

See more details on using hashes here.

File details

Details for the file dynakw-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: dynakw-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 42.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for dynakw-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 88a06695ec7383c5d65c6e7c205d01e5cd95bd82b973d318576446219904038d
MD5 b864f7fd094eef68a1b71ab69a848c3d
BLAKE2b-256 d4086200907f62af8e983d7eea9ab786e789e6a2ba8f11ac6ea99462a0cf7cf7

See more details on using hashes here.

Supported by

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