Skip to content

ocean: the eWave wake solver, on the CPU and the GPU (O8) - #1174

Merged
transfix merged 11 commits into
masterfrom
feat/ocean-ewave-gpu
Nov 13, 2026
Merged

transfix merged 11 commits into
masterfrom
feat/ocean-ewave-gpu

Conversation

@transfix

Copy link
Copy Markdown
Owner

O8 in docs/roadmap/OCEAN-AND-WEATHER-ROADMAP.md (section 6, C1, C3 and C5): Tessendorf's eWave, the solver for the waves bodies make. It is exact for any dispersion relation, so a moving body leaves a true Kelvin wake. There are two pieces: a deterministic CPU window in cvc::ocean (O8a), and the same window on the GPU in cvcGL (O8b), checked against each other.

O8a: cvc::ocean::ewave (CPU)

  • The window. An N × N window of cell dx, with one depth per window. Its state is the surface height h and the surface velocity potential φ, packed as z = h + iφ. Each step:
    1. a forward FFT;
    2. H and Φ separated through Hermitian symmetry;
    3. the exact update with κ = |k| tanh(|k| d) and ω = √(g κ), with k = 0 and the Nyquist modes handled;
    4. damping, e^(−γ k² dt) plus a global rate;
    5. the inverse FFT;
    6. in real space: the mask (1 open water, 0 land, values between for absorbing beaches), the edge sponge, and the sources (add_height and a whole-field add_heights for C2's footprints).
  • Exact for any dt, with no CFL limit. A beach's absorption is a rate per second (beach_rate), not per step.
  • Deterministic. det:: math, built without FMA contraction.

Measured in ocean_ewave_test (12 tests):

  • Exact for any dt: a standing mode at ω dt from 1.65 to 4.0 rad over 400 steps, deep and at 1.5 m, misses by at most 6.6e-14 m on 0.3 m. The test computes ω itself.
  • Energy: with no damping, mask or sponge it drifts at most 7.9e-14 over 2000 steps.
  • A Gaussian drop makes a round ring (crest heights vary 2.9 % over 16 rays). Its envelope moves at 1.019 m/s against the dominant wavelength's group velocity of 1.000.
  • A straight wall (O8's exit): nothing passes a half-plane wall, and the reflection comes back. A thin 3 m wall band passes 4.6 % of the incident amplitude; land masked as a whole region is exact.
  • The sponge leaves 0.02 % of the energy after 30 s.
  • Shallow water: a long pulse in 1 m of water travels at 3.108 m/s against √(g d) = 3.132.
  • The Kelvin wake (Phase C's exit): a moving Gaussian footprint applied as C2's −(ζ(t) − ζ(t − dt)) source leaves a wake whose envelope half-angle fits within 1.5° of 19.47° at 2.5 and 3.0 m/s, read at the 30, 40 and 50 % edge thresholds.
  • Pinned digest 8f51571acc023425, measured on Windows MSVC; CI checks it on Linux and macOS.
  • Cost per step on one thread, on a loaded machine: 0.16–0.22 ms at N = 64, 0.6–1.0 ms at 128 and 2.7–3.5 ms at 256.

O8b: EWave (GPU, cvcGL)

  • Shared butterflies. OceanFFT's butterfly passes move to src/cvcGL/ocean/OceanButterfly.{h,cpp}, which adds the forward transform (conjugated twiddles). OceanFFT and EWave share it, and OceanFFT's output is unchanged: cvcgl_ocean_band's table matches O7b's digit for digit.

  • EWave holds z = h + iφ in an RG32F ping-pong. Each step is 34 passes at 256²:

    • 16 forward butterflies;
    • one update pass that separates H and Φ by reading texels k and −k;
    • 16 inverse butterflies;
    • one real-space pass (normalise, mask, sponge, sources). A source adds one pass.

    The shaders are WebGL2-portable fragment shaders, and every pass disables the scissor test (O7b's lesson).

  • cvcgl_ewave runs the same scenario on the GPU and on the CPU class: a drop beside a wall, a beach band, the sponge, both dampings, a field source and two step sizes. It checks:

    • that they agree within float tolerance;
    • that the GPU reflects off the wall too (exactly 0 beyond it, with the reflection returning);
    • the measured pass count.

    It skips without float render targets, as cvcgl_ocean_fft does. GPU time per step at 256² on the Intel Arc iGPU, while other builds ran: 0.28–1.23 ms.

  • THIRD_PARTY_NOTICES.md names OceanButterfly (ABYSSAL, MIT).

Checked locally (Windows Release, GL build)

  • ocean_ewave_test 12/12, ocean_sea_test 16/16 and ocean_shore_test 16/16.
  • cvcgl_ewave passes, with 0 checks failed; before the review fixes it passed 7 runs in a row.
  • cvcgl_ocean_fft and cvcgl_ocean_band pass, the band table unchanged.

Independent reviews found five issues in O8a and four in O8b, all low severity. The real ones are fixed:

  • beach absorption depended on the step rate;
  • a wall check passed by construction (now a thin-wall leak test);
  • the standing-mode test took ω from the library;
  • the Kelvin threshold was chosen after seeing the result (now read at three thresholds);
  • the GPU pass count was a constant, not a count;
  • the cost paragraph was stale.

Known limits

  • A crest reflects as a trough. The mask is a Dirichlet wall (h = φ = 0); a real vertical wall reflects a crest as a crest. This is fine for drawing, and a no-flux option can follow if it shows.
  • Thin obstacles leak a little, because the mask is a lid on water that the spectral operator still couples under. Hulls and breakwaters only a few cells wide pass a few per cent.
  • Not here (O9): drawing the wake in lsystem_coast, body sources from immersion, moving the window with the camera or boat, and a mask from water_bodies.

…(O8a)

cvc::ocean::ewave runs Tessendorf's eWave (roadmap C1, C3, C5) on an
n x n window: h and phi packed as one complex field, one forward and one
inverse FFT a step, each wavenumber moved on exactly for any dt in one
depth, then the mask, the edge sponge and the sources in real space.
det math and fft.h, built without FMA contraction, so a window gives
the same bits on every platform; its digest is pinned.

ocean_ewave_test checks the exact mode oscillation, energy conservation,
the ring's group velocity and isotropy, reflection off a straight wall,
the sponge, shallow-water speed, the Kelvin wake angle at two speeds,
the digest and the refusals, and prints the step's cost.
- A beach mask value is now a damping rate, beach_rate (1 - m), applied as
  exp(-rate dt) like the sponge, so a beach absorbs the same share per
  second at any step size. Land (m = 0) is still zeroed every step. New
  test: a beach band leaves 68.95 / 68.96 / 68.89 % of a ring's energy
  after 10 s at 30, 60 and 10 Hz. The pinned digest moves to
  0xa4933455f6946eca.
- New test for a wall band with open water behind it: a 3 m band lets
  through 4.6 % of the incident amplitude (held below 6 %), a 6 m band less.
- The standing-mode test computes omega from the dispersion relation
  itself instead of the library's omega().
- The Kelvin test runs the source 140 m in a 512^2 window with an 8 s ramp,
  so the rows it reads are steady wake. It checks the edge at 30, 40 and
  50 % of the row maximum, at 2.5 and 3.0 m/s.
- Roadmap section 6: the as-built block gets the new measurements, a
  labelled diagnostic for the wrap-around share of thin-wall leakage, and a
  note that the update is still unchecked against the eWave paper.
EWave (src/cvcGL/ocean) runs the CPU eWave's window in float with
fragment passes: z = h + i phi in RG32F, the forward FFT, an update
pass that separates H and PHI at k and -k and applies the exact
per-mode update and damping, the inverse FFT, and a real-space pass
for the normalisation, the mask's beach, the sponge and land. 34
passes a step at 256^2. Sources go into h at once, as on the CPU.

The butterfly LUT, pass and pass setup move from OceanFFT.cpp into
OceanButterfly.{h,cpp}; the forward transform conjugates the twiddle
in the shader. OceanFFT's output is unchanged.

cvcgl_ewave runs one scenario on both windows (GPU vs CPU within
2.3e-5 of the RMS field), the wall test on the GPU, and the passes and
GPU time per step.
Count the passes step() renders instead of adding passesPerStep()'s
formula: OceanButterfly counts its own passes and EWave counts the update,
real-space and source passes, so cvcgl_ewave's 34-pass check (and a new
one-pass check for addDrop) measures something.

Say in EWave.h that only the mask is held before init(); setState, addDrop,
addHeights and step do nothing until init() succeeds.

Name OceanButterfly.{h,cpp} and the cvcgl_ocean_band and cvcgl_ewave tests
in the ABYSSAL notice, and correct roadmap section 6's Cost paragraph: a
cascade is 35 passes, so three are 105 and eWave adds about 32 % by pass
count, not the +60 % the old count of 57 gave.
@transfix
transfix enabled auto-merge (squash) November 12, 2026 08:28
#1159 (O7c) kept the last source sea_surface found in a thread_local, so
the velocity a fluid field reads after a cell's height at the same point
and time did not invert the sideways move again. A thread_local that
keeps state between calls is a static cache, which libcvc's no-singletons
rule forbids (VOLROVER-LIBRARY-PORTS-ROADMAP.md 1.3,
tools/singleton_scan). #1159's release-grpc job, where the scan runs, was
cancelled, so the scan never judged it; the next PR that merges master
would fail that lane on it.

The memo now belongs to the caller:

- sea_surface::source_memo, and height() / velocity() overloads that take
  one. The plain reads share nothing.
- fluid_surface::height_with / velocity_with and a surface_memo the
  caller owns; the defaults ignore it. ocean_surface passes it to the sea.
- field_set::apply keeps one memo per cell, for the cell's height and its
  velocity at the same clipped centre.

The memo is keyed on the point, the time and the digest as before, so
every value is unchanged.
…finite

GCC's glibc declares ::finite(double), so inside EWave's member functions an unqualified
finite() found both it and the file's own helper and was ambiguous; MSVC has no ::finite,
so only the Linux lanes failed to build cvcgl_ewave. Rename the helper; nothing else
changes.
…ocal

The writable-data scan (#1152 made its allowlist a ratchet) refuses process-wide state, and
sea_surface::source kept its last source in a thread_local (O7c, #1159), so every PR's
package-linux release-grpc lane now fails on master's code. The memo moves into the time's
frame, under the mutex the frame already has for its lattice: a frame is the surface at one
time, so the point alone is the key, and as a memo of a pure function it changes no value.
ocean_sea_test (19, pins unchanged) and physics_field_test (22, goldens unchanged) pass; the
exact height-and-velocity pair still costs about what it did (3.8 us, 1.76 us on the lattice).
@transfix

Copy link
Copy Markdown
Owner Author

This branch carried #1193's fix for the sea's source memo, so the writable-data scan would pass. #1193 was closed as superseded by #1181, Joe's pick, so I swapped it:

Until #1181 merges, this PR's diff includes #1181's 10 files. Once #1181 lands they match master, and this PR merges with only its own changes.

The other order is safe too: the branch now carries exactly #1181's code, so whichever merges first, the master that results was tested. Physics and ocean tests pass locally on Windows Release.

@transfix
transfix merged commit 0078189 into master Nov 13, 2026
29 of 33 checks passed
@transfix
transfix deleted the feat/ocean-ewave-gpu branch November 13, 2026 07:21
transfix added a commit that referenced this pull request Nov 13, 2026
transfix added a commit that referenced this pull request Nov 13, 2026
The one conflict was arigl_web_smoke.mjs. Both sides are kept:
- the /apps/up endpoint, with #1200's ISOLATION headers on its replies as on every response;
- the settle probe reads out and isolated/sab;
- each case runs its before/inject and #1200's isolation check.
The headless-Chrome smoke passes 6/6 here, the picked-file upload included.
Master since then: #1179, #1174, #1196, #1198, #1178, #1157, #1172, #1200.
transfix added a commit that referenced this pull request Nov 15, 2026
…os, exp, sqrt or tanh on the GPU (#1219)

* EWave: each mode's rates from a texture worked out in double, not sqrt and tanh in float

cvcgl_ewave fails on the macOS package lanes (Apple Software Renderer): the
GPU window drifts from the CPU one at a steady 4.2e-3 of the RMS height per
second of simulated time, the same at dt 0.2 and 0.1, to 3e-2 by step 48
against a 1e-3 bound (#1171, job 131824127881). A per-step
error in cos, sin or exp would double its rate when dt halves; a rate off by
about 1e-3 (omega = sqrt(g kappa), kappa = k tanh(min(k d, 20))) does not.
#1174's macOS package jobs were all cancelled, so it never showed there.

The update pass now reads omega, kappa / omega, g / omega and the damping
rate from an RGBA32F texture that init() fills in double with the CPU
window's formulas (det::tanh), and takes only the cos, sin and exp of a step,
so a new dt still costs nothing.

On Windows (Intel Arc) cvcgl_ewave passes before and after: step 48 h 1.95e-5
before, 1.92e-5 after; the wall run 5.62e-5 before, 5.60e-5 after.

* EWave: each step's coefficients and real-space factors from the host, no cos/sin/exp on the GPU

The first try (fea1efb) moved each mode's rates to a texture worked out in double but left the
step's cos, sin and exp in the shader. On macOS CI (Apple Software Renderer) cvcgl_ewave failed
with the same numbers to the digit: h 3.05e-2 at step 48, the wall run 4.36e-2. So the rates were
never the problem. A drift that grows per second of simulated time is what a sin or cos off in
proportion to its small angle gives.

Now the host works out, in double and only when dt or the mask changes, what ewave::prepare and
ewave::step work out on the CPU: each mode's 2 x 2 update with its damping (RGBA32F) and each
cell's real-space factor (R32F, the beach, the sponge and land). The update and real-space passes
are multiply-adds only. A new dt costs that host work and an n^2 upload; the same dt costs nothing
more.

Windows (Intel Arc): cvcgl_ewave step 48 h 1.92e-5 -> 8.80e-6, phi -> 9.06e-6; the wall run
5.60e-5 -> 9.62e-6. So Intel's in-shader cos/sin/exp were most of its GPU-CPU difference too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant