Vector assembly that changes over time

Hi everyone,

I have the following weak formulation:

ax = dot((Xh / k),phi)*dx + vare*inner(grad(Xh),grad(phi))*dx

Lx = inner((Xh0 / k),phi)*dx + inner(kp*u10*n_oriented,phi)*dx +  inner(lamb*n_oriented,phi)*dx

The value of lamb is uniform over the domain but changes over time. I am defining the matrices, vector and solver like this

bilinear_form = form(ax)
linear_form = form(Lx)

Ax = assemble_matrix(bilinear_form)
Ax.assemble()
b = create_vector(linear_form)
assemble_vector(b, linear_form)

b.ghostUpdate(addv=PETSc.InsertMode.ADD_VALUES,
            mode=PETSc.ScatterMode.REVERSE)

solverx = PETSc.KSP().create(mesh.comm)
solverx.setOperators(Ax)
solverx.setType(PETSc.KSP.Type.PREONLY)
solverx.getPC().setType(PETSc.PC.Type.LU)

I tried putting the line assemble_vector(b, linear_form) inside the for loop, but it wasn’t successful.

How can I implement this?

Thank you.

Is lamb defined as a fem.Constant ? If so this should work, I would try to use the built-in fem.petsc.LinearProblem as a starting point