Skip to main content

LS-DYNA® Keyword Reader (dynakw)

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

The library is designed to scale by incorporating LS-DYNA documentation and keyword examples.

The maintenance and expansion of the library is automated by supplying the relevant LS-DYNA information to AI coding agents, the details of which are handled by the slash commands provided for the Gemini CLI and Claude Code.

Status

Currently implemented:

  • *BOUNDARY_PRESCRIBED_MOTION
  • *CONSTRAINED_JOINT_TYPE
  • *CONTROL_TERMINATION
  • *DEFINE_CURVE
  • *ELEMENT_SHELL
  • *ELEMENT_SOLID
  • *MAT_ELASTIC
  • *MAT_RIGID
  • *NODE
  • *PARAMETER
  • *PARAMETER_EXPRESSION
  • *PART
  • *SECTION_SHELL
  • *SECTION_SOLID
  • *SET_NODE
  • *SET_SEGMENT
  • *SET_SHELL
  • *SET_SOLID

*CONSTRAINED_JOINT covers all fourteen joint types (SPHERICAL, REVOLUTE, CYLINDRICAL, PLANAR, UNIVERSAL, TRANSLATIONAL, LOCKING, the two MOTOR types, GEARS, RACK_AND_PINION, CONSTANT_VELOCITY, PULLEY and SCREW) with the ID, LOCAL and FAILURE options.

All of these can be built from data as well as read, so a program can generate a deck rather than only edit one. Ask the library using Listing the supported keywords to report an up-to-date list of the supported keywords and the related keyword documentation.

The keywords not supported are preserved as raw text, which can be written out unchanged, allowing the complete 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)

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:

# To modify data in a specific keyword
if kw.type == KeywordType.BOUNDARY_PRESCRIBED_MOTION:
    kw.cards['Card 1']['SF'] = kw.cards['Card 1']['SF'] * 1.5

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

To obtain the parameter names and values specified using *PARAMETER:

par_dict = dkr.parameters()

To change the parameter values:

parameters_to_change = {
        "term": 0.5,
        "plot": "term/(states-50) * 2.0"
}
dkr.set_parameters(parameters_to_change)
dkr.write(output_file)

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

Installation

Install dynakw using pip:

pip install dynakw

Example problems

The example problems demonstrate:

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

Listing the supported keywords

Ask the library rather than reading a list that might be out of date. The report is derived from the same card definitions that drive reading and writing, so it always matches what the code does.

python -m dynakw.manifest                            # summary table
python -m dynakw.manifest --describe '*MAT_ELASTIC'  # cards and fields
python -m dynakw.manifest --format json              # machine-readable

The same information is available in Python, which is how a deck-generating tool would check that what it needs is implemented before it starts:

import dynakw

for spec in dynakw.supported_keywords():
    print(spec.keyword, spec.description)

spec = dynakw.describe_keyword("*MAT_ELASTIC_FLUID")
for card in spec.cards:
    for f in card.fields:
        print(card.name, f.name, f.type, f.description)

The keywords not supported are preserved as raw text, which can be written out unchanged, allowing

More documentation

Online documentation is available here

See also 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 an AI coding agent

The same slash commands are available in both the Gemini CLI and Claude Code:

/generate_instructions SECTION_SPH
/implement_keyword SECTION_SPH
/update_qa

The /generate_instructions SECTION_SPH will create a file named SECTION_SPH_instructions.txt, which is used by /implement_keyword.

Two further commands are provided: /get_keyword_example retrieves example decks containing a given keyword, and /update_docs rebuilds and publishes the online documentation.

See .gemini/commands/*.toml and .claude/skills/*/SKILL.md for the prompts, and the GEMINI.md file for an explanation of the code structure.

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. Prefer the declarative approach: describe the card layout with CardField/CardSchema class attributes and the base class handles parsing and writing for you. Only override _parse_raw_data and write when the layout cannot be expressed declaratively.
  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/ 2.

License

This project is licensed under the MIT License.

  1. If this is your only use case then lsdyna-mesh-reader is an alternative. lsdyna-mesh-reader however only supports the reading of the nodes and linear elements, so the plotting of loads etc. is not possible.

  2. The examples are currently provided free of charge, please see the instructions on the website, specifically the home page.

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.7.0.tar.gz (103.8 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.7.0-py3-none-any.whl (134.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dynakw-1.7.0.tar.gz
Algorithm Hash digest
SHA256 e54e3e0a3688c3d1cd44a672cd03cce908326e0377dfb5df9b3ed8686799555a
MD5 74f318a3b63e9b909c6bb690023d7cad
BLAKE2b-256 84be93d775cfc4e4489fcfa05086dc4cfdf87d89f6972f95582dad2011cdc681

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for dynakw-1.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ad2209ca3ea776719d27fb9639c266abcbcb8ea4079cb804aad4fd124b138c6
MD5 31fcc785ff7e2a516567816a32a4d6f5
BLAKE2b-256 f8d2ea2270ca82e626d876b3af6e290226eeac1e35349ffbadea72628d37dd68

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.7.0 This release

2 files

1.6.0

2 files

1.5.0

2 files

1.3.1

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page