Callbacks on Newton solver

I just wanted to add that, to me, it feels wrong to define res and Dres globally and then use those global variables in the CustomNonlinearProblem class.
Just for - in my opinion - cleaner code I would set the linear and bilinear forms as attributes supplied to the __init__ method as done here:

For this kind of reply I would really like to have something like a comment function as known from stackoverflow…