Repository navigation
ocean: the eWave wake solver, on the CPU and the GPU (O8) - #1174
Merged
Merged
Conversation
…(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
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).
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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 incvc::ocean(O8a), and the same window on the GPU in cvcGL (O8b), checked against each other.O8a:
cvc::ocean::ewave(CPU)add_heightand a whole-fieldadd_heightsfor C2's footprints).beach_rate), not per step.Measured in
ocean_ewave_test(12 tests):8f51571acc023425, measured on Windows MSVC; CI checks it on Linux and macOS.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.EWaveholds z = h + iφ in an RG32F ping-pong. Each step is 34 passes at 256²:The shaders are WebGL2-portable fragment shaders, and every pass disables the scissor test (O7b's lesson).
cvcgl_ewaveruns 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:It skips without float render targets, as
cvcgl_ocean_fftdoes. GPU time per step at 256² on the Intel Arc iGPU, while other builds ran: 0.28–1.23 ms.THIRD_PARTY_NOTICES.mdnamesOceanButterfly(ABYSSAL, MIT).Checked locally (Windows Release, GL build)
ocean_ewave_test12/12,ocean_sea_test16/16 andocean_shore_test16/16.cvcgl_ewavepasses, with 0 checks failed; before the review fixes it passed 7 runs in a row.cvcgl_ocean_fftandcvcgl_ocean_bandpass, the band table unchanged.Independent reviews found five issues in O8a and four in O8b, all low severity. The real ones are fixed:
Known limits
water_bodies.