Notebook · Simulation 27 min read

Every drop, every three metres

Skybrudd floods a Norwegian town with a cloudburst or a river in flood, in your browser, on your own graphics card. How the water is calculated, from laser terrain and Horton soil to the catchments above town, the sea, NVE's flood zones and today's river discharge, the equations, the bugs that looked like floods, every data source it calls, and the WGSL that runs it all in seconds.

Skybrudd answers one question: what happens to this place if a cloudburst hits it, or the river rises? You pick a spot on the map, choose how much rain or how big a flood, and a minute later you can watch the water run down the streets, pool against walls and fill the underpass. The water is computed on your own GPU, in the page, with no server doing the work.

This piece is about how that water is calculated. It covers what goes in, the equations, the numbers I had to get right, every service the calculation calls, and the checks a result has to pass before anyone else gets to see it.

The flood in a browser: a dithered town with water spreading between the houses
A title card from the explainer film. The right half is a real run, drawn the way the film draws everything.
  • 147 456cells per step512 × 288, 3 m each for the default area
  • 4.8 sa 3 km cloudburston the GPU, against 25 s on eight CPU threads
  • × 13water from outsideBalderheia gets 13 times its own rain from the hills
  • 10⁻¹⁴mass balance errorrelative, double precision

The ground, to the metre#

Water goes where the ground sends it, so everything starts with the terrain. Kartverket publishes a laser-scanned terrain model of most of Norway at 1 m resolution. An area in Skybrudd is a 16:9 rectangle. The result file always holds 256 × 144 cells, and the solver works on cells half that size: 512 × 288, 3 m each for the default 1.5 km area.

On top of the terrain go the things that change where water flows:

  • Buildings from OpenStreetMap raise the bed by their height. A building with four storeys and no height tag is 13 m tall: 3 m per storey plus 1 m of roof. Rain on a roof runs off its edges.
  • Roads are graded. Real roads are cut into slopes and built up over dips, so they are level across and smooth along. Averaging laser points smears that out and tilts the road with the hill, which lets water cross it sideways. Each drivable road's centreline profile is smoothed over 20 m and burned back in, with a cut-or-fill shoulder. No change is larger than 2.5 m, so a smoothed road never dams a valley.
  • Land cover sets the roughness and how much water the ground can take.
  • Drains come from NVDB, the road authority's database: gullies take up to 20 l/s, grates 30 l/s, and culverts are pipes under the embankment.
Surface Manning nn Infiltration
Road 0.015 none
Roof 0.020 none
Open water 0.030 none
Open ground 0.035 × 1.0
Grass 0.040 × 1.2
Forest 0.100 × 2.0

Going from 6 m to 3 m cells uncovered one problem. A footprint that rasterises with a missing cell in the middle leaves a 3 m pit walled in by roofs. Every drop that lands on those roofs drains into the pit, which fills to the eaves: 5 m of water in a hole the size of a parking space. Any patch of ground smaller than 50 m² that buildings wall in on every side now counts as roof.

The rain, shaped like a storm#

There are four scenarios; the river flood has a section of its own further down. A cloudburst puts 0.5 to 6 hours of rain on the area in 10-minute steps, then runs 6 dry hours so the water can drain away. The year scenario takes the place's total precipitation for last year and drops it in 24 hours. The forecast scenario takes the rain MET says is coming, and is described below.

Rain never falls evenly, so the intensity follows a Chicago design storm around a peak at tpt_p:

i(t)∝(1+∣t−tp∣b)−0.8,tp=0.4 D,b=1.5 h⋅D24 hi(t) \propto \left(1 + \frac{|t - t_p|}{b}\right)^{-0.8}, \qquad t_p = 0.4\,D, \quad b = 1.5\ \text{h} \cdot \frac{D}{24\ \text{h}}

Each step is the shape averaged over 20 sub-steps, then scaled so the total comes out exact. A climate factor multiplies the total; 1.4 is the usual allowance for cloudbursts towards 2100. Here is 49 mm in an hour, times 1.4:

Cloudburst, 49 mm in 1 h × 1.4

0 mm/h50 mm/h100 mm/h150 mm/h0–10 · Intensity: 47.9 mm/h10–20 · Intensity: 78.3 mm/h20–30 · Intensity: 137.8 mm/h30–40 · Intensity: 69 mm/h40–50 · Intensity: 44.7 mm/h50–60 · Intensity: 33.9 mm/h0–1010–2020–3030–4040–5050–60
Minutes into the storm. The steps add up to 68.6 mm; the peak is 2.9 times the mean.

The rain that is forecast#

A design storm answers "what if". When NVE puts out an orange flood warning, the question is what the rain that is actually coming will do. So the forecast scenario uses no shape at all. You choose an hour and up to 48 hours, and the page fetches MET Nordic's hourly precipitation for the centre of the area through Open-Meteo. That series is the rain, hour for hour, with nothing reshaped or scaled. Then come 12 dry hours for the water to drain. Open-Meteo stamps each hour's rain at the end of the hour, so the value for 02:00 is the rain from 01:00 to 02:00. The series is read one hour on, so hour 0 really is the hour that starts at the chosen time.

Everything else stays the same: the same Horton soil, today's seNorge ground state, the catchments above the area with their Clark hydrographs fed by the same series, and the drains. No areal reduction is applied, because forecast rain is already an average over MET's 1 km grid cell rather than a peak at a point.

On 25 October 2026 NVE warned of 40–60 mm in 12 hours over Telemark, Buskerud and Vestfold. Here is MET's forecast for Skien, as it stood the evening before, run through the model:

MET's forecast for Skien, Saturday and Sunday

0 mm10 mm20 mm30 mmSat 01 · Rain in 3 h: 0 mmSat 04 · Rain in 3 h: 1.3 mmSat 07 · Rain in 3 h: 0.8 mmSat 10 · Rain in 3 h: 1.5 mmSat 13 · Rain in 3 h: 1.9 mmSat 16 · Rain in 3 h: 1.3 mmSat 19 · Rain in 3 h: 4.3 mmSat 22 · Rain in 3 h: 2.7 mmSun 01 · Rain in 3 h: 2 mmSun 03 · Rain in 3 h: 15.9 mmSun 06 · Rain in 3 h: 22.4 mmSun 09 · Rain in 3 h: 4 mmSun 12 · Rain in 3 h: 2.9 mmSun 15 · Rain in 3 h: 5 mmSun 18 · Rain in 3 h: 1.8 mmSun 21 · Rain in 3 h: 1.2 mmSat 01Sat 07Sat 13Sat 19Sun 01Sun 03Sun 06Sun 12Sun 18Sun 21
Local time; the clocks go back at 03:00 on Sunday, so the bar from Sun 01 covers 01:00 to 02:00 twice. 69 mm in 48 h, of which 38 mm fall in six hours on Sunday morning, at most 8.4 mm in an hour.

Spread over two days the rain looks harmless: 8 mm in the worst hour is nothing next to a cloudburst. What makes it a flood is that the ground is already wet and the hills above town all drain at once.

The soil fills up#

The first version let every pervious cell soak up water at a fixed rate forever. For a short storm that is roughly right. For a year's rain in a day it is badly wrong, because a forest at 10 mm/h would swallow 240 mm and still ask for more.

Now infiltration follows Horton's curve. Dry ground takes water fast, and the rate decays towards a steady fcf_c (5 mm/h by default) until the soil has taken its storage SS. After that, only slow percolation continues:

f(t)=fc(1+2 e−t/τ),τ=30 min,until∫0tf dt=S=120 mm,then f=0.2 fcf(t) = f_c \left(1 + 2\,e^{-t/\tau}\right), \quad \tau = 30\ \text{min}, \qquad \text{until} \int_0^{t} f\,dt = S = 120\ \text{mm}, \quad \text{then } f = 0.2\,f_c

The trick that makes this cheap on a GPU is that ff depends only on the time since the rain started, so every cell shares one curve and no cell needs a soil state of its own. A cell takes its land-cover factor times the curve, and only the water actually standing on it. The time the soil fills, tfullt_\text{full}, is found once by bisection, and the integral is exact between any two times, so the step size never changes how much water soaks in. On the day of the run, seNorge's ground state scales fcf_c and SS by the unsaturated fraction, and by another 0.1 when the ground is frozen.

seNorge's cells are a kilometre across, and along the coast many of them are mostly sea or bare rock. Those answer 0 % saturation, or nothing at all, while the land next to them is soaked. Risør's own cell said 0 % on a day when the cell 1.2 km inland said 54 %. Taken at face value, that would make the wettest coast in the warning the driest ground in the model. Now a cell with 0 % or no value is replaced by the nearest cell within 3 km that has soil water, and the run says how far away that cell was.

Infiltration capacity, f_c = 5 mm/h

  • Open ground
  • Forest (× 2)
