Skip to content

crashmetrics.synthetic

synthetic

Synthetic LS-DYNA-style crash output for examples, tests and teaching.

A lumped full-width frontal crash against a rigid wall, small enough to run in a fraction of a second and detailed enough to show what load-path analysis looks for:

  • Load paths (LoadPath) in parallel: upper (shotgun) rails, main rails, lower (subframe) path, each a chain of crushable parts (CrushElement) behind an elastic spring and an optional gap before contact.
  • Crushing: a part crushes at its strength (mean force with an initial peak and folding waves); in a chain the weakest part crushes first, so a weak rear part crushes before a strong front one, as in a real structure with a wrong crush sequence.
  • Vehicle: one mass at an initial speed; forces stop it, the elastic energy gives a small rebound.

  • Spot welds (WeldLine): lines of welds on the flanges of a part carry a share of the path force as shear and, as the part folds, a peel (axial) force. A weld fails when (axial / Sn)^2 + (shear / Ss)^2 reaches 1; its neighbours take part of its load, and the part loses strength as its welds fail.

  • Model quality (ModelQuality): mass scaling (added mass), time step, contact friction and negative contact energy, warnings and the termination, as a solver would report them.

frontal_model gives a reference car and variants with known causes (VARIANTS); simulate runs it; FrontalRun.write writes matsum (part energies), secforc (section forces), swforc (spot weld forces), glstat (global energies), sleout (contact energies) and a short d3hsp in the LS-DYNA ASCII format, so every reader and analysis of crashmetrics can be tried without a solver. write_matsum, write_secforc, write_swforc, write_glstat, write_sleout, write_d3hsp and write_nodout (nodal time histories, used by crashmetrics.pedestrian.synthetic) write any data in those formats.

Units: mm, ms, kg (force kN, energy J = kN mm). The model is a teaching model, not a vehicle simulation; the files say so in their header.

VARIANTS module-attribute

VARIANTS: dict[str, str] = {
    "baseline": "Reference car: bumper, crash boxes, front and rear rails; upper rails; subframe extensions and subframe",
    "weak_front_rail_lh": "LH front rail 80 kN instead of 150 kN: it crushes before the LH crash box (wrong crush sequence)",
    "no_lower_path": "Subframe extensions and subframe removed: the upper and main paths take the load, the rear rails crush",
    "weak_welds_front_rail_lh": "LH front rail flange welds at 40 % strength: they unzip while the rail crushes, and the rail loses strength",
    "poor_model_quality": "The baseline crash from a poorly prepared model: 5.8 % added mass rising to 7.9 %, 16 % hourglass energy in the crash boxes, negative contact energy, very small elements",
}

Variants of frontal_model and what changes.

CrushElement dataclass

CrushElement(
    part_id: int,
    name: str,
    mean_force: float,
    length: float,
    initial_peak: float = 1.0,
    peak_length: float = 6.0,
    fold_length: float = 0.0,
    fold_amplitude: float = 0.0,
    mass: float = 1.0,
    hourglass: float = 0.0,
)

A crushable part in a load path.

The crushing force is mean_force times a factor: falling linearly from initial_peak to 1 over the first peak_length of crush (the force to start the first fold), then 1 + fold_amplitude sin(2 pi s / fold_length) (progressive folding).

mean_force instance-attribute

mean_force: float

kN.

length instance-attribute

length: float

Crush length available, mm.

fold_length class-attribute instance-attribute

fold_length: float = 0.0

mm; 0 for no folding waves.

mass class-attribute instance-attribute

mass: float = 1.0

kg (moves with the vehicle).

hourglass class-attribute instance-attribute

hourglass: float = 0.0

Share of the crush energy reported as hourglass energy.

strength

strength(crush: float) -> float

Force needed to crush further after crush mm, kN.

Section dataclass

Section(
    section_id: int,
    name: str,
    direction: tuple[float, float, float] = (
        -1.0,
        0.0,
        0.0,
    ),
    share: float = 1.0,
    mass_ahead: float = 0.0,
    centroid: tuple[float, float, float] = (0.0, 0.0, 0.0),
    area: float = 800.0,
)

