Atomistic Spin Dynamics: Foundations and Applications