The writer_utils.py module#

Summary#

create_node_keyword

Create node keyword from a NumPy array of nodes.

add_nodes_to_kw

Add nodes to an existing *NODE keyword.

add_beams_to_kw

Add beams to an existing *ELEMENT_BEAM keyword.

create_segment_set_keyword

Create a segment set keyword from an array with the segment set definition.

create_node_set_keyword

Create a nodeset.

create_element_shell_keyword

Create an element shell keyword.

create_element_solid_keyword

Format the *ELEMENT_SOLID keyword with the provided input.

create_element_solid_ortho_keyword

Format the *ELEMENT_SOLID_ORTHO keyword with the provided input.

create_define_curve_kw

Create define curve from x and y values.

create_define_sd_orientation_kw

Create define SD orientation keyword.

create_discrete_elements_kw

Create discrete elements based on input arguments.

get_list_of_used_ids

Get array of used IDs in the database.

fast_element_writer

Fast implementation of the element writer.

Description#

Module for useful methods to help format LS-DYNA keywords.

Module detail#

writer_utils.create_node_keyword(nodes: numpy.ndarray, offset: int = 0) ansys.dyna.core.keywords.keywords.Node#

Create node keyword from a NumPy array of nodes.

Parameters:
nodesnp.ndarray

NumPy array containing the node coordinates.

Returns:
keywords.Node

Formatted node keyword.

writer_utils.add_nodes_to_kw(nodes: numpy.ndarray, node_kw: ansys.dyna.core.keywords.keywords.Node, offset: int = 0) ansys.dyna.core.keywords.keywords.Node#

Add nodes to an existing *NODE keyword.

Parameters:
nodesnp.ndarray

NumPy array of node coordinates to add. If (n,3), the node ID is continuous by offset. If (n,4), the first column is the node ID.

node_kwkeywords.Node

Node keyword.

offsetint

Node ID offset.

Notes

If nodes are already defined, this method adds both the nodes in the previous keyword and the specified array of nodes. It automatically computes the index offset in case node_kw.nodes is not empty.

writer_utils.add_beams_to_kw(beams: numpy.ndarray, beam_kw: ansys.dyna.core.keywords.keywords.ElementBeam, pid: int, offset: int = 0) ansys.dyna.core.keywords.keywords.ElementBeam#

Add beams to an existing *ELEMENT_BEAM keyword.

Parameters:
beamsnp.ndarray

NumPy array of beam coordinates to add.

beam_kwkeywords.ElementBeam

Beam keyword.

offsetint

Beam ID offset.

Notes

If beams are already defined, this method adds both the beams in the previous keyword and the specified array of beams. It automatically computes the index offset in case beam_kw.elements is not empty.

writer_utils.create_segment_set_keyword(segments: numpy.ndarray, segid: int = 1, title: str = '') ansys.dyna.core.keywords.keywords.SetSegment#

Create a segment set keyword from an array with the segment set definition.

Parameters:
segmentsnp.ndarray

Array of node indices that make up the segment. If three columns are provided, it is assumed that the segments are triangular

segidint, default: 1

Segment set ID.

titlestr, default: “”

Title of the segment set.

Returns:
keywords.SetSegment

Formatted segment set keyword.

writer_utils.create_node_set_keyword(node_ids: numpy.ndarray | list[int] | int, node_set_id: int = 1, title: str = 'nodeset-title') ansys.dyna.core.keywords.keywords.SetNodeList#

Create a nodeset.

Parameters:
node_idsnp.ndarray | list[int] | int

List of node IDs to include in the nodeset.

node_set_idint, default: 1

ID of the nodeset.

titlestr, default: 'nodeset-title'

Title of the nodeset

Returns:
keywords.SetNodeList

Formatted nodeset.

writer_utils.create_element_shell_keyword(shells: numpy.ndarray, part_id: int = 1, id_offset: int = 0) ansys.dyna.core.keywords.keywords.ElementShell#

Create an element shell keyword.

Notes

This method creates an element shell keyword from a NumPy array of elements. Each row corresponds to an element.

writer_utils.create_element_solid_keyword(elements: numpy.ndarray, e_id: numpy.ndarray, part_id: numpy.ndarray, element_type: str = 'tetra') ansys.dyna.core.keywords.keywords.ElementSolid#

Format the *ELEMENT_SOLID keyword with the provided input.

Parameters:
elementsnp.ndarray

NumPy array of integers with element definition.

part_idnp.ndarray

Part IDs of each element.

e_idnp.ndarray

Element ID.

element_typestr, default: 'tetra'

Type of element to write

Returns:
keywords.ElementSolid

Formatted *ELEMENT_SOLID keyword.

writer_utils.create_element_solid_ortho_keyword(elements: numpy.ndarray, a_vec: numpy.ndarray, d_vec: numpy.ndarray, e_id: numpy.ndarray, part_id: numpy.ndarray, element_type: str = 'tetra') ansys.dyna.core.keywords.keywords.ElementSolidOrtho#

Format the *ELEMENT_SOLID_ORTHO keyword with the provided input.

Parameters:
elementsnp.ndarray

NumPy array of integers with element definition

a_vecnp.ndarray

Vector specifying the A direction.

d_vecnp.ndarray

Vector specifying the D direction.

part_idnp.ndarray

Part IDs of each element.

e_idnp.ndarray

Element ID.

element_typestr, default: 'tetra'

Type of element to write.

Returns:
keywords.ElementSolidOrtho

Formatted *ELEMENT_SOLID_ORTHO keyword.

writer_utils.create_define_curve_kw(x: numpy.ndarray, y: numpy.ndarray, curve_name: str = 'my-title', curve_id: int = 1, lcint: int = 15000) ansys.dyna.core.keywords.keywords.DefineCurve#

Create define curve from x and y values.

writer_utils.create_define_sd_orientation_kw(vectors: numpy.ndarray, vector_id_offset: int = 0, iop: int = 0) ansys.dyna.core.keywords.keywords.DefineSdOrientation#

Create define SD orientation keyword.

Parameters:
vectorsnp.ndarray

Array of shape Nx3 with the defined vector.

vector_id_offsetint, default: 0

Offset for the vector ID.

iopint, default: 0

Option.

writer_utils.create_discrete_elements_kw(nodes: numpy.ndarray, part_id: int, vector_ids: numpy.ndarray | int, scale_factor: numpy.ndarray | float, element_id_offset: int = 0) ansys.dyna.core.keywords.keywords.ElementDiscrete#

Create discrete elements based on input arguments.

Parameters:
nodesnp.ndarray

Nx2 array with node IDs used for the discrete element.

part_idint

Part ID of the discrete elements given.

vector_idsnp.ndarray | int

Orientation IDs (vector IDs) that the spring acts on. You can provide either an array of length N or a scalar integer.

scale_factornp.ndarray | float

Scale factor on forces. You can provide either an array of length N or a scalar value.

element_id_offsetint, default: 0

Offset value for the element IDs.

init_offsetfloat, default: 0.0

Initial offset, which is the initial displacement or rotation at t=0.

writer_utils.get_list_of_used_ids(keyword_db: ansys.dyna.core.Deck, keyword_str: str) numpy.ndarray#

Get array of used IDs in the database.

Parameters:
databaseDeck

Database of keywords.

keywordstr

Keyword to find.

Returns:
np.ndarray

Array of IDs (integers) that are already used

Notes

For example, for *SECTION, you would get *PART and *MAT IDs.

writer_utils.fast_element_writer(element_kw: ansys.dyna.core.keywords.keywords.ElementSolidOrtho | ansys.dyna.core.keywords.keywords.ElementSolid, filename: str) None#

Fast implementation of the element writer.

Notes

Use this method as an alternative to the PyDYNA keywords module.