Skip to content

Sensitivity: gradients through a solve with self-contact, tested - #17

Merged
mattjolley merged 1 commit into
mainfrom
mattjolley/contact-adjoint
Nov 28, 2026
Merged

mattjolley merged 1 commit into
mainfrom
mattjolley/contact-adjoint

Conversation

@mattjolley

Copy link
Copy Markdown
Contributor

What does this change, and why?

Records, as tests and in the notes, that adjoint gradients through a solve with active self-contact work with the smooth contact tier of pull request 16. This is piece 6 of the plan in contact_in_run.md, for one equilibrium solve. No library code changes: the adjoint already solves with the system matrix, which carries the contact tangent, with the pairs as they are at the converged state.

On sh_self_contact_fold, the gradient of a displacement with respect to the four material parameters of the shell, against central differences of the whole run:

Contact form Largest relative error
Smooth tier 7e-9
FEBio's form 7e-2

With the smooth tier the frozen-pair adjoint is exact, because the contact tangent is the derivative of the contact force and pairs enter and leave at zero force and zero stiffness. FEBio's form has a Newton tangent that is not that derivative (FEBio has no adjoint, so this is not a defect there); the second row is why this code's adjoint is not built on it (decision K7).

Not built: gradients with respect to the contact parameters themselves, and through the dynamic steps of a closure.

Merged by the author; comments afterwards are welcome.

Validation

  • Tests added or changed: tests/test_contact_in_run.py, GradientThroughContactTests (the smooth-tier check in the quick tier, the FEBio-form check in the full tier).
  • FEBio reference (input file, quantity compared, tolerance, FEBio version), or N/A: N/A; FEBio has no gradients. The check is central differences of this code.
  • Devices the full tier ran on (CPU, and the GPU model if CUDA; say so clearly if no GPU was used): both new tests on CPU and on a Quadro RTX 8000 (cuda:0); quick tier on CPU (240 tests). The full tier as a whole was not rerun.

Checklist

  • I have read the contributing guide.
  • uvx pre-commit run --all-files passes.
  • The full tier passes. (The new tests on both devices and the quick tier on CPU; the CI job runs the full tier on CPU.)
  • 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

On sh_self_contact_fold the adjoint gradient of a displacement with
respect to the four material parameters of the shell, through a solve
with active self-contact, matches central differences of the whole run
to 7e-9 with the smooth contact tier. With FEBio's form of the law it
is off by up to 7 percent, since that form's tangent is not the
derivative of its force. No new code was needed: the adjoint solves
with the system matrix, which carries the contact tangent, with the
pairs as they are at the converged state; with the smooth tier that is
exact, because pairs enter and leave at zero force and zero stiffness.

GradientThroughContactTests keeps both checks (the FEBio-form one in
the full tier). The contact, sensitivity and README notes are updated.
Not built: gradients with respect to the contact parameters, and
through the dynamic steps of a closure.

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 3d9be6d into main Nov 28, 2026
2 checks passed
@mattjolley
mattjolley deleted the mattjolley/contact-adjoint branch November 28, 2026 16:47
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