Skip to content

Hold the anchors of a State in the adjoint - #118

Open
mattjolley wants to merge 3 commits into
mainfrom
mattjolley/gradients-through-anchors
Open

mattjolley wants to merge 3 commits into
mainfrom
mattjolley/gradients-through-anchors

Conversation

@mattjolley

Copy link
Copy Markdown
Contributor

This pull request sits on #117 (mattjolley/sliding-elastic-friction) and is to be merged after it. Until the rows below it are merged, the diff here also shows their commits; the one commit of this pull request is the last. It needs the anchored-point terms of rows 11 to 14 (contact/anchored.py), where the anchors of a tied or sticky interface are kept with each State.

What does this change, and why?

The adjoint refused a system with a tied or sticky interface. The anchors of such an interface (for each point, the facet it is held to and where on it) are history: linearizing at a stored State would have brought the term there with the anchors of whichever state it saw last.

A State that a run keeps carries its anchors in its restart record. The adjoint now gives them back to the term before it linearizes at that State, by the call a restart uses (Term.set_restart_data), and again after the term's update, which for a sticky interface tests for attachment and release anew. The reverse sweep over steps does the same for every State. This is the first piece of section 14 of the sensitivity note ("Gradients through history"; order of work, piece 1; decision S3: events are held as the forward run found them). Design note: docs/design/sensitivity.md, section 5, "Anchors held".

What is built, all in sensitivity/:

  • adjoint.py: HISTORY_HELD = (AnchoredPoints,), hold_history(system, state) and update_holding(system, state, record). adjoint_solve and the two branches of run_gradient (over_steps.py) update through update_holding.
  • check.py: check_equilibrium_gradients, the adjoint against central differences of the equilibrium solved again from the State with the anchors held. It is the check for what this gradient is.
  • Nothing in contact/ changes, and the terms' own flag adjoint_ready stays False: it says that the term alone, without the State's record, cannot be linearized at an earlier state. The anchors are read and not moved.

What the gradient is, stated plainly. It is the gradient of the equilibrium with the anchors as the run found them.

Input Against the equilibrium with the anchors held Against central differences of the whole run So
ti_blocks (tied, anchors placed in the undeformed mesh) 1e-8 1e-8 The derivative of the run: the anchors do not move with a parameter
st_grasp_quad4 (sticky; 20 nodes attached; at the end, three time steps after the last event) 1e-8 2e-5 to 6e-5 relative Not the derivative of the run. The run places each anchor where the node meets the surface, which moves with the parameter; the gradient with the anchors held has no such part

For sticky contact there is a second reason, which no check here measures: the anchor is chosen in the update after an iterate, so the forward result depends on the path of the Newton iteration. At an event neither kind of difference means anything; the checks are made away from one. The same holds for a tied interface activated in a later step: its anchors are placed in a deformed state and are held as constants.

