I have been trying to write up a code for a mixed element problem and I encountered something I thought somewhat weird. I have something similar to the following simple code:
from dolfin import *
mesh = UnitSquareMesh(10,10)
P1 = FiniteElement('P', triangle, 1)
P2 = FiniteElement('R', triangle, 0)
P = P1*P2
V = FunctionSpace(mesh, P)
(u, c) = TrialFunction(V)
(v, d) = TestFunction(V)
f = Constant(1.0)
a = dot(grad(u), grad(v))*dx + c*v*ds + d*u*ds
L = f*v*dx
w = Function(V)
solve(a == L, w)
(w1, w0) = w.split()
w_ = project(w1,V.sub(0))
The final line produces the following error:
*** Error: Unable to create function.
*** Reason: Cannot be created from subspace. Consider collapsing the function space.
What does collapsing technically do? Why is it necessary? They appear to be the same space structurally(?)
print repr(V.sub(0))
print repr(V.sub(0).collapse())
====================================
FunctionSpace(Mesh(VectorElement(FiniteElement('Lagrange', triangle, 1), dim=2), 30), FiniteElement('Lagrange', triangle, 1))
FunctionSpace(Mesh(VectorElement(FiniteElement('Lagrange', triangle, 1), dim=2), 30), FiniteElement('Lagrange', triangle, 1))