Statistical definitions of heat and work

My understanding of heat and work from a statistical mechanics perspective (mainly extracted from Schrödinger's Statistical Thermodynamics) is as follows.

We have some system, let us say a box of gas. It can be in many different states (microstates), labelled by $$i$$, each with an energy $$E_i$$. Now take a large number $$M$$ of copies of the system. Consider as equally likely all configurations $$\{i_1, \dots, i_M\}$$ such that the total energy $$E_{i_1} + \cdots + E_{i_M}$$ is equal to $$E_\mathrm{tot}$$. This is the canonical ensemble.

Let $$n_i$$ be the number of systems in state $$i$$. Then call the most likely combination $$\{n_0, n_1, \dots\}$$ the macrostate. Combinatorics then shows that the percentages $$p_i = \frac{n_i}{M}$$ follow the Boltzmann distribution $$p_i = \frac{1}{Z} e^{-\beta E_i}$$ where $$Z = \sum_i e^{-\beta E_i}$$, and we identify $$\beta = \frac{1}{k_B T}$$.

Define the internal energy $$U = \left\langle E\right\rangle = \sum_i p_i E_i = -\frac{\partial}{\partial \beta} \ln Z$$ and the entropy $$S = -k_B \sum_i p_i \ln p_i = k_B (\ln Z + \beta U)$$. Then, varying both $$\beta$$ and the energies $$E_i$$ (in a quasistatic process), we may show that $$dU = T\,dS + \sum_i p_i dE_i.$$

I interpret $$\sum_i p_i dE_i$$ as the average increase $$\left\langle dE\right\rangle$$ in energy, over all microstates $$i$$, due to changing external conditions, that is, a change in the Hamiltonian of the system, which causes the energy levels $$E_i$$ to change. I take this as the definition of work: $$\delta W = -\sum_i p_i dE_i$$ (minus sign because it is the work done by the system, physicist's convention).

Now, the change in $$U$$ would just be $$-\delta W$$ if all the occupation numbers $$n_i$$ (the distribution $$\{p_i\}$$) stayed the same. However, by changing the $$E_i$$, we will most likely break the Boltzmann distribution, which is not possible (in a quasistatic process). Thus, to get back to equilibrium, the occupation numbers must somehow change. I interpret $$T\,dS$$ as the change in $$U$$ due to this effect, and I call it heat, $$\delta Q$$. Because $$U = \sum_i p_i E_i$$, I immediately find $$\delta Q = T\,dS = dU - \sum_i p_i dE_i = \sum_i E_i dp_i$$, which exactly matches this interpretation!

TLDR: I say that work is change in internal energy due to changes in the Hamiltonian, i.e. the energy of individual microstates, and heat is change in internal energy due to changes in occupation numbers. This seems in excellent agreement with both answers to this question and the Wikipedia article on microstates, for example.

The problem is that there seem to be other definitions of work and heat out there. The general sense is that work is due to macroscopic forces, while heat is due to microscopic forces. It is also said that heat transfer always occurs at the boundary of a system. Some authors make a distinction between heat and dissipative work, which I suppose may be related.

For example, in a recent discussion in the comments to an answer, the example of stirring a fluid came up. The above reasoning leads me to say that stirring does not entail doing work, but rather adding heat to the fluid. If one takes the whole fluid with $$N$$ molecules as the system, and the states $$i = \{\vec{x}_1, \vec{p}_1, \dots, \vec{x}_N, \vec{p}_N\}$$ (in the simplest case), stirring means increasing the occupation number $$n_i$$ of high-energy states $$i$$ where the fluid is sloshing around. After finishing stirring, the fluid settles into a Boltzmann distribution with a higher internal energy that before, while the energy $$E_i$$ of individual states does not change. This seems to mean that no work is being done. However, since one stirs the fluid with a macroscopic object, it is natural to call this work.

My question: Are there inequivalent definitions of heat and work that one needs to be aware of, or am I just making a mistake? How to express the distinction between microscopic and macroscopic forces with statistical mechanics?

(Common terminology seems to differ. The Wikipedia article on work does not consider "shaft work" and "stirring" to be work, but the names certainly suggest it.)

• Maybe this link will help hyperphysics.phy-astr.gsu.edu/hbase/thermo/heat.html#c2 Feb 5, 2020 at 5:33
• @Elias Riedel Gårding I didnt quite understand the second paragraphy where you explain the canonical ensemble. In my opinion, canonical ensemble is a collection of microstates all of which could be the microstate of a system in contact with a heat reservoir. Would you please explain a litttle bit to me about the second paragraph. Thank you!
• @FaDA Of the $M$ copies of the system, you view one of them as "the system" and the remaining $M - 1$ as the reservoir. The total energy $E_\mathrm{tot} = MU$ shared among all systems determines the temperature. Schrödinger claims that this formulation is due to Gibbs. He doesn't use the words "canonical ensemble" but I think it is the same thing? Feb 5, 2020 at 10:54
• Also, I am not completely sure if my definition of "macrostate" agrees with the term's usual meaning. I guess it would more properly include the energy levels: $\{T, E_0, E_1, \dots\}$ or equivalently $\{E_0, n_0, E_1, n_1, \dots\}$. I don't think this affects the rest of my question, though. Feb 5, 2020 at 11:05