Skip to content

Contact: a smooth tier of the contact potential, for gradients - #16

Merged
mattjolley merged 2 commits into
mainfrom
mattjolley/contact-smooth-tier
Nov 28, 2026
Merged

mattjolley merged 2 commits into
mainfrom
mattjolley/contact-smooth-tier

Conversation

@mattjolley

Copy link
Copy Markdown
Contributor

What does this change, and why?

Adds a smooth tier of the contact potential, chosen by a setting (build_system(model, contact="smooth")), as the form that gradients through leaflet closure will use. FEBio's form stays the default and is what every comparison with FEBio uses. This is piece 5 of the plan in contact_in_run.md (now v0.5).

Merged by the author so the work can continue; comments afterwards are welcome. This is a deliberate difference from FEBio and is listed as such (row 14a of docs/design/deviations.md, decisions K6 and K7 of the contact note). It follows the original formulation (Kamensky et al. 2018) in the two places where FEBio's implementation departs from it:

FEBio's form (contact="febio", default) Smooth tier (contact="smooth")
Self-contact exclusion The normal test w_tol, a switch that depends on the solution By topology (elements that share a node) and by reference distance, at least 1.5 R_out; neither depends on the solution
Weights From the current configuration, not differentiated From the reference configuration
Consequence The tangent is not the derivative of the force An energy exists; the tangent is its exact second derivative; pairs enter and leave at zero force and zero stiffness

Measured.

  • On sh_self_contact_fold, by central differences at a state with contact: with the smooth tier the force is minus the gradient of the contact energy to 2e-8 and the tangent minus the derivative of the force to 1e-8. With FEBio's form they are off by 9 and 25 percent. An adjoint built on FEBio's form would be wrong by those amounts.
  • On the two small contact cases the smooth tier has the same active pairs as FEBio's form and results within 0.1 to 4 percent of it; on the two-block case it takes 56 Newton iterations where FEBio's form takes 94.
  • On the open mitral input (examples/valve/mitral_closure.py, third argument smooth): closure in 248 steps and 857 iterations, 2.3 minutes against 7.8 with FEBio's form; contact starts at the same time as in FEBio (0.00304); leaflet stresses 0.49 percent from FEBio's in the median, the same as FEBio's form achieves; contact area 76.5, which is the part between opposing leaflets (FEBio's 89.6 includes pairs within one leaflet, pull request 15).

Validation

  • Tests added or changed: tests/test_contact_in_run.py (SmoothTierTests: the settings; closeness to FEBio's form on the small cases; force against the energy gradient and tangent against the force derivative, for both forms).
  • FEBio reference (input file, quantity compared, tolerance, FEBio version), or N/A: FEBio's form is unchanged and its comparisons with FEBio pass as before. The smooth tier is not FEBio's model; it is compared with FEBio's form and, on the mitral input, with the stored FEBio 4.9.0 results as in pull request 14.
  • Devices the full tier ran on (CPU, and the GPU model if CUDA; say so clearly if no GPU was used): quick tier on CPU (238 tests); full tier on a Quadro RTX 8000 (cuda:0, 238 tests); the mitral run on the same GPU from an environment with nvmath-python. The full tier on CPU was not run locally.

Checklist

  • I have read the contributing guide.
  • uvx pre-commit run --all-files passes.
  • The full tier passes. (GPU: yes. CPU: quick tier; 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

mattjolley and others added 2 commits November 28, 2026 11:17
build_system(model, contact="smooth") runs the contact potential in a
form whose energy is smooth in the positions (contact/in_run.py,
TIERS). FEBio's form stays the default and is what the comparisons
with FEBio use.

The smooth form differs from FEBio's in two ways, each deliberate
(decisions K6 and K7 of docs/design/contact_in_run.md):
- No normal test w_tol, which switches a pair on or off by the
  solution. A pair is excluded by topology (elements that share a node)
  and by the distance of its points in the reference configuration, at
  least 1.5 R_out, as the original formulation does for self-contact
  (Kamensky et al. 2018, R_self; FEBio's R0_min).
- Weights from the reference configuration, as in the original
  formulation. FEBio's follow the current configuration and are not
  differentiated, so its tangent is not the derivative of its force.

Measured on sh_self_contact_fold at a state with contact, by central
differences: with the smooth form the force is minus the gradient of
the contact energy to 2e-8 and the tangent is minus the derivative of
the force to 1e-8; with FEBio's form the two are off by 9 and 25
percent. So an adjoint through closure needs the smooth form.

On the small cases the smooth form has the same active pairs as
FEBio's and results within a few percent of it. On the open mitral
input (examples/valve/mitral_closure.py, third argument "smooth") it
closes the valve in 248 steps and 857 iterations, 2.3 minutes against
7.8; contact starts at the same time as in FEBio; leaflet stresses are
0.49 percent from FEBio's in the median, the same as with FEBio's
form; the contact area is 76.5, which is the part between opposing
leaflets (FEBio's 89.6 includes pairs within one leaflet).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
docs/design/contact_in_run.md (v0.5): what the smooth tier is, a table
of what was checked for it and for FEBio's form (force against the
energy gradient, tangent against the force derivative, the small
cases, the open mitral input), piece 5 of the plan marked done, and
decisions K6 and K7 updated. docs/design/deviations.md lists the tier
among the additions FEBio does not have.

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 60d6941 into main Nov 28, 2026
2 checks passed
@mattjolley
mattjolley deleted the mattjolley/contact-smooth-tier branch November 28, 2026 16: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