ansys.dyna.core.lib.kwd_line_formatter#

Keyword line formatter.

Attributes#

Classes#

FormatSpec

Immutable, hashable specification for parsing fixed-width data lines.

Functions#

read_line(→ Tuple[str, bool])

Read and return the line, and a flag on whether to stop reading.

at_end_of_keyword(→ bool)

Return whether the buffer is at the end of the keyword

buffer_to_lines(→ List[str])

Read from the buffer into a list of string.

seek_text_block(→ Tuple[int, str])

Returns the text block from the line at the given position and width.

has_value(→ bool)

Given a text block - determine if a keyword value exists.

load_dataline(→ List)

Loads a keyword card line from string, auto-detecting fixed-width or comma-delimited format.

load_dataline_with_format(→ Tuple[List, str])

Like load_dataline, but also returns the detected format.

Module Contents#

ansys.dyna.core.lib.kwd_line_formatter.logger[source]#
ansys.dyna.core.lib.kwd_line_formatter.read_line(buf: TextIO, skip_comment=True) Tuple[str, bool][source]#

Read and return the line, and a flag on whether to stop reading.

ansys.dyna.core.lib.kwd_line_formatter.at_end_of_keyword(buf: TextIO) bool[source]#

Return whether the buffer is at the end of the keyword

ansys.dyna.core.lib.kwd_line_formatter.buffer_to_lines(buf: TextIO, max_num_lines: int = -1) List[str][source]#

Read from the buffer into a list of string. buf: buffer to read from max_num_lines: number of lines to read. -1 means no limit

ansys.dyna.core.lib.kwd_line_formatter.seek_text_block(line_data: str, position: int, width: int) Tuple[int, str][source]#

Returns the text block from the line at the given position and width.

If the position is past the end, it will return an empty string.

ansys.dyna.core.lib.kwd_line_formatter.has_value(text_block: str) bool[source]#

Given a text block - determine if a keyword value exists.

If its an empty string (i.e. the seek_text_block returned an empty string) then there is no value. If its just whitespace, then the keyword file did not include data for that field.

ansys.dyna.core.lib.kwd_line_formatter.load_dataline(spec: List[tuple], line_data: str, parameter_set: ansys.dyna.core.lib.parameters.ParameterSet = None) List[source]#

Loads a keyword card line from string, auto-detecting fixed-width or comma-delimited format.

LS-DYNA supports both fixed-width format and comma-delimited (free) format. This function automatically detects which format is used based on the presence of commas in the line. Per the LS-DYNA manual, formats can be mixed within a deck but not within a single card.

Parameters:
speclist of tuple

List of tuples representing the (offset, width, type) of each field. Type can be a Flag which represents the True and False value.

line_datastr

String with keyword data (fixed-width or comma-delimited).

parameter_setParameterSet, optional

Optional parameter set.

Returns:
list

Parsed values from the keyword card line.

Examples

>>> load_dataline([(0,10, int),(10,10, str)], '         1     hello')
(1, 'hello')
>>> load_dataline([(0,10, int),(10,10, str)], '1,hello')
(1, 'hello')
ansys.dyna.core.lib.kwd_line_formatter.load_dataline_with_format(spec: List[tuple], line_data: str, parameter_set: ansys.dyna.core.lib.parameters.ParameterSet = None) Tuple[List, str][source]#

Like load_dataline, but also returns the detected format.

Returns:
tuple

A tuple of (values, format) where format is ‘csv’ or ‘fixed’.