Index' object is not subscriptable

Dear All,
Hope you are doing well and safe. I am trying to solve a nonlinear problem in 2D. Part of my code is given below for your consideration:

s = as_vector(( cos(thta), sin(thta)))
m = as_vector((-sin(thta), cos(that)))

delta = Identity(2)
i, j, k, l, p, q, r, s = indices(8)
# Reorientation matrix
Q = as_tensor(2*m[i]*m[j] - delta[i, j], (i, j))
C_0 = as_tensor(lmbda * delta[i, j] * delta[k, l] + mu * delta[i, k] *
	delta[j, l] + mu * delta[i, l] * delta[j, k], (i, j, k, l))
C_1 = as_tensor(Q[p, i]*Q[q, j]*Q[r, k]*Q[s, l]*C_0[i, j, k, l], (p, q, r, s))
C_ = as_tensor(C_0[i, j, k, l] + (C_1[i, j, k, l] - C_0[i, j, k, l]) *  (3*deta**2 - 2*deta**3), (i,j,k,l))


df0_detta3 = (3*deta**2 - 2*deta**3)*gamma_0

F = as_tensor(du[i].dx(j) + delta[i, j], (i, j))
F_eta = as_tensor(delta[i, j] + df0_detta3*s[i]*m[j], (i, j))
F_E = as_tensor(F[i, j] * inv(F_eta)[j, k], [i, k])
C_E = as_tensor(F_E[i, k]*F_E[i, j], (k, j))
E_E = as_tensor(1./2.*(C_E[k, j] - delta[k, j]), (k, j))
S = as_tensor(C_[i, j, k, l] * E_E[k, l], (i, j))
P = as_tensor(F[j, l] * S[i, l], (i, j))

I got the following error message:
Traceback (most recent call last):
File “large_deformation1.py”, line 103, in
F_eta = as_tensor(delta[i, j] + df0_detta3*s[i]*m[j], (i, j))
TypeError: ‘Index’ object is not subscriptable

I appreciate your time and help if you can help me resolve this issue.

Regards,
Ben

Isn’t s already an index? So s[i] is indexing an index? Which doesn’t make much sense. Perhaps that’s a typo?

Your issue seems to be you’ve overwritten s as an Index.

s = as_vector(( cos(thta), sin(thta)))
...
i, j, k, l, p, q, r, s = indices(8)

Hi Nate,
That is a good point actually. My bad.
Thanks a lot for your help.

Bests,
Benhour

1 Like