0 mm/h10 mm/h20 mm/h30 mm/h0 · Open ground: 15 mm/h0.25 · Open ground: 11.1 mm/h0.5 · Open ground: 8.68 mm/h1 · Open ground: 6.35 mm/h2 · Open ground: 5.18 mm/h3 · Open ground: 5.02 mm/h4 · Open ground: 5 mm/h6 · Open ground: 5 mm/h8 · Open ground: 5 mm/h12 · Open ground: 5 mm/h16 · Open ground: 5 mm/h20 · Open ground: 5 mm/h22 · Open ground: 5 mm/h23 · Open ground: 1 mm/h24 · Open ground: 1 mm/h30 · Open ground: 1 mm/h36 · Open ground: 1 mm/h42 · Open ground: 1 mm/h48 · Open ground: 1 mm/h0 · Forest (× 2): 30 mm/h0.25 · Forest (× 2): 22.1 mm/h0.5 · Forest (× 2): 17.4 mm/h1 · Forest (× 2): 12.7 mm/h2 · Forest (× 2): 10.4 mm/h3 · Forest (× 2): 10 mm/h4 · Forest (× 2): 10 mm/h6 · Forest (× 2): 10 mm/h8 · Forest (× 2): 10 mm/h12 · Forest (× 2): 10 mm/h16 · Forest (× 2): 10 mm/h20 · Forest (× 2): 10 mm/h22 · Forest (× 2): 10 mm/h23 · Forest (× 2): 2 mm/h24 · Forest (× 2): 2 mm/h30 · Forest (× 2): 2 mm/h36 · Forest (× 2): 2 mm/h42 · Forest (× 2): 2 mm/h48 · Forest (× 2): 2 mm/h00.52481622243648
Hours since the rain started (uneven steps). The soil is full after 23.0 h: 120 mm in open ground, 240 mm in forest.

Water from beyond the edge#

This was the biggest gap. A town in a valley also gets the rain that fell on the hills above it, and the first version simply did not. Its edges only let water out.

Now the model searches 20 km around the area on Terrarium elevation tiles (zoom 11, about 60 m), routes every pixel downhill with a priority flood that fills pits so even lakes drain somewhere, and adds up the area of every pixel whose path enters the box. That gives a list of catchments, each with an area, a place where it crosses the edge, and a time of concentration TcT_c: the longest travel time to the edge, from a velocity at every pixel.

vhill=4.92S(TR-55, unpaved),vchannel=R2/3S0.045,R=0.3 A0.3v_\text{hill} = 4.92\sqrt{S} \quad (\text{TR-55, unpaved}), \qquad v_\text{channel} = \frac{R^{2/3}\sqrt{S}}{0.045}, \quad R = 0.3\,A^{0.3}

Each catchment's rain, less the same Horton losses, becomes a Clark unit hydrograph. The HEC time–area curve spreads the excess over TcT_c, and a linear reservoir with K=0.6 TcK = 0.6\,T_c smooths it:

A(x)A={1.414 x1.5x≤121−1.414 (1−x)1.5x>12Ok+1=c Ik+(1−c) Ok,c=ΔtK+Δt/2\frac{A(x)}{A} = \begin{cases} 1.414\,x^{1.5} & x \le \tfrac12 \\ 1 - 1.414\,(1-x)^{1.5} & x > \tfrac12 \end{cases} \qquad O_{k+1} = c\,I_k + (1-c)\,O_k, \quad c = \frac{\Delta t}{K + \Delta t/2}

A cloudburst is local, so over catchments larger than 1 km² the rain is reduced by the Flood Studies Report's areal reduction factor. The largest catchment above Balderheia is 18.0 km² with TcT_c = 4.3 h, which reduces the storm above by 11 %. Its runoff enters through two edge cells:

18 km² above Balderheia, the cloudburst above

  • Time–area only
  • After the reservoir
0 m³/s50 m³/s100 m³/s0 · Time–area only: 0 m³/s0.5 · Time–area only: 16.8 m³/s1 · Time–area only: 45 m³/s1.5 · Time–area only: 63.3 m³/s2 · Time–area only: 77 m³/s2.5 · Time–area only: 86.4 m³/s3 · Time–area only: 80.8 m³/s3.5 · Time–area only: 68 m³/s4 · Time–area only: 51.9 m³/s4.5 · Time–area only: 25.9 m³/s5 · Time–area only: 2.8 m³/s5.5 · Time–area only: 0 m³/s6 · Time–area only: 0 m³/s6.5 · Time–area only: 0 m³/s7 · Time–area only: 0 m³/s7.5 · Time–area only: 0 m³/s8 · Time–area only: 0 m³/s8.5 · Time–area only: 0 m³/s9 · Time–area only: 0 m³/s9.5 · Time–area only: 0 m³/s10 · Time–area only: 0 m³/s10.5 · Time–area only: 0 m³/s11 · Time–area only: 0 m³/s11.5 · Time–area only: 0 m³/s12 · Time–area only: 0 m³/s0 · After the reservoir: 0 m³/s0.5 · After the reservoir: 1.1 m³/s1 · After the reservoir: 6.6 m³/s1.5 · After the reservoir: 15.2 m³/s2 · After the reservoir: 25 m³/s2.5 · After the reservoir: 35.2 m³/s3 · After the reservoir: 43.9 m³/s3.5 · After the reservoir: 49.3 m³/s4 · After the reservoir: 51.1 m³/s4.5 · After the reservoir: 49 m³/s5 · After the reservoir: 42.3 m³/s5.5 · After the reservoir: 34.9 m³/s6 · After the reservoir: 28.8 m³/s6.5 · After the reservoir: 23.7 m³/s7 · After the reservoir: 19.5 m³/s7.5 · After the reservoir: 16.1 m³/s8 · After the reservoir: 13.2 m³/s8.5 · After the reservoir: 10.9 m³/s9 · After the reservoir: 9 m³/s9.5 · After the reservoir: 7.4 m³/s10 · After the reservoir: 6.1 m³/s10.5 · After the reservoir: 5 m³/s11 · After the reservoir: 4.1 m³/s11.5 · After the reservoir: 3.4 m³/s12 · After the reservoir: 2.8 m³/s01.534.567.5910.512
Hours after the storm starts. 51.8 mm of excess rain, 0.9 million m³, peaking at 51 m³/s four hours after the storm.

This changes the answer a lot. In most of the eleven demo areas, more water now comes in across the edge than falls on the area itself:

Water from outside, as a multiple of the rain on the area

  1. Bærum16.3×
  2. Balderheia M13.4×
  3. Rissa5.2×
  4. Sørumsand4.9×
  5. Balderheia L3.8×
  6. Verdal3×
  7. Orkanger2.6×
  8. Borregaard1.8×
  9. Gjerdrum1.4×
  10. Tune0.8×
  11. Eidsvoll0.06×
Eidsvoll sits on a ridge and gets almost nothing; Bærum and Balderheia sit at the bottom of long valleys.

Rivers get no base flow. The laser terrain already shows them at their usual level, so only the storm's rise is added.

The sea takes it#

Water that reaches the sea should leave. The first versions had no sea at all: OpenStreetMap draws the coast as a line, and the laser terrain shows the sea surface as flat ground at 0 m. So rain that ran down to the harbour stopped there and spread out over the "ground" offshore, and coastal towns came out far wetter than they are.

Now ground at or below 0.5 m above sea level (NN2000), not buildings or roads, that connects to the area's edge through more such ground counts as sea. A sea cell is held at sea level: whatever runs into it leaves the area as outflow. In Rissa this took the flooded area from 172 ha down to 13 ha, and the 13 ha left are on land. The flooded area also ignores rivers, lakes and the sea now, since they hold water without being flooded.

Kartverket's laser has no ground under the sea, so the holes it leaves are filled from AWS Terrarium tiles, which do carry depths. Some Terrarium pixels in the Oslofjord decode to −2 484 m. The sea is held at sea level, so the depth never mattered to the water, but a run at Sandvika was refused when it was shared, since terrain that deep cannot be real. Terrarium is now floored at −100 m, the lowest the server accepts.

When the river rises#

A cloudburst is local and short. A river flood is neither: Glomma rises for days on snowmelt and rain that fell hundreds of kilometres upstream. Simulating that from rain would mean the whole catchment, 41 000 km² for Glomma, far outside what a page should compute. But NVE has already done the hydraulics for the rivers that matter most. Their flood zone maps (flomsonekart) show the land a river covers in a 100-year flood, a 200-year flood, and a 200-year flood with climate allowance, computed from surveyed river cross-sections.

A flood zone is an extent, not a water level. But where the zone's edge meets dry land, the water stands exactly at the height of the ground. That gives the level. For every river cell, which is open water in the zone or within 30 m of it, not the sea:

  1. find the distance d0d_0 to the zone's nearest edge on dry, open ground,
  2. take the median ground height of the edge within d0+40d_0 + 40 m,
  3. smooth that level over six passes along the river, so it falls steadily downstream,
  4. and hold the cell at that level, times a share LL (1 for the zone's own flood).

The level rises and falls as smoothstep curves, s(x)=x2(3−2x)s(x) = x^2(3 - 2x): up over 6 hours, held until hour 18, down by hour 24, and six more hours to drain.

hheld(t)=L (ηedge−z)⋅{s(t/6 h)t<6 h1t<18 h1−s((t−18 h)/6 h)t<24 h0afterh_\text{held}(t) = L\,\big(\eta_\text{edge} - z\big)\cdot\begin{cases} s(t/6\,\text{h}) & t < 6\ \text{h} \\ 1 & t < 18\ \text{h} \\ 1 - s\big((t - 18\,\text{h})/6\,\text{h}\big) & t < 24\ \text{h} \\ 0 & \text{after} \end{cases}

The held cells work like the sea, which is the same mechanism with a held depth of 0. After every substep they are set to their level. What ran into them leaves as outflow, and what they lacked counts as water given by the river. Everything else is the ordinary solver: the river pushes over its banks, past houses, along roads and into hollows the zone map may not show, and it drains back as the level falls. The zones say how high; the solver says where the water goes.

At Borregaard in Sarpsborg, the 200-year zone holds 17.6 ha of Glomma on average 2.9 m and at most 5.2 m above its normal level. At the peak, 13.5 ha of land is under water. On the GPU it takes 23 seconds.

A waterfall made the first river run pour 29 000 m³/s. Sarpsfossen drops about 20 m through the area. The held cells above and below the falls sit at very different levels, and the solver did what it does with a 20 m step in the water surface: it pushed water through at the speed cap, every substep, from held cell to held cell. Both cells were reset afterwards, so the map looked fine and the water balanced, but the river was "giving" seven times Glomma's 200-year flood. Nothing needs to move between two held cells, since both are set again after the step. Now the faces between them carry nothing, and neither does a held cell at the area's edge. What is left is the water that really goes over the banks.

Water exchanged by the held river at Borregaard, mean over 30 h

  1. Flow between held cells29,134 m³/s
  2. Only across the banks2,884 m³/s
For comparison, Glomma's 200-year flood is about 4 000 m³/s, by the Gumbel fit in the next section.

What the river carries today#

The flood zone is a what-if. To make it about today, the app asks NVE's HydAPI what the river carries right now. The hard part is finding the right gauge. The nearest gauge with flood statistics to Borregaard is on Vidnesbekken, a 43 km² brook, which says nothing about Glomma. So:

  • the river is the area's largest in NVE's river network (Elvenett), the one with the highest Strahler order;
  • a gauge counts when it is in the same watercourse (the REGINE number before the dot, 002 for Glomma), within 60 km, and drains at least 4order−34^{\text{order} - 3} km², so a river of order 8 needs a gauge with over 1 000 km²;
  • it must have hourly discharge and flood statistics.

For Borregaard that is Solbergfoss, 40 km upstream, with 40 464 km². The gauges at Sarpsfoss itself publish no discharge, because the river is regulated there. From the gauge's mean annual flood Qˉ\bar Q and 50-year flood Q50Q_{50}, a Gumbel distribution gives the 100- and 200-year floods:

QT=Qˉ+KT s,KT=−6π(0.5772+ln⁡ln⁡TT−1),s=Q50−QˉK50Q_T = \bar Q + K_T\,s, \qquad K_T = -\frac{\sqrt 6}{\pi}\left(0.5772 + \ln\ln\frac{T}{T - 1}\right), \qquad s = \frac{Q_{50} - \bar Q}{K_{50}}

How high the river stands then follows a wide channel's rating, where depth goes as Q0.6Q^{0.6}. Measured from the mean flow QmeanQ_\text{mean}, which is roughly where the laser saw the river, the share of the zone's rise is

L=Q0.6−Qmean0.6QT0.6−Qmean0.6L = \frac{Q^{0.6} - Q_\text{mean}^{0.6}}{Q_T^{0.6} - Q_\text{mean}^{0.6}}

and the held river is scaled by LL. As I write, Solbergfoss measures 671 m³/s against a mean of 682 m³/s, so Glomma is at its normal level and LL is 0. The app says so and offers only the full zone.

Glomma at Solbergfoss: share of the 200-year zone's rise

00.51682 · L: 01000 · L: 0.141500 · L: 0.322235 · L: 0.553000 · L: 0.753492 · L: 0.884019 · L: 1682100015002235300034924019
Discharge in m³/s: the mean flow, then up through the mean annual flood (2 235) and the 50-year flood (3 492) to the 200-year flood by Gumbel (4 019).

Shallow water, local-inertial#

The solver is a local-inertial scheme from the LISFLOOD-FP family (Bates et al., 2010). It solves the 2D shallow-water equations without the advection term. That holds for floods over land, where friction dominates, and it means each face of the grid can be updated on its own, which suits a GPU.

Depth hh lives in cell centres, and unit discharge qq (m²/s) on the faces between them. With the water level η=z+h\eta = z + h, the depth that can cross a face is

hf=max⁡(ηi,ηj)−max⁡(zi,zj)h_f = \max(\eta_i, \eta_j) - \max(z_i, z_j)

so only the water above the top of a kerb or wall gets across it. The momentum update blends the old discharge with its two neighbours along the same axis (de Almeida et al., 2012), treats gravity explicitly and Manning friction semi-implicitly:

qn+1=θqn+1−θ2(qℓn+qrn)−g hf Δt ηj−ηiΔx1+g Δt n2 ∣qn∣ / hf7/3,θ=0.7q^{n+1} = \frac{\theta q^n + \tfrac{1-\theta}{2}\left(q^n_{\ell} + q^n_{r}\right) - g\,h_f\,\Delta t\,\dfrac{\eta_j - \eta_i}{\Delta x}}{1 + g\,\Delta t\,n^2\,|q^n|\,/\,h_f^{7/3}}, \qquad \theta = 0.7

Then come three rules that keep it honest. The velocity is capped so a waterfall off a roof stays at a Courant number of α\alpha or below. Outflow is limited so no cell gives away more water than it holds. Continuity adds up the rest:

∣q∣≤hf α ΔxΔt|q| \le h_f\,\frac{\alpha\,\Delta x}{\Delta t}
hin+1=hin+ΔtΔx(∑qin−∑qout)+(r−f) Δt−dih_i^{n+1} = h_i^n + \frac{\Delta t}{\Delta x}\Big(\sum q_\text{in} - \sum q_\text{out}\Big) + (r - f)\,\Delta t - d_i

where rr is the rain, ff the infiltration and did_i what the drains take from the cell.

The time step follows the fastest gravity wave in the domain, and is never longer than a third of a second per metre of cell:

Δt=min⁡(α Δxg hmax, Δx3),α=0.5\Delta t = \min\left(\frac{\alpha\,\Delta x}{\sqrt{g\,h_\text{max}}},\ \frac{\Delta x}{3}\right), \qquad \alpha = 0.5

A 2 m deep pond in 3 m cells gives Δt=0.5⋅3/9.81⋅2≈0.34\Delta t = 0.5 \cdot 3 / \sqrt{9.81 \cdot 2} \approx 0.34 s, so a seven-hour storm run takes about 40 000 steps. Water leaves at the edges at normal depth, q=h5/3S/nq = h^{5/3}\sqrt{S}/n. Rain, inflow, storage, outflow, infiltration and drains are tracked separately and balance to about 10−1410^{-14} of the total.

Three bugs that looked like floods#

Explicit schemes fail quietly. The water still balances and the map still looks wet, but the numbers are wrong. When I went back to check whether the water was calculated correctly, I found three faults.

The Courant number was too high. At α=0.7\alpha = 0.7, deep pools sloshed by metres between neighbouring cells, and the fastest velocity in a storm run reached 275 m/s. LISFLOOD-FP recommends 0.5–0.7, and 0.5 is stable in every test I have, deep pools included.

Fastest velocity in a storm run

  1. α = 0.7, fixed 5 s cap275 m/s
  2. α = 0.5, Δx/3 cap, θ = 0.74 m/s
Before: the first storm run I checked. After: the Borregaard cloudburst at 3 m. Real water in a town moves at a few metres per second.

The time-step cap was fixed. A cap of 5 s regardless of cell size let thin sheet flow grow a checkerboard. On a plane, the peak depth of a test storm came out at 16 cm where the kinematic wave gives 9 to 10. The cap is now Δx/3\Delta x/3, and a test compares the plane against the kinematic wave at 3, 6 and 12 m cells.

Deep, smooth water oscillated. The plain local-inertial scheme grows oscillations on deep water with little friction. De Almeida's blending of each face with its neighbours, θ=0.7\theta = 0.7, damps them while keeping the mass exact. A lake-at-rest test, still water over rough ground with a building standing in it, must give a fastest velocity below 10−910^{-9} m/s.

One step, nine kernels#

The same Rust code runs on the server, in the desktop app and in the browser, and so does the same WGSL: the server and the desktop app run it natively through wgpu, and fall back to the CPU solver when there is no GPU. Compiled to WebAssembly, it runs in a worker: it fetches the terrain, buildings, drains and catchments, builds the grids, and hands them to a WGSL port of the solver. Every time step is nine compute passes:

// one time step, in dispatch order
ctrl      // one thread: next Δt from the CFL, h_max and the time left in the frame
old       // copy every face's discharge, so the blend reads the previous step
fluxes    // the momentum update of every face, with the velocity cap
limit     // per cell: scale outgoing fluxes so nothing goes below zero
depths    // continuity, rain, Horton, the sea and a held river, max-depth and arrival trackers
inflows   // pour each catchment's hydrograph into its edge cells
sinks     // gullies and grates take up to their capacity
culverts  // move water through the pipes under the roads
network   // share the municipal pipe capacity among the wet road cells

The hard part was precision. GPUs compute in 32-bit floats, which carry about seven significant digits. At 400 m above sea level, that leaves the bed with about 0.03 mm of resolution, which is enough to lose a film of rain. So the bed is uploaded relative to the lowest point in the area, and depths and the clock are carried as pairs of floats, a high part and a low part, that together hold more than 40 bits.

The GPU and the CPU solver give the same answer. On the same storm, mean max depth differs by 0.1 mm and every volume total agrees within 0.01 %.

A 3 km cloudburst, 147 456 cells, 40 000 steps

  1. WebGPU4.8 s
  2. Rust, 8 threads25 s
  3. WebAssembly, 1 thread189 s
A run in the browser: the area is fetched and prepared in WebAssembly, then the GPU steps it.

Solve fine, store coarse#

Ditches, kerbs and the gaps between houses decide where water goes, so the solver runs at twice the file's resolution. Every 2 × 2 block of solver cells then becomes one file cell, by rules that keep what matters from each:

Field From the four solver cells
Depth the mean, so the volume is unchanged
Velocity mean discharge divided by mean depth
Max depth the deepest
Arrival time the earliest moment any of them reaches 10 cm
Max discharge the largest

Halving the cell size costs about eight times the work: four times as many cells and twice as many steps, since Δt\Delta t scales with Δx\Delta x. On the GPU that is still under five seconds for a storm. The difference in the results is large. Narrow channels between buildings now carry water that 6 m cells averaged away. Here are the eleven demos before and after the whole review: finer cells, Horton soil, inflow and the stability fixes.

Deepest water in each demo area

  • Before
  • After
0 m2 m4 m6 mBærum · Before: 2.72 mBærum · After: 3.13 mBald. L · Before: 3.7 mBald. L · After: 4.42 mBald. M · Before: 2.91 mBald. M · After: 2.83 mBorreg. · Before: 2.69 mBorreg. · After: 2.55 mEidsvoll · Before: 2.17 mEidsvoll · After: 1.98 mGjerdrum · Before: 3.36 mGjerdrum · After: 4.24 mOrkanger · Before: 2.18 mOrkanger · After: 2.77 mRissa · Before: 1.39 mRissa · After: 2.49 mSørumsand · Before: 3.55 mSørumsand · After: 5.11 mTune · Before: 3.08 mTune · After: 5.29 mVerdal · Before: 3.81 mVerdal · After: 4.91 mBærumBald. MEidsvollOrkangerSørumsandVerdal
Max depth over the whole run. Water from upstream raises most areas; Balderheia M, Borregaard and Eidsvoll drop slightly.

The result file is plain binary: a JSON header, then terrain, buildings, land cover, the three trackers, and one frame of depth and velocity every ten minutes.

"FLOM" · u32 version · u32 json_len · JSON metadata · pad to 4
f32 terrain[N] · f32 building_h[N] · u8 landcover[N] · pad
f32 max_depth[N] · f32 arrival_h[N] · f32 max_q[N]
per frame:  u16 depth_mm[N] · i16 vx_cms[N] · i16 vy_cms[N]      N = 256 × 144
A finished run: water depth, buildings at risk and the timeline.

Trust, but run it again#

Anyone can share a run to the public map, and the run was computed on their machine, so the server does not take the file on trust. Before it keeps one, it checks:

  • the grid matches the centre and width, in Norway, and the rain series matches the scenario (a forecast is taken as it came, but must be whole hours starting on the hour, at most 48 of them, 0–200 mm each, then exactly 12 dry hours);
  • frames, totals and trackers agree, and the water balances within 0.1 %, inflow included;
  • the soil storage and every catchment's inflow volume are what the model gives, and the water a held river gave counts in the balance;
  • the terrain matches Kartverket's (median at most 1.5 m off), and the catchments, worked out again from the terrain around the area, match the ones in the file;
  • for a river flood, the flood zones in the file are NVE's, and the server holds the river again from them for the steps it re-runs;
  • the last rain step and a random one are simulated again from the frame before, and must land within 5 % of the volume, 10 % of the flooded cells and 3 cm of mean depth.

For a refined run the server rebuilds the 3 m grids from Kartverket's terrain and the buildings and roads listed in the file, and spreads each file cell's water over its four solver cells by level-pooling, before it steps the run forward.

Water that looks like water#

Rivers, lakes and the sea are drawn as water of their own kind, on the map and in 3D. A water cell is sea when it reaches the edge at sea level. It is river when its smoothed surface slopes by more than 0.2 ‰, with a current from Manning's equation. Otherwise it is lake. The laser terrain is the water's surface, so in 3D each body gets an assumed bed under it, sloping from the shore to a few metres for a river and 15 to 25 m for a lake or the sea. The shallows are see-through, and the deep is dark.

Waves come from the current wind (Open-Meteo): four trains spread around the wind direction, each at its deep-water speed, longer on the sea than on a lake. Whitecaps cover the share of the sea that Monahan's fit gives for that wind. Waves too small to draw at a distance are not simply dropped. Their slope variance from Cox and Munk, σ2=0.003+0.00512 U\sigma^2 = 0.003 + 0.00512\,U, roughens the sun's reflection instead, so far water shows a broad, soft glint path rather than a sparkling mirror. Flood water is silty: grey-brown, darker as it deepens, with a dull sheen roughened by its own flow. That is how a flooded street looks, and it keeps the blue for the rivers the water came from.

Every service it calls#

The whole calculation runs on open data. This is every endpoint a run touches, roughly in the order an area is prepared:

What Service Used for
Terrain, 1 m Kartverket, hoydedata.no ImageServer DTM the ground, and the sea at ≤ 0.5 m
Surface, 1 m Kartverket, hoydedata.no DOM and DTM_punkttetthet building heights, tree canopy, how good the laser data is
Building outlines Kartverket's topographic map, cache.kartverket.no WMTS footprints traced from the map tiles
Roads, water, land cover, facilities OpenStreetMap through Overpass (overpass-api.de, two mirrors as fallback) grading roads, roughness, infiltration, what is at risk
Gullies, grates, culverts Statens vegvesen NVDB, nvdbapiles.atlas.vegvesen.no drains, and pipes under the roads
Last year's precipitation Open-Meteo archive (ERA5), archive-api.open-meteo.com the year scenario
Rain forecast MET Nordic through the Open-Meteo forecast API, api.open-meteo.com (models=metno_seamless) the forecast scenario, hour by hour
Ground today seNorge, NVE's GridTimeSeries at gts.nve.no soil saturation, frost, snow and melt
Terrain around the area AWS Terrain Tiles (Terrarium), s3.amazonaws.com/elevation-tiles-prod catchments 20 km out, the water from beyond the edge
Flood zones, flood awareness, landslides, quick clay, river network NVE's ArcGIS services, kart.nve.no the river flood, and the other hazards shown
River discharge now NVE HydAPI, hydapi.nve.no (with a key, through the server) today's river level
Polluted ground Miljødirektoratet, kart.miljodirektoratet.no what a flood could wash out
Warnings MET MetAlerts, api.met.no turning a warning into a cloudburst run
Wind now Open-Meteo forecast, api.open-meteo.com waves on the water
Place search Kartverket's place names (api.kartverket.no/stedsnavn), Nominatim finding a place

The browser can't call all of them itself. seNorge sends no CORS headers, and HydAPI needs a key that must stay off the page, so those two go through the site's own server. That server keeps the shared runs and checks them, but it never runs a whole flood.

What it does not model#

The underground pipe network is the biggest gap. Gullies drain at full capacity for the whole run, which is optimistic once the pipes are full, and the municipal network is an assumed rate per area because its layout is not open data. Buildings have no doors, so water piles up against walls and flows around them. A very deep pool usually means a culvert or underpass that is missing from NVDB. Erosion, debris and blocked inlets, which do much of the damage in real cloudbursts, are not modelled at all.

A forecast run puts one point's rain on the whole area and on every catchment above it. In a long valley the hills 15 km up can get quite different rain from the town. And a forecast changes: a run made on Friday evening shows Friday evening's forecast, and needs to be run again when MET updates.

The river flood is only as good as NVE's zones. Where no zone is mapped there is no river flood, and the level comes from where the zone's edge meets the ground: an edge drawn against a wall, an embankment or the area's border gives a poorer level than one on open ground. The river is held, not routed. Dams, bridges and the flood wave travelling down the valley are in NVE's zone, not in Skybrudd. Today's level uses one rating exponent and a Gumbel fit from two numbers. That is fine for "how close to the zone are we", not for a forecast. And regulated rivers often have no public gauge with discharge at all.

You can try your own street at skybrudd.dagthom.as.

  • simulation
  • webgpu
  • rust
  • hydrology
  • wasm