How to recover thermodynamic volume in statistical physics?

In statistical mechanics, after finding the cannoncial partition function,

$$Z = \frac{1}{N!h^{3N}}\int\mathrm{d}p \int\mathrm{d}q \exp[-\beta H(p, q)],$$

we then recover our dear thermodynamical variables,

$$\beta = \frac{1}{k_bT},\quad F = -\frac{1}{\beta} \ln(Z), \quad E = -\frac{\partial \ln{Z}}{\partial \beta}, \quad S = -\frac{\partial F(V, T)}{\partial V}, \quad P = -\frac{\partial F(V, T)}{\partial T}$$

My question regareds the last two. Here, we rely on the thermodynamic identity

$$\mathrm{d}F = -S \mathrm{d}T - p \mathrm{d}V,$$

however to exploit this, we need to express $$F$$, and therfore $$Z$$, as a function of of $$V$$, which I have problems understanding how to do. For ideal gasses, it falls out easily as $$Z$$ is proportional to $$V = \int \mathrm{d}q$$. But in genereal, $$H$$ does not depend on $$V$$, which makes formulas like

$$P = - \frac{1}{Z}\sum_r \frac{\partial E_r}{\partial V}, \quad \mathrm{(Statistical\, Mechanics, \,P.\,K.\,Pathria\,(3.3\, eq.11) )}$$ look like nonsens to me: we have nerver told the hamiltonian what the volume does. In his "Elementary Principles of Statistical Mechanics", Gibbs talks about "coordinates $$a_1, a_2$$ of bodies which we call external, meaning by this simply that they are not to be regarded as forming any part of the system, although their positions afect the forces which act on the system." (p. 47-48 in the project gutenber version). This sounds like a way to tell the hamiltonian, and thus the partition function, about the volume, but I have never seen it anywhere else. How could this be best understood?

• The volume is in the region of integration for the partition function in the first equation. Commented Apr 30, 2020 at 19:05

You either tell the Hamiltonian about the volume, by making the potential energy "outside" the system very large (for example, it could be that your system is in a harmonic potential, and the volume of the system corresponds to a characteristic size of the potential), or you tell the partition function about the volume, by restricting your integration of $$dq$$ to only refer to particles inside a specified volume. In either case, $$Z$$ knows about the volume explicitly.
• How can $\frac{\partial E_r}{\partial V}$ be interpreted if the hamiltonian is not dependent on $V$? Commented May 1, 2020 at 12:03