# Mass conservation in fluid dynamics

I am trying to derive the mass conservation equation:

In one of the step we are given the equation to find Fluid mass gained through a small element of the surface 𝑑𝑆 in a time 𝑑𝑡 is:

I don't understand how the equation is got.

Here is diagram i was given

Mass is equal to density times volume, in your case: $$dM = \rho \cdot dV.$$

To compute $$dV$$, you need the volume of a parallelogram with base area $$dS$$ and (perpendicular) height $$h$$ so that $$dV = dS \cdot h$$. Your base area is $$dS = dA$$ in your sketch, and the height $$h$$ is the distance travelled perpendicular to $$dS$$.
Since $$\hat{\mathbf{n}}$$ is by definition normal to $$dS$$, the height is just the projcection of the total distance travelled $$\ell$$ onto this axis, so $$h = \boldsymbol{\ell}\cdot \hat{\mathbf{n}}$$.
What is $$\ell$$? Distance is equal to velocity times time: $$\ell = \mathbf{u}\cdot dt$$.

The minus sign is probably because mass is flowing out of your surface and hence it's a loss.

Putting it all together:

$$dM = -\rho \cdot dV = -\rho\, \mathbf{u}\cdot \hat{\mathbf{n}}\,dS\, dt$$

The given equation $$dm=-\rho\ \mathbf{u}\cdot\hat{n}\ dSdt$$ or $$\frac{dm}{dt}=-\rho \ \mathbf{u}\cdot\hat{n}\ dS$$ On the left-hand side, You have a rate at which the mass is changing in the given volume. On the right-hand side, You have the mass flux that goes out of the volume in time $$dt$$ multiplied with density. That way it makes sense.

Now How to derive this:

Note that $$\hat{n}$$ is a unit vector perpendicular to the surface. We emphasize that $$\mathbf{u}$$ is the velocity of a fluid at a given point $$(x,y,z)$$ in space and at a given time $$t$$. The mass of fluid flowing in unit time through an element $$d\mathbf{S}$$ of the surface bounding this volume is $$\rho \mathbf{u}\cdot d\mathbf{S}$$; the magnitude of the vector $$d\mathbf{S}$$ is equal to the area of the surface element, and its direction is along normal. $$\rho \mathbf{u}\cdot d\mathbf{S}=\rho \mathbf{u}\cdot \hat{n}dS$$ For time dt this would give the above relation $$dm=\rho \mathbf{u}\cdot d\mathbf{S} dt$$ The vector $$\mathbf{j}=\rho \mathbf{u}$$ is called the mass flux density.