\chapter{Divergence}

After implementing the glyphs it was time for the divergence. This is a value which can be calculated using the already known value at each vertex and that of its
neighbors. \\

\section{Description}

The divergence shows the amount of mass which is compressed or expanded. If mass enters the field at some point, called a source point, then that point will have a
positive divergence value. If mass exits the field at some point, called a sink point, then that point will have a negative divergence value. \\

\section{Implementation}

The calculation of the divergence is rather simple, once you get it. For the divergence of the velocity it looks like:

$$ \nabla \cdot v = \frac{\partial v}{\partial x} + \frac{\partial v}{\partial y} = $$
$$ \frac{v_x(i + 1, j) - v_x(i, j)}{cell_x} + \frac{v_y(i + 1, j) - v_y(i, j)}{cell_y}$$

Where $ v_x(i, j) $ is the x-value at the gridpoint (i, j) and similar for the y-value. The $ cell_x $ and $ cell_y $ are the width and height of the cell. We also
implemented the divergence of the force field with the same formula. \\

The definition of the divergence says high values should appear where matter is injected and low values where matter exits the field. This means high values should
appear in front of the mouse while dragging and low values behind it. \\

\section{Difficulties}

Although we have a good definition of what the divergence is and what the result should look like, it is rather difficult to verify it using the simulation. This is
a know difficulty. The divergence can be verified by setting up a test environment where the outcome of the divergence should be obvious. For instance create one
source and one sink point. \\
