Modeling gravitational collapse of rectangular granular piles in air and water