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

MixedFunctionSpace in 2016.2.0

+6 votes

Hi,

I am relatively new to FEniCs.
I changed to the new version 2016.2.0, but now my program does not work anymore.
The problem is the following formulation:

V = VectorFunctionSpace(mesh, 'CG', 1)
F = FunctionSpace(mesh, 'CG', 1)
MS = MixedFunctionSpace([V, V, F, F])

My question is:
Is there another formulation to use a mixed function space?

Or is it possible to change back to an older FEniCS version?
I unfortunately did not find a way to do this.

Here is a part of the code:

from ufl import *
from ufl.classes import *
from mshr import *
import numpy as np
from dolfin import *
disc = Cylinder(Point(np.array([0.0,0.0,0.0])), Point(np.array([0.0, 0.0, 1.0])), 10.0, 10.0)
mesh = generate_mesh (disc, 30)
V = VectorFunctionSpace(mesh, 'CG', 1)
F = FunctionSpace(mesh, 'CG', 1)
MS = MixedFunctionSpace([V, V, F, F])

Thanks in advance

asked Dec 18, 2016 by alice FEniCS Novice (260 points)

3 Answers

+9 votes

MixedFunctionSpace has been deprecated since 2016.2.0. Now, you can create mixed function spaces as follows (the example below is copy-pasted from the documented 'demo_stokes-taylor-hood.py'):

from dolfin import *
mesh = UnitSquareMesh(4,4)

P2 = VectorElement("Lagrange", mesh.ufl_cell(), 2)
P1 = FiniteElement("Lagrange", mesh.ufl_cell(), 1)

# Make a mixed space
TH = P2 * P1
W = FunctionSpace(mesh, TH)
answered Dec 20, 2016 by jmmal FEniCS User (5,890 points)
+6 votes

Update: Using the " * " operator for more than two FunctionSpaces is still not working!
If you want to determine a mixed space with more than 2 single FunctionSpaces like:

V = VectorFunctionSpace(mesh, 'CG', 1)
F = FunctionSpace(mesh, 'CG', 1)
MS = MixedFunctionSpace([V, V, F, F])

you can do it via MixedElement which luckily is not deprecated so far:

p = 1
V_ele = VectorElement("CG", mesh.ufl_cell(), p) # probably one needs to set dim=3?
f_ele = FiniteElement("CG", mesh.ufl_cell(), p)
MS = df.FunctionSpace(mesh, MixedElement([V_ele, V_ele,
                                          F_ele, F_ele]))
answered Jan 12, 2017 by RR FEniCS User (3,330 points)
+1 vote

Thank you very much. That solved the problem

answered Jan 13, 2017 by alice FEniCS Novice (260 points)
...