The dynamics of avalanches of granular materials from initiation to runout. Part I: Analysis