Contact dynamics as a nonsmooth discrete element method