Suppose that I need to compute a variation of the usual finite element method for the Poisson equation using Lagrange elements of degree one:
Find $u_h\in V_h$ such that
$$(\nabla u_h, \nabla v) = (f, I_h v), \forall v\in V_h,$$
where the unusual aspect is that instead of $(f, v)$ on the right hand side we have $(f, I_h v)$, where $I_h$ is the interpolant into the space of piecewise constants.
How could I implement this in Dolfin? The obvious code snippet
mesh = UnitSquareMesh(4, 4)
Vh = FunctionSpace(mesh, "Lagrange", 1)
Wh = FunctionSpace(mesh, "DG", 0)
f = Expression('x[0]')
uh = TrialFunction(Vh)
vh = TestFunction(Vh)
a = inner(grad(uh), grad(vh)) * dx
b = f * interpolate(vh, Wh) * dx
is not allowed, since one cannot apply interpolate to a test function. Is there another way?
BTW, this is not our real application, but rather a simplification, but interpolation on the test function does arise in real applications.