Skip to content

Add the dynamics of a rigid body with open components - #113

Merged
mattjolley merged 4 commits into
mainfrom
mattjolley/rigid-body-dynamics
Dec 3, 2026
Merged

mattjolley merged 4 commits into
mainfrom
mattjolley/rigid-body-dynamics

Conversation

@mattjolley

Copy link
Copy Markdown
Contributor

This pull request sits on #112 (mattjolley/rigid-body-unknowns) and is to be merged after it. Until that is merged, the diff here also shows its commits; the commits of this pull request are the last one.

What does this change, and why?

A rigid body with open components was refused in a dynamic step. This adds what a dynamic step needs, to FEBio 4.13.0 at e4df3f8 (FERigidSolverNew::InertialForces and UpdateRigidBodies, FERigidSolver::RigidMassMatrix, FESolidSolver2::InitAccelerations). Design note: docs/design/rigid_bodies.md, sections 4.3 and 13.

What is built:

  • Mass, center of mass and inertia of a body from its density, by FEBio's rules: one integration point for a tet4, a given center_of_mass used as it is, also for the inertia.
  • Translation through the mass of the system: the mass of a body sits on the block of its translation entry, so the inertial force, the mass in the tangent and the initial accelerations are those the system already forms.
  • Rotation in the rigid system term: FEBio's update of the angular velocity and acceleration from the rotation of the time step, the angular momentum and its rate, the inertial moment, and the rotational mass block.
  • A body force on a rigid part, which reaches the body through the nodes of the part (FERigidSolidDomain::BodyForce).
  • Initial accelerations with the bodies in the mass matrix.

Three things of FEBio that are easy to miss are followed, because its iterations depend on them:

  • A symmetric stiffness keeps the upper triangle. The rotational mass block is not symmetric; where the input asks for symmetric_stiffness symmetric, which is the default, FEBio stores the upper triangle and its solve sees it mirrored. Before this was followed, the spinning body below converged in fewer iterations than FEBio's. Newton gets the mirrored block; linearize(exact=True) gives the block itself.
  • The stiffness of a time step is formed before its first residual (FENewtonSolver::QNInit), with the angular momentum of the last state.
  • The initial angular acceleration is beta dt^2 times the one the moments give: in the mass matrix of time zero FEBio sets 1 / (beta dt^2) to 1 for the translation of a body and not for its rotation.

