This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Significance of collapsing?

+2 votes

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))
asked Dec 17, 2016 by bcsj FEniCS Novice (280 points)

1 Answer

+2 votes
 
Best answer

Hi, you should think about V.sub(0) as a view of that component of the function space. Collapsing the view the gives you a proper function space. The following shows the difference between the two

from dolfin import *

mesh = UnitSquareMesh(10,10)
P1 = FiniteElement('P', triangle, 1)
P = P1*P1
V = FunctionSpace(mesh, P)

try:
    view = V.sub(0)
    Function(view)
except RuntimeError: 
    print 'Using proper FunctionSpace'
    V1 = V.sub(0).collapse()
    Function(V1)

dim = V1.dim()
assert view.dim() == dim

# Illustrate that V.sub(0) is related to mixed function space by showing that
# some dofs (local) exceed dim
assert all(V1.dofmap().dofs() < dim)

print any(view.dofmap().dofs() > dim) 
answered Dec 17, 2016 by MiroK FEniCS Expert (80,920 points)
selected Dec 18, 2016 by bcsj

Thank you, I think that helped me understand better.

Just to really wrap my head around it...

Could I think of the view as a subspace of the original space (in the sense that it expresses everything in terms of the basis elements of the original space; that is, the basis elements have higher dimension than the space) and then collapsing as picking a proper basis for my subspace so it becomes its own self-contained space?

Hi, yes that sounds about right.

...