A cross-section through a load path (*DATABASE_CROSS_SECTION).

It carries the path force (the parts of a chain are in series), in the direction direction (its sign is the section normal: a negative x means compression is written as negative x force).

share class-attribute instance-attribute

share: float = 1.0

Share of the path force through this section.

mass_ahead class-attribute instance-attribute

mass_ahead: float = 0.0

kg between the wall and the section: decelerating it takes part of the path force, so sections further back carry slightly less.

WeldLine dataclass

WeldLine(
    name: str,
    part_id: int,
    first_id: int,
    count: int,
    shear_share: float,
    shear_strength: float,
    axial_strength: float,
    peel: float = 0.5,
    gradient: float = 0.3,
    redistribution: float = 0.4,
    strength_loss: float = 0.45,
    length: float = 1.2,
)

A line of spot welds on the flanges of one part of a load path.

The line carries shear_share of the path force as shear, more on the welds at the front (gradient); each weld also gets a peel (axial) force of peel times its shear force times the crushed fraction of the part. A weld fails when (axial / axial_strength)^2 + (shear / shear_strength)^2 >= 1; the welds left take redistribution of the lost share, and the part loses strength_loss of its strength when all its welds have failed.

shear_strength instance-attribute

shear_strength: float

kN.

axial_strength instance-attribute

axial_strength: float

kN.

gradient class-attribute instance-attribute

gradient: float = 0.3

First weld 1 + gradient times the mean load, last 1 - gradient.

length class-attribute instance-attribute

length: float = 1.2

Weld length written to swforc, mm.

ids property

ids: range

Weld IDs, front to rear.

LoadPath dataclass

LoadPath(
    name: str,
    elements: tuple[CrushElement, ...],
    gap: float = 0.0,
    stiffness: float = 50.0,
    sections: tuple[Section, ...] = (),
    welds: tuple[WeldLine, ...] = (),
)

Parts in series, front to rear, reached after gap mm of crush.

stiffness class-attribute instance-attribute

stiffness: float = 50.0

Elastic stiffness of the path, kN/mm.

ModelQuality dataclass

ModelQuality(
    added_mass: float = 0.004,
    added_mass_growth: float = 0.002,
    timestep: float = 0.001,
    mass_scaled: bool = True,
    timestep_drop: float = 0.0,
    friction: float = 0.008,
    contact_loss: float = 0.0,
    smallest_timestep: float = 0.0009,
    smallest_part: int = 110,
    warnings: int = 2,
    error_at: float | None = None,
    mass_center: tuple[float, float, float] = (
        1310.0,
        2.0,
        545.0,
    ),
)

What a solver would report about the model itself (it does not change the crash): mass scaling, time step, contacts, messages and termination.

added_mass class-attribute instance-attribute

added_mass: float = 0.004

Mass added by mass scaling at the start, share of the model mass.

added_mass_growth class-attribute instance-attribute

added_mass_growth: float = 0.002

Further share added by the time of maximum crush.

timestep class-attribute instance-attribute

timestep: float = 0.001

Time step, ms (dt2ms is written as its negative over 0.9).

timestep_drop class-attribute instance-attribute

timestep_drop: float = 0.0

Share by which the time step falls at maximum crush (without mass scaling).

friction class-attribute instance-attribute

friction: float = 0.008

Contact friction energy, share of the absorbed energy.

contact_loss class-attribute instance-attribute

contact_loss: float = 0.0

Negative energy of the self contact, share of the absorbed energy.

smallest_timestep class-attribute instance-attribute

smallest_timestep: float = 0.0009

Smallest element time step before mass scaling, ms.

error_at class-attribute instance-attribute

error_at: float | None = None

ms at which the run stops with an error termination.

mass_center class-attribute instance-attribute

mass_center: tuple[float, float, float] = (
    1310.0,
    2.0,
    545.0,
)

mm.

FrontalModel dataclass

FrontalModel(
    name: str,
    paths: tuple[LoadPath, ...],
    mass: float = 1500.0,
    speed: float = 56.0,
    body_part: tuple[int, str] = (
        200,
        "Body and rest of vehicle",
    ),
    quality: ModelQuality = ModelQuality(),
)

