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)