Skip to content

crashmetrics.lsdyna_ascii

lsdyna_ascii

Readers for LS-DYNA ASCII time-history output (nodout, rcforc, sleout ...).

Each reader returns an AsciiOutput: the output times, the entities (nodes, contacts, sections, airbags ...) in file order, and one array of shape (n_times, n_entities) per channel. Channel names follow the binout variable names (x_acceleration, x_force, total_moment ...), so code written for binout data reads the same.

Supported files (KINDS):

File Content Entities
nodout Nodal displacement, velocity, acceleration, rotation Nodes
rcforc Contact resultant forces and moments Contacts (surfa_*, surfb_*)
sleout Contact (sliding interface) energies Contacts; totals in totals
secforc Section forces, moments, centroid and area Cross sections
rwforc Rigid wall forces Rigid walls
sbtout Belt force and length, slip ring slip, retractor pull-out Belts
deforc Discrete element (spring, damper) forces Elements
jntforc Joint forces and moments, joint stiffnesses Joints
abstat Airbag volume, pressure, mass, temperature ... Airbags, control volumes
rbdout Rigid body motion Rigid bodies
spcforc Constraint (SPC) reaction forces Nodes; totals
swforc Spotweld and constrained weld forces, failure Welds

Glstat and matsum have their own readers in crashmetrics.lsdyna (read_glstat, read_matsum), which feed the energy checks.

The readers parse numbers that touch each other (1.0E+00-2.0E+00), Fortran exponents without the E (1.00000-100) and overflow fields (*****, read as NaN). When a run was restarted and the file goes back in time, the states after the restart time are replaced by the restarted ones. Unknown lines are skipped, so labels added by newer LS-DYNA versions do not break the readers.

Functions:

  • read_ascii, parse_ascii: Any supported file (kind from the file name or the content).
  • read_nodout, read_rcforc, read_sleout, read_secforc, read_rwforc, read_sbtout, read_deforc, read_jntforc, read_abstat, read_rbdout, read_spcforc, read_swforc: One file type each.
  • read_run: Every supported file found in a run directory.
  • detect_kind: The file type from a file name or text.
  • main: Command-line entry point: crashmetrics-ascii PATH ... [--csv DIR].

AsciiOutput dataclass

AsciiOutput(
    kind: str,
    time: ndarray,
    ids: tuple[Key, ...],
    data: dict[str, ndarray],
    totals: dict[str, ndarray] = dict(),
    names: dict[int, str] = dict(),
    title: str = "",
    version: str = "",
    cycle: ndarray | None = None,
)

Time histories read from one LS-DYNA ASCII output file.

Attributes:

Name Type Description
kind str

File type, e.g. "nodout".

time ndarray

Output times, in the model's time unit, shape (n,).

ids tuple[Key, ...]

Entity IDs (node, contact, section ...) in the order they first appear in the file.

data dict[str, ndarray]

Channel name -> array of shape (n, len(ids)); NaN where an entity has no value at a time (or the channel does not apply to it, e.g. belt_force of a retractor).

totals dict[str, ndarray]

File-level sums printed by LS-DYNA (sleout and spcforc), name -> array of shape (n,).

names dict[int, str]

Entity titles from the {BEGIN LEGEND} block (may be empty).

title, version

First two header lines: the model title and the LS-DYNA version line.

cycle ndarray | None

Cycle numbers where the file gives them, else None.

channels property

channels: list[str]

Channel names, in the order they were first read.

index

index(entity: Key) -> int

Column of an entity in the data arrays.

channel

channel(name: str, entity: Key | None = None) -> ndarray

One channel: shape (n,) for one entity, else (n, n_ids).

With entity=None and a single entity in the file, the 1-D history of that entity is returned.

entity

entity(entity: Key) -> dict[str, ndarray]

All channels of one entity that have at least one value.

magnitude

magnitude(
    channels: Sequence[str], entity: Key | None = None
) -> ndarray

Resultant of channels, e.g. ("x_force", "y_force", "z_force").

name

name(entity: Key) -> str

Title of an entity from the legend ("" if none).

summary

summary() -> str

Short text description of the file content.

to_csv

to_csv(
    path: str | Path,
    channels: Sequence[str] | None = None,
    ids: Sequence[Key] | None = None,
) -> Path

Write a wide CSV table: time, then one column per channel and entity.

Columns are named channel[id]; totals are added as total.name when no channel selection is given.

