Variational analysis and optimal control of dynamic unilateral contact models with friction