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:
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.