In physics and engineering sources, calculus-based formalisms - whether differential forms on a manifold, or "differentials" of functions of several variables - are presented as a way of modeling and reasoning about thermodynamic systems. However, I've found little to no mathematical background given to justify these formal manipulations when there are phase changes or other discontinuities. In such regions, one would expect the theory to break down since partial derivatives and differential forms are not defined.
Nevertheless, if you "shut up and calculate", everything seems to work out fine. Why is this the case, and what is the proper mathematical state space and framework for systems with phase transitions or other non-smooth properties? (perhaps some sort of "weakly-differentiable" manifold?)