Unable to define linear variational problem a(u, v) = L(v) for all v

Here is my minimal code:
mesh = Mesh(‘mesh.xml’)# a square mesh

ele_d = FiniteElement(“DG”, mesh.ufl_cell(), 0)
ele_h = FiniteElement(“BDM”, mesh.ufl_cell(), 1)
ele_u = VectorElement(“CG”, mesh.ufl_cell(), 1)
W = MixedElement([ele_d, ele_h, ele_u])
W = FunctionSpace(mesh, W)

(d,h,u)= TrialFunctions(W)
(q,k,v) = TestFunctions(W)

Xold = Function(W)
(dold,hold,uold)= Xold.split()
Xnew = Function(W)
(dnew,hnew,unew)= Xnew.split()

def sigma(u):
return 2.0muepsilon(u)+lmbda*tr(epsilon(u))*Identity(len(u))

class LeftBoundary(SubDomain):
def inside(self, x, on_boundary):
return near(x[0],-0.5) and
left_boundary = LeftBoundary()

class RightBoundary(SubDomain):
def inside(self, x, on_boundary):
return near(x[0],0.5)
right_boundary = RightBoundary()

class BottomBoundary(SubDomain):
def inside(self, x, on_boundary):
return near(x[1],-0.5)
bottom_boundary = BottomBoundary()

class TopBoundary(SubDomain):
def inside(self, x, on_boundary):
return near(x[1],0.5)
top_boundary = TopBoundary()

boundary_edge_function = MeshFunction(‘size_t’, mesh, 1)
boundary_edge_function.set_all(0)
left_boundary.mark(boundary_edge_function,1)
right_boundary.mark(boundary_edge_function,2)
bottom_boundary.mark(boundary_edge_function,3)
top_boundary.mark(boundary_edge_function,4)

ubctop = DirichletBC(W.sub(2), Constant((0.0,0.0)), boundary_edge_function, 4)
ubcbot = DirichletBC(W.sub(2), Constant((0.0,0.0)), boundary_edge_function, 3)
ubcleft = DirichletBC(W.sub(2), Constant((0.0,0.0)), boundary_edge_function, 1)
ubcright = DirichletBC(W.sub(2), Constant((0.0,0.0)), boundary_edge_function, 2)

bc_u = [ubctop, ubcbot,ubcleft,ubcright]

E_u = inner(sigma(u),grad(v))*dx

p_u = LinearVariationalProblem(lhs(E_u), rhs(E_u), unew, bc_u)

solver_u = LinearVariationalSolver(p_u)

conc_u = File ("./mixed0608/u.pvd")

while t<=150.0 :
t += deltaT
iter = 0
err = 1

while err > tol:
    iter += 1
    solver_u.solve()
 
    err_disp = errornorm(unew,uold,norm_type = 'l2',mesh = None)
          
    uold.assign(unew)    

    if err_disp < tol:
        print ('Iterations:', iter, ', Total time', t)

        if round(t*1e4) % 10 == 0:
            conc_u << unew
           print ('Simulation completed') 

produced the following error:
Error: Unable to define linear variational problem a(u, v) = L(v) for all v.
*** Reason: Expecting the solution variable u to be a member of the trial space.
*** Where: This error was encountered inside LinearVariationalProblem.cpp.
*** Process: 0
I shortened the exception a bit to make it more readable. Thank you for taking the time to help me out!

The direct cause of this error is that unew is just one component of a Function from a mixed FunctionSpace. Presumably, your end goal is to simultaneously solve for all components of Xnew, so you would pass Xnew to the LinearVariationalProblem constructor instead of unew. Of course the given residual does not involve the other solution components, so the problem would be singular if only that modification were made, but I assume the code is simplified from some more complete application.

The mixed FunctionSpace includes three variables.I want to solve them in the staggered scheme not simultaneously.So I want to pass unew to the LinearVariationalProblem constructor instead of Xnew.I do not know why u is not a member of the trial space.

Then you should not use mixed spaces. You should set up each scheme with a separate function space and corresponding trial and test functions.

Why can three variables be solved simultaneously with one variational equation in the use of mixed element?

Because then the corresponding matrix and vector will contain the degrees of freedom for each of the elements in the mixed function space, as @kamensky said.
If you first want to solve for u (in CG-1), define the function space for CG and set up the corresponding variational form. Once you have the solution (let’s call it uh) it can be inserted in either the left or right hand side of a variational formulation for the next problem.

I’ve learned.Thank you for your patience.