# Filling of a gas in a cylinder

The problem statement is as follows:

An insulated rigid vessel of volume $V$ initially contains $N_i$ moles of an ideal gas at temperature $T_i$. A pipe is now connected to the vessel and the same type of gas (but held at a different constant temperature $T_\text{in}$ in the pipe) is slowly pumped into the vessel until the total number of moles in the vessel becomes $N_f$. Obtain an explicit expression for the final temperature in the vessel in the form $T_f = f(T_i, T_\text{in}, N_f/N_i, \gamma)$ where $\gamma = C_p/C_v$, the ratio of molar isobaric heat capacity of the gas $C_p$ to the molar isochoric heat capacity of the gas $C_v$, both of which are independent of temperature. Assume there is negligible heat transfer between the gas in the tank and the vessel walls during the process.

My thoughts are that the energy it takes to heat the initial moles in the tank, $N_i$, to the final temperature, $T_f$, is equal to $(N_i)(C_v)(T_f-T_i)$. Would this be equal to the energy lost by the incoming gas $(N_f-N_i)(C_p)(T_\text{in}-T_f)$? Then all one would need to do is isolate $T_f$ in terms of the other variables. I am unsure if I'm missing some energy term and if my equating of $\Delta U$ of the preexisting gas to the $\Delta H$ of the incoming gas is correct.

It looks similar to this problem in this book ("FUNDAMENTALS OF ENGINEERING THERMODYNAMICS" by By E. RATHAKRISHNAN) on page 67 (uniform flow process):

You perform an energy balance on the control volume, and simplifying leads to: $$(N_f-N_i)*h_{in}=N_f u_f-N_i u_i$$
With: $$u_f = c_vT_f$$ $$u_i = c_vT_i$$ $$h_{in} = c_pT_{in}$$
Therefore: $$T_f = (1-N_i/N_f).\gamma.T_{in}+ T_i.(N_i/N_f)$$