Mathematical Thermodynamics of Complex Fluids