ansys.dyna.core.lib.deck.Deck#
- class ansys.dyna.core.lib.deck.Deck(title: str = None, **kwargs)#
Bases:
ansys.dyna.core.lib.validation_mixin.ValidationMixinProvides a collection of keywords that can read and write to a keyword file.
- property format: ansys.dyna.core.lib.format_type.format_type#
Format type of the deck.
- __add__(other)#
Add two decks together.
- clear()#
Clear all keywords from the deck.
- property transform_handler: ansys.dyna.core.lib.transform.TransformHandler#
Handles transformations for the deck.
- register_import_handler(import_handler: ansys.dyna.core.lib.import_handler.ImportHandler) None#
Registers an ImportHandler object
- property parameters: ansys.dyna.core.lib.parameters.ParameterSet#
Deck parameters.
- append(keyword: ansys.dyna.core.lib.keyword_base.KeywordBase | str, check=False) None#
Add a keyword to the collection.
- property all_keywords: List[str | ansys.dyna.core.lib.keyword_base.KeywordBase | ansys.dyna.core.lib.encrypted_keyword.EncryptedKeyword]#
List of all keywords.
- property keywords: ansys.dyna.core.lib.keyword_collection.KeywordCollection#
Get all processed keywords as a KeywordCollection.
This provides access to the fluent filtering API for all keywords in the deck. The collection supports indexing, iteration, and comparison with lists for backward compatibility.
- Returns:
KeywordCollectionA collection of all KeywordBase instances in the deck.
Examples
>>> # Access by index (backward compatible) >>> first = deck.keywords[0] >>> # Iterate (backward compatible) >>> for kwd in deck.keywords: ... print(kwd.keyword) >>> # Filter with fluent API >>> high_id_sections = deck.keywords.where( ... lambda k: k.keyword == "SECTION" and k.secid > 100 ... )
- extend(kwlist: list) None#
Add a list of keywords to the deck.
- Parameters:
- kwlist
list List of keywords.
- kwlist
- expand(cwd=None, recurse=True, strict=False)#
Get a new deck that is flattened copy of self.
A flattened deck is one where the
*INCLUDEkeywords are replaced by the contents of the file that is included.- Parameters:
- cwd
str,optional Working directory used to resolve include filenames. Defaults to the current working directory.
- recursebool,
optional If True,
*INCLUDEkeywords within included decks are expanded recursively. Default is True.- strictbool,
optional If True, raise errors when keyword parsing fails for any reason (undefined parameters, invalid field values, malformed data, etc.). If False (default), keywords that fail to parse are retained as raw strings and a warning is emitted. Default is False for backward compatibility. TODO: Consider making strict=True the default in a future version.
- cwd
- dumps() str#
Get the keyword file representation of all keywords as a string.
- Returns:
strKeyword file representation of all keywords as a string.
- write(buf: TextIO | None = None, format: ansys.dyna.core.lib.format_type.format_type | None = None, validate: bool = False, retain_parameters: bool = False)#
Write the card in the dyna keyword format.
- Parameters:
- buf
optional Buffer to write to. The default is
None, in which case the output is returned as a string.- format
optional Format to write in. The default is
None.- validatebool,
optional If True, validate the deck before writing. The default is False. Validation uses registered validators and raises ValidationError if errors are found.
- retain_parametersbool,
optional If True, write original parameter references (e.g., &myvar) instead of substituted values for fields that were read from parameters. Default is False.
- buf
- loads(value: str, context: ansys.dyna.core.lib.import_handler.ImportContext | None = None) ansys.dyna.keywords.lib.deck_loader.DeckLoaderResult#
Load all keywords from the keyword file as a string.
When adding all keywords from the file, this method overwrites the title and user comment, if any.
- Parameters:
- value
str - context: ImportContext
the context
- value
- get_kwds_by_type(str_type: str) Iterator[ansys.dyna.core.lib.keyword_base.KeywordBase]#
Get all keywords for a given type.
- Parameters:
- str_type
str Keyword type.
- str_type
- Returns:
typing.Iterator[KeywordBase]
Examples
Get all
*SECTION_*keywords in the deck.>>>deck.get_kwds_by_type(“SECTION”)
- get_kwds_by_full_type(str_type: str, str_subtype: str) Iterator[ansys.dyna.core.lib.keyword_base.KeywordBase]#
Get all keywords for a given full type.
- Parameters:
- Returns:
typing.Iterator[KeywordBase]
Examples
Get all
*SECTION_SHELLkeyword instances in the deck.>>>deck.get_kwds_by_full_type(“SECTION”, “SHELL”)
Get all
*SET_NODE*keyword instances (matches NODE, NODE_LIST, NODE_LIST_TITLE, etc).>>>deck.get_kwds_by_full_type(“SET”, “NODE”)
- get_section_by_id(id: int) ansys.dyna.core.lib.keyword_base.KeywordBase | None#
Get the SECTION keyword in the collection for a given section ID.
- get_set_by_id(id: int) ansys.dyna.core.lib.keyword_base.KeywordBase | None#
Get the SET keyword in the collection for a given set ID.
- get(**kwargs) List[ansys.dyna.core.lib.keyword_base.KeywordBase]#
Get a list of keywords.
- Parameters:
- - *kwargs* (``dict``) –
Keyword arguments. * type (
str) – The type of keyword to get. For example, “SECTION” returns all section keywords. * filter (callable) – The filter to apply to the result. Only keywords which pass the filter will be returned.
- import_file(path: str, encoding: str = 'utf-8') ansys.dyna.keywords.lib.deck_loader.DeckLoaderResult#
Import a keyword file.
- Parameters:
- path
str Full path for the keyword file.
- encoding: str
String encoding used to read the keyword file.
- path
- export_file(path: str, encoding='utf-8', validate: bool = False, retain_parameters: bool = False) None#
Export the keyword file to a new keyword file.
- Parameters:
- path
str Full path for the new keyword file.
- encoding
str,optional String encoding for the file. The default is “utf-8”.
- validatebool,
optional If True, validate the deck before export. The default is False. Validation uses registered validators and raises ValidationError if errors are found.
- retain_parametersbool,
optional If True, write original parameter references (e.g., &myvar) instead of substituted values for fields that were read from parameters. Default is False.
- path
Examples
>>> deck.export_file("output.k", validate=True) # Validate before export >>> deck.export_file("output.k", retain_parameters=True) # Keep parameter references
- __getitem__(key: str | Tuple[str, str]) ansys.dyna.core.lib.keyword_collection.KeywordCollection#
Get keywords by type using dict-like access.
- Parameters:
- Returns:
KeywordCollectionA collection of matching keywords.
Examples
>>> sections = deck["SECTION"] >>> shells = deck["SECTION", "SHELL"]
- __iter__() Iterator[ansys.dyna.core.lib.keyword_base.KeywordBase | str | ansys.dyna.core.lib.encrypted_keyword.EncryptedKeyword]#
Iterate over all keywords in the deck.
- Returns:
Iterator[Union[KeywordBase,str,EncryptedKeyword]]An iterator over all keywords.
Examples
>>> for kwd in deck: ... if isinstance(kwd, KeywordBase): ... print(kwd.keyword)
- __len__() int#
Get the number of keywords in the deck.
- Returns:
intThe total number of keywords (including strings and encrypted).
Examples
>>> num_keywords = len(deck)
- property sections: ansys.dyna.core.lib.keyword_collection.KeywordCollection#
Get all SECTION_* keywords.
- Returns:
KeywordCollectionA collection of all section keywords.
Examples
>>> shells = deck.sections.by_subtype("SHELL")
- property materials: ansys.dyna.core.lib.keyword_collection.KeywordCollection#
Get all MAT_* keywords.
- Returns:
KeywordCollectionA collection of all material keywords.
Examples
>>> elastic_mats = deck.materials.by_subtype("ELASTIC")
- property elements: ansys.dyna.core.lib.keyword_collection.KeywordCollection#
Get all ELEMENT_* keywords.
- Returns:
KeywordCollectionA collection of all element keywords.
Examples
>>> solid_elements = deck.elements.by_subtype("SOLID")
- property nodes: ansys.dyna.core.lib.keyword_collection.KeywordCollection#
Get all NODE keywords.
- Returns:
KeywordCollectionA collection of all node keywords.
Examples
>>> all_nodes = deck.nodes.to_list()
- property parts: ansys.dyna.core.lib.keyword_collection.KeywordCollection#
Get all PART* keywords.
- Returns:
KeywordCollectionA collection of all part keywords.
Examples
>>> parts = deck.parts.to_list()
- property sets: ansys.dyna.core.lib.keyword_collection.KeywordCollection#
Get all SET_* keywords.
- Returns:
KeywordCollectionA collection of all set keywords.
Examples
>>> node_sets = deck.sets.by_subtype("NODE")
- property defines: ansys.dyna.core.lib.keyword_collection.KeywordCollection#
Get all DEFINE_* keywords.
- Returns:
KeywordCollectionA collection of all define keywords.
Examples
>>> curves = deck.defines.by_subtype("CURVE")
- split(key_func: Callable[[ansys.dyna.core.lib.keyword_base.KeywordBase | str | ansys.dyna.core.lib.encrypted_keyword.EncryptedKeyword], Any]) Dict[Any, Deck]#
Split the deck into multiple decks based on a key function.
The key function is called on each keyword and should return a value that will be used to group keywords. Keywords with the same return value will be placed in the same deck.
- Parameters:
- key_func
Callable[[Union[KeywordBase,str,EncryptedKeyword]],Any] A function that takes a keyword and returns a grouping key.
- key_func
- Returns:
Dict[Any,Deck]A dictionary mapping keys to Deck instances.
Examples
>>> # Split by keyword type >>> decks_by_type = deck.split(lambda k: k.keyword if isinstance(k, KeywordBase) else "string") >>> section_deck = decks_by_type["SECTION"]
>>> # Split by domain using the domain mapper >>> from ansys.dyna.core.lib.domain_mapper import by_domain >>> decks_by_domain = deck.split(by_domain) >>> mat_deck = decks_by_domain["mat"]
>>> # Custom splitting logic >>> def by_id_range(kwd): ... if isinstance(kwd, KeywordBase) and hasattr(kwd, 'secid'): ... if kwd.secid < 100: ... return "low" ... else: ... return "high" ... return "other" >>> decks = deck.split(by_id_range)
- split_by_domain() Dict[str, Deck]#
Split the deck by keyword domain (mat, section, control, etc.).
This is a convenience method that uses the domain mapper to categorize keywords. For custom splitting logic, use the split() method directly.
- Returns:
Dict[str,Deck]A dictionary mapping domain names to Deck instances.
See also
splitGeneric splitting method with custom key function.
Examples
>>> decks = deck.split_by_domain() >>> mat_deck = decks["mat"] >>> control_deck = decks["control"] >>> section_deck = decks["section"]
- plot(**args)#
Plot the node and element of the mesh using PyVista.
Automatically detects Jupyter notebook environments and configures appropriate rendering backend for display.
- Parameters:
- cwd
str,optional Current working directory if the deck and include files are in a separate directory.
- jupyter_backend
str,optional Jupyter backend to use. Options are:
'static'- Static image (default for notebooks)'server'- Interactive with server backend'trame'- Interactive with Trame (requires pyvista[trame])None- Disable Jupyter mode, use default windowing'auto'- Automatically detect (default)
- color
str,optional Color of the mesh.
- scalars
str,optional Name of scalars to color by (e.g., ‘part_ids’, ‘element_ids’).
- **args
Additional keyword arguments passed to PyVista’s plot method.
- cwd
- Returns:
DependsonbackendCamera position or plot object depending on the backend used.
Examples
Plot a deck in a regular Python script:
>>> deck.plot()
Plot with a specific working directory:
>>> deck.plot(cwd='/path/to/includes')
Plot in a Jupyter notebook with interactive backend:
>>> deck.plot(jupyter_backend='server')
Color by part IDs:
>>> deck.plot(scalars='part_ids')