A variational approach to statics and dynamics of elasto-plastic systems