crashmetrics.deck¶
deck
¶
LS-DYNA keyword decks: read, check, summarise and edit, before a run.
- Read (
read_deck): every file of a deck through*INCLUDE,*INCLUDE_PATHand*INCLUDE_TRANSFORM, with*PARAMETERvalues and expressions, in fixed, long and comma formats. Every line is kept, so a deck written back is identical except where it was edited. Typed values of any described keyword:Deck.records. Version information:Deck.info. - Model tables (
model_summary,time_steps): every part with its elements, section, thickness, material, density, mass and centre of gravity; the total mass and centre; estimated element time steps and the mass that mass scaling would add. - Checks (
check_deck): missing includes and parameters, duplicate IDs (also between include files), references to undefined IDs, parts without elements, thickness or density, degenerate elements, free nodes, parts in no contact, spot welds without a tied contact, unused definitions. - Load case (
load_case,output_requirements): termination, time step, energy settings, initial velocities, walls, motions, gravity, contacts, outputs; whether the outputs give what crashmetrics' analyses read (model quality, load paths, spot welds, node channels). - Edit (
set_parameter,set_thickness,set_material,set_end_time,set_output,prepare_outputs...) and write DOE variants (write_variants).
The layouts are written from the keyword file format itself; keywords
without a layout are kept, listed (DeckInfo.unknown) and written back
unchanged.
UNIT_SYSTEMS
module-attribute
¶
UNIT_SYSTEMS: dict[str, tuple[float, float, float]] = {
"mm-ms-kg": (1.0, 1.0, 1.0),
"mm-s-t": (1.0, 1000.0, 1000.0),
"mm-s-kg": (1.0, 1000.0, 1.0),
"m-s-kg": (1000.0, 1000.0, 1.0),
}
Unit system -> factors to mm, ms and kg (length, time, mass).
ANALYSES
module-attribute
¶
ANALYSES: dict[str, str] = {
"quality": "model quality and energy checks (crashmetrics.quality, .energy_check)",
"load_paths": "load paths and energy across runs (crashmetrics.loadpath)",
"spot_welds": "spot weld failure (crashmetrics.spotweld)",
"nodes": "head and dummy criteria, intrusions and pulses from nodout (crashmetrics.pedestrian.clearance, .intrusion, .pulse)",
"contacts": "contact forces (rcforc)",
"walls": "rigid wall forces (rwforc)",
}
Analyses output_requirements checks for.
Deck
¶
A keyword deck: its files, blocks in reading order, parameters.
blocks
property
¶
blocks: list[Block]
All blocks in the order LS-DYNA reads them (an include file's
blocks where its *INCLUDE is).
find
¶
find(pattern: str) -> list[Block]
Blocks whose keyword matches a pattern (SECTION_SHELL*,
CONTACT_*; case ignored).
records
¶
Typed records of every block matching a pattern.
refresh
¶
Read the parameters again and forget derived tables (after parameter edits).
write
¶
Write the deck into a folder: the main file and the include files
inside its folder at the same relative paths. Include files outside
it are not copied; their *INCLUDE lines are changed to their
absolute paths. Returns the files written.
DeckFile
¶
DeckFile(
deck: Deck,
path: Path,
text: str,
parent: DeckFile | None,
include: Block | None = None,
)
One file of a deck.
include
instance-attribute
¶
The *INCLUDE block that read this file (None for the main file).
DeckInfo
dataclass
¶
DeckInfo(
keyword_line: str,
title: str,
long_format: bool,
creators: tuple[str, ...],
files: int,
keywords: int,
unknown: tuple[str, ...],
)
What a deck says about itself and its origin.
Block
¶
Block(file: DeckFile, lines: list[str], start: int)
One keyword with its lines (lines[0] is the keyword line).
data_lines
¶
(line number in the block, text) of the data lines: no comments; blank lines count as cards of default values, except at the end.
Parameter
dataclass
¶
IncludeTransform
dataclass
¶
IncludeTransform(
idnoff: int = 0,
ideoff: int = 0,
idpoff: int = 0,
idmoff: int = 0,
idsoff: int = 0,
idfoff: int = 0,
iddoff: int = 0,
idroff: int = 0,
prefix: str = "",
suffix: str = "",
fctmas: float = 1.0,
fcttim: float = 1.0,
fctlen: float = 1.0,
fcttem: str = "",
tranid: int = 0,
)
*INCLUDE_TRANSFORM settings of an include file.
ModelSummary
dataclass
¶
ModelSummary(
parts: tuple[PartInfo, ...],
lumped_mass: float,
total_mass: float,
cg: tuple[float, float, float],
nodes: int,
elements: dict[str, int],
unit_system: str | None,
notes: tuple[str, ...] = (),
)
PartInfo
dataclass
¶
TimeStepEstimate
dataclass
¶
TimeStepEstimate(
smallest: tuple[ElementTimeStep, ...],
by_part: dict[int, float],
tssfac: float,
dt2ms: float,
added_mass: float,
model_mass: float,
skipped: dict[str, int] = dict(),
unit_system: str | None = None,
)
DeckCheck
dataclass
¶
LoadCase
dataclass
¶
LoadCase(
title: str,
unit_system: str | None,
end_time: float,
tssfac: float,
dt2ms: float,
energy: dict[str, int],
hourglass: dict[str, float],
velocities: tuple[str, ...],
speeds: tuple[float, ...],
walls: tuple[str, ...],
motions: tuple[str, ...],
gravity: tuple[str, ...],
contacts: tuple[str, ...],
outputs: dict[str, Output],
history_nodes: tuple[int, ...],
history_node_sets: tuple[int, ...],
cross_sections: tuple[str, ...],
implicit: bool = False,
notes: tuple[str, ...] = tuple(),
)
energy
instance-attribute
¶
CONTROL_ENERGY flags (hgen, rwen, slnten, rylen).
Output
dataclass
¶
read_deck
¶
read_deck(path: str | Path) -> Deck
Read a keyword deck and every file it includes.
Problems that do not stop reading (missing include files, undefined
parameters, unreadable fields) are listed in Deck.notes.
parse_deck
¶
parse_deck(text: str, name: str = 'deck.k') -> Deck
A deck from text (includes are looked for next to name).
nodes
¶
nodes(deck: Deck) -> Nodes
All *NODE rows (later duplicates are kept; the checks report
them).
elements
¶
elements(deck: Deck) -> dict[str, Elements]
Elements by kind (shell, solid, beam, tshell, discrete, seatbelt).
sets
¶
sets(deck: Deck) -> dict[tuple[str, int], SetInfo]
All sets by (kind, ID); _ADD sets are expanded.
model_summary
¶
model_summary(
deck: Deck, unit_system: str | None = None
) -> ModelSummary
Parts, mass and centre of gravity of a deck (see the module notes).
time_steps
¶
time_steps(
deck: Deck,
top: int = 20,
unit_system: str | None = None,
) -> TimeStepEstimate
Estimated explicit time step of every shell, solid, thick shell and beam (see the module notes): characteristic length over sound speed, times TSSFAC. Shells (ISDO 0): area over the longest side (twice that for triangles); ISDO 1: over the longest diagonal. Solids: volume over the largest face (three times that for tetrahedra). Beams: the length. Rigid parts and materials without E, PR in their first card are skipped.
guess_units
¶
guess_units(deck: Deck) -> str | None
The unit system from *CONTROL_UNITS, else the one most
materials' density and Young's modulus agree with (None if unclear).
check_deck
¶
check_deck(
deck: Deck,
*,
unit_system: str | None = None,
mass_scaling_limit: float = 5.0,
) -> DeckSheet
Check a deck before running it (see the module notes).
mass_scaling_limit: added mass that mass scaling would add, % of
the model mass, above which the time step check warns.
load_case
¶
How a deck is set up to run (see the module notes).
output_requirements
¶
output_requirements(
deck: Deck,
analyses: Sequence[str] = tuple(ANALYSES),
*,
unit_system: str | None = None,
cfc: float = 1000.0,
) -> DeckSheet
Does the deck write what these analyses read? (keys of ANALYSES)
cfc: filter class of the node channels; the nodout interval must
give at least 10 samples per CFC cutoff (CFC 1000: 0.1 ms, 10 kHz).
set_parameter
¶
set_parameter(
deck: Deck, name: str, value: float | int | str
) -> None
Change a *PARAMETER value (or an expression's text, given as a
string); fields that use it read the new value.
set_thickness
¶
set_thickness(
deck: Deck,
part: int,
thickness: float,
*,
shared: str = "error",
) -> int
Set the shell thickness of a part (T1 to T4 of its
*SECTION_SHELL). If other parts use the section: shared="error"
raises, "all" changes it for all of them, "copy" gives this
part its own copy of the section (a new section ID, returned).
set_material
¶
set_material(deck: Deck, part: int, material: int) -> None
Give a part another material (the material must exist).
set_section
¶
set_section(deck: Deck, part: int, section: int) -> None
Give a part another section (the section must exist).
set_end_time
¶
set_end_time(deck: Deck, end_time: float) -> None
*CONTROL_TERMINATION ENDTIM (model time units; added if missing).
set_mass_scaling
¶
set_mass_scaling(
deck: Deck, dt2ms: float, tssfac: float | None = None
) -> None
*CONTROL_TIMESTEP DT2MS (negative: mass added only where the
time step is below TSSFAC x |DT2MS|) and optionally TSSFAC.
set_initial_velocity
¶
set_initial_velocity(
deck: Deck,
velocity: Sequence[float] | None = None,
*,
speed: float | None = None,
which: int | None = None,
) -> int
Set the initial velocity of *INITIAL_VELOCITY_GENERATION,
*INITIAL_VELOCITY or *INITIAL_VELOCITY_RIGID_BODY cards: the
components, or only the speed (model units) in the same direction.
which: index of the card (all cards by default). Returns the
number of cards changed.
set_output
¶
Write an ASCII output (GLSTAT, NODOUT ...) every dt
(model time units); binary 1 ASCII, 2 binout, 3 both. Added to
the main file if missing.
add_history_nodes
¶
Add a *DATABASE_HISTORY_NODE with these nodes (to the main file).
prepare_outputs
¶
prepare_outputs(
deck: Deck,
analyses: Sequence[str],
dt: float,
*,
node_dt: float | None = None,
energy: bool = True,
unit_system: str | None = None,
) -> list[str]
Add the outputs and energy settings output_requirements finds
missing for these analyses (every dt; nodout every node_dt,
model time units). Cross sections and history nodes are not made up;
they stay as findings. Returns what was changed.
write_variants
¶
write_variants(
deck: Deck | str | Path,
design: Any,
folder: str | Path,
*,
setters: Mapping[str, Callable[[Deck, float], None]]
| None = None,
name: str = "run_{:03d}",
) -> Path
One deck per design row in folder/run_001, run_002 ...
design: a crashmetrics.doe.Design or (names, rows). A variable
with a setter in setters (lambda deck, value: ...) is applied
with it, any other must be a *PARAMETER of the deck. Each variant
is read fresh from the original files. Writes design.csv (run
folder and values) and returns its path.
main
¶
crashmetrics-deck MAIN.k: model summary, checks, load case and
output requirements of a deck. Exit code 1 if a check fails.