A vehicle mass on parallel load paths, against a rigid wall.

mass class-attribute instance-attribute

mass: float = 1500.0

Total mass, kg (crushable parts included).

speed class-attribute instance-attribute

speed: float = 56.0

km/h.

replace_element

replace_element(
    part_id: int, path: str | None = None, **changes: Any
) -> FrontalModel

A copy with one part changed (in every path, or only path).

replace_welds

replace_welds(name: str, **changes: Any) -> FrontalModel

A copy with one weld line (by name) changed.

weld_groups

weld_groups() -> dict[str, range]

Weld line name -> its weld IDs (swforc has no titles).

without_paths

without_paths(*names: str) -> FrontalModel

A copy without the named load paths.

FrontalRun dataclass

FrontalRun(
    model: FrontalModel,
    time: FloatArray,
    displacement: FloatArray,
    velocity: FloatArray,
    path_force: dict[str, FloatArray],
    crush: dict[tuple[str, int], FloatArray],
    plastic_energy: dict[tuple[str, int], FloatArray],
    notes: tuple[str, ...] = (),
    meta: dict[str, object] = dict(),
    weld_time: FloatArray = (lambda: zeros(0))(),
    weld_ids: tuple[int, ...] = (),
    weld_axial: FloatArray = (lambda: zeros((0, 0)))(),
    weld_shear: FloatArray = (lambda: zeros((0, 0)))(),
    weld_failure_time: FloatArray = (lambda: zeros(0))(),
)

Result of simulate: histories at every integration step.

time instance-attribute

time: FloatArray

ms.

displacement instance-attribute

displacement: FloatArray

Vehicle displacement (crush at the wall), mm.

velocity instance-attribute

velocity: FloatArray

mm/ms (= m/s).

path_force instance-attribute

path_force: dict[str, FloatArray]

Force of each load path, kN (compression positive).

crush instance-attribute

crush: dict[tuple[str, int], FloatArray]

(path, part ID) -> crush of that part in that path, mm.

plastic_energy instance-attribute

plastic_energy: dict[tuple[str, int], FloatArray]

(path, part ID) -> crush energy, J.

weld_time class-attribute instance-attribute

weld_time: FloatArray = field(
    default_factory=lambda: np.zeros(0)
)

Times of the weld histories, ms.

weld_axial class-attribute instance-attribute

weld_axial: FloatArray = field(
    default_factory=lambda: np.zeros((0, 0))
)

(time, weld), kN (tension positive).

weld_failure_time class-attribute instance-attribute

weld_failure_time: FloatArray = field(
    default_factory=lambda: np.zeros(0)
)

ms per weld, NaN if it holds.

wall_force property

wall_force: FloatArray

Total force on the rigid wall, kN.

deceleration property

deceleration: FloatArray

Vehicle deceleration, g.

parts

parts() -> dict[int, str]

Part IDs and names (crushable parts and the body).

sections

sections() -> dict[int, tuple[LoadPath, Section]]

Section ID -> (its load path, the section), by ID.

part_energies

part_energies(
    times: ArrayLike | None = None,
) -> PartEnergies

Part energies as LS-DYNA's matsum gives them (J): internal (crush energy less hourglass, plus the elastic energy of each path in its last part), kinetic, hourglass.

section_output

section_output(
    times: ArrayLike | None = None,
) -> AsciiOutput

Section forces as LS-DYNA's secforc gives them (kN, kN mm).

part_masses

part_masses() -> dict[int, float]

Part ID -> mass, kg (the body takes the rest of the model mass).

contact_output

contact_output(
    times: ArrayLike | None = None,
) -> AsciiOutput

Contact energies as LS-DYNA's sleout gives them (J): the wall contact and a bumper contact with friction, and the self contact of the front end, which loses energy when the model's contact_loss is set.

global_energies

global_energies(
    times: ArrayLike | None = None,
) -> GlobalEnergies

Global energies as LS-DYNA's glstat gives them (J, kg, ms): the part energies summed, the contact (sliding) energy, the added mass and the time step.

weld_output

weld_output(times: ArrayLike | None = None) -> AsciiOutput

