Heavy ion circulation in the Earth's magnetosphere