Skip to content

Dynamics and mass damping, direct linear solves, loads in a step; where the code differs from FEBio - #9

Merged
mattjolley merged 6 commits into
mainfrom
mattjolley/dynamics-template
Nov 28, 2026
Merged

mattjolley merged 6 commits into
mainfrom
mattjolley/dynamics-template

Conversation

@mattjolley

Copy link
Copy Markdown
Contributor

What does this change, and why?

First templates for what a valve run needs beyond the elements: implicit dynamics with mass damping, loads written inside a step, and direct linear solves. Design notes: dynamics.md, linear_solve.md, and, new with this pull request, deviations.md: every place this work differs from FEBio, with the reason and the setting that gives FEBio's behavior back where there is one.

Second of three pull requests merged in order (elements; this one; then a first contact template). It is merged by the author so the work can continue, and is left here as the record for review afterwards: comments on a merged pull request are welcome and will be acted on. Nothing in it is settled.

Commit What
Solvers: direct solves on the host (sparse LU) and on the device (cuDSS) A sparse LU on the host, and an optional solve with NVIDIA cuDSS through nvmath-python (not a dependency). On the 1863-shell patch: dense host solve 4.5 min, Warp's CG 20 s, sparse LU 21 s, cuDSS 1.9 s, results equal to 3e-13. A solve that fails numerically is a failed step, which the time stepper cuts
Dynamics: implicit dynamic steps and mass damping, after FEBio's solid solver FEBio's parameter rules, initial accelerations, kinematic update, consistent mass and inertial force, for alpha_f = 1. Velocity and acceleration live in the State; the mass goes through the existing block pattern. mass damping on a whole part
Coverage: loads written inside a single step; tangent_scale reported Two things the open mitral input uses
Verification: the three dynamic user patches against FEBio Point load, pressure, and pressure with four chord springs: FEBio's 15 steps at FEBio's times
Docs The notes above, and status entries in the notes this touches
Fix a spelling-check failure in a docstring For the pre-commit hook

The deliberate differences from FEBio, in short (details and measurements in deviations.md):

  1. Newton's stiffness for mass damping is the derivative of the damping force by default. FEBio uses C/dt per unit mass, which is not the derivative, and its shell domain adds it with the opposite sign of its solid and truss domains (FEElasticShellDomain::ElementBodyForceStiffness). The derivative gives the same solution in far fewer iterations (325 against 1400 on the shell reference case; FEBio itself takes 1397) and is the tangent the adjoint needs. FEBio's form is kept as a setting, System.damping_tangent = "febio", and reproduces FEBio's iteration counts. Whether the shell sign is intended is a question for the FEBio team.
  2. tangent_scale is not applied. It changes how FEBio's Newton converges, not what it converges to; the exact tangent is used and the coverage report says so.
  3. Full Newton, no line search or BFGS yet. Not a choice. Where FEBio's line search stays at 1 the iteration counts match exactly; suite problem sh58 follows FEBio for 14 steps, until FEBio's line search first shortens a step.
  4. Linear solvers are Warp's Krylov methods, a host LU, or cuDSS, in place of Pardiso.

Validation

  • Tests added or changed: tests/test_dynamics_units.py and tests/test_mass_damping.py (closed forms: consistent mass, the kinematic update, a free body, decay under mass damping), tests/test_dynamics.py (against FEBio), tests/test_linear_solvers.py, tests/test_loads_in_step.py, and additions to tests/test_run_path.py and tests/test_io_model.py.
  • FEBio reference (input file, quantity compared, tolerance, FEBio version), or N/A: bk_mass_damping (displacement, velocity, stress over 200 steps; 6e-14; FEBio's 902 iterations reproduced), sh_lee_sacks_pressure (displacement and stress; 3e-8 at the input's dtol, 6e-13 with dtol 1e-10 in both codes; 1400 iterations against FEBio's 1397 with FEBio's damping stiffness). FEBio test suite at 986005f: dy16 and dy07 with the suite's step and iteration counts exactly. The three dynamic patches under references/febio/originals/patchwarp against their stored plot files (final displacement within 4e-6). Stored references are from FEBio 4.13.0 provisional source builds; iteration counts were taken from FEBio 4.13.0 at e4df3f8 built by tools/build_febio.sh.
  • Devices the full tier ran on (CPU, and the GPU model if CUDA; say so clearly if no GPU was used): CPU with CUDA hidden at the tip of the three-branch stack (229 tests) and a Quadro RTX 8000 (cuda:0) at the tip of this branch and of the stack. Every commit passes lint and the quick tier on CPU on its own. The cudss method was run from a separate environment with nvmath-python 1.0.1; it is skipped in the project environment.

