Gradient of a tensor

Hello,
For a tensor S_{i j} I am trying to write its convective derivative in the velocity field v_k that will involve term v_k * d (S_{i j} ) / d x_k . Will this term be written as inner (v, nabla_grad(S)) or somehow else? I looked at the difference between grad and nabla_grad for vector but not sure if it will be the same for tensor. Thank you!

1 Like

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