NonlinearSolve.jl : mimic SimpleNewtonRaphson with NewtonRaphson

Hi everyone,

I’m trying to solve a non-linear equation using a Newton-Raphson method using NonlinearSolve.jl . I have my own implementation of a basic Newton-Raphson algorithm, and the SimpleNewtonRaphson algorithm does reproduce the same results. Now, I’d like to use the NewtonRaphson alg (with advanced features) but first I would like to reproduce my reference results. In other words, I’d like to mimic the SimpleNewtonRaphson with NewtonRaphson. So far, I’ve tried

alg = NewtonRaphson(; linsolve = LUFactorization(), linesearch = NoLineSearch())

but the algorithm does not lead to the correct solution.

Is it possible to set the NewtonRaphson in order to obtain exactly the same results as the SimpleNewtonRaphson?

PS : unfortunately, I cannot give a MWE, the non-linear function involves a whole finite-element discretization etc.

This is probably not possible? Little differences in SIMD would be hard to track down.

Provide the same initial vector for both algorithms and print the iteration information for each step. You can examine them carefully.

This situation might be related to the termination_cache mechanism of NewtonRaphson. From my understanding, when the SimpleNewtonRaphson reaches the maximum number of iterations, it returns the solution obtained from the last iteration performed. When the NewtonRaphson hits the maximum number of iterations, it does not return the solution obtained from the last iteration, but the minimizer of f from all the performed iterations. For stiff problems, the two solutions (minimizer of f accross all the newton iterations vs last solution obtained from the iterations) are not equal, hence the differences.

I see, and yes there are different termination algorithm choices, so if you swap that to one that doesn’t use best is it matching?

Yes if I “skip” this termination algorithm, NewtonRaphson and SimpleNewtonRaphson return the same result.
For now I solved my problem here and the one related to the “callback” (cf my other topic) by using the step! interface. Thanks for all these features :wink: