Chemistry - What is the entropy of mixing of two ideal gases starting out with different pressures?
Solution 1:
A strategy that often works is to look at the initial and the final states and then compare them. A good place to start is usually the Gibbs free energy of the system (with the intention to use $\Delta_{\mathrm{mix}} S = - \frac{\partial \Delta_{\mathrm{mix}}G}{\partial T} \big|_{p, \{ n_{i} \}}$ later): for isothermal and isobaric conditions it is
\begin{equation} G = \sum_{i} n_{i} \mu_{i} + \mathrm{constant} = n_{\mathrm{tot}} \sum_{i} \underbrace{x_{i}}_{= \, \frac{n_{i}}{n_{\mathrm{tot}}}} \mu_{i} + \mathrm{constant} \hspace{4em} (1) \end{equation}
with $n_{i}$, $\mu_{i}$, and $x_{i} = \frac{n_{i}}{n_{\mathrm{tot}}}$ being the amount, the chemical potential, and the mole fraction of the $i$th component in the system, respectively, and $n_{\mathrm{tot}} = \sum_{i} n_{i}$ being the total amount of gas in the system. So, now we need an expression for the chemical potential of an ideal gas. It can be shown that this is given by
\begin{equation} \mu_{i} = \mu_{i}^{0} + R T \ln\biggl(\frac{p_{i}}{P^{0}}\biggr) \hspace{18em} (2) \end{equation}
where $\mu_{i}^{0}$ is the chemical potential of the $i$th component in a given standard state, $R$ is the universal gas constant, $T$ is the temperatur, $p_{i}$ is the partial pressure of the $i$th component, and $P^{0}$ is the standard pressure (i.e. the pressure connected to the standard state). For ideal gases we can apply Raoult's law stating that
\begin{equation} p_{i} = x_{i} P_{\mathrm{tot}} \end{equation}
where $P_{\mathrm{tot}}$ is the total pressure of the system. Using this with equation (2) we get
\begin{equation} \mu_{i} = \mu_{i}^{0} + R T \ln\biggl(\frac{x_{i} P_{\mathrm{tot}}}{P^{0}}\biggr) = \mu_{i}^{0} + R T \ln x_{i} + R T \ln\biggl(\frac{P_{\mathrm{tot}}}{P^{0}}\biggr) \hspace{6em} (3) \end{equation}
Furthermore, it is known that the partial pressures in a system must add up to the total pressure, i.e.
\begin{equation} P_{\mathrm{tot}} = \sum_{i} p_{i} \end{equation}
Ok, now that the stage is set we simply have to apply equations (1) and (3) to the initial and the final state of the mixing process. At the initial state the chambers are seperated (whereby chamber $i$ contains only one sort of gas labeled by $i$) and so these subsystems are completely independent from each other. Thus, the Gibbs free energy of the total system of chambers is simply the sum of the Gibbs free energies of each chamber, whereby the gas in each of the chambers feels the pressure $P_{\mathrm{tot}} = P_{i}$ in the system (whereby $P_{i}$ is the ambient pressure in chamber $i$), since $x_{i} = 1$ (each chamber/independent subsystem holds just one kind of gas). According to equation (1) the Gibbs free energy of the $i$th chamber is then given by
\begin{align} G_{i} &= n_{i} \mu_{i} = n_{i} \biggl( \mu_{i}^{0} + R T \underbrace{\ln 1}_{= \, 0} + R T \ln\biggl(\frac{P_{i}}{P^{0}}\biggr) \biggr) \\ &= n_{i} \biggl( \mu_{i}^{0} + R T \ln\biggl(\frac{P_{i}}{P^{0}}\biggr) \biggr) \end{align}
and the Gibbs free energy of the total system at the initial state is
\begin{align} G_{\mathrm{ini}} &= \sum_{i} G_{i} \\ &= \sum_{i} \underbrace{n_{i}}_{= \, x_{i} n_{\mathrm{tot}}} \biggl( \mu_{i}^{0} + R T \ln\biggl(\frac{P_{\mathrm{tot}}}{P^{0}}\biggr) \biggr) \\ &= n_{\mathrm{tot}} \biggl( \underbrace{\sum_{i} x_{i} \mu_{i}^{0}}_{= \, G_{\mathrm{ini}}^{0}} + \sum_{i} x_{i} R T \ln\biggl(\frac{P_{i}}{P^{0}}\biggr) \biggr) \\ &= n_{\mathrm{tot}} \biggl( G_{\mathrm{ini}}^{0} + \sum_{i} x_{i} R T \ln\biggl(\frac{P_{i}}{P^{0}}\biggr) \biggr) \ . \hspace{7em} (4) \end{align}
For a multicomponent system with more than two components I would simply use this equation. But for a system with exactly two components we can introduce some substitutions that will simplify the final equations a little. For that purpose we want to establish a relationship between the initial pressures $P_{1}$ and $P_{2}$ and the final pressure $P_{\mathrm{fin}}$. In order to get there we use the ideal gas law and the additivity relations for the volumes and amounts: From
\begin{equation} n_{\mathrm{tot}} = n_{1} + n_{2} \ , \qquad V_{\mathrm{tot}} = V_{1} + V_{2} \\ P_{1} V_{1} = n_{1} R T \ , \qquad P_{2} V_{2} = n_{2} R T \ , \qquad P_{\mathrm{fin}} V_{\mathrm{tot}} = n_{\mathrm{tot}} R T \end{equation}
it follows that
\begin{align} P_{1} V_{1} + P_{2} V_{2} = P_{\mathrm{fin}} V_{\mathrm{tot}} \ . \end{align}
Now, we can express $P_{2}$ in terms of $P_{\mathrm{fin}}$ by introducing the deviation factor $\alpha$ which is defined by $P_{2} = (1 - \alpha) P_{\mathrm{fin}}$ and use this in the previous equation
\begin{align} P_{1} V_{1} + P_{2} V_{2} &= P_{\mathrm{fin}} V_{\mathrm{tot}} \\ P_{1} V_{1} + (1 - \alpha) P_{\mathrm{fin}} V_{2} &= P_{\mathrm{fin}} V_{\mathrm{tot}} \\ P_{1} V_{1} &= P_{\mathrm{fin}} \bigl( \underbrace{V_{\mathrm{tot}} - V_{2}}_{= \, V_{1}} + \alpha V_{2} \bigr) \\ P_{1} &= \biggl( 1 + \alpha \frac{V_{2}}{V_{1}} \biggr) P_{\mathrm{fin}} \end{align}
which gives us the relation between $P_{1}$ and $P_{\mathrm{fin}}$. Introducing these equations into equation (4) yields
\begin{align} G_{\mathrm{ini}} &= n_{\mathrm{tot}} \biggl( G_{\mathrm{ini}}^{0} + x_{1} R T \ln\biggl(\frac{P_{1}}{P^{0}}\biggr) + x_{2} R T \ln\biggl(\frac{P_{2}}{P^{0}}\biggr) \biggr) \\ &= n_{\mathrm{tot}} \biggl( G_{\mathrm{ini}}^{0} + x_{1} R T \ln\frac{\bigl( 1 + \alpha \frac{V_{2}}{V_{1}} \bigr) P_{\mathrm{fin}}}{P^{0}} + x_{2} R T \ln\frac{(1 - \alpha) P_{\mathrm{fin}}}{P^{0}} \biggr) \\ &= n_{\mathrm{tot}} \biggl( G_{\mathrm{ini}}^{0} + x_{1} R T \ln\biggl( 1 + \alpha \frac{V_{2}}{V_{1}} \biggr) + x_{2} R T \ln(1 - \alpha) + \underbrace{(x_{1} + x_{2})}_{= \, 1} R T \ln\biggl( \frac{P_{\mathrm{fin}}}{P^{0}} \biggr) \biggr) \\ &= n_{\mathrm{tot}} \biggl( G_{\mathrm{ini}}^{0} + x_{1} R T \ln\biggl( 1 + \alpha \frac{V_{2}}{V_{1}} \biggr) + x_{2} R T \ln(1 - \alpha) + R T \ln\biggl( \frac{P_{\mathrm{fin}}}{P^{0}} \biggr) \biggr) \ . \end{align}
At the final state the chambers are connected and the gases mix, so the chambers are not independent subsystems anymore and the Gibbs free energy cannot be broken down into independent parts like before. Also, the ambient pressure in the system changes to $P_{\mathrm{tot}} = P_{\mathrm{fin}}$. Now, the complete system of connected chambers must be treated via equation (1)
\begin{align} G_{\mathrm{final}} &= \sum_{i} \underbrace{n_{i}}_{= \, x_{i} n_{\mathrm{tot}}} \biggl( \mu_{i}^{0} + R T \ln x_{i} + R T \ln\biggl(\frac{P_{\mathrm{fin}}}{P^{0}}\biggr) \biggr) \\ &= n_{\mathrm{tot}} \biggl( \sum_{i} x_{i} \mu_{i}^{0} + \sum_{i} R T x_{i} \ln x_{i} + \sum_{i} x_{i} \underbrace{R T \ln\biggl(\frac{P_{\mathrm{fin}}}{P^{0}}\biggr)}_{= \, \mathrm{constant}} \biggr) \\ &= n_{\mathrm{tot}} \biggl( \underbrace{\sum_{i} x_{i} \mu_{i}^{0}}_{= \, G_{\mathrm{ini}}^{0}} + R T \sum_{i} x_{i} \ln x_{i} + R T \ln\biggl(\frac{P_{\mathrm{fin}}}{P^{0}}\biggr) \underbrace{\sum_{i} x_{i}}_{= \, 1} \biggr) \\ &= n_{\mathrm{tot}} \biggl( G_{\mathrm{ini}}^{0} + R T \sum_{i} x_{i} \ln x_{i} + R T \ln\biggl(\frac{P_{\mathrm{fin}}}{P^{0}}\biggr) \biggr) \\ &= n_{\mathrm{tot}} \biggl( G_{\mathrm{ini}}^{0} + R T \left( x_{1} \ln x_{1} + x_{2} \ln x_{2} \right) + R T \ln\biggl(\frac{P_{\mathrm{fin}}}{P^{0}}\biggr) \biggr) \ . \end{align}
Now, that we have the Gibbs free energies of the initial and final state we simply need to subtract the former from the latter one in order to obtain the change in Gibbs free energy during the mixing process:
\begin{align} \Delta_{\mathrm{mix}}G &= G_{\mathrm{final}} - G_{\mathrm{ini}} \\ &= n_{\mathrm{tot}} \biggl( G_{\mathrm{ini}}^{0} + R T \left( x_{1} \ln x_{1} + x_{2} \ln x_{2} \right) + R T \ln\biggl(\frac{P_{\mathrm{fin}}}{P^{0}}\biggr) \biggr) \\ &\quad - n_{\mathrm{tot}} \biggl( G_{\mathrm{ini}}^{0} + x_{1} R T \ln\biggl( 1 + \alpha \frac{V_{2}}{V_{1}} \biggr) + x_{2} R T \ln(1 - \alpha) + R T \ln\biggl( \frac{P_{\mathrm{fin}}}{P^{0}} \biggr) \biggr) \\ &= n_{\mathrm{tot}} R T \left( x_{1} \ln x_{1} + x_{2} \ln x_{2} \right) - n_{\mathrm{tot}} R T \biggl( x_{1} \ln\biggl( 1 + \alpha \frac{V_{2}}{V_{1}} \biggr) + x_{2} \ln(1 - \alpha) \biggr) \qquad (5) \end{align}
Now you see why we went through those substitutions for $P_{1}$ and $P_{2}$. This way the $n_{\mathrm{tot}} R T \ln\Bigl(\frac{P_{\mathrm{fin}}}{P^{0}}\Bigr)$ terms cancelled in equation (5).
Differentiating equation (5) with respect to the temperature we get the entropy of mixing since $\frac{\partial G}{\partial T} \big|_{p, \{ n_{i} \}} = - S$
\begin{align} \Delta_{\mathrm{mix}} S &= - \frac{\partial \Delta_{\mathrm{mix}}G}{\partial T} \bigg|_{p, \{ n_{i} \}} \\ &= - n_{\mathrm{tot}} R \left( x_{1} \ln x_{1} + x_{2} \ln x_{2} \right) + n_{\mathrm{tot}} R \biggl( x_{1} \ln\biggl( 1 + \alpha \frac{V_{2}}{V_{1}} \biggr) + x_{2} \ln(1 - \alpha) \biggr) \end{align}
The first term $- n_{\mathrm{tot}} R \left( x_{1} \ln x_{1} + x_{2} \ln x_{2} \right)$ is just the usual entropy of mixing. The second term $n_{\mathrm{tot}} R \Bigl( x_{1} \ln\Bigl( 1 + \alpha \frac{V_{2}}{V_{1}} \Bigr) + x_{2} \ln(1 - \alpha) \Bigr)$ describes the contribution of the pressure equilibration to the entropy.
Solution 2:
I would like to give an alternative derivation for theorist's answer. You can get the same answer with statistical mechanics using a lattice model.
Let us discretize the container into $M_1$ respective $M_2$ cells. The volume of a cell is $V_{cell}$. Each gas particle fits exactly into one cell and can hop from cell to cell in a discrete manner. Since we are dealing with an ideal gas, the particles ignore each other. In other words, all particles can in principle occupy the same cell, i.e. all particles can always choose from all the cells. We therefore get the following number of possible states $\Omega$: $$\Omega_1 = (M_1)^{N_1} \\ \Omega_2 = (M_2)^{N_2} \\ \Omega_{mix} = (M_1+M_2)^{(N_1+N_2)}$$
where $N_i$ is the respective number of particles. If the states are degenerated, i.e. have the same energy, we can use Boltzmann's entropy formula: $$S = k_B\ln(\Omega)$$ $$\implies\Delta S=k_B\ln(\Omega_{mix})-k_B\ln(\Omega_1)-k_B\ln(\Omega_2)$$
When we plug in all $\Omega_i$ and summarize with logarithmic identities, we obtain: $$\Delta S=N_1k_B\ln\left( \frac{M_1+M_2}{M_1}\right)+N_2k_B\ln\left(\frac{M_1+M_2}{M_2}\right)$$
Finally, when we plug in $M_i = V_i/V_{cell}$ and $N_ik_B=n_iR$, we obtain theorist's solution: $$\Delta S = n_1R\ln\left( \frac{V_1+V_2}{V_1}\right)+n_2R\ln\left(\frac{V_1+V_2}{V_2}\right)$$ Bonus: If we consider the constant pressure case for an ideal gas by plugging in $V_i=n_i\cdot RT/p$: $$\Delta S = n_1R\ln\left( \frac{n_1+n_2}{n_1}\right)+n_2R\ln\left(\frac{n_1+n_2}{n_2}\right)$$
This expression can be reformed to OP's formula by applying logarithmic identities and $x_i=n_i/n_{tot}$: $$\Delta S = -n_{tot}R(x_1\ln x_1 + x_2\ln x_2)$$