Nonlinear PDE + scalar constraint with PETSc?

Hello,

I would like to solve a nonlinear PDE together with an additional scalar constraint (involving some integral of the PDE solution).

I have a working serial code, where I assemble a block matrix and use a “hand-coded” Newton method (iteratively solving the linearized problem with something like x=A^-1*rhs).
Now I would like to go parallel. I see two methods and, in case both are possible, I am wondering which one would be easier and/or more efficient:

  1. use a “hand-coded” Newton method (with iterations of the linear solver KSPSolve, somewhat similar to the constrained but linear example in laplace-lagrange-PETSc.edp),
  2. use directly the nonlinear solver SNESSolve (similar to the nonlinear but non-constrained example in navier-stokes-2d-PETSc.edp).

Is method 1 much worse than method 2?

For method 2, I have some trouble defining the arguments to be given to SNESSolve (the equivalent of J, funcJ and funcRes in navier-stokes-2d-PETSc.edp). Specifically, how should one properly resize, change numbering, and assemble/extract the blocks?
Is there by chance a working example somewhere?

Thank you in advance for your help!

Hi there! Check out this thread.