Problems with symmetrical tensor spaces

Hello everyone,

I have just started using FEniCSx and I am toying around with some tensor approximation spaces. Here is my code

# FEniCSx libraries
from dolfinx.fem import TensorFunctionSpace,assemble_scalar,form
from dolfinx.fem.petsc import LinearProblem
from dolfinx.mesh import CellType,create_rectangle
from ufl import SpatialCoordinate,TestFunction,TrialFunction,inner,grad,div,sym,dx,as_vector
import ufl

# Other libraries
from mpi4py import MPI
import numpy as np

# Mesh ------------------------------------------------------------------------

msh = create_rectangle(comm=MPI.COMM_WORLD,
                       points=((0.0,0.0), (1.0,1.0)), n=(8,8),
                       cell_type=CellType.triangle)

x = SpatialCoordinate(msh)

# Variational problem ----------------------------------------------------------

# Some vector field
def ue1(x):
    return ufl.sin(ufl.pi*x[0])*ufl.sin(ufl.pi*x[1])

def ue2(x):
    return ufl.sin(ufl.pi*x[0])*ufl.sin(ufl.pi*x[1])

ue =  as_vector([ue1(x), ue2(x)])

# Tensor space
V = TensorFunctionSpace(msh,('CG',1),symmetry=True)

# Bilinear and linear forms
sig = TrialFunction(V)
tau = TestFunction(V)
a = inner(sig,tau)*dx
L = inner(sym(grad(ue)),tau)*dx

# Linear system
problem = LinearProblem(a,L,bcs=[],petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
wh = problem.solve()

It seems to work as expected when I set “symmetry=False”, but when I change it to “symmetry=True” I get the following error message

Expecting pulled back expression with shape ‘(2, 2)’, got ‘(3,)’
ERROR:UFL:Expecting pulled back expression with shape ‘(2, 2)’, got ‘(3,)’

Can someone help me to understand what is wrong?

See: [BUG]: TensorFunctionSpace not working with symmetric mode · Issue #2534 · FEniCS/dolfinx · GitHub for further developements. There is also a proposed work-around here.

Thanks Dokken, hope the bug gets solved soon. I was able to implement symmetrical tensors adapting the ideas suggested here: