Considering a medium with a mass density $\rho: \mathbb{R}^4 \to \mathbb{R}$ and a velocity field $\mathbf{v}: \mathbb{R}^4 \to \mathbb{R}^3$ consisting of a orientable finite sized surface element $d\mathbf{A} \in \mathbb{R}^3$.
> *Definition*: a surface must be orientable for the surface integral to exist. It must be able to move along the surface continuously without ending up on the "other side".
We then have a volume $dV \in \mathbb{R}$ defined by the parallelepiped formed by $dV = \langle d\mathbf{x}, d\mathbf{A} \rangle$ with the vector $d\mathbf{x} = \mathbf{v} dt$, for a time interval $dt \in \mathbb{R}$. The mass flux $d\Phi$ per unit of time through the surface element $d\mathbf{A}$ may then be given by
$$
d \Phi = \rho \langle \mathbf{v}, d\mathbf{A} \rangle.
$$
The mass flux $\Phi: \mathbb{R} \to \mathbb{R}$ through a orientable finite sized surface $A \subseteq \mathbb{R}^3$ is then given by
The (mass) flux density is a vector-valued function of position and time that expresses the rate of transport of a quantity per unit of time of area perpendicular to its direction.
The mass flux $\Phi$ through $A$ may then be given by
> for all $(\mathbf{x}, t) \in \mathbb{R}^4$ for a volume $V \subset \mathbb{R}^3$ with closed orientable boundary surface $A \subset V$.
Note that this "dot product" between the nabla operator and the flux density $\mathbf{\Gamma}$ does not imply anything and is only there for notational sake. An alternative to this notation is using $\text{div } \mathbf{\Gamma}$ to denote the divergence.
The definition of the divergence can be interpreted with the particle mass balance for a medium with a particle density $n: \mathbb{R}^4 \to \mathbb{R}$ and a velocity field $\mathbf{v}: \mathbb{R}^4 \to \mathbb{R}^3$. Furthermore we have that the particles are produced at a rate $S: \mathbb{R}^4 \to \mathbb{R}^3$.
For a volume $V \subseteq \mathbb{R}^3$ with a closed orientable boundary surface $A \subseteq \mathbb{R}^3$ we have that the amount of particles inside this volume for a specific time is given by
$$
\int_V n(\mathbf{x}, t) dV,
$$
for all $t \in \mathbb{R}$. We have that the particle flux through $A$ is given by
for all $t \in \mathbb{R}$ and we have that the particle production rate in this volume $V$ is given by
$$
\int_V S(\mathbf{x}, t)dV,
$$
for all $t \in \mathbb{R}$. We conclude that the sum of the particle flux through $A$ and the time derivative of the particles inside the volume $V$ must be equal to the production rate inside this volume $V$. Therefore we have
Assuming the system is stationary the time derivative of the particles inside the volume $V$ must vanish. The divergence is then defined to be the total production for a position $\mathbf{x} \in V$.
## Divergence in curvilinear coordinates
> *Theorem*: the divergence of a flux density $\mathbf{\Gamma}: \mathbb{R}^4 \to \mathbb{R}^3$ for a curvilinear coordinate system is given by
Please note that the scaling factors may also depend on the position $\mathbf{x} \in \mathbb{R}^3$ depending on the coordinate system.
It has been found that the volume integral over the divergence of a vector field is equal to the integral of the vector field itself over the surface that bounds the volume. It is known as the divergence theorem and is given below.
> *Theorem*: for a volume $V \subset \mathbb{R}^3$ with a closed and orientable boundary surface $A \subset V$ with a continuously differentiable flux density $\mathbf{\Gamma}: \mathbb{R}^4 \to \mathbb{R}^3$ we have that