'<' not supported between instances of 'Mesh' and 'Mesh' Error

I tried following code .

 def vel( w1, w2):
    class PeriodicBoundary(SubDomain):
        def inside(self, x, on_boundary):
            return bool( x[0] <DOLFIN_EPS or x[0] > -DOLFIN_EPS and on_boundary)

        def map(self, x, y):
            y[0] = x[0] - 5120.0
            y[1] = x[1]

       # pbc =  PeriodicBoundary()
        
    # Create mesh and define the function space
    mesh1 = RectangleMesh(Point(0, 0),Point(5120, 6400), nx, ny)
    V1 = FunctionSpace(mesh1, "CG", 1, constrained_domain=PeriodicBoundary()  )
    dof_coordinates = V.tabulate_dof_coordinates()

    # Define Boundary Condition
    pbc =  PeriodicBoundary()

    # Define variational problem
    u1 = TrialFunction(V1)
    v1 = TestFunction(V1)
    f  = - div ( K(w1, w2))
    a = dot(grad(u1), grad(v1))*dx
    L = f*v1*dx

    # Compute solution
    u1 = Function(V)
    solve(a == L, u1 , pbc)

    return(u1)

The definition of the function K(w1, w2) is:

#Define function
def K(u_1, u_2):
    return( (L*(P(u_1)-P_c)+L*(Q(u_1)-Q_c)+(F_s-F_c))/M_s(u_2))

The following error occurred.

File "AN.py", line 128, in vel
    L = f*v1*dx
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/measure.py", line 437, in __rmul__
    domains = extract_domains(integrand)
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/domain.py", line 355, in extract_domains
    return sorted(join_domains(domainlist))
TypeError: '<' not supported between instances of 'Mesh' and 'Mesh'

How do I remove this error?

We can’t debug your code if you don’t provide a MWE. See here.

It’s likely that w1 and w2 belong to a different mesh.

# Create mesh and define function space
nx = ny = 256
mesh = RectangleMesh( Point(0, 0), Point(5120, 6400), nx, ny)

# Define function space for velocity
W = VectorFunctionSpace(mesh, 'P', 2)

#Define function space for system of equations

P1 = FiniteElement('P', triangle, 1)
element = MixedElement( [P1, P1] )
V = FunctionSpace ( mesh, element)

# Define test functions
v_1, v_2= TestFunctions(V)

# Define functions for velocity and PDE
w = Function(W)
u = Function(V)
u_n = Function(V)

# Split system functions to access components
u_1, u_2 = split(u)
u_n1, u_n2 = split(u_n)

#Define source terms
f_1 = Constant (0.14)
f_2 = Constant (0.0)

# Define expressions used in variational forms
k = Constant(dt)
M1 = Constant(M1)
D = Constant(D)
alpha_c = Constant(alpha_c)
q_s = Constant(q_s)
q_c = Constant(q_c)
M_s0 = Constant(M_s0)
Gamma = Constant(Gamma)
M2 = Constant(M2)

# Define re-evaporation function
from ufl.operators import min_value
def Re(u_1, u_2):
    return ((alpha_c/2)*u_2* (1-(min_value(u_1, q_s)/q_s)))

#Define Latent heat source
from ufl.algebra import Sum
def P(a):
    return ( alpha*(a-q_c) * H(a - q_c) )

#Define vapor to condensate conversion function
def Q(u_1):
    return(2*alpha* (u_1-q_s) * H(u_1 -q_s))

#Define function
def K(u_1, u_2):
    return( (L*(P(u_1)-P_c)+L*(Q(u_1)-Q_c)+(F_s-F_c))/M_s(u_2))

def M_s(u_2):
    return( M_s0 + Gamma * u_2)

#Define function of large scale precipitation
from ufl.operators import min_value
def P_(u_1, u_2):
    return ( (alpha_c/2) * u_2 * (min_value(u_1 , q_s) / q_s))
    



# Define Heaviside function H
#from ufl.conditional import conditional
def H(x):
    c = conditional(gt(x, 0), 1, 0)
    return(c)

