Setting goal functional for MixedElement

How can I specify a goal functional defined on MixedElement function space?

I have something like:

Pu = dolf.FiniteElement("Lagrange", mesh.ufl_cell(), 2)

Pp = dolf.FiniteElement("Lagrange", mesh.ufl_cell(), 2)

P_mixed = dolf.MixedElement([Pu, Pp])

W = dolf.FunctionSpace(mesh, P_mixed)

When I use

w = dolf.Function(W)

dolf.solve(a == L, w, bcs)

everything works fine.

Now I want to specify my goal functional to use it later with AdaptiveLinearVariationalSolver, which is an ‘inner product’ of the components of the P_mixed, namely u**2+p**2 where u and p are from Pu and Pp.

If I do something like M = inner(w,w)*dx(), or with W.sub(0) to define Function to input into M, I get:

*** Error: Unable to assemble form.

*** Reason: Invalid value rank for coefficient 0 (got 1 but expecting 0). You might have forgotten to specify the value rank correctly in an Expression subclass.

*** Where: This error was encountered inside AssemblerBase.cpp.

*** Process: 0

I can see that the problem is in how I create the M matrix, because otherwise everything works fine.

The code I have can be found here: