The example at tests/unit/book/python/chapter_10.py
explains it: Incorporate it into the NonlinearProblem
by applying it to both the nonlinear residual and the Jacobian:
class MyNonlinearProblem(NonlinearProblem):
def __init__(self, L, a, bc):
NonlinearProblem.__init__(self)
self.L = L
self.a = a
self.bc = bc
def F(self, b, x):
assemble(self.L, tensor=b)
self.bc.apply(b, x)
def J(self, A, x):
assemble(self.a, tensor=A)
self.bc.apply(A)