Product of discrete solutions on different meshes

I was trying to do the inner product of two discrete functions on different meshes. Both are VectorElement(‘RT’,mesh_fine.ufl_cell(),1). I tried to project the RT solution on a fine mesh to a coarse mesh, but failed. I want to solve

from fenics import *

mesh_fine = UnitSquareMesh(20, 20)
mesh_coarse = UnitSquareMesh(3, 3)

tf = Expression(((“pi*sin(2*pi*x[0])*sin(2*pi*x[1])”, “2*pi*sin(pi*x[0])*sin(pi*x[0])*cos(2*pi*x[1])”), ("-2*pi*cos(2*pi*x[0])*sin(pi*x[1])*sin(pi*x[1])", “-pi*sin(2*pi*x[0])*sin(2*pi*x[1])”)),degree=6)

RT = VectorElement(‘RT’,mesh_fine.ufl_cell(),1)
R = FiniteElement(“R”, mesh_fine.ufl_cell(), 0)
elem = MixedElement(RT,R)
Q1 = FunctionSpace(mesh_coarse, elem)

w = Function(Q1)
s0, c0 = TrialFunctions(Q1)
t0, d0 = TestFunctions(Q1)

a1 = inner(div(s0),div(t0))*dx + inner(s0,t0)*dx + tr(s0)d0dx + tr(t0)c0dx
b1 = inner(tf,t0)*dx

solve(a1 == b1,w)
s, c = split(w)

RTc = VectorElement(‘RT’,mesh_coarse.ufl_cell(),1)
Q1c = FunctionSpace(mesh_coarse, RTc)
s_coarse = Function(Q1c)
s0_coarse = TrialFunction(Q1c)
t0_coarse = TestFunction(Q1c)
ac = inner(div(s0_coarse),div(t0_coarse))*dx + inner(s0_coarse,t0_coarse)*dx
bc = inner(s,t0_coarse)*dx
solve(ac == bc,s_coarse)

Are you sure you want a VectorElement here? A FiniteElement of type RT is already vector valued, so the VectorElement here is going to be making an element with 3 vector values at each point.

If this is what you intended and you still have errors, could you reduce the length of your code to make a minimal example that produces the error and post the error message so we can more easily see what if going wrong.

Thank you for your help. I just reduce the code to make a minimal example. The element I want to use is a matrix, and each row of the matrix is the RT element.

I’m more familiar with dolfinx than dolfin: in dolfinx VectorElements of spaces other than CG or DG are not tested, so I’d not be confident that the work. I guess similar is true in dolfin.

MixedElements are more thoroughly tested. Could you try replacing your VectorElement with:

rt_1d = FiniteElement("RT", mesh_fine.ufl_cell(), 1)
RT = MixedElement(rt_1d, rt_1d)

This is almost equivalent to the VectorElement but has more chance of working.