# Define variational problem
F =  - M1 * dot(grad( vel(u_1, u_2)), grad( u_1))*v_1* dx \
    - M2 * dot(grad( vel(u_1, u_2)), grad( u_2))*v_2* dx

This is the actual code, and I defined a function vel(u_1, u_2) as follows:

# Finding the wind variable v1
def vel( w1, w2):
    class PeriodicBoundary(SubDomain):
        def inside(self, x, on_boundary):
            return bool( x[0] <DOLFIN_EPS or x[0] > -DOLFIN_EPS and on_boundary)

        def map(self, x, y):
            y[0] = x[0] - 5120.0
            y[1] = x[1]

       # pbc =  PeriodicBoundary()
        
    # Create mesh and define the function space
    mesh1 = RectangleMesh(Point(0, 0),Point(5120, 6400), nx, ny)
    V1 = FunctionSpace(mesh1, "CG", 1, constrained_domain=PeriodicBoundary()  )
    dof_coordinates = V.tabulate_dof_coordinates()

    # Define Boundary Condition
    pbc =  PeriodicBoundary()

    # Define variational problem
    u1 = TrialFunction(V1)
    v1 = TestFunction(V1)
    f  = - div ( K(w1, w2))
    a = dot(grad(u1), grad(v1))*dx
    L = f*v1*dx

    # Compute solution
    u1 = Function(V)
    solve(a == L, u1 , pbc)

    return(u1) 

Here I solved How to define the periodic and Neumann boundary condition?

The following error occurred here:

 File "AN.py", line 128, in vel
    L = f*v1*dx
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/measure.py", line 437, in __rmul__
    domains = extract_domains(integrand)
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/domain.py", line 355, in extract_domains
    return sorted(join_domains(domainlist))
TypeError: '<' not supported between instances of 'Mesh' and 'Mesh'

Could you please let me know my mistake here?

You’re using functions defined on two separate meshes, mesh and mesh1, in the same form. Consider using only one mesh, as per your requirements.

The following error occurred.

RuntimeError: solve variational problem. Unable to extract boundary condition arguments

As @nate said, you have to produce a minimal code example that reproduces the error

@dokken I want to solve one term by Poisson equation with Neumann and periodic boundary conditions are given. My code is not working for the vel function that mentioned in the variational problem of first code.

Here is the minimal example:

from __future__ import print_function
from fenics import *
from dolfin import *

# Create mesh and define function space
nx = ny = 256
mesh = RectangleMesh( Point(0, 0), Point(5120, 6400), nx, ny)

# Define function space for velocity
W = VectorFunctionSpace(mesh, 'P', 2)

#Define function space for system of equations

P1 = FiniteElement('P', triangle, 1)
element = MixedElement( [P1, P1] )
V = FunctionSpace ( mesh, element)

# Define test functions
v_1, v_2= TestFunctions(V)

# Define functions for velocity and PDE
w = Function(W)
u = Function(V)
u_n = Function(V)

# Split system functions to access components
u_1, u_2 = split(u)
u_n1, u_n2 = split(u_n)

#Define source terms
f_1 = Constant (0.14)
f_2 = Constant (0.0)

#Define function
def K(u_1, u_2):
return( (L*(P(u_1)-P_c)+L*(Q(u_1)-Q_c)+(F_s-F_c))/M_s(u_2))
# Define variational problem
F = - M1 * dot(grad( vel(u_1, u_2)), grad( u_1))v_1 dx
- M2 * dot(grad( vel(u_1, u_2)), grad( u_2))v_2 dx

