LS-DYNA keyword decks: check before you run¶
Module: crashmetrics.deck (NumPy only). Command: crashmetrics-deck.
The other LS-DYNA modules read what a run wrote. This one reads the
deck before the run: every include file, every *PARAMETER, the parts,
sections, materials, contacts, controls and outputs. It answers the
questions a run should not be wasted on:
- Is every include file there, and is every referred ID defined?
- What do the parts weigh, where is the centre of gravity, what time step will the smallest elements give, how much mass would mass scaling add?
- Is the load case what I think it is: end time, impact speed, wall, contacts, energy settings?
- Will the run write what I need afterwards (glstat, matsum, secforc and cross sections, swforc, nodout at a high enough rate)?
It also edits a deck and writes it back with only the edited fields changed, so it can make the variants of a design study.
from crashmetrics import deck as dk
deck = dk.read_deck("model/main.k")
print(deck.info.summary()) # files, version, unknown keywords
print(dk.model_summary(deck).table(top=20)) # parts, mass, centre of gravity
print(dk.check_deck(deck).summary()) # pass / warn / fail sheet
print(dk.load_case(deck).summary()) # what the run will do
print(dk.output_requirements(deck, ["quality", "load_paths", "nodes"]).summary())
From the command line (exit code 1 if a check fails, so it can stop a batch script before a job is submitted):
1. Reading¶
read_deck follows *INCLUDE, *INCLUDE_PATH, *INCLUDE_PATH_RELATIVE
and *INCLUDE_TRANSFORM (ID offsets, length scale and
*DEFINE_TRANSFORMATION moves, scales and rotations), in the order
LS-DYNA reads them. A missing or circular include is reported, not an
error, so a deck without its mesh can still be checked.
- Formats: fixed (10-character fields), long (
*KEYWORD LONG=Yor+after a keyword, 20 characters),%(10-character IDs for large models) and comma separated; Fortran numbers such as1.5+3. - Parameters:
*PARAMETER,*PARAMETER_LOCAL(seen by the file and its includes),*PARAMETER_EXPRESSION(evaluated withouteval: numbers, names, + - * / and ^, the usual functions) and*PARAMETER_DUPLICATION.&nameand-&nameare replaced where they are used. - Version:
deck.info.versionis the tool that wrote the deck and its version (LS-PrePost, ANSA, HyperMesh, PRIMER), from the header comments;deck.info.unknownlists keywords without a layout here. These are kept and written back unchanged, never dropped. - Typed values:
deck.records("SECTION_SHELL")gives each card's values by name (rec["t1"]), with parameters applied and where each value is written, so it can be changed in place.
Bulk data has its own fast readers: nodes, elements (shell, solid,
thick shell, beam, discrete, seat belt, with option cards such as
_THICKNESS), mass_elements, sets (lists, _GENERATE, _ADD,
segments) and curves (with their scale factors and offsets).
Keywords with a layout¶
| Group | Keywords |
|---|---|
| Parts | *PART (_INERTIA, _CONTACT, _PRINT), *PART_COMPOSITE |
| Sections | *SECTION_SHELL, _SOLID, _TSHELL, _BEAM, _DISCRETE, _SEATBELT |
| Materials | Every *MAT_... (ID, density; elastic constants of the common crash materials; *MAT_024 / *MAT_123 curves), *MAT_ADD_..., *MAT_THERMAL_..., *EOS_..., *HOURGLASS |
| Mesh | *NODE, *ELEMENT_..., *ELEMENT_MASS..., *ELEMENT_INERTIA, *SET_... |
| Contacts | *CONTACT_... with _ID / _TITLE and _MPP cards |
| Connections | *CONSTRAINED_SPOTWELD, _NODAL_RIGID_BODY, _EXTRA_NODES, _RIGID_BODIES, _INTERPOLATION_SPOTWELD |
| Load case | *INITIAL_VELOCITY..., *RIGIDWALL_PLANAR... and others, *BOUNDARY_SPC, *BOUNDARY_PRESCRIBED_MOTION, *LOAD_BODY |
| Controls | *CONTROL_TERMINATION, _TIMESTEP, _ENERGY, _HOURGLASS, _SHELL, _SOLID, _CONTACT, _ACCURACY, _BULK_VISCOSITY, _OUTPUT, _UNITS, _IMPLICIT_GENERAL, _DYNAMIC_RELAXATION |
| Outputs | *DATABASE_ ASCII files (glstat, matsum, nodout, secforc, rcforc ...), _BINARY_..., _HISTORY_..., _CROSS_SECTION_... |
| Definitions | *DEFINE_CURVE, _TABLE, _COORDINATE_..., _VECTOR, _BOX, _TRANSFORMATION |
2. Model table and time step¶
model_summary gives every part with its element count, section,
element formulation, thickness, material, density, mass and centre of
gravity, and the total. Solid volumes are the ones the solver uses
(one-point for under-integrated formulations, so a coarse sphere weighs
what it weighs in the run, not what the true sphere would). Lumped masses, *ELEMENT_MASS_PART and
*ELEMENT_INERTIA are included; *PART_INERTIA replaces a rigid
part's mass and centre with the given ones. The unit system is taken
from *CONTROL_UNITS or guessed from the material densities and
moduli; give unit_system= to be sure.
time_steps estimates every element's time step the way the solver
does for shells and solids (characteristic length over sound speed,
times TSSFAC) and, with negative DT2MS, the mass that mass scaling
would add. Rigid parts and materials whose elastic constants are not
read here are counted as not estimated.
3. Checks¶
check_deck gives one sheet:
| Group | Check | Fails when |
|---|---|---|
| Reading | Include files, parameters | A file or a parameter is missing (other reading notes warn) |
| IDs | Duplicate IDs | The same part, section, material, curve, set, node or element ID is defined twice, also across include files and after include offsets |
| References | Missing sections, materials, curves, sets ... | A card refers to an ID that is not defined |
| Model | Parts without elements | Warns |
| Model | Shell thickness, density | A shell part has no thickness, or a part has no density |
| Model | Degenerate elements | A shell has zero area or a solid zero or negative volume |
| Model | Free nodes | Info only |
| Contacts | Contacts, parts in a contact | Warns without any contact, and for deformable parts in no part or part-set contact (info only when other contacts use segment or node sets) |
| Contacts | Spot welds | Warns when weld elements (*MAT_100 parts) have no tied or spot weld contact |
| Time step | Smallest step, mass scaling | Info; mass scaling warns above 5 % added mass (mass_scaling_limit=) |
| Unused | Sections, materials, curves, sets | Info only |
4. Load case and outputs¶
load_case lists what the run will do: end time, time step control,
energy flags, initial velocities (with km/h when the units are known),
walls, prescribed motions, gravity, contacts and outputs.
output_requirements(deck, analyses) checks the outputs against what
crashmetrics' own analyses read afterwards:
| Analysis | Needs |
|---|---|
quality (model quality sheet) |
glstat, matsum, sleout when there are contacts, *CONTROL_ENERGY with HGEN, SLNTEN (and RWEN with walls) 2 |
load_paths |
matsum, secforc and at least one cross section |
spot_welds |
swforc |
nodes (HIC, intrusion, clearance) |
nodout, history nodes, and an interval of at most 1 / (10 × CFC): 0.1 ms for CFC 1000 |
contacts |
rcforc |
walls |
rwforc |
An output written only to binout (BINARY 2) warns, since the ASCII
readers need the ASCII file or a converted binout.
5. Editing and design variants¶
Edits change only the fields they name, in the field's own format, and keep every comment and every other line:
dk.set_parameter(deck, "t_rail", 1.6) # a *PARAMETER
dk.set_thickness(deck, 2001, 1.8, shared="copy") # own section for this part
dk.set_material(deck, 2001, 12)
dk.set_end_time(deck, 120.0)
dk.set_initial_velocity(deck, speed=15.56) # same direction
dk.prepare_outputs(deck, ["quality", "nodes"], dt=0.1, node_dt=0.01)
deck.write("loop13", only_modified=True)
A value given by a parameter cannot be changed in place (the error says
which parameter to change instead). A section shared by several parts
is not changed silently: shared="all" changes it for all of them,
shared="copy" gives the part its own copy.
write_variants writes one deck per row of a design from
crashmetrics.doe (or any names and rows), each read fresh from the
original files, with a design.csv:
from crashmetrics.doe import latin_hypercube
design = latin_hypercube({"t_rail": (1.2, 2.0), "speed": (12.0, 16.0)}, 30)
dk.write_variants("model/main.k", design, "doe",
setters={"speed": lambda d, v: dk.set_initial_velocity(d, speed=v)})
Example¶
"""Example 35: check an LS-DYNA keyword deck before running it, then edit it.
Real decks (MIT licence, see tests/data/lsdyna/README.md): a ball dropped
on a plate and a tube crushed against a rigid wall, both written for
LS-DYNA R14, and a small deck with a deliberate fault.
1. Read: files, includes, version, unknown keywords.
2. Model table: parts, masses and centre of gravity (equal to what
LS-DYNA printed in d3hsp for this run), estimated time step.
3. Checks: a clean deck and one with a missing section.
4. Load case and output requirements for crashmetrics' analyses.
5. Edit: thickness, end time, impact speed, missing outputs; write back
with only the changed lines different.
6. DOE: three variants from a Latin hypercube.
"""
from pathlib import Path
from crashmetrics import deck as dk
from crashmetrics.doe import latin_hypercube
data = Path(__file__).resolve().parents[1] / "tests" / "data" / "lsdyna"
ball = data / "kagent" / "cold_start" / "ball_drop.k"
tube = data / "kagent" / "crash" / "crash.k"
broken = data / "lsprepost_mcp" / "impact_broken.k"
# --- 1. Read --------------------------------------------------------------------
deck = dk.read_deck(ball)
print(deck.info.summary())
print("files:", ", ".join(f.name for f in deck.files))
# --- 2. Model table -------------------------------------------------------------
summary = dk.model_summary(deck) # units guessed from the materials: mm-s-t
print()
print(summary.summary())
print(summary.table())
print("d3hsp of this run: part 1 1.2149954E-04, part 2 1.2569384E-05, "
"centre z 2.8125846")
print(dk.time_steps(deck).summary(top=1))
print("d3hsp of this run: smallest time step 8.4091E-07")
# --- 3. Checks ------------------------------------------------------------------
print()
print(dk.check_deck(deck).summary())
print(dk.check_deck(dk.read_deck(broken)).summary())
# --- 4. Load case and outputs ---------------------------------------------------
crash = dk.read_deck(tube)
print()
print(dk.load_case(crash).summary())
print(dk.output_requirements(crash, ["quality", "contacts", "nodes"]).summary())
# --- 5. Edit and write back -----------------------------------------------------
dk.set_thickness(crash, 1, 1.8)
dk.set_end_time(crash, 6e-3)
dk.set_initial_velocity(crash, speed=15_000.0) # 54 km/h in mm/s
for change in dk.prepare_outputs(crash, ["quality", "contacts", "nodes"],
dt=1e-5, node_dt=1e-6):
print("added:", change)
dk.add_history_nodes(crash, [1, 49, 97])
written = crash.write("edited", only_modified=True)
print("written:", ", ".join(p.name for p in written), "(mesh_tube.k unchanged)")
before = tube.read_text().splitlines()
after = written[0].read_text().splitlines()
for old, new in zip(before[:-1], after):
if old != new:
print(f" - {old}\n + {new}")
print(f" + {len(after) - len(before)} new lines before *END")
again = dk.read_deck(written[0])
print(dk.output_requirements(again, ["quality", "contacts", "nodes"]).summary())
# --- 6. DOE variants ------------------------------------------------------------
design = latin_hypercube({"thickness": (1.2, 2.0), "speed": (12_000.0, 16_000.0)},
3, seed=7)
table = dk.write_variants(
tube, design, "doe",
setters={"thickness": lambda d, t: dk.set_thickness(d, 1, t),
"speed": lambda d, v: dk.set_initial_velocity(d, speed=v)},
)
print()
print(table.read_text().strip())
for run in sorted(Path("doe").glob("run_*")):
d = dk.read_deck(run / "crash.k")
s, lc = dk.model_summary(d), dk.load_case(d)
print(f"{run.name}: t {s.part(1).thickness:g} mm, mass {s.mass_kg:.3f} kg, "
f"{lc.kmh(lc.speeds[0]):.1f} km/h")
Output:
cold start: steel ball drop onto aluminum plate (mm-ton-s): 31 keywords in 3 files
files: ball_drop.k, mesh_plate.k, mesh_ball.k
2 parts, 988 nodes, 900 shell, 8 solid
Total mass 0.000134069 (0.1341 kg), centre of gravity (5.054e-17, -1.074e-15, 2.813) [mm-s-t]
| Part | Title | Elements | Section | t | Material | Density | Mass (kg) |
| --- | --- | --- | --- | --- | --- | --- | --- |
| 1 | aluminum plate 150x150x2mm | 900 shell | 1 SHELL 16 | 2 | 1 024 PIECEWISE_LINEAR_PLASTICITY | 2.7e-09 | 0.1215 |
| 2 | rigid steel ball r8 (50 mm drop) | 8 solid | 2 SOLID 1 | | 2 020 RIGID (rigid) | 7.85e-09 | 0.01257 |
d3hsp of this run: part 1 1.2149954E-04, part 2 1.2569384E-05, centre z 2.8125846
Smallest estimated time step 0.0008409 ms (TSSFAC 0.9)
shell 100000 (part 1): 0.0008409 ms, length 5
8 elements not estimated: rigid (solid)
d3hsp of this run: smallest time step 8.4091E-07
ball_drop.k: PASSED (0 failed, 0 warnings, 10 passed, 3 info)
ℹ️ INFO Time step / Smallest estimated time step: 0.0008409 ms (shell 100000, part 1)
shell 100000 part 1: 0.0008409 ms
shell 100001 part 1: 0.0008409 ms
shell 100002 part 1: 0.0008409 ms
shell 100003 part 1: 0.0008409 ms
shell 100004 part 1: 0.0008409 ms
... 5 more
ℹ️ INFO Time step / Not estimated: 8 rigid (solid)
ℹ️ INFO Unused / Unused node sets: 4
11: mesh_plate.k:1870
12: mesh_plate.k:1877
13: mesh_plate.k:1884
14: mesh_plate.k:1891
impact_broken.k: FAILED (1 failed, 1 warnings, 8 passed, 1 info)
❌ FAIL References / Missing sections: 1 IDs referred to but not defined
3: *PART (impact_broken.k:15)
⚠️ WARN Contacts / Contacts: no contact defined
ℹ️ INFO Time step / Smallest estimated time step: 0.0005999 ms (solid 1, part 1)
solid 1 part 1: 0.0005999 ms
solid 2 part 1: 0.0005999 ms
solid 3 part 1: 0.0005999 ms
solid 4 part 1: 0.0005999 ms
solid 5 part 1: 0.0005999 ms
... 5 more
crash: thin-wall tube axial impact on rigid wall, 20kg tail mass, mm-ton-s [mm-s-t]
End time 4 ms
Time step: TSSFAC 0.9, no mass scaling
Energy: HGEN 2, RWEN 2, SLNTEN 2, RYLEN 2
Initial velocity: part 1: (0, 0, -10000) (36.0 km/h)
Rigid wall: planar at (0, 0, 0.5), normal (0, 0, 1), friction 0.3
1 contacts:
automatic_single_surface 1 'tube self contact': part set 801, friction 0.2/0.2, SOFT 1
Outputs: glstat every 0.02 ms (ASCII); matsum every 0.02 ms (ASCII); rwforc every 0.02 ms (ASCII); d3plot every 0.2 ms
crash.k: outputs: FAILED (4 failed, 0 warnings, 5 passed, 0 info)
❌ FAIL Model quality / sleout: not written; add *DATABASE_SLEOUT (contact energies)
❌ FAIL Node channels / nodout: not written; add *DATABASE_NODOUT (node motion)
❌ FAIL Node channels / history nodes: none: add *DATABASE_HISTORY_NODE
❌ FAIL Contacts / rcforc: not written; add *DATABASE_RCFORC (contact forces)
added: SLEOUT every 1e-05
added: NODOUT every 1e-06
added: RCFORC every 1e-05
written: crash.k (mesh_tube.k unchanged)
- 4.000E-3 0 0.0 0.0 1.000E8 0
+ 0.006 0 0.0 0.0 1.000E8 0
- 1.5 1.5 1.5 1.5 0.0 0.0 0.0 0
+ 1.8 1.8 1.8 1.8 0.0 0.0 0.0 0
- 1 2 0.0 0.0 0.0 -1.000E4 0 0
+ 1 2 0.0 0.0 0.0 -1.5E+4 0 0
+ 8 new lines before *END
crash.k: outputs: PASSED (0 failed, 0 warnings, 10 passed, 0 info)
run,thickness,speed
run_001,1.633358791,13196.28507
run_002,1.940182851,14966.94292
run_003,1.280044343,14498.07126
run_001: t 1.63336 mm, mass 20.290 kg, 47.5 km/h
run_002: t 1.94018 mm, mass 20.344 kg, 53.9 km/h
run_003: t 1.28004 mm, mass 20.227 kg, 52.2 km/h
Tested with¶
- Real decks (MIT licence, in the repository): a ball dropped on a
plate whose
d3hspfrom LS-DYNA R14.1.1 is also included: part masses, the model's centre of gravity and the smallest time step are the same as the solver printed; a tube crushed against a rigid wall; a small deck with one deliberate fault; a thermal-mechanical deck written by LS-PrePost 2024/R2 with*PARAMETER_DUPLICATION, titled curves and two missing mesh includes. - Write-back: the decks written back unchanged are byte for byte the same as the originals; after edits only the edited lines differ.
- Synthetic decks for long,
%and comma formats, parameters, local parameters and expressions, include paths and transforms, duplicates and missing references, contacts with_IDand_MPPcards, shared sections and design variants. - Checked locally, not included: the full thermal deck above (20 276 nodes, 15 390 solids) and a 765 kB 2D impact deck written by LS-PrePost 4.9.9.
The card layouts were written from the keyword file format itself; no code or documentation of other keyword readers was used. See the protocol notes for the interpretations.