Shared files, named plainly: six lines in solvers/nonlinear/newton.py (after an increment is taken, a term may write the total increment of the time step as FEBio's solution vector holds it, since the convergence norm counts it: for a body, the composed rotation increment; no effect was measured on the cases below) and two hooks in analysis/dynamics.py, initial_state.

Where a body meets the work of #104 and of the static step after a dynamic one: it refuses, with the reason, and a test holds each. A dynamic step with alpha_f below 1 (FEBio takes the arm of a rigid node at the interpolated configuration, which is not joined to State.domain_u yet); static and dynamic steps in one run, in either order (FEBio's rigid solver updates the velocities of a body in a static step too). Also refused: initial velocities of a body.

Validation

All of the following with Warp 1.20.0.

  • Tests added or changed:

    • tests/test_rigid_dynamics.py, new: the two generated inputs and the suite input below; mass, center and inertia of a hex8 cube and of tet4 parts against closed forms; the initial accelerations; the rotational mass block as Newton and as the adjoint get it.
    • tests/test_rigid_unknowns.py: the refusal of a dynamic step becomes the two refusals named above.
  • FEBio reference (input file, quantity compared, tolerance, FEBio version), or N/A: Two generated inputs with references from FEBio 4.13.0 at e4df3f8 (displacement of the eight nodes at every state; compared at 1e-9) and one suite input (986005f, preset FEBIO_4_13).

    Input What it has Iterations per time step, here and FEBio Agreement
    rb_spin A skewed rigid hex8, free in all six, spun up by two moments and pushed by a force; symmetric stiffness, a reformation in every iteration 3 3 4 4 5 5 5 6 6 6, the same 2.5e-12
    rb_spin_from_zero The same with the loads from time zero (initial accelerations), a non-symmetric stiffness and BFGS updates 4 4 5 6 6 6 6 7 8 8, the same 8.1e-13
    Suite dy05 A rigid element under a body force 10 and 10, in 10 steps Norm to 9e-16

    The same on CPU and on a Tesla P100. The reference of rb_spin_from_zero is from the FEBio build with MKL Pardiso at the same commit, since FEBio's skyline solver takes no non-symmetric matrix; the other references of this repository are from the skyline build.

  • Devices the full tier ran on (CPU, and the GPU model if CUDA; say so clearly if no GPU was used):

    • At this branch's own tip d876c2e, which is the tip of the five rigid body pull requests, Warp 1.20.0: quick tier of the whole repository on CPU, 1,187 tests, none failed (91 skipped); on a Tesla P100 (cuDSS; the versions of the gpu extra), 1,187 tests, one failure (82 skipped): tests/test_history_adjoint.py, ForwardSweep.test_the_jacobian_of_a_static_run_goes_through_the_steps (from History in the forward sweep #101), which fails on unchanged main at 25b5aac on the same GPU and passes on CPU; it is not of this pull request. The full tier of the nine test files these five pull requests add, change or meet (test_rigid_wall, test_reduction, test_rigid_unknowns, test_rigid_dynamics, test_rigid_moved, test_rigid_refusals, test_sticky, test_alpha_f, test_static_after_dynamic): 125 tests, none failed, on CPU and on a Tesla P100.
    • Not run: the full tier of the whole repository, on either device. The suite scoreboard was not run again on this base.

Checklist

  • I have read the contributing guide.
  • uvx pre-commit run --all-files passes. (Run on the files of this change: passes.)
  • The full tier passes: FEBIO_WARP_TEST_LEVEL=full uv run -m unittest discover -s tests, and with FEBIO_WARP_TEST_DEVICE=cuda:0 for code that runs on the device. (Not run in full; see Validation.)
  • 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 4 commits December 2, 2026 18:58
A node of a rigid body, and the parent of a linear constraint, has no
equation of its own in FEBio: what is assembled on it is carried to
other equations. This adds that mechanism once, for both (decision R1
of docs/design/rigid_bodies.md), so that the rigid bodies of thread K1
and the linear constraints of thread K3 share it.

The terms assemble on node entries as before. The system then carries
the residual and the blocks of a dependent entry to its masters, in
three kernels, and the matrix pattern stays fixed. An owner fills the
table; none exists yet, so no run changes. The adjoint and the forward
sensitivities refuse a system with a table.

Checked against the dense product on a small elastic problem, on CPU
and on a Tesla P100.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
A rigid body that shares no element with anything (dy05 of the suite)
has dependent entries and no carried block, and the empty slice of the
block list raised.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
A rigid body with a component that no condition holds was refused. It
is the most common reason a suite input does not run, and the last
stage of the published clip procedure needs it (Handoff K, thread K1).

Such a body now has two entries in the field table, its translation
and its rotation vector, and its nodes are dependent entries that the
system eliminates. The orientation is a quaternion updated as FEBio's
rigid solver updates it; rigid_force and rigid_moment are read with
load_type LOAD. Static steps only: the mass and inertia of a body are
not built yet, and a contact surface on such a body is refused until
its stiffness is carried to the body.

Suite inputs ri01, ri03, ri07 and co42 as published take FEBio's time
steps and iterations on CPU and on a Tesla P100. Three generated
inputs with a released component agree with FEBio 4.13.0 to 4e-12,
and a moved body gives the same result on the old path and the new.
A body with no open component stays on the old path.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
A body with unknowns was refused in a dynamic step. This adds its mass
and inertia from the density, FEBio's update of the angular velocity
and acceleration, the inertial force and moment, the rotational mass
block, a body force on a rigid part and the initial accelerations.

Three things of FEBio's rigid solver are followed because its
iterations depend on them: the stiffness of a time step is formed
before its first residual, with the angular momentum of the last
state; a symmetric stiffness keeps the upper triangle of the
rotational mass block, which is not symmetric; and the initial angular
acceleration is scaled by beta dt^2.

Two generated cases of a body spun up by moments agree with FEBio
4.13.0 to 3e-12 with its iterations in every time step, and suite
input dy05 takes FEBio's counts, on CPU and on a Tesla P100. A dynamic
step after a static one, and initial velocities, are refused.

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 a6fb46d into main Dec 3, 2026
2 checks passed
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