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

Working with sub-spaces of a mixed function space for mixed FEM formulations

+3 votes

Hello

I have a multi-physics problem for which I am working with a mixed function space which combines 4 spaces. I create the space as follows:

V   = VectorFunctionSpace(mesh, "CG", 1, dim=2)
P   = FunctionSpace(mesh, "CG", 1, dim=1)
U  = VectorFunctionSpace(mesh, "R", 0, dim=2)
L   = VectorfunctionSpace(mesh, "R", 0, dim=2)

Then I find two syntaxes in FEniCS documentation for creating the space:

S = V * P * U * L

and

S = MixedFunctionSpace([V, P, U, L])

which one should be the better/more preferred alternative (if at all there is any such choice) ?

Additionally, now when I want to extract the sub-spaces and define the forms for the variational problem, are the following two syntaxes equivalent ?

s = Function(S)
(w,q,up,lp) = (as_vector(s[0],s[1]),s[2],as_vector(s[3],s[4]),as_vector(s[5],s[6])

and

(w,q,up,lp) = TrialFunctions(S)

Similarly, for the solver-variable, I was wondering whether the instantiation should be done as s=Function(S) and then use s.split() to extract the data.

These may sound like simple questions, however (and especially since I am a beginner in FEniCS), it will really be of great help if I can get some clarifications on these.

Thanks.

asked Sep 23, 2014 by debmukh FEniCS Novice (880 points)
edited Sep 26, 2014 by debmukh

Looking further into the matter, I think I already have the answer to the first question above, and I would like to edit my post here with the same. I believe the syntax:

S = V * P

can be used to create mixed function spaces from two function sub-spaces. On the other hand, the syntax:

S = MixedFunctionSpace([V, P, U, L])

will allow for creation of mixed spaces from multiple (more than 2) function sub-spaces.
Is there anything else I have missed ?

That's actually an issue if you ask me:

mesh = UnitSquareMesh(10, 10)
A = FunctionSpace(mesh, "CG", 2)
B = FunctionSpace(mesh, "DG", 2)
C = FunctionSpace(mesh, "N1curl", 2)
V = A * B * C

works like a charm (i.e. doesn't even throw a warning) but

>>> V.sub(0)
<dolfin.functions.functionspace.FunctionSpaceBase; proxy of <Swig Object of type 'std::shared_ptr< dolfin::FunctionSpace > *' at 0x7eff0184aba0> >
>>> V.sub(1)
<dolfin.functions.functionspace.FunctionSpaceBase; proxy of <Swig Object of type 'std::shared_ptr< dolfin::FunctionSpace > *' at 0x7eff01859d80> >
>>> V.sub(2)
Traceback (most recent call last):
File "", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/dolfin/functions/functionspace.py", line 224, in sub
(self.num_sub_spaces() - 1))
ValueError: Can only extract SubSpaces with i = 0 ... 1

produces an error which is hard to understand (especially for beginners) if you didn't get a warning in the first place.

However

>>> W = MixedFunctionSpace([A, B, C])
>>> W.sub(0)
<dolfin.functions.functionspace.FunctionSpaceBase; proxy of <Swig Object of type 'std::shared_ptr< dolfin::FunctionSpace > *' at 0x7eff0184aba0> >
>>> W.sub(1)
<dolfin.functions.functionspace.FunctionSpaceBase; proxy of <Swig Object of type 'std::shared_ptr< dolfin::FunctionSpace > *' at 0x7eff01859690> >
>>> W.sub(2)
<dolfin.functions.functionspace.FunctionSpaceBase; proxy of <Swig Object of type 'std::shared_ptr< dolfin::FunctionSpace > *' at 0x7eff0184aba0> >

behaves as expected, so kudos debmukh!

...