M0.1 Counting Gate Crossings: Divergence and Flux
Builds on1 note
We cannot see inside the station
You manage a station with no interior camera. Counters record entries and exits at four gates.
Is the population inside increasing or decreasing, and at what rate?
Adding entries and subtracting exits works only if every crossing is counted. Trains can carry people through another part of the boundary.
How can we formalize boundary flow and then localize it to a small region?
DiscussionQ1
What are the region, boundary, measured quantity, and desired quantity?
Show the reasoning
Before subtracting counts, identify the objects.
The region is the station interior. Its total population is , and we seek .
The boundary separates inside and outside. Gates are traversable parts; walls have no crossing flow.
Counters measure net people crossing a boundary segment per time, with a chosen outward-positive sign convention.
Conservation connects crossings to enclosed change: no one appears or disappears inside. Complete boundary accounting is also required.
A sprinkler, a drain, and a corridor
To count people, speed alone is insufficient. Define the flow field , multiplying density by velocity. Its arrows represent transported amount.
Outward arrows around a sprinkler give positive net outflow; inward arrows around a drain give negative net outflow. Uniform corridor flow has equal inflow and outflow.
Shrink a surrounding region to each point and measure net outflow per area. The resulting signed local quantity is divergence.
Figure: positive divergence at a source, negative at a sink, and zero for uniform through-flow.
Express the local counting mathematically
Flux. In two dimensions, has units people per length per time. For a boundary element with outward unit normal , counts outward flow. Only the normal component crosses:
This is outward-positive flux. Conservation gives
Enclosed change equals net inflow, provided all changes arise from boundary crossings and there are no internal source terms.
Divergence. Consider a small rectangle. Horizontal outflow minus inflow is
Divide by area, add the vertical contribution, and take the limit:
Divergence adds directional outflow differences. tracks mass transport; instead measures local volume expansion. Population density requires the former.
Divergence theorem. Tile the region with small cells. Shared internal edges contribute equal and opposite flows, canceling and leaving only the external boundary:
For sufficiently regular fields and boundaries, integrated interior divergence equals boundary flux.
DetailsWhy do internal boundaries cancel exactly?
The same edge flow is for one cell and for its neighbor. Their sum is exactly zero. Taking a sufficiently regular continuum limit yields the divergence theorem.
State the assumptions behind the intuitive answer
The result. Population change equals negative outward flux. This is an exact conservation balance.
The assumptions. Include every traversable boundary and any internal sources. Train doors, staff exits, and emergency doors can invalidate a calculation based only on fare gates. A net gate inflow can coexist with a falling station population if a train carries more people away.
What divergence adds. Boundary counts describe total change. The density-weighted flow field allows local density-change calculations. Disagreement between them can indicate missing channels, measurement error, or incorrect assumptions.
Calculate the balance
The grid example verifies exact cancellation, then adds an unrecorded removal:
import numpy as np
n = 40; rho = np.full((n, n), 5.0)
Fx = 0.3 + 0.1*np.random.randn(n, n+1)
Fy = 0.1*np.random.randn(n+1, n)
inside = (slice(10, 30), slice(10, 30))
for leak in (0.0, 0.5):
N0 = rho[inside].sum()
div = (Fx[:, 1:] - Fx[:, :-1]) + (Fy[1:, :] - Fy[:-1, :])
rho_new = rho - div; rho_new[20, 20] -= leak
flux_out = Fx[10:30, 30].sum() - Fx[10:30, 10].sum() + Fy[30, 10:30].sum() - Fy[10, 10:30].sum()
print(f"actual {rho_new[inside].sum()-N0:+.3f}; boundary {-flux_out:+.3f}")
Without the removal, the numbers agree. With it, they differ by 0.5. In this grid code the extra removal is represented as a source/sink term rather than an explicit boundary edge.
Check your understanding
References
- Strang, G. Calculus. Wellesley-Cambridge Press; MIT OpenCourseWare RES.18-001
- Feynman, R. P., Leighton, R. B., Sands, M. The Feynman Lectures on Physics, Vol. II, Ch. 3: Vector Integral Calculus.
- Marsden, J. E., Tromba, A. J. Vector Calculus. W. H. Freeman.