Writing symmetric tensor function fails

Hi guys,

Writing a symmetric tensor to a file fails with an error message. Can someone explain me this behavior?
Is there a way to output Functions defined on a TensorFunctionSpace (or constructed with TensorElement)?

Error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
 in 
     12 v = Function(TensorFunctionSpace(mesh, "Lagrange", 1, symmetry=True))
     13 v.vector()[:] = 1.0
---> 14 File("v.pvd") << v
     15 print("wrote v")

/usr/local/lib/python3.6/dist-packages/dolfin/io/__init__.py in __lshift__(self, u)
     12 
     13     if isinstance(u, dolfin.function.function.Function):
---> 14         self.write(u._cpp_object)
     15     elif isinstance(u, tuple):
     16         if isinstance(u[0], dolfin.function.function.Function):

RuntimeError: interpolate_vertex_values: Failed to set physical value size correctly for subelements.

MWE (as done in the test file dolfin/test/unit/python/io/test_vtk.py):

from dolfin import *

mesh = UnitSquareMesh(16, 16)

# works
u = Function(TensorFunctionSpace(mesh, "Lagrange", 1))
u.vector()[:] = 1.0
File("u.pvd") << u
print("wrote u")

# fails
v = Function(TensorFunctionSpace(mesh, "Lagrange", 1, symmetry=True))
v.vector()[:] = 1.0
File("v.pvd") << v
print("wrote v")

Hello,
many features of symmetry=True option for Tensor elements seem to be broken (see https://bitbucket.org/fenics-project/ffc/issues/78/tensorelement-symmetry-true-is-totally). They should be used with much care.

Hi, I solved the problem in the meantime with a projection into a non-symmetric tensor space before writing the files.

MWE:

"This solves the problem with a hack"

from dolfin import *

mesh = UnitSquareMesh(4, 4)

# works
u = Function(TensorFunctionSpace(mesh, "Lagrange", 1))
u.vector()[:] = 1.0
File("u.pvd") << u
print("wrote u")

# fails
v = Function(TensorFunctionSpace(mesh, "Lagrange", 1, symmetry=True))
v.vector()[:] = 1.0
# v.assign(u) # also does not work because v afterwards lives in symmetric space
# File("v.pvd") << v # fails
# print("wrote v")

# projection works up to machine precision
vp = project(v, TensorFunctionSpace(mesh, "Lagrange", 1))
error = vp.vector()[:] - u.vector()[:]
print(error)
File("vp.pvd") << vp
print("wrote vp")