It meets the reverse sweep through the history of a material (#99) in adjoint_solve and run_gradient. The two are independent: #99 carries the sensitivity of a material's history from step to step; the anchors are held. The conflict with #99 and with alpha-f in those two functions was both sides adding at the same place; tests/test_history_adjoint.py and the gradient tests of tests/test_alpha_f.py pass unchanged.

What is refused, and why:

Refused Why
A State without its restart record (made by hand, or not kept by a run) The anchors it was solved with are not known. The wording of the refusal every such term had before is kept
A tied interface with offset_shells The point is held half a thickness from the facet along the facet's current normal, and the stiffness, FEBio's, leaves out the turning of that normal: not the derivative of the force, so there is no exact tangent to solve the adjoint with
The other terms with anchors: sliding-elastic between two deformable bodies, tied-elastic Not of the kind held here; they keep their own refusal. For the first, FEBio's stiffness is not the derivative of the force
Forward sensitivities through these terms Not built

Not built: the projection of the node on the facet on the tape of the step of the event, which would give the missing part for an anchor placed in a deformed state (decision S13).

For K2, not in this pull request: the sentences in contact/anchored.py, contact/sticky.py, contact/tied.py and docs/design/contact.md that say the adjoint refuses these terms are out of date with this; contact/ is K2's, and the wording has been sent for a later branch.

Validation

All of the following with Warp 1.20.0, on CPU and on a Tesla P100 (cuDSS; the versions of the gpu extra), at this branch's own tip e53e3f8.

  • Tests added or changed: tests/test_gradients_through_anchors.py, new, six tests: the two rows of the table above; that the sticky gradient is not the derivative of the run (it asserts the difference, so that the statement cannot silently stop being true); a State before the last event; a State without its record; a tied interface with a shell offset. No existing test is changed: tests/test_sticky.py and tests/test_tied.py pass as they are.
  • FEBio reference (input file, quantity compared, tolerance, FEBio version), or N/A: N/A. FEBio has no gradients; the checks are against central differences. The forward runs of the two inputs are compared with FEBio in rows 11 to 14.
  • Devices the full tier ran on (CPU, and the GPU model if CUDA; say so clearly if no GPU was used):
    • Quick tier of the whole repository: CPU, 1,252 tests, none failed (96 skipped); Tesla P100, 1,252 tests, one failure (87 skipped), named below.
    • Full tier of test_gradients_through_anchors, test_sticky, test_tied, test_history_adjoint, test_alpha_f, test_static_after_dynamic: CPU, 100 tests, none failed; Tesla P100, 100 tests, the same one failure.
    • The one failure on the P100 is present on unchanged main at 25b5aac on the same GPU and is not of this pull request: tests/test_history_adjoint.py, ForwardSweep.test_the_jacobian_of_a_static_run_goes_through_the_steps (from History in the forward sweep #101; it passes on CPU).
    • Not run: the full tier of the whole repository, on either device.

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 3 commits December 2, 2026 20:02
FEBio's tied-elastic interface holds two surfaces at the separation
they have when the interface is activated: each integration point of
the primary surface is tied to the point of the secondary it projects
on along its normal, and the vector between the two is kept. It is the
anchored-point force of valve_workflow.md, section 4.1, with the points
at integration points.

contact/tied_elastic.py has it as a term of a run: one or two passes,
both forms of FEBio's stiffness (the non-symmetric one is the exact
derivative of the force), a penalty on a load curve, also declared in a
step. Under a solver that asks for a symmetric matrix the term gives
Newton the lower triangle of its stiffness mirrored, which is what
FEBio's symmetric format holds of it.

Four generated two-block cases agree with FEBio 4.13.0 (the build with
MKL Pardiso) to 2e-12 with FEBio's iterations in every time step, on
CPU and on a Tesla P100. One of them shows what the stored triangle
costs: 5 to 14 iterations per time step where the whole stiffness takes
3, in FEBio as here.

The suite's co52 and co53 wait on rigid bodies with unknowns and on the
augmented Lagrangian form; auto_penalty is refused until it is shared
with sliding-elastic.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
The friction of FEBio's sliding-elastic interface in its penalty form,
for the term between two surfaces that move: fric_coeff, slip_tol, and
knmult 1, which FEBio sets itself with friction. It is the
anchored-point force with a release rule: a point is held to where it
was on the secondary surface at the end of the time step before while
the shear part of that traction stays below fric_coeff times its
pressure, and slips otherwise.

contact/sliding_friction.py has the trial, stick and slip of FEBio's
ContactTraction and the two branches of its stiffness, transcribed with
FEBio's names. With fric_coeff 0 and knmult 0 they give the forces and
the stiffness of the frictionless kernels, which stay in use there.

The anchors of a time step are the projection of the last converged
state, also for a point that stuck (FESolidSolver2::PrepStep updates
the model before the interface takes them). With the first anchor kept
instead, co47 is 1e-5 off in its third time step.

co47 takes the suite's stored 51 steps and 292 iterations, FEBio's
count in each step, and the norm to 2e-12, on CPU and on a Tesla P100;
three generated cases agree with FEBio 4.13.0 to 6e-13. co34, which
sets knmult 1 without friction, takes its stored 20 steps and 42
iterations and the norm to 1e-12.

This branch is cut from mattjolley/sliding-elastic-deformable, which it
needs. The suite's other friction inputs, co48 and co44, set augmented
Lagrangian, which waits on an augmentation loop in the Newton solver.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
The adjoint refused a system with a tied or sticky interface: the
anchors of such an interface are history, and linearizing at a stored
State would have brought the term there with the anchors of whichever
state it saw last.

A State that a run keeps carries its anchors in its restart record
(contact/anchored.py, "The anchors and the State"). The adjoint now
gives them back to the term before it linearizes at that State, by the
call a restart uses, and again after the term's update, which for a
sticky interface tests for attachment and release anew. The reverse
sweep over steps does the same per State. The anchors are read and not
moved; nothing in contact/ changes, the term's own flag stays False,
and a State without its record is refused as before.

What the gradient is, measured on CPU and on a Tesla P100:

  ti_blocks (tied, anchors placed in the undeformed mesh): the adjoint
  agrees with central differences of the equilibrium solved again from
  the State and with central differences of the whole run, 1e-8. It is
  the derivative of the run.

  st_grasp_quad4 (sticky, 20 nodes attached, three time steps after the
  last event): 1e-8 against the equilibrium with the anchors held, and
  2e-5 to 6e-5 relative against the whole run, which places the anchors
  where the nodes meet the surface. It is the derivative of the model
  with the grasp as found, not of the run.

check_equilibrium_gradients is the check with the anchors held.

Refused, beside a State without its record: a tied interface with
offset_shells, whose stiffness leaves out the turning of the facet
normal, as FEBio's does, so that there is no exact tangent; and the
other terms with anchors (sliding-elastic between two deformable
bodies, tied-elastic), which keep their own refusal.

The anchors are those of contact/anchored.py (the tied and sticky
interfaces of Handoff K, thread K2).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Matthew Jolley <12954190+mattjolley@users.noreply.github.com>
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