Divergence, surface integrals, and flux
Flux and surface integrals
Consider a surface \(S\). Let \(\bm{r}(u,v) = [x(u,v), y(u,v),z(u,v)]\) be a parametric position vector on a Euclidean vector space \(\mathbb{R}^3\). Furthermore, let \(\bm{F}: \mathbb{R}^3 \rightarrow \mathbb{R}^3\) be a vector-valued function of \(\bm{r}\) and let \(\bm{n}\) be a unit-normal vector on a surface \(S\). The \[\begin{align} \iint\limits_S \bm{F} \cdot \bm{n} \diff S \end{align}\] which integrates the normal of \(\bm{F}\) over the surface. We call this quantity the of \(\bm{F}\) out of the surface \(S\). This terminology comes from fluid flow, for which the flux is the mass flow rate out of \(S\). In general, the flux is a measure of a quantity (or field) passing through a surface. For more on computing surface integrals, see schey2005 and kreyszig2011.
Continuity
Consider the flux out of a surface \(S\) that encloses a volume \(\Delta V\), divided by that volume: \[\begin{align} \frac{1}{\Delta V} \iint\limits_S \bm{F} \cdot \bm{n} \diff S. \end{align}\] This gives a measure of flux per unit volume for a volume of space. Consider its physical meaning when we interpret this as fluid flow: all fluid that enters the volume is negative flux and all that leaves is positive. If physical conditions are such that we expect no fluid to enter or exit the volume via what is called a or a , and if we assume the density of the fluid is uniform (this is called an fluid), then all the fluid that enters the volume must exit and we get \[\begin{align} \frac{1}{\Delta V} \iint\limits_S \bm{F} \cdot \bm{n} \diff S = 0. \end{align}\]
This is called a , although typically this name is given to equations of the form in the next section. This equation is one of the governing equations in continuum mechanics.
Divergence
Let’s take the flux-per-volume as the volume \(\Delta V \rightarrow 0\) we obtain the following.This is called the of \(\bm{F}\) and is defined at each point in \(\mathbb{R}^3\) by taking the volume to zero about it. It is given the shorthand \(\Div\bm{F}\).
What interpretation can we give this quantity? It is a measure of the vector field’s flux outward through a surface containing an infinitesimal volume. When we consider a fluid, a positive divergence is a local decrease in density and a negative divergence is a density increase. If the fluid is incompressible and has no sources or sinks, we can write the continuity equation \[\begin{align} \Div\bm{F} = 0. \end{align}\]
In the Cartesian basis, it can be shown that the divergence is easily computed from the field \[\begin{align} \bm{F} = F_x \bm{\hat{i}} + F_y \bm{\hat{j}} + F_z \bm{\hat{k}} \end{align}\] as follows.Exploring divergence
Divergence is perhaps best explored by considering it for a vector field in \(\mathbb{R}^2\). Such a field \(\bm{F} = F_x \bm{\hat{i}} + F_y \bm{\hat{j}}\) can be represented as a “quiver” plot. If we overlay the quiver plot over a “color density” plot representing \(\Div\bm{F}\), we can increase our intuition about the divergence.
First, load some Python packages.
import numpy as np
import sympy as sp
import matplotlib.pyplot as plt
from matplotlib.ticker import LogLocator
from matplotlib.colors import *
from sympy.utilities.lambdify import lambdify
Now we define some symbolic variables and functions.
= sp.Symbol('x', real=True)
x = sp.Symbol('y', real=True)
y = sp.Function('F_x')(x, y)
F_x = sp.Function('F_y')(x, y) F_y
Rather than repeat code, let’s write a single function quiver_plotter_2D()
to make several of these
plots.
def quiver_plotter_2D(
={},
field=3, grid_decimate_x=8, grid_decimate_y=8,
grid_width=Normalize(), density_operation='div',
norm=True):
print_density= sp.symbols('x y', real=True)
x, y = sp.Function('F_x')(x, y), sp.Function('F_y')(x, y)
F_x, F_y = field
field_sub # Calculate density
= F_x.diff(x) + F_y.diff(y) if density_operation == 'div' else None
den if den is None:
raise ValueError(f'Unknown density operation: {density_operation}')
= den.subs(field_sub).doit().simplify()
den_simp if den_simp.is_constant():
print('Warning: density operator is constant (no density plot)')
if print_density:
print(f'The {density_operation} is:')
print(den_simp)
# Lambdify for numerics
= F_x.subs(field_sub)
F_x_sub = F_y.subs(field_sub)
F_y_sub = sp.lambdify((x, y), F_x.subs(field_sub), 'numpy')
F_x_fun = sp.lambdify((x, y), F_y.subs(field_sub), 'numpy')
F_y_fun if F_x_sub.is_constant:
= F_x_fun # Dummy
F_x_fun1 = lambda x, y: F_x_fun1(x, y) * np.ones(x.shape)
F_x_fun if F_y_sub.is_constant:
= F_y_fun # Dummy
F_y_fun1 = lambda x, y: F_y_fun1(x, y) * np.ones(x.shape)
F_y_fun if not den_simp.is_constant():
= sp.lambdify((x, y), den_simp, 'numpy')
den_fun # Create grid
= grid_width
w = np.mgrid[-w:w:100j, -w:w:100j]
Y, X # Evaluate numerically
= F_x_fun(X, Y)
F_x_num = F_y_fun(X, Y)
F_y_num if not den_simp.is_constant():
= den_fun(X, Y)
den_num # Plot
= plt.subplots()
fig, ax if not den_simp.is_constant():
= plt.get_cmap('coolwarm')
cmap = plt.pcolormesh(X, Y, den_num, cmap=cmap, norm=norm)
im
plt.colorbar()= grid_decimate_y, grid_decimate_x
dx, dy
plt.quiver(X[::dx, ::dy], Y[::dx, ::dy], F_x_num[::dx, ::dy], ='xy', scale=10)
F_y_num[::dx, ::dy], unitsfr'$F(x, y) = \left[{sp.latex(F_x.subs(field_sub))},' +
plt.title(fr'{sp.latex(F_y.subs(field_sub))}\right]$')
return fig, ax
Let’s inspect several cases.
= quiver_plotter_2D(field={F_x: x**2, F_y: y**2})
fig, ax plt.draw()
= quiver_plotter_2D(field={F_x: x*y, F_y: x*y})
fig, ax plt.draw()
= quiver_plotter_2D(field={F_x: x**2 + y**2, F_y: x**2 + y**2})
fig, ax plt.draw()
= quiver_plotter_2D(
fig, ax ={F_x: x**2/sp.sqrt(x**2+y**2), F_y: y**2/sp.sqrt(x**2+y**2)},
field=SymLogNorm(linthresh=.3, linscale=.3)
norm
) plt.show()
Online Resources for Section 5.1
No online resources.