The stress tensor in thermodynamics and statistical mechanics