Repository navigation
Hold the anchors of a State in the adjoint - #118
Open
mattjolley wants to merge 3 commits into
Open
mattjolley wants to merge 3 commits into
mattjolley wants to merge 3 commits into
Conversation
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>
3 of 5 tasks
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.
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)andupdate_holding(system, state, record).adjoint_solveand the two branches ofrun_gradient(over_steps.py) update throughupdate_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.contact/changes, and the terms' own flagadjoint_readystays 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.
ti_blocks(tied, anchors placed in the undeformed mesh)st_grasp_quad4(sticky; 20 nodes attached; at the end, three time steps after the last event)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_solveandrun_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 withalpha-fin those two functions was both sides adding at the same place;tests/test_history_adjoint.pyand the gradient tests oftests/test_alpha_f.pypass unchanged.What is refused, and why:
offset_shellssliding-elasticbetween two deformable bodies,tied-elasticNot 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.pyanddocs/design/contact.mdthat 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
gpuextra), at this branch's own tipe53e3f8.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.pyandtests/test_tied.pypass as they are.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.mainat25b5aacon 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).Checklist
uvx pre-commit run --all-filespasses. (Run on the files of this change: passes.)FEBIO_WARP_TEST_LEVEL=full uv run -m unittest discover -s tests, and withFEBIO_WARP_TEST_DEVICE=cuda:0for code that runs on the device. (Not run in full; see Validation.)git commit -s).🤖 Generated with Claude Code