Divergence

Level UniversityDifficulty ★★★★★Concept⌖ Open in the map

What is it?

∇⋅F=∂xP+∂yQ+∂zR\nabla\cdot F = \partial_x P + \partial_y Q + \partial_z R: the net outflow per unit volume at a point. Positive at sources, negative at sinks, zero for incompressible flow.

Why does it exist?

To express conservation laws locally. "Mass is neither created nor destroyed" becomes ∂tρ+∇⋅(ρu)=0\partial_t\rho + \nabla\cdot(\rho u) = 0; "water does not compress" becomes ∇⋅u=0\nabla\cdot u = 0; "electric charge produces electric field" becomes Gauss's law.

Intuition

Draw a tiny box around the point and count what flows out minus what flows in, divided by the box's volume. A tap is a source (positive divergence), a drain a sink (negative). In a river, water entering a region must leave it: divergence zero.

Formal definition

∇⋅F=∂P∂x+∂Q∂y+∂R∂z=lim⁡V→{p}1∣V∣∮∂VF⋅n dS.\nabla\cdot F = \frac{\partial P}{\partial x} + \frac{\partial Q}{\partial y} + \frac{\partial R}{\partial z} = \lim_{V\to\{p\}}\frac{1}{|V|}\oint_{\partial V}F\cdot n\,\dd S.

Formulas

∇⋅F=∂xP+∂yQ+∂zR\nabla\cdot F = \partial_x P + \partial_y Q + \partial_z R
∂ρ∂t+∇⋅(ρ u)=0\frac{\partial\rho}{\partial t} + \nabla\cdot(\rho\,u) = 0
continuity equation (conservation of mass)
∇⋅E=ρε0\nabla\cdot E = \frac{\rho}{\varepsilon_0}
Gauss's law

Example

F=(x,y,z)F = (x, y, z) points straight out from the origin: ∇⋅F=3\nabla\cdot F = 3 everywhere — every point is a source. F=(−y,x,0)F = (-y, x, 0) rotates around the zz-axis: ∇⋅F=0\nabla\cdot F = 0 — it swirls but nothing is created.

Why does it matter?

Every incompressible fluid solver in games and films (stable fluids, FLIP) has a "projection" step that removes the divergence of the velocity field by solving a Poisson equation. Electromagnetic simulators and finite-volume CFD codes are organized around fluxes and divergence.

Where it shows up in computing

  • Fluid dynamics and CFD★★★★★fundamentalPhysics and simulation

    Incompressibility ∇⋅u=0\nabla\cdot u = 0 is enforced each step by a pressure projection.

  • Electromagnetism (Maxwell's equations)★★★★★fundamentalPhysics and simulation

    Two of Maxwell's equations are divergence equations: ∇⋅E=ρ/ε0\nabla\cdot E = \rho/\varepsilon_0, ∇⋅B=0\nabla\cdot B = 0.

Where it shows up in AI

  • Generative models★★★★★advancedAI and machine learning

    Continuous normalizing flows track log-density with the divergence of the velocity field (instantaneous change of variables).

Where is it used?

Computing topics reachable from here, through the chain of ideas that leads to them:

What depends on it

Exercises

1Computation

Compute ∇⋅F\nabla\cdot F for F=(x2y, −xy2, z)F = (x^2y,\ -xy^2,\ z).

Solution

2xy−2xy+1=12xy - 2xy + 1 = 1.

↑ ↓ to navigate · ↵ · Esc