added assertions to ensure thermal energy remains non-negative, see #141