Skip to content

physics, ariadne: the waves floating bodies make push the others, opt-in (C5, D6) - #1344

Merged
transfix merged 4 commits into
masterfrom
feat/wake-coupling
Nov 18, 2026
Merged

transfix merged 4 commits into
masterfrom
feat/wake-coupling

Conversation

@transfix

@transfix transfix commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

The roadmap's C5 ("bodies are not pushed by wakes") and decision D6's option (b): an opt-in, deterministic CPU eWave inside the physics step, so boats feel each other's wakes and the debris' rings.

What it is

  • cvc::physics::field_wake / field::wake (inc/cvc/physics/field.h, private src/cvc/physics/field_wake.{h,cpp}). Off by default (cells = 0). A fluid with a free surface may keep a window of cells² cells of cell m (64 of 1 m from the water node) on the world's whole-cell grid, centred on the boats in its water (bodies with a hull), else on all its floating bodies, moved by whole cells once their middle is cells/8 off.
  • One wave state per body that makes waves (at most sources, 8): its source is its immersed columns' change over the window (add_immersion, against the surface), smoothed [1 2 1]/4. The states step by ewave's exact step (no walls) every period (1/30 s) in whole physics steps, through one shared ewave.
  • Each body reads the others' waves, never its own (sum of states less its own): their height under its cells and hull vertices, their velocity (∇φ, dh/dt) for drag and damping, and −g∇h for an inertial fluid's Froude-Krylov push. Reading its own waves back would cancel a body's heave spring as it moves (its source lowers the water under it as it sinks; the waves refill it a few tenths of a second later) and count its wave-making twice. A sleeping body the others' waves reach (> 1 mm) is woken.
  • World state: a save() section after the boats' (CVCWAKE1), so state_hash() covers it and restore() restores it; other wakes or none refuse the state. set_field with the same wake keeps the waves. world::field_wake_info / field_wake_height for renderers and tests.
  • Ariadne: a water node's wake_push key (props wake_push_cells, wake_push_cell, wake_push_depth) sets the field's wake; SceneWorld sets such a field in place on a new sea keyframe (it removed and re-added it before, which would drop the waves; without a wake nothing changes). water_controls.ari: "Wakes push bodies".
  • With it off the physics is bit for bit as before: no read changes, no new state section.

Measured (Windows, MSVC Release, Jolt)

  • A crate dropped from 1.2 m alone: ring up to 0.060 m high 3 m off; the crate's path is identical, bit for bit, to its path with no wake.
  • A crate afloat 5 m from the drop (asleep when the ring arrives): no motion without a wake; 0.038 m heave, 0.085 m drift, 0.035 rad tilt with one.
  • Two launches on kBoatNode's lake, one at full throttle passing the other (moored broadside) 5 m off: without wake_push the moored launch does not move at all; with it, 0.036 m heave, 0.131 m drift, 0.046 rad roll.
  • Frame pacing: the same scene with wake_push, at a frame per clock quantum and at 0.137 s frames (which the clock caps at 8 quanta an advance): identical state hashes at every shared tick; and at frames of 1, 3, 2, 5, 7 quanta (see the review fixes).
  • Cost: the fields' push 0.139 ms a step with a 64² wake and two sources, 0.007 ms without.

Tests run locally (all pass): physics_field_test (36, incl. the 6 new PhysicsFieldWake.* and the golden hashes), ariadne_scene_world_test (70, incl. the 2 new boat tests), physics_boat_test, physics_dyn_boat_plant_test, physics_world_test, physics_vehicle_test, physics_hull_test, physics_immersion_test, physics_energy_test, physics_codec_test, physics_parity_test, physics_plant_host_test, physics_plant_log_test, physics_pose_tracker_test, physics_jolt_rollout_test, physics_dyn_{4w,bike}_plant_test, physics_dyn_contact_test, physics_mujoco_robot_test, physics_replay_test (checked-in trace), ocean_ewave_test, cvcgl_ewave, cvcgl_wake, cvcgl_ariadne_physics, cvcgl_ariadne_realize.

Not verified / not done: Linux, macOS and the wasm replay lane (CI); the browser. The physics wake has no shores (no coast mask: it runs over land and does not reflect); water_at (a propeller and rudder) reads the water without it; the waves' velocity is not decayed with depth; the drawn wake is unchanged and separate (not drawn from the physics states); pycvc does not bind field::wake yet.

Docs: the roadmap's C5 "As built", D6, the boats' notes and its status line; ARIADNE.md's water node; PHYSICS_API.md.

