Diffusion across an interface and conservation of mass I am reading a physiology book chapter (Mathematical Physiology, by Keener --Respiration chapter) about the gas exchange between capillaries and alveoli. It seems that this gas exchange can be modeled after some simple physical relationships. Since I am not usually studying physics, I do not fully understand some concepts that the author uses to derive a conservation law and I would appreciate any help. 
I do admit, however, that this question may be off-topic since it could be a mathematical lapsus rather than a physics question. 
Preliminaries
First, the author indicates that if a gas with partial pressure $P_g$ is in contact with a liquid, the steady-state concentration $U$ of gas is given by:
$$
U = \sigma P_s
$$
where $\sigma$ is the solubility of the gas in the liquid. I assume that this is a particular version of Henry's Law.
Then, it explains if there is a difference between the partial pressure of the gas ($P_g$) and the partial pressure on the fluid ($\frac{U}{\sigma}$), then there should be some flux between the gas and the fluid and the simplest model would be to assume that this flux is linearly proportional to the pressure difference:
$$
q = D_s \left(P_g - \frac{U}{\sigma}\right)
$$
Problem
The author then considers a segment of a capillary (a cylindrical tube) of length $L$, constant cross-sectional area $A$ and perimeter $p$, that is in contact with a gas with partial pressure $P_g$. The fluid moves through the tube with a velocity $v(x)$. Finally, they say that since mass is conserved:
$$
\frac{d}{dt} \left( A \int_{0}^{L} U(x,t) dt \right) = v(0)AU(0,t) - v(L)AU(L,t) + p \int_{0}^{L} q(x,t) dx
$$
Question
How is the relationship below derived? 
I understand that $A \int_{0}^{L} U(x,t) dt$ is in fact the total amount of the dissolved gas in the tube at a given time. I also understand how $\int_{0}^{L} q(x,t) dx$ represents the total flux of gas across the whole capillary wall. However, I fail to see what the two first elements of the right-hand represent and why is the left-side derived with respect to $t$.
 A: It's just the usual conservation law. When something is conserved then its amount in some observed region can't disappear but must be flowing in or out. So this means that time derivative of the integral of the quantity in a given volume (the LHS) must be equal to total flux associated with the quantity through a surface of that volume (the RHS).
In your case surface (and flux through it) splits into horizontal and vertical parts. Horizontal part is just diffusion across the wall due to pressure difference while vertical part is a fluid's flow through the tube. The amount that flows in depends on the concentration at a given location $U(0,t)$, the speed $v(0)$ at that location and the cross-section $A$. Similarly for the outflow (but note the minus sign).
A: Think about it physically. How much gas is in the tube? There are three sources:


*

*The gas coming in at $x=0$ which was already in solution.

*The gas being carried away by the fluid at the other end, $x=L$

*Diffusion across the walls of the tube.


These three terms are represented in the equation $$
\frac{d}{dt} \left( A \int_{0}^{L} U(x,t) dt \right) = v(0)AU(0,t) - v(L)AU(L,t) + p \int_{0}^{L} q(x,t) dx
$$
The first term is the velocity of the liquid, $v$, times the cross section, $A$, giving the total volume of liquid coming in at $x=0$. We multiply this by the concentration of gas in the liquid at $x=0$ to get the velocity that gas enters at $x=0$.
The second term goes in much the same way, but we have a negative sign because it is the gas which is leaving at the other end.
You say you understand that the third term as diffusion through the walls, which is correct.
