A thermodynamical study of the Martian permafrost