My code is not working for the function vel(u_1, u_2). In this function, I want to calculate
-\Delta u = - div (K(u_1, u_2) on [0,5120] \times [o,6400]
\frac{\partial u}{\partial n} = 0 on y =0 and y=6400
u(0,y)=u(5120, y).
The code for vel(u_1,u_2) is :

def vel( w1, w2):
    class PeriodicBoundary(SubDomain):
        def inside(self, x, on_boundary):
            return bool( x[0] <DOLFIN_EPS or x[0] > -DOLFIN_EPS and on_boundary)

        def map(self, x, y):
            y[0] = x[0] - 5120.0
            y[1] = x[1]

    V1 = FunctionSpace(mesh, "CG", 1, constrained_domain=PeriodicBoundary()  )
    dof_coordinates = V1.tabulate_dof_coordinates()
    # Define variational problem
    u1 = TrialFunction(V1)
    v1 = TestFunction(V1)
    f  = - div ( K(w1, w2))
    a = dot(grad(u1), grad(v1))*dx
    L = f*v1*dx

    # Compute solution
    u1 = Function(V1)
    solve(a == L, u1 )

    return(u1)

The following error occurred:

File "AN.py", line 124, in vel
    solve(a == L, u1 )
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/fem/solving.py", line 220, in solve
    _solve_varproblem(*args, **kwargs)
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/fem/solving.py", line 241, in _solve_varproblem
    problem = LinearVariationalProblem(eq.lhs, eq.rhs, u, bcs,
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/fem/problem.py", line 55, in __init__
    L = Form(L, form_compiler_parameters=form_compiler_parameters)
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/fem/form.py", line 43, in __init__
    ufc_form = ffc_jit(form, form_compiler_parameters=form_compiler_parameters,
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/jit/jit.py", line 47, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/jit/jit.py", line 97, in ffc_jit
    return ffc.jit(ufl_form, parameters=p)
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ffc/jitcompiler.py", line 217, in jit
    module = jit_build(ufl_object, module_name, parameters)
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ffc/jitcompiler.py", line 130, in jit_build
    module, signature = dijitso.jit(jitable=ufl_object,
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dijitso/jit.py", line 165, in jit
    header, source, dependencies = generate(jitable, name, signature, params["generator"])
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ffc/jitcompiler.py", line 65, in jit_generate
    code_h, code_c, dependent_ufl_objects = compile_object(ufl_object,
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ffc/compiler.py", line 142, in compile_form
    return compile_ufl_objects(forms, "form", object_names,
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ffc/compiler.py", line 185, in compile_ufl_objects
    analysis = analyze_ufl_objects(ufl_objects, kind, parameters)
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ffc/analysis.py", line 89, in analyze_ufl_objects
    form_datas = tuple(_analyze_form(form, parameters)
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ffc/analysis.py", line 89, in <genexpr>
    form_datas = tuple(_analyze_form(form, parameters)
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ffc/analysis.py", line 169, in _analyze_form
    form_data = compute_form_data(form,
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/algorithms/compute_form_data.py", line 264, in compute_form_data
    form = apply_algebra_lowering(form)
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/algorithms/apply_algebra_lowering.py", line 186, in apply_algebra_lowering
    return map_integrand_dags(LowerCompoundAlgebra(), expr)
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/algorithms/map_integrands.py", line 57, in map_integrand_dags
    return map_integrands(lambda expr: map_expr_dag(function, expr, compress),
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/algorithms/map_integrands.py", line 38, in map_integrands
    mapped_integrals = [map_integrands(function, itg, only_integral_type)
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/algorithms/map_integrands.py", line 38, in <listcomp>
    mapped_integrals = [map_integrands(function, itg, only_integral_type)
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/algorithms/map_integrands.py", line 46, in map_integrands
    return itg.reconstruct(function(itg.integrand()))
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/algorithms/map_integrands.py", line 57, in <lambda>
    return map_integrands(lambda expr: map_expr_dag(function, expr, compress),
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/corealg/map_dag.py", line 37, in map_expr_dag
    result, = map_expr_dags(function, [expression], compress=compress)
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/corealg/map_dag.py", line 86, in map_expr_dags
    r = handlers[v._ufl_typecode_](v, *[vcache[u] for u in v.ufl_operands])
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/algorithms/apply_algebra_lowering.py", line 152, in div
    return a[..., i].dx(i)
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/exproperators.py", line 449, in _getitem
    all_indices, slice_indices, repeated_indices = create_slice_indices(component, shape, self.ufl_free_indices)
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/index_combination_utils.py", line 181, in create_slice_indices
    error("Component and shape length don't match.")
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/log.py", line 172, in error
    raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Component and shape length don't match.

I am first time dealing with Neumann and periodic boundary condition. Can you suggest the possible correction in the code?

Please format all of the code appropriately.
Only parts of your code is properly formatted.
Also make the code runnable as one single code block.

@dokken I split this to explain my question. Can you made changes in the code below? I am not sure I understand the error. Sorry for this silly question.

from __future__ import print_function
from fenics import *
from dolfin import *

# Create mesh and define function space
nx = ny = 256
mesh = RectangleMesh( Point(0, 0), Point(5120, 6400), nx, ny)

# Define function space for velocity
W = VectorFunctionSpace(mesh, 'P', 2)

#Define function space for system of equations

P1 = FiniteElement('P', triangle, 1)
element = MixedElement( [P1, P1] )
V = FunctionSpace ( mesh, element)

# Define test functions
v_1, v_2= TestFunctions(V)

# Define functions for velocity and PDE
w = Function(W)
u = Function(V)
u_n = Function(V)


# Split system functions to access components
u_1, u_2 = split(u)
u_n1, u_n2 = split(u_n)

#Define source terms
f_1 = Constant (0.14)
f_2 = Constant (0.0)

# Define variational problem
F =  - M1 * dot(grad( vel(u_1, u_2)), grad( u_1))*v_1* dx \
    - M2 * dot(grad( vel(u_1, u_2)), grad( u_2))*v_2* dx

def vel( w1, w2):
    class PeriodicBoundary(SubDomain):
        def inside(self, x, on_boundary):
            return bool( x[0] <DOLFIN_EPS or x[0] > -DOLFIN_EPS and on_boundary)

        def map(self, x, y):
            y[0] = x[0] - 5120.0
            y[1] = x[1]

    V1 = FunctionSpace(mesh, "CG", 1, constrained_domain=PeriodicBoundary()  )
    dof_coordinates = V1.tabulate_dof_coordinates()
    # Define variational problem
    u1 = TrialFunction(V1)
    v1 = TestFunction(V1)
    f  = - div ( K(w1, w2))
    a = dot(grad(u1), grad(v1))*dx
    L = f*v1*dx

    # Compute solution
    u1 = Function(V1)
    solve(a == L, u1 )

    return(u1)

I am still getting the same error.
File “AN.py”, line 136, in
- f_1v_1dx - f_2v_2dx - M1 * dot(grad( vel(u_1, u_2)), grad( u_1))v_1 dx
File “AN.py”, line 123, in vel
solve(a == L, u1 )
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/fem/solving.py”, line 220, in solve
_solve_varproblem(*args, **kwargs)
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/fem/solving.py”, line 241, in _solve_varproblem
problem = LinearVariationalProblem(eq.lhs, eq.rhs, u, bcs,
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/fem/problem.py”, line 55, in init
L = Form(L, form_compiler_parameters=form_compiler_parameters)
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/fem/form.py”, line 43, in init
ufc_form = ffc_jit(form, form_compiler_parameters=form_compiler_parameters,
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/jit/jit.py”, line 47, in mpi_jit
return local_jit(*args, **kwargs)
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dolfin/jit/jit.py”, line 97, in ffc_jit
return ffc.jit(ufl_form, parameters=p)
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ffc/jitcompiler.py”, line 217, in jit
module = jit_build(ufl_object, module_name, parameters)
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ffc/jitcompiler.py”, line 130, in jit_build
module, signature = dijitso.jit(jitable=ufl_object,
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/dijitso/jit.py”, line 165, in jit
header, source, dependencies = generate(jitable, name, signature, params[“generator”])
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ffc/jitcompiler.py”, line 65, in jit_generate
code_h, code_c, dependent_ufl_objects = compile_object(ufl_object,
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ffc/compiler.py”, line 142, in compile_form
return compile_ufl_objects(forms, “form”, object_names,
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ffc/compiler.py”, line 185, in compile_ufl_objects
analysis = analyze_ufl_objects(ufl_objects, kind, parameters)
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ffc/analysis.py”, line 89, in analyze_ufl_objects
form_datas = tuple(_analyze_form(form, parameters)
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ffc/analysis.py”, line 89, in
form_datas = tuple(_analyze_form(form, parameters)
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ffc/analysis.py”, line 169, in _analyze_form
form_data = compute_form_data(form,
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/algorithms/compute_form_data.py”, line 264, in compute_form_data
form = apply_algebra_lowering(form)
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/algorithms/apply_algebra_lowering.py”, line 186, in apply_algebra_lowering
return map_integrand_dags(LowerCompoundAlgebra(), expr)
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/algorithms/map_integrands.py”, line 57, in map_integrand_dags
return map_integrands(lambda expr: map_expr_dag(function, expr, compress),
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/algorithms/map_integrands.py”, line 38, in map_integrands
mapped_integrals = [map_integrands(function, itg, only_integral_type)
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/algorithms/map_integrands.py”, line 38, in
mapped_integrals = [map_integrands(function, itg, only_integral_type)
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/algorithms/map_integrands.py”, line 46, in map_integrands
return itg.reconstruct(function(itg.integrand()))
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/algorithms/map_integrands.py”, line 57, in
return map_integrands(lambda expr: map_expr_dag(function, expr, compress),
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/corealg/map_dag.py”, line 37, in map_expr_dag
result, = map_expr_dags(function, [expression], compress=compress)
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/corealg/map_dag.py”, line 86, in map_expr_dags
r = handlers[v.ufl_typecode](v, *[vcache[u] for u in v.ufl_operands])
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/algorithms/apply_algebra_lowering.py”, line 152, in div
return a[…, i].dx(i)
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/exproperators.py”, line 449, in _getitem
all_indices, slice_indices, repeated_indices = create_slice_indices(component, shape, self.ufl_free_indices)
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/index_combination_utils.py”, line 181, in create_slice_indices
error(“Component and shape length don’t match.”)
File “/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/log.py”, line 172, in error
raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Component and shape length don’t match.

@dokken I observed that my source term is in the vector form here. So I cannot do the integration of vector form.

from __future__ import print_function
from fenics import *
from dolfin import *

# Create mesh and define function space
nx = ny = 256
mesh = RectangleMesh( Point(0, 0), Point(5120, 6400), nx, ny)

# Define function space for velocity
W = VectorFunctionSpace(mesh, 'P', 2)

#Define function space for system of equations

P1 = FiniteElement('P', triangle, 1)
element = MixedElement( [P1, P1] )
V = FunctionSpace ( mesh, element)
# Define variational problem
F =  - M1 * dot(grad( vel(u_1, u_2)), grad( u_1))*v_1* dx \
- M2 * dot(grad( vel(u_1, u_2)), grad( u_2))*v_2* dx



def vel( w1, w2):
    class PeriodicBoundary(SubDomain):
        def inside(self, x, on_boundary):
            return bool( x[0] <DOLFIN_EPS or x[0] > -DOLFIN_EPS and on_boundary)

        def map(self, x, y):
            y[0] = x[0] - 5120.0
            y[1] = x[1]
    #V1 = FunctionSpace(mesh, "CG", 1, constrained_domain=PeriodicBoundary()  )
    #dof_coordinates = V.tabulate_dof_coordinates()
    # Define variational problem
    #V1 = FunctionSpace(mesh, "P", 2)
    u1 = TrialFunction(V)
    v1 = TestFunction(V)
    f  = - div ( K(w1, w2))
    #a = dot(grad(u), grad(v))*dx
    
    F1 = PETScVector()
    a = assemble (inner(grad(u1), grad(v1))*dx, tensor =F1)
    L = f*v1*dx
    #L = dot(f,v1)*dx

    # Compute solution
    #u1 = Function(W)
    #solve(a == L, u1 )

    return(u1)

I tried to find its solution, but not able to resolve this issue.

The following is the error:

 L = f*v1*dx
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/measure.py", line 418, in __rmul__
    error("Can only integrate scalar expressions. The integrand is a "
  File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/log.py", line 172, in error
    raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Can only integrate scalar expressions. The integrand is a tensor expression with value shape (2,) and free indices with labels ().

Could you please suggest the possible solution to fix this issue?