# 2d-mini element-can't use sub(0),but bubble element is ok

My program (in Python, using FEniCS):

mesh=UnitSquareMesh(16,16)
U_h = VectorFunctionSpace(mesh, "Lagrange", 1)
B = VectorFunctionSpace(mesh, "Bubble", degree=3,dim=2)
Mini_h = U_h + B


Boundary definition (for example, u0_boundary and u1_boundary are part of square, respectively):

w0 = Constant("0.0")
bc0 = DirichletBC(Mini_h.sub(0), w0, u0_boundary) #error
bc1 = DirichletBC(Mini_h.sub(1), w0, u1_boundary)


I get: ValueError: Can only extract SubSpaces with i = 0 ... -1

Who can tell me why? Mini_h.sub(0) is the first component of Mini_h.

Actually, the problem is only for vector bubble element, everything is OK. For example:

B = VectorFunctionSpace(mesh, "Bubble", degree=3,dim=2)
bc0 = DirichletBC(B.sub(0), w0, u0_boundary)
bc1 = DirichletBC(B.sub(1), w0, u1_boundary)


In addition, I want to know why can not directly added to a mini finite element, rather than CG + Bubble.

• Mini_h.num_sub_spaces() returns 0 for your example, so the problem is probably in the construction of Mini_h. – Christian Clason May 22 '13 at 15:05

You can define the Mini element in this alternative manner if you want a mixed enriched element rather than an enriched mixed element:

U = FunctionSpace(mesh, "Lagrange", 1)
B = FunctionSpace(mesh, "Bubble", 3)
M = U + B
Mini_h = MixedFunctionSpace([M, M])


The vector part of the MINI element is not a mixed function space, which is why you cannot extract a subspace from it. The bubble is an enrichment (which is indicated by the '+' in your construction of Mini_h.

The distinction between mixed and enriched spaces is discussed in Section 2.3 of the UFL paper:

• Yes, but consider that one would appreciate associativity of * and + operation so that Mini_h.sub(0) == U_h.sub(0) + B.sub(0). Is there major design issue why it is not possible? – Jan Blechta May 22 '13 at 19:17
• Yes,you are right. U = FunctionSpace(mesh, "Lagrange", 1) B = FunctionSpace(mesh, "Bubble", 3) Q = FunctionSpace(mesh, "DG", 1) M = (U + B)*(U + B) Mixed_h = MixedFunctionSpace([M,Q]) – jiangliuer2013 May 27 '13 at 13:05

You have two options:

This problem have be solved,thanks everyone!

U = FunctionSpace(mesh, "Lagrange", 1)
B = FunctionSpace(mesh, "Bubble", 3)
Q = FunctionSpace(mesh, "DG", 1)
M = (U + B)*(U + B)
Mixed_h = MixedFunctionSpace([M,Q])


This time we can use Mixed_h.sub(0).sub(0).