API Reference¶
LS-DYNA Keywords Reader Library
- class dynakw.DynaKeywordReader(filename: str, follow_include: bool = False, debug: bool = False)¶
Main class for reading and writing LS-DYNA keyword files
Initializes the LSDynaKeyword object.
- Parameters:
filename (str) – The path to the LS-DYNA file.
follow_include (bool) – Read include files.
debug (bool) – Whether to print debug statements.
- find_keywords(keyword_type: KeywordType) List[LSDynaKeyword]¶
Find all keywords of a specific type
- keywords() Iterator[LSDynaKeyword]¶
Iterator over keywords, reading from the file as needed.
- parameters() Dict[str, float | int | str]¶
Returns a dictionary of parameter names and values found in the file.
- set_parameters(params_update_dict: Dict[str, float | int | str])¶
Updates parameters in the file based on the dictionary.
- Parameters:
params_update_dict (dict) – Dictionary where keys are parameter names (str) and values are the new values (float, int, str). Keys are matched case-insensitively.
- write(filename: str)¶
Write all keywords to a file
- class dynakw.KeywordType(*values)¶
Enumeration of supported LS-DYNA keywords
- class dynakw.LSDynaKeyword(keyword_name: str, raw_lines: List[str] = None, start_line: int = None)¶
Base class for all LS-DYNA keyword objects.
This class provides the basic structure for representing an LS-DYNA keyword, including methods for parsing from raw text and writing back to a file format.
Subclasses can either: - Define
card_schemas(a list of CardSchema objects) to get automaticparse and write behaviour provided by this base class, or
Override
_parse_raw_dataandwritedirectly for custom logic.
- cards¶
The cards content as described in the LS-DYNA manual; e.g. kw.cards[‘Card 1’][‘SF’]
- Type:
Dict[str, Dict[str, np.ndarray]] = {}
- card_schemas¶
Declarative card layout. When set, the base class automatically handles parsing and writing.
- Type:
List[CardSchema]
Initializes the LSDynaKeyword object.
- Parameters:
keyword_name (str) – The full name of the keyword (e.g., “*BOUNDARY_PRESCRIBED_MOTION_NODE”).
raw_lines (List[str], optional) – The raw text lines for the keyword. Defaults to None.
start_line (int, optional) – The line number where the keyword starts in the file. Defaults to None.
- KEYWORD_MAP: Dict[str, LSDynaKeyword] = {'*BOUNDARY_PRESCRIBED_MOTION': <class 'dynakw.keywords.BOUNDARY_PRESCRIBED_MOTION.BoundaryPrescribedMotion'>, '*ELEMENT_SHELL': <class 'dynakw.keywords.ELEMENT_SHELL.ElementShell'>, '*ELEMENT_SOLID': <class 'dynakw.keywords.ELEMENT_SOLID.ElementSolid'>, '*MAT_001': <class 'dynakw.keywords.MAT_ELASTIC.MatElastic'>, '*MAT_001_FLUID': <class 'dynakw.keywords.MAT_ELASTIC.MatElastic'>, '*MAT_ELASTIC': <class 'dynakw.keywords.MAT_ELASTIC.MatElastic'>, '*MAT_ELASTIC_FLUID': <class 'dynakw.keywords.MAT_ELASTIC.MatElastic'>, '*NODE': <class 'dynakw.keywords.NODE.Node'>, '*PARAMETER': <class 'dynakw.keywords.PARAMETER.Parameter'>, '*PARAMETER_EXPRESSION': <class 'dynakw.keywords.PARAMETER_EXPRESSION.ParameterExpression'>, '*PART': <class 'dynakw.keywords.PART.Part'>, '*SECTION_SHELL': <class 'dynakw.keywords.SECTION_SHELL.SectionShell'>, '*SECTION_SOLID': <class 'dynakw.keywords.SECTION_SOLID.SectionSolid'>, '*UNKNOWN': <class 'dynakw.keywords.UNKNOWN.Unknown'>}¶
A registry of all known keyword strings and the classes that handle them.
- card_groups: List[CardGroup] = []¶
Grouped card layout for interleaved (per-element) parse/write. When set, each group is written as: all headers first, then one row per schema per element. Takes precedence over card_schemas in the default implementations.
- card_schemas: List[CardSchema] = []¶
Declarative card layout. Override in subclasses to enable auto-parse/write.
- static discover_keywords()¶
Dynamically imports all keyword modules from the ‘keywords’ directory to ensure they are registered in the KEYWORD_MAP.
- write(file_obj: TextIO)¶
Writes the keyword and its data to a file object.
If
card_groupsis defined, uses interleaved grouped writing. Ifcard_schemasis defined, uses sequential schema writing. Otherwise subclasses must override this method.
- class dynakw.ParameterRef(name: str)¶
A reference to a *PARAMETER variable in a data field.
In LS-DYNA files, parameter references appear as
&VARNAMEinside numeric or string card fields. Instead of attempting (and failing) to convert the field to int or float, the parser stores aParameterRefobject so that the reference is preserved faithfully on round-trip.Example:
*MAT_ELASTIC $ MID RO E PR 1 7.85e-9 &Emod &PRvalAfter parsing,
kw.cards['Card 1']['E'][0]isParameterRef('Emod')rather than raising a ValueError.- name: str¶
Variable name without the leading
&.