Realtime simulation of an hourglass based on granular dynamics