Review fixes (eb63283)

  1. Restore is all or nothing. Every wake's section is parsed into a saved state first, then all are committed; a failed restore used to leave a wake pointing at freed outlines. Test AFailedRestoreLeavesTheWakeAsItWas (fails on the first build).
  2. Another wake's state is refused. The section carries every parameter (cells, cell, depth, period, damping, sponge, samples, sources), not only id, cells and cell. Test AStateFromAnotherWakeIsRefused.
  3. The sea work stays parallel. The waves read the step's held surface (one per field per step, its frame worked out on the field workers) through height_with; the first build called height() on the stepping thread, which worked out the sea's frame serially. While every body sleeps and no wave is left nothing is read: ASleepingWorldReadsNoSurface, 812 reads in 100 steps before, 0 after. Cost on a three-cascade sea (64 modes each, 3 field workers, six crates and a boat; TheWakesCostOnTheSea, medians of three interleaved runs): 8.04 ms a step without a wake (7.24–8.45), 8.30 ms with (7.23–8.80); the first build measured the same way 7.40 vs 7.69 ms, also inside the spread, so the serial frame's cost is not established on this machine.
  4. Pacing tests. The old test's 0.137 s frames are capped at 8 quanta per advance (world_clock), so it is reworded as such; new TheWakesPushIsTheSameAtUnevenFrames (frames of 1, 3, 2, 5, 7 quanta) and TheWakesWavesSurviveANewSea (a wind change makes a new sea keyframe; the wake keeps its field, window, sources and heights; fails without set_in_place: "unknown or removed field id 0").
  5. The window holds bodies. It sits where it holds the most floating bodies (a boat counting as four), recentred by whole cells; bodies outside it make and feel none (wake_info::outside). Test TheWindowHoldsTheBodies.
  6. No re-radiation; sleepers make no source. A body's immersion is cut against the sea plus the other bodies' waves, and a sleeping body makes no source. PackedBodiesStayBoundedAndSleep: nine crates packed 2.2 m apart on calm water all sleep by 120 s with and without a wake, and the wake's peak falls from 0.35 m to under 0.001 m; in a 0.25 m, 5 s swell no crate sleeps with or without a wake (0 / 0), the wake's peak at most 0.18 m. The first build also stayed bounded and slept, but scattered more (swell peak 0.32 m, calm 0.82 m); the bounds the test asserts fail on it.
  7. Limits and memory documented in field.h: cells 8..128 (a power of two), cell 0.05..100 m, depth finite and at most 1e4 m, period (0, 10], samples 1..8, sources 1..16; at most sources + 4 states of 80 cells² bytes each.
  8. Smaller: set_field with the same wake keeps it (no discarded fluid_wake); the cut shape is kept only for convex hulls; llround and cell indices guarded; CrossPlatformGoldenHash pinned (0x8052b235300e8e23); the docs say the section is versioned by its magic alone; water_controls.ari's header under 100 columns.

Tests (pass, Windows Release): physics_field_test (43), ariadne_scene_world_test (72), the physics suites, ocean_ewave_test, physics_replay_test with the trace, cvcgl_ewave, cvcgl_wake, cvcgl_ariadne_physics, cvcgl_ariadne_realize. Unverified: Linux, macOS, the wasm replay lane (CI), the browser.

Re-review fixes (fb35d6d), then master merged (2512084)

  • A body that falls asleep gives its slot up (its waves fade on); woken, it takes a free slot again. Free slots go to boats first, then nearest the window's centre, id order on ties. SleepingBodiesLeaveTheirSlotsToABoat: six crates asleep and still, four slots, a boat arriving later takes a slot, its waves wake all six and move the farthest 0.64 m. Before: no slot for the boat, nothing woken or moved (fails).
  • Placement weighs at most 64 proposals a wave step (every boat, then the first body per square of a coarse grid), not every body against every body.
  • The save carries the count outside the window (restored, not 0 until the next wave step; fails before) and refuses a window over 2e12 cells off (AWindowOutOfRangeIsRefused, fails before) or more sources than allowed. Golden re-pinned to 0x7a5a40b81d1d2433 (format change).
  • Small: the 4-step period at 120 Hz in the comments; the vacuous asleep check dropped; restore atomicity stated for the wakes' section only; physics_field_test gets a 1200 s ctest timeout; the roadmap notes that a hand-set wind change takes its sea keyframe at a frame's time (Storm wind: gust fronts in the scene's wind, and the wind on MuJoCo robots (O20, part 2: F4, F6's gusts) #1345's clock-period sea covers storms only).
  • PackedBodiesStayBoundedAndSleep: more crates now make waves (the ninth gets a freed slot); the last tenth's wave peak is 0.0058 m (0.0006 before), so its die-down bound is now 5 % of the early peak.
  • Merge: conflicts in the roadmap status line (both kept: F4 now on master), scene_water.h (both fields kept) and src/cvc/CMakeLists.txt (field_wake.cpp and hull.cpp both in the exact-math list). After the merge: physics_field_test 45, ariadne_scene_world_test 84, all physics suites, ocean_ewave_test, physics_replay with the trace, cvcgl_ewave, cvcgl_wake, cvcgl_ariadne_physics, cvcgl_ariadne_realize and cvcgl_ocean_fft pass.