Checklist

  • I have read the contributing guide.
  • uvx pre-commit run --all-files passes.
  • The full tier passes: WARP_FEBIO_TEST_LEVEL=full uv run -m unittest discover -s tests, and with WARP_FEBIO_TEST_DEVICE=cuda:0 for code that runs on the device.
  • If this changes what a design note says, the note is updated; open design questions are in its decision points, not only in this pull request.
  • The change is focused, and every commit is signed off (git commit -s).

🤖 Generated with Claude Code

mattjolley and others added 6 commits November 28, 2026 09:29
Two direct methods behind the existing linear solve call, for models
beyond the dense check solve.

"sparse" is SciPy's sparse LU on the host. "direct" uses it above 3000
unknowns where SciPy is installed (SciPy is not a dependency of the
package), since a dense matrix is no longer a check on a small model
there.

"cudss" solves with NVIDIA cuDSS on the device through nvmath-python,
which is optional and not a dependency. Warp 1.19 has no sparse direct
solver, and its Krylov solvers with the diagonal preconditioner need
hundreds of iterations per solve on shells. The BSR pattern is
converted once on the device to scalar CSR index arrays and a gather
map; each solve gathers the values, factors and solves. The analysis
is reused while the pattern stays and repeated only when it differs,
which contact will need. The Warp arrays are viewed by CuPy without a
copy. Matrix type GENERAL, so non-symmetric and indefinite tangents
are accepted; with the SPD type cuDSS returns NaN on an indefinite
matrix without raising.

Whole-run times on a Quadro RTX 8000 for the static 1863-shell patch
on spring chords: 4.5 minutes with the dense solve, 20 s with Warp's
CG, 21 s with "sparse", 1.9 s with "cudss", with results equal to
3e-13.

Errors. A solve that fails numerically (a singular matrix, a
non-finite result) raises SolveError, so the time stepper cuts the
step as it does for a diverging Newton iteration; before, a
LinAlgError from the dense solve ended the run. Without nvmath-python,
or on CPU, "cudss" raises CudssUnavailable with what to install, which
is not a SolveError: a method that is not installed is not a failed
step and is not retried.

tests/test_linear_solvers.py checks the call on small block matrices:
the methods against a host solve, symmetric and not; a singular matrix
as SolveError; and the change of method with size.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
…d solver

One implicit dynamic step series for alpha_f = 1 (the defaults, and
rhoi = 0 or -1). Followed from FESolidSolver2 at e4df3f8: the
parameter rules of Init, the initial accelerations from M a = F when a
load acts at time zero, the start of a step and the update of velocity
and acceleration (PrepStep, UpdateKinematics), the inertial force on
alpha_m a + (1 - alpha_m) a_n, and the mass scaled by
alpha_m / (beta dt^2) in the stiffness. Nodal reaction forces count
the inertial force and mass damping at prescribed components, as
FEBio's element-wise assembly does.

Arranged for Warp:
- Velocity and acceleration are arrays of the State, one 3-vector per
  entry, updated by one kernel after every increment. A step is then a
  function from one State to the next (decision D2).
- The mass is consistent, as FEBio's, and needs no matrix pattern of
  its own: each term gives one number per stiffness block
  (Term.mass_coefficients; hex8, quad4 shell, truss), computed once,
  and the system applies it through the blocks it already has.

