 Problem when setting DirichletBC for subspace in mixed formulation with ufl function

Hello,
I use version 2019.01 on Ubuntu. When I try to set a DirichletBC with a ufl function for a subspace of a mixed function space, I get an error, see below. This does not happen when I use an Expression or when setting the DirichletBC like this for a complete function space (without the sub(0)).

Is there a way to fix this?

from dolfin import *

mesh = UnitSquareMesh(10,10)

x = SpatialCoordinate(mesh)

V_ele = VectorElement('CG', mesh.ufl_cell(), 2)
Q_ele = FiniteElement('CG', mesh.ufl_cell(), 1)
W = FunctionSpace(mesh, V_ele*Q_ele)

u_exact = as_vector([sin(4*pi*x)*cos(4*pi*x), -cos(4*pi*x)*sin(4*pi*x)])
u_exact_expr = Expression(('sin(4*pi*x)*cos(4*pi*x)','-cos(4*pi*x)*sin(4*pi*x)'), degree = 3)

f = as_vector([28*pi*pi*sin(4*pi*x)*cos(4*pi*x), -36*pi*pi*cos(4*pi*x)*sin(4*pi*x)])

(u, p) = TrialFunctions(W)
(v, q) = TestFunctions(W)

a = inner(grad(u), grad(v))*dx - p*div(v)*dx + q*div(u)*dx
A = assemble(a)

L = inner(f, v)*dx
b = assemble(L)

bc = DirichletBC(W.sub(0), u_exact, 'on_boundary')
bc.apply(A, b)

Error message:

Traceback (most recent call last):
File “Fenics_test.py”, line 25, in
bc = DirichletBC(W.sub(0), u_exact, ‘on_boundary’)
File “/usr/lib/python3/dist-packages/dolfin/fem/dirichletbc.py”, line 76, in init
expr = project(args, args, solver_type = ‘mumps’) # FIXME: This should really be interpolaton (project is expensive)
File “/usr/lib/python3/dist-packages/dolfin/fem/projection.py”, line 137, in project
function = Function(V)
File “/usr/lib/python3/dist-packages/dolfin/function/function.py”, line 216, in init
self._cpp_object = cpp.function.Function(V._cpp_object)
RuntimeError:

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at

*** Remember to include the error message listed below and, if possible,
*** include a minimal running example to reproduce the error.

*** -------------------------------------------------------------------------
*** Error: Unable to create function.
*** Reason: Cannot be created from subspace. Consider collapsing the function space.
*** Where: This error was encountered inside Function.cpp.
*** Process: 0

*** DOLFIN version: 2019.1.0
*** Git changeset: unknown
*** -------------------------------------------------------------------------

Interpolate or project u_exact to a FunctionSpace of your choosing. Evaluation of ufl expressions in dolfin expressions is not supported as far as I’m aware.

Thanks for the answer, I was just irritated, since a construction like below works, but it does not on a mixed function space.

from dolfin import *

mesh = UnitSquareMesh(10,10)
x = SpatialCoordinate(mesh)

V_ele = VectorElement('CG', mesh.ufl_cell(), 2)
W = FunctionSpace(mesh, V_ele)

u_exact = as_vector([sin(4*pi*x)*cos(4*pi*x), -cos(4*pi*x)*sin(4*pi*x)])

u = TrialFunction(W)
v = TestFunction(W)