I am doing some work in elasticity and as a result am working with tensors. In particular, I would like to calculate the contraction of a fourth order tensor (the stiffness tensor) with a second order tensor (the velocity gradient) to get another tensor (the time derivative of the stress, for anyone interested).
For my material, the stiffness tensor is easily written down in terms of products of Kronecker Delta Functions such as $\delta_{ij}\delta_{kl}$. I can then easily compute the contraction by manually entering the second order tensor of interest, and using Sum
in combination with Part
to extract the result.
The problem is that, naturally, Mathematica displays the output in terms of KroneckerDelta[3, i]
, for example, and there's a lot of them - it's essentially writing the matrix out elementwise using delta functions. Is there a way I can easily view this as a matrix, or map them to a matrix, or alternatively, approach this problem from a different perspective which would avoid this issue altogether? I am trying to apply something along the lines of the following to my expression:
Replace[KroneckerDelta[i, j], KroneckerDelta[i, j] ->
TensorProduct[Part[IdentityMatrix[3], i], Part[IdentityMatrix[3], j]]]
If this were valid Mathematica code, it would work in theory, but I get the error The expression i cannot be used as a part specification.
along with the same for j
.
SparseArray[{k_, k_, k_} -> 1, {3, 3, 3}]
or are you just manipulating symbolic tensors? $\endgroup$KroneckerDelta
as, for example,stiff[i_, j_, k_, l_] = L KroneckerDelta[i, j] KroneckerDelta[k, l] + \[Mu] (KroneckerDelta[i, k] KroneckerDelta[j, l] + KroneckerDelta[i, l] KroneckerDelta[j, k])
$\endgroup$SparseArray[{{i_, j_, k_, l_} :> L KroneckerDelta[i, j] KroneckerDelta[k, l] + μ (KroneckerDelta[i, k] KroneckerDelta[j, l] + KroneckerDelta[i, l] KroneckerDelta[j, k])}, {3, 3, 3, 3}]
. Consider reading the docs forSparseArray[]
andSymmetrizedArray[]
too, while you're at it. $\endgroup$