SunnySuite / Sunny.jl

Spin dynamics and generalization to SU(N) coherent states
Other
86 stars 19 forks source link

Inhomogeneous interactions #59

Closed kbarros closed 1 year ago

kbarros commented 1 year ago

This PR introduces a new function new_sys = to_inhomogeneous(sys). The new system new_sys is a copy of sys that allows inhomogeneous interactions. The new system supports functions like set_exchange_at! which sets an exchange interaction on just a single bond, ignoring symmetry and symmetry propagation.

kbarros commented 1 year ago

At the types level, the main difference is that System.interactions_union now stores a union, which is either Vector{Interactions} or Array{Interactions, 4}. Which one determines the "mode" (homogeneous or inhomogeneous). https://github.com/SunnySuite/Sunny.jl/blob/inhomogeneous/src/System/Types.jl#L56

There is now a function is_homogeneous to query this mode: https://github.com/SunnySuite/Sunny.jl/blob/inhomogeneous/src/System/Interactions.jl#L20

To minimize code duplicated, this PR refactors various functions. For example, energy now calls energy_aux, which loops over contributions for a list of cells. In the case of inhomogeneous cells, the list of cells has only one cell at a time: https://github.com/SunnySuite/Sunny.jl/blob/inhomogeneous/src/System/Interactions.jl#L204