How to convert nonlinear operator in FEniCS to PETSc?

Hi all, I have a question on how to convert the FEniCS object to PETSc object for a non-linear operator since I need to implement my solver (SNES) by pure PETSc/PETSc4py.

If A is a linear matrix in FEniCS format, then A = A.mat() gives the pure PETSc object matrix.

Now if F is a nonlinear operator, like
F = inner((1 + u**2) * grad(u), grad(v)) * dx - f*v*dx
then how to convert this to a pure PETSc object? And how to apply the nonlinear operator to some vector F(u) by PETSc?

Thank you for any help

1 Like