Repository navigation
Conversation
Simulation.step(dt, ContactDynamicsParameters) advances cell growth and contact in one convex problem per substep: contact forces are non-negative, gaps stay non-negative, and a cell's elongation responds to the axial load its contacts put on it. Rows that the move opens are added to the same solve, and a substep that fails is retried at half its length. The CPU backend implements the solve; a backend without the feature rejects the step. A box or cylinder container reports one wall contact per face to this solve, so a cell end in a corner is held by every wall that meets there. MechanicsConfig(contact_dynamics=ContactDynamicsConfig(...)) selects the solve in a native controller, and payloads without the entry keep the relaxation passes.
The projected-gradient iteration is shared: a backend supplies the gap evaluation and the reductions over its own storage. The Metal backend keeps the step length and stopping test on the device and runs a batch of steps per command buffer. The CUDA backend reads the reduced step terms back each step. Simulation.solve_contact_system solves a standalone contact system on the selected backend, and the conformance test holds every backend to the CPU solution of the same systems and to the chamber and free-colony trajectories.
A contact that persists from one substep to the next carries nearly the same force, so the solve of the next substep starts there. A substep is lengthened only after one that settled within two refinement rounds, which stops the step length from alternating between one that fails and one that succeeds.
With flow drift enabled, the velocity and Jeffery rotation the flow gives each cell enter the contact solve as a known velocity, so contacts resist the flow pressing cells together instead of correcting overlap after a separate drift move. Contacts with constraints use their own stiffness, a hundred times the cell value by default, so cells rest on a wall within a small fraction of the overlap they have with each other. The trap example solves growth and contact together with a linear growth load response in place of its overlap-based growth rule.
The settled colony's axial load climbs steeply from the trap mouth, levels off where it slows growth, and peaks against the back wall.
A pair of cells spanning a closed chamber turns out of line when its growth ignores load, and a perfectly straight pair with a load response stalls where it is. A colony whose growth falls exponentially with load follows the published continuum pressure profile and expansion speed.
Contact dynamics is the only contact solve. The regularized least-squares solve, its conjugate-gradient iteration, the mechanics integration of its corrections, the wall projection, and their Metal and CUDA kernels are gone, with the backend feature, bindings, and tests that served them. No compatibility with the removed solve is kept. MechanicsConfig holds the contact dynamics parameters directly, and a controller configured with it solves growth and contact together on every step. Every example and tutorial model uses it. The planarity diagnostic observes the contact step in place of relaxation passes. FlowDriftParameters replaces the integration parameters as the argument of the standalone flow drift.
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.
Summary
Implements the plan in #53: contact is solved with non-negative forces, and growth is part of the same convex problem. This replaces the least-squares relaxation, which could not keep growing cells apart in a full space or stop growth when the space is full (#51). The old relaxation is removed; no compatibility with it is kept.
Simulation.step(dt, ContactDynamicsParameters)advances growth and contact together.MechanicsConfigholds its parameters, and a controller configured with it takes every step this way.docs/architecture/0026-contact-dynamics.md.Removed
Simulation.solve_cell_mechanics,Simulation.relax_cell_mechanics,MechanicsParameters,MechanicsSolveResult,CellCorrection,SolverStatus,SolverBreakdown,SolverReport, andBackendFeature.CELL_MECHANICS.MechanicsConfigfieldspasses,gamma,mu_a,residual_rms_tolerance,require_convergence,max_rotation_radians, and the two activation margins. Controller checkpoints written with the old fields do not load.MechanicsIntegrationParametersis replaced byFlowDriftParametersas the argument of the standaloneapply_flow_drift.Still present, and only meaningful to the removed solve: the
weightfield of contacts and thecoefficientfield of constraints. They are part of the checkpoint and scene formats, so removing them is a format change and is left out of this PR.Results
Performance
A step now costs roughly 50–100 times what a least-squares relaxation pass did. The two are not doing the same work: the relaxation took one cheap linear solve and left the contacts unresolved, and the new step iterates until they are resolved.
Cost per step
Unconfined colony, no load response,
dt = 0.05, default parameters, measured on an Apple-silicon laptop before the old solve was removed. Each figure is the mean of three steps.Starting each substep's solve from the previous substep's forces, added afterwards, brought the 5,000-cell CPU figure to 1.2 s. The Metal figures predate that change.
The trap example, about 500 cells at steady state, runs 1,500 steps in about 34 s on CPU, or roughly 23 ms per step.
What has been tried
The iteration count is set by the conditioning of the contact network, which scales with contact stiffness × step length ÷ drag. That is why the changes below move it so little.
What could be tried
Why the new solve is more accurate
The claim rests on physical constraints the old solve violated and on agreement with analytic solutions. Neither solve has been compared with experimental data here.
What the least-squares relaxation got wrong
Measured on master during the investigation in #51:
gamma = 10had a median per-cell overlap of 0.32 at radius 0.5, about two thirds of a radius. The solver reported convergence on every step.gamma = 100reduced the free colony's overlap to about 0.003 but made a full chamber creep;gamma = 10did the reverse.These follow from the formulation, not from tuning. Contacts were equalities solved in a least-squares sense, so a contact could pull as well as push, the solve minimized the sum of squared overlaps and so did not bound the largest one, and growth was committed before the solve with no way to yield.
What the new solve gets right
Limits of the accuracy claim
Verification
nvidia/cuda:12.8.1-devel-ubuntu24.04. It has not been run: no NVIDIA GPU was available.Closes #53. Closes #51. Supersedes #52.