Skip to content

Add the linear constraint boundary condition, by elimination - #119

Open
mattjolley wants to merge 3 commits into
mainfrom
mattjolley/linear-constraint-bc
Open

mattjolley wants to merge 3 commits into
mainfrom
mattjolley/linear-constraint-bc

Conversation

@mattjolley

Copy link
Copy Markdown
Contributor

This pull request sits on #118 (mattjolley/gradients-through-anchors) 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 only the table of dependent entries (mattjolley/dependent-entries, row 8) and the two constraint terms of row 3; it is at the end of the line so that the rows between did not have to be rebased again.

What does this change, and why?

FEBio's <bc type="linear constraint"> (FELinearConstraint, FELinearConstraintManager) makes one degree of freedom a linear function of others and gives it no equation: its residual and stiffness go to the children. It was refused, with the three suite inputs that miss nothing else (mi04, mi05, mi37). This is the other half of K3-3 of Handoff K: the linear constraint set and the node distance, which enforce by a force, are terms (row 3); this one is by elimination.

It is built on the table of dependent entries that the rigid bodies with unknowns brought (assembly/reduction.py), so that the two share one mechanism, as the handoff asks. Design note: docs/design/constraints.md, the status of December 2 at its head and section 8.

What is built (constraints/linear_constraints.py, with the wiring in compiled.py and analysis/steps.py):

Point FEBio Here
The parent Marked fixed, so it gets no equation (FELinearConstraint::Activate); the other components of its node keep theirs A dependent entry whose constrained components follow and whose others stay unknowns; the components are marked DEPENDENT
Residual and stiffness R_k += a_k R_parent; a_k K a_l on both sides (AssembleResidual, AssembleStiffness) One link per (parent entry, child entry), with the coefficients at (parent component, child component) of its 3 x 3 matrix; the residual is carried by the transpose
The parent's value Written after every update (Update) The table's spread, from the hook of the Newton loop
A coefficient on a load curve (mi37) Read at the current time wherever the manager assembles The matrices are rewritten at the time being solved
The first right-hand side K times the parent's pending change is moved there only for a nonzero offset. With an offset of zero a parent whose coefficient has changed takes its new value at the first update The same; a nonzero offset is refused

The table is constant in the displacement, so the reduced tangent is the derivative of the reduced residual.

What is refused, and why (each by the coverage report, with the reason):

Refused Why
A nonzero offset The move of the parent's pending change to the first right-hand side is not built
A constraint declared in a step Activation by step is not built for the elimination
A child that is the parent of another constraint An error in FEBio too
A child at a node that is a parent in another component FEBio accepts it, since it rules by degree of freedom; the table rules by entry (node), and an entry cannot be both dependent and a master. A difference from FEBio, said in the report
Two constraints with the same parent; a parent that another condition names One equation per degree of freedom
Degrees of freedom other than the displacement and the shell displacement Not unknowns of this code
A setting that is not read Named in the report
A model that also has a rigid body with unknowns A system has one table of dependent entries, and the two are not merged. Added in the rebase, since on the base this was first built on no model could have both
Gradients The adjoint does not yet spread its solution to the dependent entries; adjoint_solve refuses a system with a table, for rigid bodies and for this alike

Open question B1 of docs/design/open_questions.md (the route for linear constraints) is updated: both routes are built. No new numbered question.

What conflicted in the rebase onto the line: the README row of loads and constraints and one status paragraph of constraints.md, both sides adding; and in analysis/steps.py the place where build_system gives the system its table, which the rigid bodies now also do. Both are kept, and the model that would need both is refused as the table above says.

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 e6d221a.

  • Tests added or changed: tests/test_linear_constraints_bc.py, new, five tests: the three suite problems on FEBio's steps, iterations and norm; that the parents follow their children at every state, to round-off; a coefficient on a load curve; coverage with every refusal above; that gradients are refused. No existing test is changed. The mechanism itself is checked without FEBio by K1's tests/test_reduction.py, which passes unchanged.

  • FEBio reference (input file, quantity compared, tolerance, FEBio version), or N/A: the stored values of FEBio's test suite (FEBio 4.13.0 at e4df3f8), with the preset FEBIO_4_13, on FEBio's quasi-Newton path.

    Suite input What it has Steps and iterations, here and FEBio Solution norm
    mi04 x of three nodes follows x of a fourth, on one hex8 10 and 31; 10 and 31 To 3e-14
    mi05 z of one node is minus x of another 10 and 50; 10 and 50 To 6e-13
    mi37 mi04 with two of the coefficients on a load curve 10 and 49; 10 and 49 To 4e-12

    FEBio's norm is over its equations, which the parents do not have, so it is compared with the norm over the free components. The test allows two iterations of slack, as for the other suite problems that take quasi-Newton updates, and holds the norm to 1e-6; the counts were FEBio's on CPU and on the P100. These three need a checkout of the FEBio test suite (FEBIO_TEST_SUITE) and are skipped without one, so CI does not run them; they ran here. No small input is generated: the suite is the reference.

  • 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,257 tests, none failed (96 skipped); Tesla P100, 1,257 tests, one failure (87 skipped), named below.
    • Full tier of test_linear_constraints_bc, test_reduction, test_constraint_terms, test_gradients_through_anchors, test_activity: CPU, 54 tests, none failed; Tesla P100, 54 tests, none failed.
    • The one failure of the quick tier 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. The suite scoreboard was not run on this tip.

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:03
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>
FEBio's <bc type="linear constraint"> makes one degree of freedom a
linear function of others and gives it no equation: its residual and
stiffness go to the children. It was refused, with the three suite
inputs that miss nothing else (mi04, mi05, mi37).

It is built on the table of dependent entries of the rigid bodies
(assembly/reduction.py), so that the two share one mechanism, as
Handoff K asks. constraints/linear_constraints.py owns the table: each
parent is a dependent entry whose constrained components follow, each
(parent, child) pair a link with the coefficients in its 3 x 3 matrix.
The parents are written after every update by the table's spread, and
a coefficient on a load curve is read at the time being solved. As in
FEBio, nothing of a parent's pending change goes to the first
right-hand side when the offset is zero.

Against the suite's stored values (FEBio 4.13.0 at e4df3f8), on CPU and
on a Tesla P100 with cuDSS: mi04 10 steps and 31 iterations, mi05 10
and 50, mi37 10 and 49, all FEBio's counts, with the norm to 4e-12.

Refused with the reason: a nonzero offset, a constraint declared in a
step, a child at a node that is a parent in another component (FEBio
rules by degree of freedom, the table by entry), a model that also has
a rigid body with unknowns (a system has one table, and the two are not
merged), and gradients, which a system with a table does not have yet.

The table came with the rigid bodies (mattjolley/dependent-entries).

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