Ferrite-FEM / Tensors.jl

Efficient computations with symmetric and non-symmetric tensors with support for automatic differentiation.
https://ferrite-fem.github.io/Tensors.jl/
Other
170 stars 38 forks source link

Third order tensors and mutable tensors #192

Open DRollin opened 1 year ago

DRollin commented 1 year ago

Hello,

I am currently working with sensitivities in multi-scale modelling. In one case I am considering, third order tensors are used. However, third order tensors are apparently not full supported e.g. zero(Tensor{3,dim}) errors. I created a quick solution for my code, but probably it would be nice to have that in general.

Furthermore, the sensitivities are computed part by part, so they are tensors that need to be adapted. This adaption is like inserting a tensor into another tensor of higher order. In my case I do the operation using arrays, but maybe it would also be nice to have a general solution for that like mutable tensors or functions doing the insertion.

Just two suggestions. What do you think? I am also willing to contribute, I am just still a bit unexperienced.

termi-official commented 1 year ago

Regarding mixed tensors, Knut was so nice and started putting something together in this PR: https://github.com/Ferrite-FEM/Tensors.jl/pull/188 .

KnutAM commented 11 months ago

Perhaps a @setindex macro could be used for the mutable part, something like

@setindex a[1,:] = a[1,:] + v[:]
# Generates the expression
a = typeof(a)((i,j) -> (i == 1) ? a[i,j] + v[j] : a[i,j]
KnutAM commented 7 months ago

3rd order (partially) supported by #205 Regarding mutability, perhaps a similar strategy to StaticArrays could be useful, overloading the non-exported Base.setindex? https://juliaarrays.github.io/StaticArrays.jl/stable/pages/api/#Base.setindex-Tuple{StaticArray,%20Any,%20Int64}