Index operation: shapes do not match

Hello, I am learning to operate with indices.

In the following example I try to calculate a 4-order tensor and then perform a double contraction but when I use inner I get the error “shapes do not match”.

from dolfin import *
from ufl import indices
import numpy as np

mesh = UnitSquareMesh(2,2) 
i,j,k,l,m = indices(5)
I  = Identity(2)
a = as_tensor([[1.0,2.0],[0.5,0.5]])
b = as_tensor([[1.5,1.0],[0.3,0.8]])
R = as_tensor(a[i,l]*a[j,k]+a[i,m]*a[j,m]*I[k,l],(i,k,j,l))

c = inner(R,b)

I know I can do it by doing:

c2 = as_tensor(R[i,k,j,l]*b[j,l],(i,k))

but, is there any way to make it work with inner?

Thanks!

Consider the documentation for ufl.inner. If this doesn’t satisfy your needs you’ll need to define the product yourself as you have done already.

1 Like