The numerical simulation of atmospheric gravity currents. Part II. Environments with stable layers