Continuum modeling of discrete systems: a variational approach