Skip to content

crashmetrics.binout

binout

Reader for LS-DYNA binout files (the binary form of the ASCII outputs).

A binout holds the same time histories as the ASCII files (glstat, matsum, nodout, rcforc, secforc, sleout, spcforc, swforc, abstat ...), in one or more files (binout, binout0000, binout0001 ...). read_binout reads them all and gives each output as the same objects the ASCII readers return, so every analysis works on either:

from crashmetrics.binout import read_binout

bo = read_binout("runs/loop12")           # a run folder, a file or a list
print(bo.summary())                        # outputs, states, time range
nodout = bo.output("nodout")               # AsciiOutput, as read_nodout gives
energies = bo.glstat()                     # GlobalEnergies, as read_glstat
parts = bo.matsum()                        # PartEnergies, as read_matsum
bo.read("nodout", "x_acceleration")        # one variable, (states, nodes)
The file layout

This reader was written from the file layout itself, worked out from public binout files (byte dumps checked against the ASCII files the same runs wrote). No code or documentation of other binout readers was used.

  • Header (8 bytes): header length, then the sizes in bytes of the record length field (8), of file offsets (8), of the command field (1) and of the type field (1), then a byte-order flag (1: little-endian).
  • Records: [length][command][payload], the length including its own field. Commands: 2 changes the directory (absolute, or relative to the current one); 3 stores a variable, [type][name length (1 byte)][name][values]; 7 gives the offset of the first symbol table; 5 is a symbol table (a directory and, per variable, its name, type, offset and value count, ending with the offset of the next table, 0 for the last).
  • Types: 1 text, 3 32-bit and 4 64-bit integers, 9 32-bit and 10 64-bit floats (single and double precision runs).
  • Directories: one per output, /nodout, or per output and kind, /elout/shell, /ncforc/slave_1, /jntforc/type0. Each has a metadata folder (title, version, IDs, legend) and one folder per output state (d000001, d000002 ... or d1, d2 ...), some with a misc sub-folder.

The records are read in file order, so a file whose run was stopped while writing is read up to its last complete record (the symbol tables are not needed; Binout.verify compares them with the records). When a run was restarted and an output goes back in time, the states from the restart time on are replaced by the restarted ones, as for the ASCII files.

BinoutVariable dataclass

BinoutVariable(
    name: str,
    type: int,
    file: int,
    offset: int,
    nbytes: int,
    record: int,
)

One stored variable: where its values are.

type instance-attribute

type: int

Type code (1 text, 3/4 integers, 9/10 floats).

file instance-attribute

file: int

Index of the file in Binout.files.

offset instance-attribute

offset: int

Offset of the first value in the file.

record instance-attribute

record: int

Offset of the variable's record (as the symbol table gives it).

count property

count: int

Number of values (characters for text).

Binout

Binout(paths: Sequence[str | Path])

The outputs of one or more binout files of a run.

Outputs are named by their folder without the leading slash: "glstat", "nodout", "elout/shell", "ncforc/slave_1".

branches property

branches: list[str]

Output names in file order (glstat, elout/shell ...).

metadata

metadata(
    branch: str, file: int | None = None
) -> dict[str, Any]

The metadata folder of an output: text stripped, numbers as arrays. From the first file that has it, or from file.

time

time(branch: str) -> ndarray

Output times of an output (model time unit).

variables

variables(branch: str) -> list[str]

Names of the variables of an output's states, in file order; sub-folder variables as "misc/x_moment0".

variable

variable(
    branch: str, name: str, state: int = 0
) -> BinoutVariable

Where a variable of one state is stored.

read

read(branch: str, name: str) -> ndarray

One variable over all states: shape (states, values), or (states,) when every state has one value. States with fewer values are padded with NaN; missing in a state: NaN.

legend

legend(branch: str) -> dict[int, str]

Entity titles from the metadata legend (fixed-width entries).

output

output(branch: str) -> AsciiOutput

An output as the ASCII readers return it (AsciiOutput).

Channel names are the binout variable names, which the ASCII readers use too; rcforc channels get surfa_ / surfb_ by the contact side, sleout's slave and master energies become surfa_energy / surfb_energy, spcforc's resultants its totals. Variables with one value per state (glstat, the totals) go to totals; variables whose length is not the number of entities (several integration points) are left out (read them with read).

glstat

glstat() -> GlobalEnergies

The glstat output as GlobalEnergies (as read_glstat).

matsum

matsum() -> PartEnergies

The matsum output as PartEnergies (as read_matsum). The added mass of a part is added_mass if the file has it, else added_cms_mass + added_sms_mass (conventional and selective mass scaling).

to_csv

to_csv(
    folder: str | Path,
    branches: Iterable[str] | None = None,
) -> list[Path]

One CSV per output (AsciiOutput.to_csv); returns the files.

verify

verify() -> list[str]

Compare each file's symbol tables with its records: every variable must be listed with the right type, place and count. Returns the problems found (empty: consistent).

find_binout

find_binout(folder: str | Path) -> list[Path]

The binout files of a run folder (binout, binout0000 ..., also with a job prefix such as run1.binout0000), in name order.

read_binout

read_binout(
    path: str | Path | Sequence[str | Path],
) -> Binout

Read binout files: a run folder (all its binout files), one file, or a list of files (read in the order given).

write_binout

write_binout(
    path: str | Path,
    folders: Mapping[str, Mapping[str, Any]],
) -> Path

Write a binout file in the layout read here: folders maps a folder ("/nodout/metadata", "/nodout/d000001") to its variables (text, or integer or float arrays; float32 and int32 arrays are written in single precision). One symbol table at the end.

For tests and synthetic runs; whether LS-PrePost or other tools read the files has not been checked.

main

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

crashmetrics-binout PATH [--csv DIR] [--output NAME]: list the outputs of a binout (a run folder or files), or write them as CSV.