detect_kind

detect_kind(
    name: str | Path | None = None, text: str | None = None
) -> str

The file type: from the file name (e.g. nodout, run1.rcforc) or, failing that, from the text.

parse_ascii

parse_ascii(
    text: str,
    kind: str | None = None,
    ids: Iterable[Key] | None = None,
) -> AsciiOutput

Parse the text of an LS-DYNA ASCII output file.

Parameters:

Name Type Description Default
text str

File content.

required
kind str | None

File type (see KINDS); detected from the text if None.

None
ids Iterable[Key] | None

Read only these entities (faster for large nodout files).

None

read_ascii

read_ascii(
    path: str | Path,
    kind: str | None = None,
    ids: Iterable[Key] | None = None,
) -> AsciiOutput

Read an LS-DYNA ASCII output file.

The type comes from kind, else from the file name, else from the content; ids limits the entities read.

read_nodout

read_nodout(
    path: str | Path, ids: Iterable[Key] | None = None
) -> AsciiOutput

Read an LS-DYNA nodout file: nodal time histories.

ids limits the entities read.

read_rcforc

read_rcforc(
    path: str | Path, ids: Iterable[Key] | None = None
) -> AsciiOutput

Read an LS-DYNA rcforc file: contact resultant forces.

ids limits the entities read.

read_sleout

read_sleout(
    path: str | Path, ids: Iterable[Key] | None = None
) -> AsciiOutput

Read an LS-DYNA sleout file: contact energies (totals in totals).

ids limits the entities read.

read_secforc

read_secforc(
    path: str | Path, ids: Iterable[Key] | None = None
) -> AsciiOutput

Read an LS-DYNA secforc file: cross-section forces and moments.

ids limits the entities read.

read_rwforc

read_rwforc(
    path: str | Path, ids: Iterable[Key] | None = None
) -> AsciiOutput

Read an LS-DYNA rwforc file: rigid wall forces.

ids limits the entities read.

read_sbtout

read_sbtout(
    path: str | Path, ids: Iterable[Key] | None = None
) -> AsciiOutput

Read an LS-DYNA sbtout file: seatbelt, slip ring and retractor output.

ids limits the entities read.

read_deforc

read_deforc(
    path: str | Path, ids: Iterable[Key] | None = None
) -> AsciiOutput

Read an LS-DYNA deforc file: discrete element (spring and damper) forces.

ids limits the entities read.

read_jntforc

read_jntforc(
    path: str | Path, ids: Iterable[Key] | None = None
) -> AsciiOutput

Read an LS-DYNA jntforc file: joint forces and joint stiffness output.

ids limits the entities read.

read_abstat

read_abstat(
    path: str | Path, ids: Iterable[Key] | None = None
) -> AsciiOutput

Read an LS-DYNA abstat file: airbag and control volume statistics.

ids limits the entities read.

read_rbdout

read_rbdout(
    path: str | Path, ids: Iterable[Key] | None = None
) -> AsciiOutput

Read an LS-DYNA rbdout file: rigid body motion.

ids limits the entities read.

read_spcforc

read_spcforc(
    path: str | Path, ids: Iterable[Key] | None = None
) -> AsciiOutput

Read an LS-DYNA spcforc file: constraint (SPC) reaction forces.

ids limits the entities read.

read_swforc

read_swforc(
    path: str | Path, ids: Iterable[Key] | None = None
) -> AsciiOutput

Read an LS-DYNA swforc file: spotweld and constrained weld forces.

ids limits the entities read.

read_run

read_run(
    directory: str | Path,
    kinds: Iterable[str] | None = None,
    skip_errors: bool = False,
) -> dict[str, AsciiOutput]

Read every supported ASCII file in a run directory.

Files are found by name (nodout or NODOUT; a job-ID prefix such as run1.nodout also works). An output without an ASCII file is read from the folder's binout files if they have it (crashmetrics.binout). Files without any state (an empty output request) are left out.

Parameters:

Name Type Description Default
directory str | Path

Run directory.

required
kinds Iterable[str] | None

File types to read (default: all of KINDS).

None
skip_errors bool

Leave out files that cannot be read instead of raising.

False

main

main(argv: Sequence[str] | None = None) -> int

Run crashmetrics-ascii: summarise ASCII files, optionally as CSV.

Exit code 0 = all read, 2 = a file or directory could not be read.