Mass damping (FEBio's `mass damping` body load, on a whole part). Its
force, density times shape function times C v integrated by each
domain, is C M v with the consistent mass of the part, so the load has
no element code of its own: its C is given to the system, which
applies it through the mass blocks. A load on part of a part, and a
load curve on C, are refused.

A deliberate deviation from FEBio. Newton's stiffness for mass damping
is a setting, System.damping_tangent (decision D4 of
docs/design/dynamics.md):
  "exact"       the derivative of the force, C gamma / (beta dt). The
                default, and what the adjoint uses.
  "febio"       FEBio's C / dt per unit mass, with FEBio's sign per
                domain: added for solids and trusses, subtracted for
                shells (FEElasticShellDomain::ElementBodyForceStiffness).
  "consistent"  C / dt per unit mass, added for every domain.
All three converge to the same solution. Total iterations on
sh_lee_sacks_pressure: 1400 with "febio" (FEBio itself: 1397), 744
with "consistent", 325 with "exact". On bk_mass_damping: 902 (FEBio:
902), 902, 416.

Not built: alpha_f below 1 and a dynamic model with tet4 (no mass yet)
are refused by the coverage report; hex8 through warp.fem is refused
when the system is built. Several steps are not built.

Tests.
- tests/test_dynamics_units.py, closed forms with no FEBio result
  needed: FEBio's parameter rules; the consistent mass of a unit cube,
  a sheared brick, a solid and a shell model, and a truss; the
  kinematic update; and a body that nothing holds, solid and shell,
  which keeps a uniform velocity exactly.
- tests/test_mass_damping.py: a free body under mass damping has a
  closed form for one step, v1 = v0 / (1 + C dt / 2), which all three
  stiffnesses reach, the derivative in one iteration.
- tests/test_dynamics.py, against FEBio: bk_mass_damping (one hex8, a
  pressure on at time zero) to 6e-14 over 200 steps in FEBio's 902
  iterations; sh_lee_sacks_pressure (Lee-Sacks shells, pressure, mass
  damping) to 3e-8 at the input's tolerance and 6e-13 with dtol 1e-10
  in both codes; suite dy16 (trusses) and dy07 (hex8) with FEBio's step
  and iteration counts exactly; the exact tangent of a dynamic step,
  and the gradient through one dynamic step, against central
  differences.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
Two things the open mitral input uses, which the coverage report
refused.

Loads of a single step. FEBio activates a load declared inside a step
when the step starts (FEAnalysis::Activate). With one step that is the
whole analysis, so such a load is built as a load of the model.
Activation by step stays reserved for models with several steps.
tests/test_loads_in_step.py: a pressure moved into the step gives the
same states as a pressure of the model, and is refused with two steps.

tangent_scale. FEBio's tangent_scale on isotropic Lee-Sacks multiplies
c0 in the tangent only (FEIsotropicLeeSacks::Tangent), so it changes
how Newton converges and not what it converges to. The exact tangent
is used here. The coverage report now lists the parameter as having no
effect on the solution and says that iteration counts and step sizes
can differ, where before it listed the material as unsupported. It may
still matter for robustness: the mitral input sets it to 10. Carrying
a scaled Newton tangent beside the true one is decision T14 of
docs/design/materials.md, still open.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
The dynamic examples of references/febio/originals/patchwarp, a patch
of 1863 quad4 shells with FEBio's automatic time stepper: under a
point load (a2_dynamic), under a pressure ramp (pressure_dynamic), and
under a pressure ramp held by four chord springs
(four_chords_dynamic). Each takes FEBio's 15 steps at FEBio's times
and ends within 1e-6 to 4e-6 of FEBio's stored final displacement.
FEBio ran them with BFGS at dtol 1e-3, so agreement is to that
tolerance. Full tier, on a GPU only (about 20 s each with conjugate
gradients; 1.7 s with cuDSS for the one that was timed).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
docs/design/deviations.md collects, for review, every place the work
on chordae, dynamics, loads and solvers differs from FEBio:
differences that change a result or the path to it, with the reason
and the setting that gives FEBio's behavior back where there is one;
additions FEBio does not have; arrangements that differ without
changing a result; points checked and found the same; and the
questions these raise. Its rows on contact describe the first
template that follows in the next commit.

dynamics.md (v0.3): what was built, the comparisons with FEBio
including iteration counts, FEBio's sign of the damping stiffness in
its shell domain, decision D4 with the three stiffnesses measured, the
gradient through a dynamic step, and suite sh58, which follows FEBio
until FEBio's line search acts.

linear_solve.md (v0.3): first measurements on a GPU with the dense,
CG, sparse and cuDSS solves, what was measured on larger stand-in
problems, and the line search as the next piece.

Short status entries, dated November 28, in the notes this work
touches: run path, sensitivity, output, constraints, elements,
integration, materials, verification, work plan, remaining areas.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
The typos hook of pre-commit read "ba" in "(aa, ab, ba, bb)" as a
misspelling. The node pairs are now written a-a, a-b, b-a, b-b.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
@mattjolley
mattjolley merged commit 4e83ab1 into main Nov 28, 2026
2 checks passed
@mattjolley
mattjolley deleted the mattjolley/dynamics-template branch November 28, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant