Skip to content

physics: the hull model, forces per triangle against the free surface (O11a) - #1173

Merged
transfix merged 10 commits into
masterfrom
feat/physics-hull
Nov 13, 2026
Merged

transfix merged 10 commits into
masterfrom
feat/physics-hull

Conversation

@transfix

Copy link
Copy Markdown
Owner

O11a in docs/roadmap/OCEAN-AND-WEATHER-ROADMAP.md (section 7, D2): the hull model. A fluid now pushes on a boat's hull triangle by triangle, instead of on the 8-cells-per-side samples crates use.

The model (cvc/physics/hull.h)

A body declares a hull with body_desc::hull: a closed triangle list in its own frame, apart from its collision shape. box_hull() makes a box hull. Each step, for each fluid field, each triangle is split at the waterline (the free surface's height over its vertices, or the field box's top). Its submerged part feels these forces against the water's velocity:

force formula
hydrostatic pressure ρ g depth on the submerged part, along the inward normal, at its centre of pressure, so the hull floats, trims and rights itself
viscous resistance ½ ρ C_f(Re) S |u_t| u_t, with ITTC-57's C_f = 0.075 / (log10 Re − 2)²
pressure drag ½ ρ C_d S |u_n| u_n n on faces the water meets (suction_coefficient on faces it leaves)
slamming the added mass of the water set moving by a face entering the water
damping the field's damping times the immersed volume, as the cells give, on the vertical motion
  • Stability. The velocity terms are integrated implicitly in their own rate, as the cells' drag is. So a light hull in dense water never overshoots the water's velocity.
  • State. A hull is part of the world's state: its digest and each triangle's last wetted area are in save() and state_hash(). A world without hulls keeps every existing hash and file format.
  • Determinism. It is standard library only, in a fixed order, with the det:: math physics uses.
  • Default. Bodies without a hull keep the cell model.

Tests (physics_hull_test, 15)

  • At density 500, a 1 × 1 × 0.4 m box floats at 0.20000 m draft with the 12-triangle and the 432-triangle hull alike, and on the cell model. The first step's buoyancy is ρ g V to 1e-8 N, with no torque.
  • The righting moment heeled 10° and 20° matches a wall-sided box's. A box heeled 20° rights itself to 0.5° in 8 s, and a tall thin one tips over.
  • Towing resistance grows as v² for a 2 × 0.8 × 0.5 m hull: 101.5 N at 1 m/s and 413.4 N at 2 m/s, a ratio of 4.07.
  • A box dropped from 1 m never gains energy and is at rest at half draft after 9 s. A light 8 kg slab under heavy drag stops without reversing.
  • On a 0.2 m, 4 s swell it heaves with the surface: correlation 0.9995, height ratio 1.03.
  • Two runs give the same hash. A hull scene is pinned at 54099f602b79feb7, measured on Windows MSVC and to be confirmed by CI on Linux and macOS.
  • Cost per world step, Jolt included, on a loaded machine: 0.03–0.04 ms for a 12-triangle hull and 0.09–0.15 ms for 432 triangles.

Checked locally (Windows Release)

Before the review fixes: ctest -R Physics passed 134, with 2 skipped by design; the physics_replay trace passed; physics_field_test passed 21/21, its goldens unchanged.

An independent review found two medium-severity issues and four low ones, all fixed (physics_hull_test 15/15 after them):

  • the heave damping counted the water column over upward faces, so a submerged hull was damped more the deeper it sank;
  • the mesh was read live through the caller's pointer (now copied);
  • the rotational inertia estimate was not always low;
  • the heave damping shrank the surge drag;
  • no test checked the centre of pressure (now TheRightingMomentIsTheWallSidedOne);
  • the docs claimed the pin was CI-checked.

Master is merged in, after #1159.

Known limits

  • Hydrostatics are explicit, as the cells' buoyancy is. A hull very light for its waterplane in dense water (sqrt(ρ g A/m) dt ≥ 2) can oscillate in heave.
  • Depth is measured along world z, and a vertex outside the field's box counts as dry.
  • Hulls are not in snapshot() or its JSON, and pycvc doesn't bind them yet.

Next: O11, the boat (propulsion and rudder on O10's add_force_at, water kept out of the hull, a drivable boat in lsystem_coast).

…surface

A dynamic body may carry a hull (body_desc::hull, cvc/physics/hull.h): a
closed triangle list apart from its collision shape. Fluid fields push on
its triangles in place of the 8-cells-per-side sample: each triangle is
split at the waterline (the free surface's height at its vertices, or the
box top), and its submerged part feels hydrostatic pressure at its centre
of pressure, ITTC-57 friction, pressure drag growing with (v.n)^2, a
bounded added-mass slamming term and the field's damping in heave. The
velocity terms are integrated implicitly in their own linear and rotational
rates. det:: math, a fixed order.

A world with hulls saves a CVCHULL1 section (each hull's digest and its
triangles' last wetted areas), so state_hash covers them and restore
refuses other hulls; a world without hulls saves and hashes as before.
physics_hull_test covers floating, righting, towing resistance, a drop, a
light hull, heave on a swell and the state, and pins a hull scene's hash.
The field's damping on a hull now sums to the cells' c V_sub, shared among
the downward faces by the water column over each; upward faces under water
took their column too, so a submerged hull was damped more the deeper it
went. The horizontal drag is scaled in the rate without the damping, so the
damping no longer slows a towed hull. add_body keeps a private copy of the
hull mesh, so the cached normals, wetted areas and digest always describe
what is simulated. The torque's inertia estimate also takes the collision
shape's where that is lower.

New tests: the first-step torque on a heeled box is the wall-sided righting
moment (12 and 432 triangles), a sinking hull keeps its speed at depth, and
changing the caller's mesh after add_body changes nothing. The towing test
now checks the absolute resistance. The hull scene's pinned hash is
re-measured (2f71a1fe229afa75); the docs say CI has yet to confirm it.
@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.
…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 6773494 into master Nov 13, 2026
31 of 33 checks passed
@transfix
transfix deleted the feat/physics-hull branch November 13, 2026 16:53
transfix added a commit that referenced this pull request Nov 13, 2026
…erf/threaded-s1b

#925 starts ws-open's connect and ws-recv's wait where the transport does not block (the browser
without threads), and their callbacks settle the call. Its start paths kept the async_host by
reference and posted through it; here they take the host's finisher (host.make_finisher()) and
settle_started through it, as http_work and uri_fetch_work do: the callbacks answer later, and an
isolated document's group's host may be gone by then.

- net_intrinsics.cpp: the conflict kept this branch's providers by kind; have_ws takes master's
  NetAccess::ws. The any provider's comment says a host's own WebSocket transport must be as
  thread-safe as the compiled backend.
- ariadne_runtime_test: both sides' new L4 cases are kept, plus
  AStartedWebSocketCallKeepsTheHostItStartedOn, the WebSocket twin of
  AStartedRequestKeepsTheHostItStartedOn.
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