A numerical approach to the simulation of granular and multiphase flows