Thermodynamics of the Earth and Planets