In my coupled problem, I have a 2-dimensional mesh of triangle elements. I create two finite elements from which I create a mixed element:
u_space = VectorElement("CG", mesh.ufl_cell(), 1, 2)
d_space = FiniteElement("CG", mesh.ufl_cell(), 1)
joint_space = FunctionSpace(mesh, u_space * d_space)
Note that I specify the size of the vector element as 2, which should match the dimension of the mesh and elements.
I then create a function for the mixed element and split it into corresponding fields
U = Function(joint_space)
u, d = split(U)
and check the shape of u
>>> print(shape(u))
(2,)
which is normal. However when I take the gradient, the operation takes place in 3 spatial dimensions
>>> print(shape(grad(u)))
(2, 3)
This poses a problem, because when I take the symmetric part in order to calculate the strain tensor, I get the following error
>>> sym(grad(u))
Cannot take symmetric part of rectangular matrix with dimensions (2, 3).
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/ufl/operators.py", line 294, in sym
return Sym(A)
File "/usr/local/lib/python2.7/dist-packages/ufl/tensoralgebra.py", line 466, in __new__
error("Cannot take symmetric part of rectangular matrix with dimensions %s." % (sh,))
File "/usr/local/lib/python2.7/dist-packages/ufl/log.py", line 171, in error
raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Cannot take symmetric part of rectangular matrix with dimensions (2, 3).
What do I need to change in order to make sure that the gradient takes place in 2 spatial dimensions?