This models the permaculture keyline design principle "slow it, spread it, sink it": a ditch dug on contour (a swale) intercepts overland flow and holds it so the soil has time to absorb it, instead of letting it run downhill and erode topsoil.
The field is a grid of cells with elevation h(i,j). Each simulation step applies three real hydrological processes:
1. Rainfall input: d += R·Δt (R = rainfall rate)
2. Infiltration: d -= min(d, I·Δt) (I = soil infiltration capacity, Green–Ampt style cap)
3. Overland flow: Q(i→j) ∝ (H_i − H_j), H = h + d (diffusive routing toward lower total head)
H = terrain elevation + water depth is the total hydraulic head. Water only flows to a neighboring cell with lower head, in proportion to the head difference — the same principle behind Manning's-equation overland-flow routing used in hydrology models, simplified to an explicit cellular scheme for real-time computation.
- Contour swales — shallow trenches running along lines of equal elevation. Because every point on a swale sits at the same head, water pools along its whole length instead of concentrating into a single downhill channel, giving infiltration far more time and area to act (longer residence time).
- Rainfall / infiltration rate sliders — control the input and soil "sink" terms directly in the equations above.
- Slope grade — steeper slopes raise the head gradient driving flow (3), which speeds runoff and lowers infiltration unless swales interrupt it.
- Water balance bar — tracks the exact conservation identity: rain fallen = infiltrated + still stored on the field + runoff that exited downhill.
Real-world relevance: this is the mechanism behind Keyline Design (P.A. Yeomans, 1950s Australia) and contour swale earthworks used across dryland permaculture and regenerative agriculture to raise soil moisture and reduce erosion without irrigation infrastructure.