Spot weld forces as LS-DYNA's swforc gives them (kN): a weld has no force and failure 1 from its failure time on.

write

write(
    directory: str | Path,
    *,
    matsum_interval: float = 0.5,
    secforc_interval: float = 0.2,
    swforc_interval: float = 0.5,
    date: date | None = None,
    binout: bool = False,
) -> tuple[Path, Path]

Write matsum and secforc (the paths returned), glstat, sleout, d3hsp and, when the model has spot welds, swforc into directory (created), sampled every matsum_interval / secforc_interval / swforc_interval ms. A model with quality.error_at stops there.

binout=True: the time histories go into one binout file instead (crashmetrics.binout layout; the path returned twice), with d3hsp as text, as LS-DYNA writes them.

frontal_model

frontal_model(
    variant: str = "baseline",
    *,
    mass: float = 1500.0,
    speed: float = 56.0,
) -> FrontalModel

The reference car (VARIANTS for the variants).

simulate

simulate(
    model: FrontalModel,
    *,
    end_time: float = 100.0,
    dt: float = 0.01,
    weld_interval: float = 0.1,
) -> FrontalRun

Run the model from first contact to end_time ms (time step dt ms, semi-implicit Euler; spot welds are checked every weld_interval ms).

write_matsum

write_matsum(
    path: str | Path,
    time: ArrayLike,
    part_ids: Sequence[int] | ArrayLike,
    names: dict[int, str],
    internal: ArrayLike,
    kinetic: ArrayLike | None = None,
    hourglass: ArrayLike | None = None,
    *,
    title: str = "",
    date: date | None = None,
) -> Path

Write part energies (time, part) in the LS-DYNA matsum layout.

write_nodout

write_nodout(
    path: str | Path,
    time: ArrayLike,
    node_ids: Sequence[int] | ArrayLike,
    displacement: ArrayLike,
    velocity: ArrayLike,
    acceleration: ArrayLike,
    coordinates: ArrayLike | None = None,
    *,
    names: dict[int, str] | None = None,
    title: str = "",
    date: date | None = None,
) -> Path

Write nodal displacements, velocities and accelerations (each (time, node, 3)) and optionally current coordinates in the LS-DYNA nodout layout (translational block only).

write_secforc

write_secforc(
    path: str | Path,
    output: AsciiOutput,
    *,
    title: str = "",
    date: date | None = None,
) -> Path

Write section forces (an AsciiOutput with the secforc channels: forces, moments, centroids, area) in the LS-DYNA secforc layout.

write_swforc

write_swforc(
    path: str | Path,
    output: AsciiOutput,
    *,
    title: str = "",
    date: date | None = None,
    element: str = "spotweld beam",
) -> Path

Write spot weld forces (an AsciiOutput with axial, shear and failure, optionally length) in the LS-DYNA swforc layout. A weld with failure 1 or more is written as failed.

write_glstat

write_glstat(
    path: str | Path,
    energies: GlobalEnergies,
    *,
    title: str = "",
    date: date | None = None,
) -> Path

Write global energies in the LS-DYNA glstat layout (the energy lines, the energy ratio, the time step and the added mass).

write_sleout

write_sleout(
    path: str | Path,
    output: AsciiOutput,
    *,
    title: str = "",
    date: date | None = None,
) -> Path

Write contact energies (an AsciiOutput with surfa_energy, surfb_energy and friction_energy) in the LS-DYNA sleout layout.

write_d3hsp

write_d3hsp(
    path: str | Path,
    *,
    title: str = "",
    part_masses: dict[int, float],
    total_mass: float,
    mass_center: tuple[float, float, float] | None = None,
    end_time: float,
    problem_time: float | None = None,
    dt2ms: float = 0.0,
    smallest_timesteps: Sequence[
        tuple[str, int, int, float]
    ] = (),
    warnings: int = 0,
    error: bool = False,
    counts: dict[str, int] | None = None,
    date: date | None = None,
) -> Path

Write the lines of an LS-DYNA d3hsp that crashmetrics.d3hsp reads: run information, model size, termination time and dt2ms, the mass summary with the mass centre, the smallest time steps, warnings and the termination (with an error message when error).