Problem using Raviart Thomas Elements

Hi, I’m new with fenics, working with version 2019.1.0
I encountered a problem while using Raviart-Thomas Finite Elements. Here is my code :

    from __future__ import print_function
    from fenics import *
    from mshr import *

    domain = Rectangle(Point(-0.05,-0.05),Point(0.10,0.10))
    mesh = generate_mesh(domain,30)

    P2 = VectorElement('RT', mesh.ufl_cell(), 3)
    P1 = FiniteElement('RT', mesh.ufl_cell(), 3)
    element = MixedElement([P2, P1])
    V = FunctionSpace(mesh, element)

    class InitialConditions(UserExpression):
        def eval(self, values, x):
            values[0] = 0
            values[1] = 0
            values[2] =0.2*exp(-pow(x[0],2)-pow(x[1],2))
        def value_shape(self):
            return (3,)
        
    w0 = InitialConditions(V.ufl_element())

    wn = interpolate(w0, V)
    un, hn = split(wn)

And the error message i get :

>>> runfile('/home/chrx/shallow_water.py', wdir='/home/chrx')
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
    execfile(filename, namespace)
  File "/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 88, in execfile
    exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
  File "/home/chrx/shallow_water.py", line 41, in 
    wn = interpolate(w0, V)
  File "/usr/lib/python3/dist-packages/dolfin/fem/interpolation.py", line 71, in interpolate
    Pv.interpolate(v._cpp_object)
  File "/usr/lib/python3/dist-packages/dolfin/function/function.py", line 365, in interpolate
    self._cpp_object.interpolate(u)
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
***
***     fenics-support@googlegroups.com
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error:   Unable to interpolate function into function space.
*** Reason:  Dimension 0 of function (3) does not match dimension 0 of function space (6).
*** Where:   This error was encountered inside FunctionSpace.cpp.
*** Process: 0
*** 
*** DOLFIN version: 2019.1.0
*** Git changeset:  unknown
*** -------------------------------------------------------------------------

Obviously, the error concerns the definition of the initial condition but I can’t figure out what is the problem since it was perfectly working when I was using Lagrange Elements.

I also tried defining the initial condition other way like for exemple :

    w0 = Expression(('(0,0)','0.2*exp(-pow(x[0],2)-pow(x[1],2))'), V.ufl_element())

so as to respect the function space dimensions, but it didn’t work either.

Could someone help me with this issue ?

Since you are working with a Mixed space, you Need to interpolate into either
a) the full space
B) the sub space and use FunctionAssigner. See: