This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Tensor multiplication

0 votes

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.

asked May 27, 2015 by Ianx86 FEniCS User (1,050 points)
edited May 27, 2015 by Ianx86
...