Generalized discrete element method