# Put function and mixed function together in a weak form

If it is correct to put function and mixed function together in a weak form?

I use Lagrange mixed element / mixed function for a weak form of a coupled model, where a function is also involved. I am not sure if it is correct as the DOF order of a mixed functionspace may differ from that of a functionspace. If not true, how can I modify it? In my following code, the aforementioned concern is represented by

``````tau1 = c1 * (ufl.grad(u) + ufl.grad(u).T) + c2 * ufl.grad(u) * tau
weak_form = (ufl.inner(u-un, v) + ufl.inner(tau1, ufl.grad(v)) + ufl.inner(p-pn, q)) * ufl.dx
``````

where `tau` is built on a functionspace, while other variables are from mixed functionspace.

Full MWE:

``````# Test to put function and mixed function together in a weak form
# DOLFINx version: 0.7.3

from mpi4py import MPI
from dolfinx import fem, mesh
import ufl

# Mesh
_mesh = mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)
ndims = _mesh.topology.dim

# Elements
V_order = 2
Q_order = 1
VE = ufl.FiniteElement("Lagrange", _mesh.ufl_cell(), V_order)          # dummy VectorElement for velocity (vector)
FE = ufl.FiniteElement("Lagrange", _mesh.ufl_cell(), Q_order)          # FiniteElement for pressure (scalar)
ME = ufl.MixedElement([*([VE] * ndims), FE])                           # mixed element to mimic P2-P1 elements

# Mixed functionspace and function
MFS = fem.functionspace(_mesh, ME)                                     # mixed functionspace
T   = fem.functionspace(_mesh, ("Lagrange", V_order, (ndims, ndims)))  # tensor functionspace
Un  = fem.Function(MFS)                                                # mixed function
Unt = ufl.split(Un)                                                    # Un tuple
un  = ufl.as_vector(Unt[:ndims])   # mixed function
pn  = Unt[ndims]                   # mixed function
tau = fem.Function(T)              # function

# TrailFunctions
trail_functions = ufl.TrialFunctions(MFS)
u = ufl.as_vector(trail_functions[:ndims])
p = trail_functions[-1]

# TestFunctions
test_functions = ufl.TestFunctions(MFS)
v = ufl.as_vector(test_functions[:ndims])
q = test_functions[-1]

# Forms to test the functionalities programmingly
c1, c2 = 1, 2    # some coefficients