NonlinearSolve.jl: Possible to store solution in-place of initial guess?

The standard workfllow to access the solution of a nonlinear_eq = NonlinearProblem is something like

sol = SciMLBase.solve(nonlinear_eq, NewtonRaphson(autodiff = AutoFiniteDiff()));

Is it possible to suppress the build-up of the sol object and have the solution written directly to the initial guess which is supplied in construction of the NonlinearProblem?

alias_u0 = true, though we’re rolling out a whole aliasing system to simplify this, so that will be deprecated very soon for just a more comprehensive verbose

CC @jClugstor

1 Like

Thanks!

I was also wondering if there is a way to pre-allocate the du for in-place functions f!(du, u, p)

I am calling the nonlinear solver from a hot loop, and would like to cut down allocations as far as possible.

How big is your system? If it’s small, use static arrays and they all stack allocate with SimpleNonlinearSolve. If it’s big then these ones don’t matter: the Jacobian is O(n^2) vs these O(n). The general way to do the big ones would be to use the cache = init(prob) interface, though I’m cleaning that up a bit in order to get it documented so that might need to wait till over the weekend to have a fully non-allocating form.

So eventually I would like to go to millions of unknowns, as I am trying to build a special IMEX-multirate integration scheme for Trixi.jl

Thanks, good to know! I was wondering how to go about this, since NonlinearProblem itself is immutable - which leads to me currently re-initializing it all the time despite only parameter and initial guess changes.

I put a reminder to respnnd here next week, hopefully i get this done and will post

1 Like