Skip to content

crashmetrics.mesh

mesh

Read the mesh of an LS-DYNA keyword file: nodes, elements and parts.

read_mesh reads *NODE, *ELEMENT_SHELL, *ELEMENT_SOLID, *ELEMENT_BEAM (and their _TITLE or option forms), and the titles of *PART cards, in fixed, long (+ or %) and comma formats. The result, a Mesh, gives the node coordinates of any parts, for geometry checks such as bonnet clearance (crashmetrics.pedestrian.clearance). write_mesh writes nodes and shell elements in the keyword format.

Includes (*INCLUDE) are not followed: read each file and combine the meshes with Mesh.merge, or give the file that holds the parts.

Mesh dataclass

Mesh(
    node_ids: NDArray[int64],
    coordinates: FloatArray,
    elements: dict[
        str, dict[int, tuple[int, tuple[int, ...]]]
    ] = dict(),
    part_names: dict[int, str] = dict(),
    source: str = "",
)

Nodes, elements and parts of a keyword file (model units).

coordinates instance-attribute

coordinates: FloatArray

(node, 3).

elements class-attribute instance-attribute

elements: dict[
    str, dict[int, tuple[int, tuple[int, ...]]]
] = field(default_factory=dict)

Element type -> element ID -> (part ID, node IDs).

part_ids property

part_ids: tuple[int, ...]

Parts that have elements, by ID.

part_nodes

part_nodes(part_id: int) -> NDArray[int64]

IDs of the nodes of a part's elements, sorted.

points

points(parts: int | Iterable[int]) -> FloatArray

Coordinates (n, 3) of the nodes of one or several parts.

coordinates_of

coordinates_of(
    node_ids: Sequence[int] | NDArray[int64],
) -> FloatArray

Coordinates (n, 3) of the given nodes.

find_parts

find_parts(pattern: str) -> list[int]

Part IDs whose title matches a pattern (*, ?; case ignored).

merge

merge(other: Mesh) -> Mesh

This mesh and another (for example an include file).

read_mesh

read_mesh(
    path: str | Path, *, parts: Iterable[int] | None = None
) -> Mesh

Read nodes, elements and part titles of a keyword file.

parts keeps only the elements of those parts (and all nodes).

write_mesh

write_mesh(
    path: str | Path,
    node_ids: Sequence[int] | NDArray[int64],
    coordinates: FloatArray,
    shells: Mapping[int, tuple[int, Sequence[int]]],
    part_names: Mapping[int, str],
    *,
    title: str = "",
) -> Path

Write *NODE, *PART (title only, no section or material) and *ELEMENT_SHELL in fixed format.