Newton solver with Gridfunction as nonlinear term

Dear everyone,

I am working on a code that requires a nonlinear pde solve, where the nonlinearity is defined by a composition function that returns a Gridfunction. Trying the ngsolve Newton method the solve with the composition function was incorrect, which forced me to implement a slower own Newton solver.

Below is a code that displays the error we obtain when combining the composition with the ngsolve newton solver:

newton_compostion.ipynb (4.3 KB)

Is there an explanation or simple workaround for this issue?

Hi Kolja,

the issue is caused by compose_gridfunction(pi_gf, u) being evaluated while the form is constructed. Calling result.Set(...) creates a fixed GridFunction and removes its dependence on the trial function u. Consequently, Newton sees an essentially linear problem and reports convergence after one iteration.

For a one-dimensional tabulated nonlinearity, a simple workaround is to use the BSpline coefficient function. It remains part of the symbolic form, so the Newton solver can automatically assemble the chain-rule derivative.

I attached an updated notebook.

newton_composition_fixed.ipynb (7.9 KB)

Best,
Michael