Hello,

In the Linear Form of my problem I have a contraction of a third order Tensor with a Vector:

T_{\alpha \beta \gamma} P_\gamma.

Is there some handy way to do this or do I need to write it for each element?

Thanks!

Hi Jakob,

there are some options in NGSolve to handle this kind of contraction.

The most generic would be to use Einsum from ngsolve.fem, which is inspired by numpy einsum (numpy.einsum — NumPy v1.26 Manual).

```
import ngsolve.fem
T = CF( (1,2, 3,4,
5,6, 7,8), dims=(2,2,2) )
P = CF( (9,0) )
contraction = fem.Einsum('abc,c->ab', T, P)
```

For the contraction also

```
contraction2 = T[:,:,P]
contraction3 = T*P
```

should work fine.

Best,

Michael

1 Like