Combining test and trial function from different spaces

Hello everybody,

i have a problem where i want to combine test and trial functions from different spaces at the end. Is this somehow possible in fenics?

Thanks!

This is common in mixed problems, and can be done. However, if you mix the trial and test functions for your global system, you end up with a non-square (rectangular) matrix, that will not be invertible.

Thank you dokken.
Does this mean that i have to use a semi-implicit method to solve the discrete equation or should i use the pseudoinvers? What are you suggesting please?

I am sorry dokken. How is it possible please?
I am just getting the error

Did you combine test or trial functions from different spaces?
The Arguments found are:
  v_1
  v_1
  v_0
  v_0

You can for instance do:

from dolfin import *
mesh = UnitSquareMesh(10, 10)
V1 = FiniteElement("Lagrange", triangle, 1)
V2 = FiniteElement("Lagrange", triangle, 1)
el = MixedElement([V1, V2])

V = FunctionSpace(mesh, el)
u1,u2 = TrialFunctions(V)
v1,v2 = TestFunctions(V)

a = inner(u1, v2) * dx
assemble(a)

However, this is assembled into a rectangular matrix.

The following minimal example shows how to assemble with different test and trial functions:

from dolfin import *
mesh = UnitSquareMesh(10, 10)
V1 = FunctionSpace(mesh, "CG", 1)
V2 = FunctionSpace(mesh, "CG", 2)

u = TrialFunction(V1)
v = TestFunction(V2)
A = assemble(inner(u,v)*dx)
A_petsc = as_backend_type(A)                                                                                                                                             

A_dense =  A_petsc.mat()[:,:]  
print(A_dense.shape)

Thank you very much again dokken!
You are so great!