ansys.dyna.core.lib.field_writer#

Module for writing fields to buffers.

Attributes#

Functions#

check_field_type(field_type)

Check that the field type is valid.

write_field_c(→ None)

Write a single field to the buffer.

write_field(→ None)

Write a single field to the buffer.

write_c_dataframe(→ None)

Method to write a DataFrame to a buffer using hollerith format.

write_fields(→ None)

Write fields representing a line of a keyword to buf.

write_comment_line(→ None)

Writes the comment line to the buffer.

write_fields_csv(→ None)

Write fields representing a line of a keyword to buf in comma-delimited format.

write_c_dataframe_csv(→ None)

Write a DataFrame to buf in comma-delimited format.

Module Contents#

ansys.dyna.core.lib.field_writer.logger[source]#
ansys.dyna.core.lib.field_writer.check_field_type(field_type: type)[source]#

Check that the field type is valid.

ansys.dyna.core.lib.field_writer.write_field_c(buf: IO[AnyStr], field_type: type, value: Any, width: int) None[source]#

Write a single field to the buffer.

ansys.dyna.core.lib.field_writer.write_field(buf: IO[AnyStr], field_type: type, value: Any, width: int) None[source]#

Write a single field to the buffer.

ansys.dyna.core.lib.field_writer.write_c_dataframe(buf: IO[AnyStr], fields: List[ansys.dyna.core.lib.field.Field], table: pandas.DataFrame, format: ansys.dyna.core.lib.format_type.format_type) None[source]#

Method to write a DataFrame to a buffer using hollerith format.

ansys.dyna.core.lib.field_writer.write_fields(buf: IO[AnyStr], fields: List[ansys.dyna.core.lib.field.Field], values: List[Any] | None = None, format: ansys.dyna.core.lib.format_type.format_type | None = format_type.default) None[source]#

Write fields representing a line of a keyword to buf.

Use the fixed column offsets and width

Parameters:
buf: IO

buffer to write to

fields: List

fields to write

values: List

optional - list of values for the field. If not set, use the value property of each field. used by TableCard

format: format_type

optional - format to write

>>> s=io.String()
>>> fields = [
… Field(“a”, int, 0, 10, 1),
… Field(“b”, str, 10, 10, “hello”)
… ]
>>> write_fields(s, fields)
>>> s.getvalue()
‘ 1 hello’
ansys.dyna.core.lib.field_writer.write_comment_line(buf: IO[AnyStr], fields: List[ansys.dyna.core.lib.field.Field], format: ansys.dyna.core.lib.format_type.format_type | None = format_type.default) None[source]#

Writes the comment line to the buffer.

Parameters:
buf: IO

buffer to write to

fields: List

fields to write

format: format_type

format to write in

>>> s=io.String()
>>> fields = [
… Field(“a”, int, 0, 10, 1),
… Field(“b”, str, 10, 10, “hello”)
… ]
>>> write_comment_line(s, fields)
>>> s.getvalue()
‘ a b’
ansys.dyna.core.lib.field_writer.write_fields_csv(buf: IO[AnyStr], fields: List[ansys.dyna.core.lib.field.Field], values: List[Any] | None = None) None[source]#

Write fields representing a line of a keyword to buf in comma-delimited format.

This produces LS-DYNA compatible comma-delimited (free format) output.

Parameters:
bufIO

Buffer to write to.

fieldsList[Field]

Fields to write.

valuesList[Any], optional

List of values for the fields. If not set, use the value property of each field.

Examples

>>> s = io.StringIO()
>>> fields = [
...     Field("a", int, 0, 10, value=1),
...     Field("b", str, 10, 10, value="hello")
... ]
>>> write_fields_csv(s, fields)
>>> s.getvalue()
'1,hello'
ansys.dyna.core.lib.field_writer.write_c_dataframe_csv(buf: IO[AnyStr], fields: List[ansys.dyna.core.lib.field.Field], table: pandas.DataFrame) None[source]#

Write a DataFrame to buf in comma-delimited format.

Parameters:
bufIO

Buffer to write to.

fieldsList[Field]

Field definitions for the columns.

tablepd.DataFrame

The data to write.