# Continuity equation derivation from trajectories of point particles

The continuity equation, where $$\rho$$ is a conserved density advected by the velocity field $$\mathbf{v}$$,

$$\partial_t \rho(\mathbf{x},t) +\nabla \cdot [ \mathbf{v}(\mathbf{x},t) \rho(\mathbf{x},t)]=0$$

can be derived in several ways. I wonder if it can be derived as an opportune limit of a certain number $$N$$ of trajectories $$\mathbf{y}_i(t)$$ of point particles $$\dot{\mathbf{y}}_i(t) = \mathbf{v}_i(t)$$. In this case I expect that

$$\rho(\mathbf{x},t) = \sum_{i=1...N}\delta(\mathbf{x} - \mathbf{y}_i(t)) \, ,$$

where $$\delta$$ is the Dirac delta in three dimensions. How to introduce the field $$\mathbf{v}(\mathbf{x},t)$$ and arrive at the usual continuity equation? How to extrapolate from the particular $$\rho$$ that is "delta peaked" to a smooth density distribution (ie. some formal limit like $$N\rightarrow \infty$$)?

In such context, it may be suitable to define a function $$w$$, called weighting function, that to any point of space $$\mathbf{x}$$ associates a continuous fictional mass value.
This fictional mass value takes into consideration the mass $$m_i$$ of particles around its position and weights them with their relative position $$\mathbf{x}_i(t)-\mathbf{x}$$.
The condition we want to assess is that no mass is over or under weighted in the process, so that for a volume $$\mathcal{V}$$ in space $$w(\mathbf{x}_i(t)-\mathbf{x})\;\;\;\;\big|\;\;\;\;\int_{\mathcal{V}}\,\sum_i\,m_i\,w(\mathbf{x}_i(t)-\mathbf{x})\;dV_{\mathbf{x}}=\sum_i\,m_i$$ or equivalently, bringing integral in and simplifying mass $$\qquad w\equiv w(\mathbf{x}_i(t)-\mathbf{x})\;\;\;\;\big|\;\;\;\;\int_{\mathcal{V}}w(\mathbf{x}_i(t)-\mathbf{x})\;dV_{\mathbf{x}}=1\qquad\qquad\qquad\textbf{Weighting function}$$ It may be assessed that the following relation holds for $$w$$ $$\nabla w=\frac{\partial w(\mathbf{x}_i(t)-\mathbf{x})}{\partial\mathbf{x}}=\frac{\partial w(\mathbf{u}(\mathbf{x},\,t))}{\partial\mathbf{x}}=\frac{\partial w}{\partial\mathbf{u}}\;\frac{\partial \mathbf{u}}{\partial \mathbf{x}}=-\frac{\partial w}{\partial\mathbf{u}}$$ Then $$\frac{\partial w}{\partial t}=\frac{\partial w(\mathbf{u}(\mathbf{x} ,\, t))}{\partial t}=\frac{\partial w}{\partial\mathbf{u}}\cdot\,\frac{\partial \mathbf{u}}{\partial t}=-\nabla w\cdot\,\mathbf{v}_i=-\nabla\cdot\,(w\,\mathbf{v}_i)+w\,\nabla\cdot\,\mathbf{v}_i=-\nabla\cdot\,(w\,\mathbf{v}_i)$$ Eventually $$\boxed{\frac{\partial w}{\partial t}=-\nabla\cdot\,(w\,\mathbf{v}_i)}$$
We may define $$\qquad\qquad \rho_w(\mathbf{x} , \,t) \equiv\sum_i\,m_i\;w\qquad\qquad\qquad\qquad\qquad\textbf{Mass density}$$ $$\frac{\partial \rho_w}{\partial t}=\frac{\partial}{\partial t}\,\sum_i\,m_i\;w=\sum_i\,m_i\;\frac{\partial w}{\partial t}=-\sum_i\,m_i\;\nabla\cdot\,(w\,\mathbf{v}_i)=-\nabla\cdot\,\bigg(\sum_i\,m_i\,\mathbf{v}_i\;w\bigg)$$ Eventually $$\boxed{\frac{\partial \rho_w}{\partial t}+\nabla\cdot\,(\rho_w\,\mathbf{v}_w)=0}$$ Having defined $$\qquad\qquad\mathbf{v}_w(\mathbf{x},\,t)\equiv\frac{1}{\rho_w}\sum_i\,m_i\,\mathbf{v}_i\;w\qquad\qquad\qquad\qquad\textbf{Velocity field}$$