I have been playing with tensor algebra and bumbed into following problem with tensor multiplication.
from dolfin import *
dim = 2
N = 10
mesh = UnitSquareMesh(5,5)
V = VectorFunctionSpace(mesh, 'DG', 1)
W = TensorFunctionSpace(mesh, 'DG', 1, shape=(dim,dim))
U = Function(V)
B = Function(W)
M = Function(W)
for i in range(dim-1):
for j in range(dim-1):
ind = i*dim + j
M.sub(ind) += [U.sub(k)* grad(B).sub(k*dim*dim + i*dim + j ) for k in range(dim-1)]
The last lines of code represents my lousy attempt to piecewise define the result of tensor multiplication of vector U and tensor grad(B). The result should be tensor (dim x dim).
Im not sure how to approach this and how to work with grad() structure. I'am getting the error: 'Grad' object has no attribute 'sub'.
Can you pls help me with the proper approach? I believe it should be trivial but I can't google this anywhere since it is not a standard problem.