crashmetrics.energy_check and crashmetrics.lsdyna¶
energy_check
¶
Energy checks for explicit crash simulations, for any load case.
Functions:
check_energies: Run the global and per-part energy checks and return a report.
Classes:
| Name | Description |
|---|---|
GlobalEnergies |
Global energy time histories (LS-DYNA glstat). |
PartEnergies |
Per-part energy time histories (LS-DYNA matsum). |
EnergyLimits |
Acceptance limits; every one can be changed or switched off. |
The checks are solver-agnostic: fill `GlobalEnergies` and |
|
`PartEnergies` from any source, or read LS-DYNA output with |
|
`crashmetrics.lsdyna`. All energies must use one consistent unit. |
|
Checks: |
|
| Check | Value compared with its limit | |
|
| --- | --- | |
|
| energy_ratio | total / |
|
| hourglass | peak hourglass / peak internal energy | |
|
| negative_contact | most negative sliding |
|
| damping | peak system damping energy / reference | |
|
| added_mass | peak added mass, % of the model mass | |
|
| eroded_energy | peak eroded energy / reference |
|
| part_hourglass | per part: peak hourglass / peak internal energy | |
|
| part_negative_internal | per part: most negative / peak internal energy | |
|
The energy ratio uses glstat's own ratio if given. The reference |
|
energy is the largest value of initial total energy plus |
|
external work, so the checks work for impacts |
|
and for prescribed-motion or quasi-static cases |
|
Part checks cover parts whose peak internal energy is at least |
|
``part_min_internal_share`` of the model's peak internal energy. |
|
Default limits: hourglass energy below 10 % of internal energy, globally |
|
and per part, is LS-DYNA's published rule of thumb. The other defaults |
|
are common rules of thumb, not a standard. Set your own guideline values |
|
in `EnergyLimits`. |
|
GlobalEnergies
dataclass
¶
GlobalEnergies(
time: FloatArray,
kinetic: FloatArray,
internal: FloatArray,
hourglass: FloatArray | None = None,
sliding: FloatArray | None = None,
external_work: FloatArray | None = None,
damping: FloatArray | None = None,
rigidwall: FloatArray | None = None,
eroded_kinetic: FloatArray | None = None,
eroded_internal: FloatArray | None = None,
eroded_hourglass: FloatArray | None = None,
total: FloatArray | None = None,
energy_ratio: FloatArray | None = None,
added_mass: FloatArray | None = None,
added_mass_percent: FloatArray | None = None,
time_step: FloatArray | None = None,
extra: dict[str, FloatArray] = dict(),
)
Global energy time histories, in one consistent energy unit.
Only time, kinetic and internal are required; checks that
need a missing channel are reported as skipped.
sliding
class-attribute
instance-attribute
¶
Sliding interface (contact) energy.
damping
class-attribute
instance-attribute
¶
System damping energy.
total
class-attribute
instance-attribute
¶
Total energy; computed from the components if not given.
energy_ratio
class-attribute
instance-attribute
¶
Solver's energy ratio; computed if not given.
added_mass_percent
class-attribute
instance-attribute
¶
Added mass as a percentage of the model mass.
extra
class-attribute
instance-attribute
¶
Other channels, by normalised name.
from_mapping
classmethod
¶
from_mapping(
data: Mapping[str, ArrayLike],
) -> GlobalEnergies
Build from named channels, such as glstat or binout variables.
Names are matched case-insensitively and ignoring punctuation, so
"kinetic energy", "kinetic_energy" and
"Kinetic Energy" all work. Unknown channels go to extra.
total_energy
¶
Total energy: the given total, or the sum of the components.
ratio
¶
Energy ratio: the given one, or total / (initial + external work).
As in LS-DYNA, the ratio is 1 where the denominator is below 1e-8.
reference_energy
¶
Largest value of initial total energy plus external work.
PartEnergies
dataclass
¶
PartEnergies(
time: FloatArray,
part_ids: NDArray[int64],
internal: FloatArray,
kinetic: FloatArray | None = None,
hourglass: FloatArray | None = None,
added_mass: FloatArray | None = None,
part_names: dict[int, str] = dict(),
extra: dict[str, FloatArray] = dict(),
)
Per-part energy time histories, arrays of shape (time, part).
added_mass
class-attribute
instance-attribute
¶
Added mass from mass scaling (LS-DYNA matsum +mass).
from_mapping
classmethod
¶
from_mapping(
time: ArrayLike,
part_ids: ArrayLike,
data: Mapping[str, ArrayLike],
part_names: Mapping[int, str] | None = None,
) -> PartEnergies
Build from named (time, part) arrays, such as matsum variables.
"internal_energy" / "inten", "kinetic_energy" /
"kinen", "hourglass_energy" / "hgeng" and
"added_mass" / "+mass" are recognised.
EnergyLimits
dataclass
¶
EnergyLimits(
energy_ratio: tuple[float, float] | None = (0.95, 1.05),
hourglass: float | None = 0.1,
negative_contact: float | None = 0.05,
damping: float | None = 0.05,
added_mass_percent: float | None = 5.0,
eroded_energy: float | None = None,
part_hourglass: float | None = 0.1,
part_negative_internal: float | None = 0.01,
part_min_internal_share: float = 0.01,
)
Acceptance limits. Set a limit to None to report the value only.
Defaults: the 10 % hourglass limits follow LS-DYNA's rule of thumb; the others are common rules of thumb. Replace them with your own guideline values.
energy_ratio
class-attribute
instance-attribute
¶
Allowed (minimum, maximum) energy ratio over the whole run.
hourglass
class-attribute
instance-attribute
¶
Peak hourglass energy / peak internal energy.
negative_contact
class-attribute
instance-attribute
¶
Most negative contact energy (magnitude) / reference energy.
damping
class-attribute
instance-attribute
¶
Peak system damping energy / reference energy.
added_mass_percent
class-attribute
instance-attribute
¶
Peak added mass, % of the model mass.
eroded_energy
class-attribute
instance-attribute
¶
Peak eroded energy / reference energy (reported only by default).
part_hourglass
class-attribute
instance-attribute
¶
Per part: peak hourglass / peak internal energy.
part_negative_internal
class-attribute
instance-attribute
¶
Per part: most negative internal energy (magnitude) / peak.
part_min_internal_share
class-attribute
instance-attribute
¶
Parts with a peak internal energy below this share of the model's peak internal energy are not checked.
EnergyCheck
dataclass
¶
PartResult
dataclass
¶
EnergyReport
dataclass
¶
EnergyReport(
checks: tuple[EnergyCheck, ...],
parts: tuple[PartResult, ...],
reference_energy: float,
limits: EnergyLimits,
)
Results of check_energies.
normalise_name
¶
Lower-case a channel name and join its words with underscores.
check_energies
¶
check_energies(
global_energies: GlobalEnergies,
part_energies: PartEnergies | None = None,
limits: EnergyLimits | None = None,
) -> EnergyReport
Check the energy balance of a simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
global_energies
|
GlobalEnergies
|
Global energies, for example from
|
required |
part_energies
|
PartEnergies | None
|
Optional per-part energies, for example from
|
None
|
limits
|
EnergyLimits | None
|
Acceptance limits; |
None
|
Returns:
| Type | Description |
|---|---|
EnergyReport
|
|
lsdyna
¶
LS-DYNA output readers and the crashmetrics-energy command.
Functions:
read_glstat,parse_glstat: Global statistics (glstat) ASCII file -> GlobalEnergies.read_matsum,parse_matsum: Material/part energy summary (matsum) ASCII file -> PartEnergies.read_d3hsp,parse_d3hsp: d3hsp file -> D3hsp (seecrashmetrics.d3hsp).check_run: Read a run directory's glstat (and matsum) and check its energies.main: Command-line entry point:crashmetrics-energy RUN_DIR.
The readers for the other ASCII files (nodout, rcforc, sleout, secforc,
rwforc, sbtout, deforc, jntforc, abstat, rbdout, spcforc, swforc) live
in crashmetrics.lsdyna_ascii and are re-exported here, so
from crashmetrics.lsdyna import read_nodout works.
The parsers read values by their labels, not by position, so they do not depend on the line order or on which optional channels a given LS-DYNA version writes:
- glstat: lines of the form
kinetic energy....... 1.23456E+05(one or more dots after the label); a new record starts at eachtime...line. - matsum:
key= valuepairs; a new record starts at eachtime =and a new part at eachmat.#=(orpart=,pid=). Part names come from the{BEGIN LEGEND}block and per-part added mass from+mass=.
Fortran numbers such as 1.23456-100 (no E) and 1.0D+03 are
read correctly. Binout files are read by crashmetrics.binout
(Binout.glstat, Binout.matsum); check_run uses them when a run
folder has no ASCII glstat.
D3hsp
dataclass
¶
D3hsp(
version: str | None = None,
parallel: str | None = None,
precision: str | None = None,
release: str | None = None,
revision: str | None = None,
platform: str | None = None,
compiler: str | None = None,
hostname: str | None = None,
run_date: str | None = None,
command_line: tuple[str, ...] = (),
input_file: str | None = None,
ncpu: int | None = None,
termination: str = "incomplete",
termination_time: str | None = None,
messages: tuple[D3hspMessage, ...] = (),
model: dict[str, int] = dict(),
parameters: dict[str, float] = dict(),
keyword_counts: dict[str, int] = dict(),
part_masses: dict[int, float] = dict(),
rigid_parts: tuple[int, ...] = (),
total_mass: float | None = None,
mass_center: tuple[float, float, float] | None = None,
smallest_timesteps: tuple[TimestepElement, ...] = (),
problem_time: float | None = None,
problem_cycles: int | None = None,
cpu_seconds: float | None = None,
elapsed_seconds: float | None = None,
start_time: str | None = None,
end_time: str | None = None,
workers: int | None = None,
worker_type: str | None = None,
timing: tuple[TimingRow, ...] = (),
memory: dict[str, str] = dict(),
)
Summary of an LS-DYNA d3hsp file. Missing items are None or empty.
version
class-attribute
instance-attribute
¶
Version line, e.g. "smp d R16".
run_date
class-attribute
instance-attribute
¶
Date and time the run started, as printed.
termination
class-attribute
instance-attribute
¶
"normal", "error" or "incomplete".
model
class-attribute
instance-attribute
¶
Nodes, elements by type, materials, contacts (when reported).
parameters
class-attribute
instance-attribute
¶
Every echoed label..... value setting, by normalised label
(first occurrence), e.g. "termination_time",
"time_step_scale_factor".
keyword_counts
class-attribute
instance-attribute
¶
Number of each keyword in the input, e.g. {"*CONTACT_option": 2}
(first occurrence where LS-DYNA prints a name twice).
mass_center
class-attribute
instance-attribute
¶
Mass centre of the whole model (the lines after the total mass).
workers
class-attribute
instance-attribute
¶
Number of SMP threads or MPP processes from the elapsed-time line.
memory
class-attribute
instance-attribute
¶
Last memory report, e.g. {"total": "755K"}.
min_timestep
property
¶
min_timestep: TimestepElement | None
Element with the smallest time step, from the d3hsp table.
message_counts
¶
Number of messages by (kind, number), most frequent first.
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. |
time |
ndarray
|
Output times, in the model's time unit, shape |
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 |
totals |
dict[str, ndarray]
|
File-level sums printed by LS-DYNA (sleout and spcforc), name ->
array of shape |
names |
dict[int, str]
|
Entity titles from the |
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. |
channel
¶
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
¶
All channels of one entity that have at least one value.
magnitude
¶
Resultant of channels, e.g. ("x_force", "y_force", "z_force").
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.
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_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_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_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_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_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_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 |
None
|
skip_errors
|
bool
|
Leave out files that cannot be read instead of raising. |
False
|
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_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_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_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.
parse_glstat
¶
parse_glstat(text: str) -> GlobalEnergies
Parse the text of an LS-DYNA glstat ASCII file.
parse_matsum
¶
parse_matsum(text: str) -> PartEnergies
Parse the text of an LS-DYNA matsum ASCII file.
check_run
¶
check_run(
run: str | Path,
matsum: str | Path | None = None,
limits: EnergyLimits | None = None,
) -> EnergyReport
Check the energies of an LS-DYNA run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run
|
str | Path
|
Run directory containing |
required |
matsum
|
str | Path | None
|
matsum file; by default |
None
|
limits
|
EnergyLimits | None
|
Acceptance limits. |
None
|
main
¶
Run crashmetrics-energy. Exit code 0 = passed, 1 = failed, 2 = error.
d3hsp
¶
LS-DYNA d3hsp reader.
Functions:
read_d3hsp,parse_d3hsp: Read a d3hsp file into aD3hspsummary.
What is read
- Run information: version, SMP/MPP, precision, revision, platform, run date, command line options, input file, number of CPUs.
- Termination status:
"normal","error"or"incomplete"(no termination banner: still running, killed or crashed). - Warnings and errors (
*** Warning 41123 (SOL+1123)and the message lines after it), with counts by message number. - Model size (nodes, elements by type, materials, contacts) and every
label....... valuesetting echoed by LS-DYNA (parameters), plus the keyword counts (total # of *KEYWORD.... n). - Mass summary: mass of each part (rigid bodies marked), total mass and the mass centre of the model.
- The smallest time steps table: element type, element, part, time step.
- Timing: problem time and cycles, CPU and elapsed time, threads or processes, the CPU/clock breakdown by solver phase, and memory.
The reader works from labels and patterns, not line numbers, and was
built and tested on SMP d3hsp files from LS-DYNA R14.1 and R16.1. MPP
runs use the same layout for these items; the reader accepts mpp in
the version line and MPP procs in the elapsed-time line, but check it
on your own MPP output.
D3hspMessage
dataclass
¶
A warning or error message.
TimestepElement
dataclass
¶
One row of the smallest time steps table.
TimingRow
dataclass
¶
TimingRow(
name: str,
cpu: float,
cpu_percent: float,
clock: float,
clock_percent: float,
level: int,
)
One row of the timing information table.
D3hsp
dataclass
¶
D3hsp(
version: str | None = None,
parallel: str | None = None,
precision: str | None = None,
release: str | None = None,
revision: str | None = None,
platform: str | None = None,
compiler: str | None = None,
hostname: str | None = None,
run_date: str | None = None,
command_line: tuple[str, ...] = (),
input_file: str | None = None,
ncpu: int | None = None,
termination: str = "incomplete",
termination_time: str | None = None,
messages: tuple[D3hspMessage, ...] = (),
model: dict[str, int] = dict(),
parameters: dict[str, float] = dict(),
keyword_counts: dict[str, int] = dict(),
part_masses: dict[int, float] = dict(),
rigid_parts: tuple[int, ...] = (),
total_mass: float | None = None,
mass_center: tuple[float, float, float] | None = None,
smallest_timesteps: tuple[TimestepElement, ...] = (),
problem_time: float | None = None,
problem_cycles: int | None = None,
cpu_seconds: float | None = None,
elapsed_seconds: float | None = None,
start_time: str | None = None,
end_time: str | None = None,
workers: int | None = None,
worker_type: str | None = None,
timing: tuple[TimingRow, ...] = (),
memory: dict[str, str] = dict(),
)
Summary of an LS-DYNA d3hsp file. Missing items are None or empty.
version
class-attribute
instance-attribute
¶
Version line, e.g. "smp d R16".
run_date
class-attribute
instance-attribute
¶
Date and time the run started, as printed.
termination
class-attribute
instance-attribute
¶
"normal", "error" or "incomplete".
model
class-attribute
instance-attribute
¶
Nodes, elements by type, materials, contacts (when reported).
parameters
class-attribute
instance-attribute
¶
Every echoed label..... value setting, by normalised label
(first occurrence), e.g. "termination_time",
"time_step_scale_factor".
keyword_counts
class-attribute
instance-attribute
¶
Number of each keyword in the input, e.g. {"*CONTACT_option": 2}
(first occurrence where LS-DYNA prints a name twice).
mass_center
class-attribute
instance-attribute
¶
Mass centre of the whole model (the lines after the total mass).
workers
class-attribute
instance-attribute
¶
Number of SMP threads or MPP processes from the elapsed-time line.
memory
class-attribute
instance-attribute
¶
Last memory report, e.g. {"total": "755K"}.
min_timestep
property
¶
min_timestep: TimestepElement | None
Element with the smallest time step, from the d3hsp table.
message_counts
¶
Number of messages by (kind, number), most frequent first.