Gradient of a tensor

To implement v_kS_{ij,k}, you could use

T = dot(v,nabla_grad(S))
T = dot(grad(S),v)

or just specify it directly in index notation:

from ufl import indices
i,j,k = indices(3)
T = as_tensor(v[k]*(S[i,j].dx(k)),(i,j))

Basically, grad adds the “new index” from spatial differentiation at the end of the output tensor, while nabla_grad adds it at the beginning. dot sums over the last index of its first argument and the first index of its second argument. inner requires two arguments of the same shape and sums over all corresponding indices; this is equivalent to dot when passing two vectors, but differs for higher-rank tensors.

3 Likes