I'm trying to figure out how to evaluate the derivative of a tensor with sympy. Here's what I attempted based on what I could piece together from the docs. There are probably multiple errors here, but I'm having trouble finding the right docs/tutorial to figure this simple thing out.
from sympy.tensor.tensor import TensorIndexType, TensorHead
from sympy.tensor.toperators import PartialDerivative
from sympy import symbols, Idx, sympify
L = TensorIndexType("L")
B = TensorHead("B", [L])
i, j, k = symbols("i j k") # why is adding cls=Idx as a final argument wrong?
from sympy.abc import x, y
from sympy import sin, log
compB = [x, y]
F = TensorHead("F", []) # Is this the way to make a scalar?
expr = PartialDerivative(PartialDerivative(F, B(-j)), B(j))
print(expr, expr.get_free_indices(), expr.get_indices())
r = expr.replace_with_arrays({F(): sin(x), B(i): compB})
The code shows what I tried. What I was expecting was that I would be able to use replace_with_arrays or replace or some combination to evaluate this Laplacian.
Here is the output of the above code:
PartialDerivative(F(), B(-L_0), B(L_0)) [] [L_0, -L_0]
Traceback (most recent call last):
File "/mnt/c/Users/steve/OneDrive - Louisiana State University/py/x.py", line 17, in <module>
r = expr.replace_with_arrays({F(): sin(x), B(i): compB})
File "/mnt/c/Users/steve/.local/lib/python3.10/site-packages/sympy/tensor/tensor.py", line 2360, in replace_with_arrays
ret_indices, array = self._extract_data(replacement_dict)
File "/mnt/c/Users/steve/.local/lib/python3.10/site-packages/sympy/tensor/toperators.py", line 233, in _extract_data
indices, array = self.expr._extract_data(replacement_dict)
AttributeError: 'TensorHead' object has no attribute '_extract_data'