Entropy maximization under thermal contact (source code)

= Entropy maximization under thermal contact
{title2=$\partial S_{\rm tot}/\partial E_1=1/T_1-1/T_2$}

At fixed <volumes> and material inventories, two internally equilibrated bodies that exchange only <heat> within an <isolated system> have fixed total <internal energy> $E=E_1+E_2$. Their total <entropy> is
$$
S_{\mathrm{tot}}(E_1)=S_1(E_1)+S_2(E-E_1).
$$
Using $1/T_i=(\partial S_i/\partial E_i)_{V_i,N_i}$, an interior stationary point obeys
$$
\frac{dS_{\rm tot}}{dE_1}=\frac1{T_1}-\frac1{T_2}=0.
$$
Thus <entropy> stationarity requires matching <thermodynamic temperatures>. Positive values of <heat capacity at constant volume> make this a strict local maximum because
$$
\frac{d^2S_{\rm tot}}{dE_1^2}=-\frac1{C_1T_1^2}-\frac1{C_2T_2^2}<0.
$$
For bodies with positive <heat capacities> throughout the accessible range, this <concavity> gives at most one interior maximum. This is the stability check behind the equal-<temperature> condition; see <entropy concavity and positive heat capacity>. <Statistical Physics by David Tong/1 The Fundamentals of Statistical Mechanics>[David Tong, Statistical Physics, sections 1.2.1–1.2.2: entropy maximization, temperature and heat capacity]{ref}

For <thermal equilibration of two finite bodies>, <entropy from heat capacity> gives
$$
\Delta S_{\rm tot}=C_1\ln\frac{T_f}{T_{1,0}}+C_2\ln\frac{T_f}{T_{2,0}}
=\left(\ln\frac{375}{300}+3\ln\frac{375}{400}\right)\mathrm{kJ\,K^{-1}}
\simeq0.02952799\,\mathrm{kJ\,K^{-1}}>0.
$$
Body 1 gains about $0.22314355\,\mathrm{kJ\,K^{-1}}$ of <entropy>, while body 2 loses about $0.19361556\,\mathrm{kJ\,K^{-1}}$. Total <energy> is conserved even though total <entropy> increases. The <entropy> calculation uses reversible comparison paths between the endpoint states; actual exchange across a finite <temperature> difference is irreversible.

\Image[/thermal-equilibrium-entropy-maximum.png]
{title=At fixed total <energy>, matching <temperatures> maximize total <entropy>}
{description=The curve is total <entropy> relative to the initial $300\,\mathrm K$, $400\,\mathrm K$ state. Every point satisfies $C_1T_1+C_2T_2=1500\,\mathrm{kJ}$. Only $250\le T_1/\mathrm K\le500$ is shown; the mathematical model's positive-<temperature> domain is $0<T_1/\mathrm K<1500$.}

To construct the plot, vary $T_1$ while enforcing the <energy> constraint, rather than holding $T_2$ fixed. In numerical units of <kelvin>, $T_2/\mathrm K=(1500-T_1/\mathrm K)/3$, and the plotted function is
$$
\mathcal S(T_1)=C_1\ln\frac{T_1}{300\,\mathrm K}+C_2\ln\frac{T_2(T_1)}{400\,\mathrm K},\qquad
\frac{dT_2}{dT_1}=-\frac{C_1}{C_2}.
$$
Here $\mathcal S$ means $S_{\rm tot}-S_{\rm tot,initial}$, so its zero is a reference choice. The <chain rule> yields
$$
\mathcal S'(T_1)=\frac{C_1}{T_1}-\frac{C_1}{T_2},\qquad
\mathcal S''(T_1)=-\frac{C_1}{T_1^2}-\frac{C_1^2}{C_2T_2^2}<0.
$$
The unique maximum is at $T_1=T_2=375\,\mathrm K$. The physical trajectory starts at $T_1=300\,\mathrm K$ and moves toward that maximum; the rest of the curve compares other possible <energy> partitions, not later times in the trajectory.

The contact model also proves the direction of change directly:
$$
\dot S_{\rm tot}=G(T_2-T_1)\left(\frac1{T_1}-\frac1{T_2}\right)
=\frac{G(T_2-T_1)^2}{T_1T_2}\ge0.
$$
For $G>0$ and positive <temperatures>, equality holds exactly at <thermal equilibrium>. The appealing link is that a dynamical <heat transfer> law moves the system uphill on the constrained <entropy> curve, while conservation of <energy> keeps it on that curve. This predicts both why the endpoint is stable and why the reverse separation into hot and cold bodies cannot happen spontaneously in the <isolated system>.