Repository navigation
Dynamics and mass damping, direct linear solves, loads in a step; where the code differs from FEBio - #9
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
mass dampingon a whole partThe deliberate differences from FEBio, in short (details and measurements in
deviations.md):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.tangent_scaleis 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.sh58follows FEBio for 14 steps, until FEBio's line search first shortens a step.Validation
tests/test_dynamics_units.pyandtests/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 totests/test_run_path.pyandtests/test_io_model.py.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'sdtol, 6e-13 withdtol1e-10 in both codes; 1400 iterations against FEBio's 1397 with FEBio's damping stiffness). FEBio test suite at986005f:dy16anddy07with the suite's step and iteration counts exactly. The three dynamic patches underreferences/febio/originals/patchwarpagainst 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 ate4df3f8built bytools/build_febio.sh.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. Thecudssmethod was run from a separate environment with nvmath-python 1.0.1; it is skipped in the project environment.Checklist
uvx pre-commit run --all-filespasses.WARP_FEBIO_TEST_LEVEL=full uv run -m unittest discover -s tests, and withWARP_FEBIO_TEST_DEVICE=cuda:0for code that runs on the device.git commit -s).🤖 Generated with Claude Code