…-in (C5, D6)

A fluid with a free surface may keep a wake (cvc::physics::field_wake, field::wake; off by
default): a window of cvc::ocean::ewave cells around the bodies in its water, its boats first,
and one wave state in it per body that makes waves, its source the body's immersed columns'
change (add_immersion). The states step by ewave's exact step inside the physics step, every
period in whole steps, and every body reads the sum of the others' waves, never its own: their
height under its cells and hull, their velocity for its drag and damping, their acceleration for
an inertial fluid's Froude-Krylov push. A body's own waves read back would cancel its heave's
restoring force as it moves and price its wave-making twice. A sleeping body the others' waves
reach is woken.

The window and the states are world state: a save() section after the boats', so state_hash()
covers them and restore() brings them back. set_field with the same wake keeps the waves. With no
wake the step and the state are unchanged, so every pinned hash stands.

Ariadne: a water node's wake_push key (and wake_push_cells, wake_push_cell, wake_push_depth props)
gives its field a wake; SceneWorld sets such a field in place when the sea takes a new keyframe,
so the waves survive it. water_controls.ari gets a "Wakes push bodies" checkbox.

Tests: PhysicsFieldWake.* (a body alone floats bit for bit as without a wake; a crate dropped 5 m
off rocks a sleeping one only with a wake; save/restore, field workers, set_field and the window
following its bodies); AriadneBoatNode.WakePushLetsOneBoatsWakeMoveAnother and
TheWakesPushIsTheSameAtAnyFramePacing. Docs: the roadmap's C5 "as built", D6 and status line,
ARIADNE.md's water node and PHYSICS_API.md.
Fixes the review of the opt-in wake on a fluid field (C5, decision D6 (b)):

- Restore is all or nothing: every wake's section is parsed into a saved
  state first (fluid_wake::parse), then committed (commit) once all parse.
  A failed restore left a wake pointing at freed outlines; now it leaves the
  wake as it was.
- A state saved by another wake is refused: the section carries every
  parameter (cells, cell, depth, period, damping, sponge, samples, sources),
  not only the id, cells and cell.
- The surface the waves are cut against is the step's held surface (one per
  field per step, its frame worked out on the field workers), read through
  height_with; the first build read height() on the stepping thread, which
  worked the sea's frame out serially. While every body sleeps and no wave
  is left, nothing is read at all.
- The window sits where it holds the most floating bodies (a boat counting
  as four), recentred by whole cells; bodies outside it make and feel none
  (wake_info::outside). Before, it could hold no body at all.
- A body's immersion is cut against the sea plus the other bodies' waves, so
  a body riding another's wave does not re-radiate it, and a sleeping body
  makes no source.
- Limits: cells 8..128 (a power of two), cell 0.05..100 m, depth finite and
  at most 1e4 m, period (0, 10], samples 1..8, sources 1..16; at most
  sources + 4 states; memory and cost documented in field.h.
- Smaller: set_field with the same wake keeps it (no discarded fluid_wake);
  the cut shape is kept only for convex hulls; llround and cell indices are
  guarded; the cross-platform golden is pinned; the docs say the section is
  versioned by its magic alone; water_controls.ari's header is under 100
  columns.

Tests (physics_field_test, ariadne_scene_world_test): a failed restore
leaves the wake as it was; another wake's state is refused; the window holds
the bodies; packed crates stay bounded and sleep; a sleeping world reads no
surface (812 reads in 100 steps before, 0 after); the wake's cost on a
three-cascade sea; the pinned golden; the same push at uneven frame pacing
(frames of 1, 3, 2, 5, 7 quanta); the wake's waves survive a new sea
keyframe. Each behaviour test fails on the first build.

Docs: ARIADNE.md, PHYSICS_API.md and the roadmap's C5 "as built" (with the
measurements; the serial frame's cost is not established on this machine).
The re-review of the opt-in wake (C5):

- A body that falls asleep gives its slot up, as one that leaves the
  window or the world does: its state fades on, and woken it takes a free
  slot again (its columns then its last). A free slot goes to an awake
  boat first, then to the body nearest the window's centre, id order
  breaking ties. Before, sleepers kept their slots, so crates that settled
  held them all and a boat that came later made no waves. The rest flag is
  gone with it, and the docs' "at most sources awake bodies" now holds.
- Placing the window weighs at most 64 proposals a wave step: every boat,
  then the first body (by id) in each occupied square of a grid as wide as
  the window's inner square. Before, every body proposed and each scanned
  every body.
- The saved section keeps the count of bodies outside the window, so
  wake_info::outside reads after a restore what it read before; a saved
  window over 2e12 cells off is refused (moving it would overflow), and a
  saved state with more sources than the wake allows is refused.
- Small: the uneven-pacing test's comment and the roadmap say the waves'
  period is 4 steps at the clock's 120 Hz; the vacuous asleep check in
  PackedBodiesStayBoundedAndSleep is dropped; the docs say only the wakes'
  section is read whole before any wake takes it; physics_field_test gets
  a 1200 s ctest timeout for its long runs, as ocean_ewave_test has; the
  roadmap notes that a hand-set wind change takes its sea keyframe at a
  frame's time.

Tests: SleepingBodiesLeaveTheirSlotsToABoat (six crates asleep, four
slots: the boat takes one, its waves wake all six and move the farthest
0.64 m; before: no slot, none woken, none moved), AWindowOutOfRangeIsRefused
and TheWindowHoldsTheBodies' restored outside count fail before the fix.
ABodyNeverFeelsItsOwnWaves checks the crate's source while it bobs (asleep,
it now has none). PackedBodiesStayBoundedAndSleep's die-down is measured
against the early peak: more crates make waves now, and the last tenth's
peak is 0.0058 m (0.0006 before). The golden is re-pinned to
0x7a5a40b81d1d2433 (the save gained the outside count and lost the rest
flag).
…/wake-coupling

# Conflicts:
#	docs/roadmap/OCEAN-AND-WEATHER-ROADMAP.md
#	inc/cvc/ariadne/scene_water.h
#	src/cvc/CMakeLists.txt
@transfix
transfix enabled auto-merge (squash) November 18, 2026 10:10
@transfix
transfix merged commit 314d5d8 into master Nov 18, 2026
30 checks passed
@transfix
transfix deleted the feat/wake-coupling branch November 18, 2026 11:46
transfix added a commit that referenced this pull request Nov 27, 2026
…cally, same bits) (#1562)

PhysicsFieldWake.PackedBodiesStayBoundedAndSleep took 581-747 s of its 1200 s ctest budget on
package-linux / libcvc-debug and timed out three times on a slow runner (#1550's). It took 269 s
there on #1344; #1532 made every wake test 2.5-2.8x slower in Debug (the ring 3.0 to 8.2 s, the
golden 2.4 to 5.8 s, this one 269 to 702 s). The test itself is as #1344 wrote it.

Profiled locally (Debug, MSVC /Od): the calm run with a wake is 62% of the test, and 87% of that
is the wake's wave step: deepen, the motion below the top that #1532 added (2 forward and ~3
inverse 64 x 64 FFTs a state a wave step), 51%; the ewave step 21%; sum, which now adds the
depths, 9%. In an unoptimized build std::vector's operator[] is a call per element, and these
passes made ~400k of them a state a wave step. And once every crate sleeps (~90 s into the calm
run) the wake made depths for ~30 s more, while its waves died away, with nothing reading them.

- fluid_wake::ready_depths: the depths are made at the first read after a wave step (in
  field_set::apply before the field workers' reads, when an awake body is in the wake's field,
  and in field_set::water_at), not at every wave step. The same inputs in the same order: the
  same bits. motion() reads only the layers that were made.
- The wake's per-cell passes (deepen, derive, sum, the wave step's dh/dt) and fft_plan::run_2d's
  gather and scatter index through raw pointers: the same operations in the same order. On their
  own, 28% off a 20 s calm run with a wake in Debug (37.5 s to 27.1 s, three interleaved runs,
  the same peaks to 17 digits).
- The test is two: the calm half keeps its name (and #1557's 3600 s), the swell's half is
  PackedBodiesStayBoundedInASwell, so each has its own ctest budget and ctest runs them side by
  side. What the comments claimed is now asserted too: every crate sleeps on calm water (9 of 9)
  and none in the swell (0 and 0). "Without one they sleep within 40" is 3 (2.55 s).

Measured locally, Debug, the old and new builds run side by side on one loaded box: 283.6 s
before; after, the calm half 72.5 s and the swell's 87.8 s (160.3 s). Every value the test prints
is the same to the digit. No pinned hash moves: the wake golden 0xc72e26b4ef0f764a, the shore
golden 0x89789ba92fbd1853, the swell and ocean scenes.
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