Skip to content

[AnimationLoop] Introduce simulation level NewtonRaphson - #6464

Open
bakpaul wants to merge 40 commits into
sofa-framework:masterfrom
bakpaul:26_09_add_newton_raphson_time_integrator
Open

bakpaul wants to merge 40 commits into
sofa-framework:masterfrom
bakpaul:26_09_add_newton_raphson_time_integrator

Conversation

@bakpaul

@bakpaul bakpaul commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

This PR introduces a new type of animation loop : the NewtonRaphson.

First the animation loop is an endangered species : it has been supersed by TimeIntegrator, and in the future all animation loop will be deprecated given that the NewtonRaphson behaves exaclty as before when forcing it to make only one newton step on fmoving forward in time

<NewtonRaphson maxNbIterationsNewton="1" maxNbIterationsLineSearch="0" alwaydAdvanceTime="true" /> 
<= (equivalent) => 
<DefaultAnimationLoop/>

And if any constraint solver si found in the simulation it behaves like the good ol' FreeMotionAnimationLoop

<NewtonRaphson maxNbIterationsNewton="1" maxNbIterationsLineSearch="0" alwaydAdvanceTime="true" /> 
<GenericConstraintSolver />
<= (equivalent) => 
<FreeMotionAnimationLoop/>
<GenericConstraintSolver />

And can do more !!! --> Of course, setting any other number in maxNbIterationsNewton and/or maxNbIterationsLineSearch will enable the Newton-Raphson algorithm for the body dynamics.
To do this multiple changes has been made to the IS API, sacrificing some optimization in the computation of the residual (especially for the position update). The first version I wanted to build didn't work for some mathematical reason where the residual I started from wasn't really the one I was moving towards with the line search, breaking the newton for some non-linear models.

Plus, this PR adds a new mechanism to provide a first guess for the unknown : the UnknownPredictor. For exemple :

<EulerImplicitIntegrationScheme name="backward_Euler" unknownPredictor="@UnknownPredictor" />
<ConstantVelocityPredictor name="UnknownPredictor" />

in this scene, the newton is initialized at a state which is not the current position/velocity, but a state where a 'guessed' dv has already been integrated. In the specific case of 'ConstantVelocityPredictor' the guess is that dv=0, so we integrate the velocity as if it staid contant over the timestep, enabling to already integrate the previous timetep dynamics and start closer to the solution.

A second one is proposed : the ConstantAccelerationPredictor. The idea is that we can now plug any kind of predictor. Even AI-based...

Finally, a new visito had to be introduced. It is a multipurpose visitor, I call it the NewtonRaphson army knife. The idea is that is serves 6 different purposes : setuping the step, computing bot sides, evaluating residual, updating states with unknown, finalizing the step... I didn't want to add 6+ new visitor in a time where they became Componenta non grata, so I decided to create this monstrosity and wrap it inside of a helper, enabling easy trigger of all those tasks from the Newton-Raphson. This is of course subject to discussion if you have better idea.

TODOs:

  • Fix back residue -> residual (sry Themis)
  • Fix scenes using StaticEquilibriumIS
  • Integrate properly Alex's recent diff enabling the FreeMotion for Static solver in the NewtonRaphson
  • Add comment for new methods in integration schemes
  • Modify the doc (in another PR on the doc repo, this one doesn't need it right now)

Next steps :

  • Enable to solve constraints inside of the Newton loop. This would require to accumulate the lambdas in the RHS and take the constraint violation into account into the cost function
  • Add Fisher-Buchmeister constraints
  • Finalize the Non-Smooth Newton implementation (with their little numerical tricks for stability)

[ci-depends-on https://github.com/sofa-framework/SofaGLFW/pull/309]
[ci-depends-on https://github.com/sofa-framework/SofaPython3/pull/659]
[with-all-tests]


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

…is around like collision detection from FreeMotion
…steps even if it increases the norm; first working version
@bakpaul bakpaul added pr: status to review To notify reviewers to review this pull-request pr: new feature Implement a new feature pr: highlighted in next release Highlight this contribution in the notes of the upcoming release labels Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: highlighted in next release Highlight this contribution in the notes of the upcoming release pr: new feature Implement a new feature pr: status to review To notify reviewers to review this pull-request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant