adiabatic work done by gas Suppose we have an adiabatic box with a fixed volume $V$ and contains $n_0$ mol of gas at pressure $p_0$ and temperature $T_0$. Now the box is punctured by a small hole and gas from the outside flows in. The outside (surrounding) has a pressure of $p$ and a temperature of $T_0$. Assume the internal energy of $n$ mol of gas at temperature $T$ is $nc_v T$. 
What is the final temperature in the box?
I tried the above problem but couldn't get far; I can get the temperature $T$ in terms of $T_0, R, c_v$ if the box is empty at first (ie. a vacuum). $\left(T = T_0 \frac{c_v + R}{c_v}\right)$
For this problem my thinking is something like:
$\Delta Q = 0$, so $\Delta U = \Delta W$
Then the gas outside has to do both boundary and shaft/flow work
The boundary work is done as the gas outside is expanding against the pressure $p_0$ in the box and
The shaft/flow work is done as the gas enters the box through the hole
However this is where I can't quite continue
Is $\Delta W = \Delta(PV) = P\Delta V + V\Delta P$? Or is $\Delta W = P\Delta V + PV$?
Furthermore, if $\Delta W = P\Delta V + PV$, then is the $P$ in $PV$ equal to $p - p_0$?
Finally, if, as the temperature of the gas originally in the box increases due to the work done by the outside gas, in order to calculate the final temperature in the box we need to know how much gas from outside entered, how can we do this?
Thanks. 
 A: The shaft work is the amount of work by the system on its surroundings, over and above the work required to push mass into and out of the control volume.  For this problem this shaft work is zero.
The open system first law energy balance on the control volume becomes: $$\Delta U=\Delta nh_{in}$$ or $$(n_0+\Delta n)C_vT_f-n_0C_vT_0=\Delta n(C_v+R)T_0$$This gives:  $$\frac{T_f}{T_0}=1+\frac{\Delta n}{n_0+\Delta n}\frac{R}{C_v}\tag{1}$$
The final pressure is going to be equal to the outside pressure p.  From the ideal gas law we have, from the initial condition, $$p_0V=n_0RT_0$$and, from the final condition, we have:$$pV=(n_0+\Delta n)RT_f$$So, $$\frac{T_f}{T_0}=\frac{p}{p_0}\frac{n_0}{(n_0+\Delta n)}\tag{2}$$
Eqns. 1 and 2 provide two equations in the two unknowns $T_f$ and $\Delta n$.  The solution for $T_f$ is as follows:
$$\frac{T_f}{T_0}=\frac{\gamma}{1+(\gamma-1)(p_0/p)}$$
A: This Answer provides an entirely different method of solving the present problem, based on treating the box and surroundings as a closed system (and thus using the closed system version of the first law of thermodynamics).  This is the approach alluded to by @pglpm in one of his comments.  Rather than considering the surroundings outside the box as being infinite, we consider the gas outside the box as being enclosed within a larger adiabatic container of finite volume.  We then solve this problem in the limit as the outer container volume becomes infinite.
Here are the parameters employed in the present analysis:
Box:
$n_0$ = number of moles of gas in box initially
V = Volume of box
$T_0$ = Initial Temperature
$p_0$ = Initial Pressure
n = number of moles in box in final state
T = Temperature in box in final state
p* = Pressure in box in final state (identical to final pressure outside box)
Outside Enclosure:
$n_{s0}$ = number of moles of gas in enclosure initially
$V_s$ = Volume of enclosure
$T_0$ = Initial temperature
p = Initial pressure
$n_s$ = Final number of moles in enclosure
T* = Final temperature of gas in enclosure
p* = Final pressure of gas in enclosure (identical to final pressure in box)
From the ideal gas law, we have:
$$n_0=\frac{p_0V}{RT_0}\tag{1a}$$
$$n=\frac{p^*V}{RT}\tag{1b}$$
$$n_{s0}=\frac{pV_S}{RT_0}\tag{1c}$$
$$n_s=\frac{p^*V_S}{RT^*}\tag{1d}$$
As shown in Example 6.10 of Fundamentals of Engineering Thermodynamics by Moran et al, when a gas within an adiabatic enclosure escapes very slowly (in our case into the box), the gas that still remains inside the enclosure at any time during the process has suffered an adiabatic reversible expansion. This means that the final pressure and temperature of the gas in the enclosure will be less than the initial pressure and temperature.  Furthermore, quantitatively, we will have that:
$$p^*\left(\frac{V_s}{n_s}\right)^{\gamma}=p\left(\frac{V_s}{n_{s0}}\right)^{\gamma}$$or equivalently, $$\frac{n_s}{n_{s0}}=\left(\frac{p^*}{p}\right)^{1/\gamma}$$or equivalently,$$n_s=\frac{pV_S}{RT_0}\left(\frac{p^*}{p}\right)^{1/\gamma}\tag{2}$$Moreover, we have:
$$\frac{T^*}{T_0}=\left(\frac{p^*}{p}\right)^{\frac{\gamma - 1}{\gamma}}\tag{3}$$
For the closed system consisting of the box and the rigid insulated enclosure, there is no work done by the system on its surrounding and no heat exchange between the system and its surroundings.  Therefore, from the version of the first law of thermodynamics applicable to a closed system, the change in internal energy of this combined system is zero.  Initially, the gas in both the enclosure and the box are at the same temperature, $T_0$.  In the final state of the system, the $n_s$ moles of gas in the enclosure are at T* and the n moles of gas in the box are at T.  Therefore, from the first law:
$$nC_v(T-T_0)+n_sC_v(T^*-T_0)=0\tag{4}$$From a mass balance on the system, the number of moles of gas in the initial state is equal to the number of moles of gas in the final state:
$$n+n_s=n_0+n_{s0}\tag{5}$$If we substitute Eqns. 1 into Eqns. 4 and 5, we obtain:$$V\left(1-\frac{T_0}{T}\right)+V_S\left(1-\frac{T_0}{T^*}\right)=0\tag{6}$$and$$\left(V\frac{T_0}{T}+V_S\frac{T_0}{T^*}\right)=\frac{p_0V+pV_S}{p^*}\tag{7}$$
Combining Eqns. 6 and 7 yields:
$$p^*=\frac{V_S}{(V_S+V)}p+\frac{V}{(V_S+V)}p_0\tag{8}$$According to Eqn. 8, the final pressure p* is just a weighted average of the initial pressures in the enclosure and the box, weighted in terms of the volumes of the two containers.
We can now determine the final temperature T* in the enclosure by combining Eqns 3 and 8 to yield:
$$\frac{T^*}{T_0}=\left(\frac{V_S}{(V_S+V)}+\frac{V}{(V_S+V)}\frac{p_0}{p}\right)^{\frac{\gamma - 1}{\gamma}}\tag{9}$$
If we substitute this into Eqn. 6 and solve for T, the final temperature in the box, we obtain:
$$\frac{T}{T_0}=\frac{1}{\left[1+\frac{V_S}{V}\left(1-\frac{\left(1+\frac{V}{V_S}\right)^{(\gamma-1)/\gamma}}{\left(1+\frac{V}{V_S}\frac{p_0}{p}\right)^{(\gamma-1)/\gamma}}\right)\right]}\tag{10}$$If we take the limit of this relationship as $V/V_S$ approaches zero (i.e., the volume of the enclosure becomes infinite), we obtain:$$\frac{T}{T_0}=\frac{\gamma}{1+(\gamma-1)(p_0/p)}\tag{11}$$
This is exactly the same result we obtained in the previous analysis using the open system version of the first law of thermodynamics.
