To use an existing finite element function (like a previous solution in an iterative solver) within a BilinearForm or LinearForm, you must interpolate it from the nodes to the quadrature points using basis.interpolate(x).
Inside the form definition, the third argument w (for BilinearForm) or the single argument w (for LinearForm) is a dictionary containing user-provided arguments. You can access these via w.key or w['key']. By default, w.x provides global coordinates and w.h provides the local mesh parameter.
When calling .assemble(), pass the interpolated function as a keyword argument.
import skfem as fem
from skfem.helpers import grad, dot
# 1. Define the form using a keyword argument 'u_k' from the 'w' dictionary
@fem.BilinearForm
def bilinf(u, v, w):
return (w.u_k + .1) * dot(grad(u), grad(v))
# 2. Prepare the mesh and basis
m = fem.MeshTri().refined(3)
basis = fem.Basis(m, fem.ElementTriP1())
# 3. Assume 'x' is your current solution vector
x = 0. * basis.x
# 4. Interpolate 'x' and pass it to assemble
A = bilinf.assemble(basis, u_k=basis.interpolate(x))