I would like to compose blocks of arbitrary ufl tensors as in the attached example, such that the resulting ufl object is a 2D matrix rather than a higher-order tensor. Is there a simpler way to get the desired
result or do I have do everything using indices as in the MWE?
from dolfin import *
mesh = UnitSquareMesh(2,2)
I = Identity(2)
test = as_matrix([[I, -I],
[-I, I]])
# This results in a tensor of shape (2,2,2,2)
print(project(test, TensorFunctionSpace(mesh, 'CG', 1, (2,2,2,2)))(0.5,.5).reshape(2,2,2,2))
# want a matrix of shape (4,4)
desired = as_matrix([[I[0,0], I[0,1], -I[0,0], -I[0,1]],
[I[1,0], I[1,1], -I[1,0], -I[1,1]],
[-I[0,0], -I[0,1], I[0,0], I[0,1]],
[-I[1,0], -I[1,1], I[0,0], I[1,1]]])
print(project(desired, TensorFunctionSpace(mesh, 'CG', 1, (4,4)))(0.5,.5).reshape(4,4))