Skip to content

pycvc: fields, free surfaces and the field time (O6b) - #1140

Merged
transfix merged 5 commits into
masterfrom
feat/ocean-fluid-surface-py
Nov 11, 2026
Merged

transfix merged 5 commits into
masterfrom
feat/ocean-fluid-surface-py

Conversation

@transfix

@transfix transfix commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

O6b in docs/roadmap/OCEAN-AND-WEATHER-ROADMAP.md: pycvc binds the fields, O6a's free surfaces and the field time, so Python can float a body on a sea and read it at the clock's time.

#1139 (O6a) has merged and master is merged in, so the diff is O6b alone.

pycvc_physics.i

  • Fields. pycvc had no field API until now.
    • physics_world.add_field(volume, kind="fluid", velocity=None, drag_coefficient, damping, traction, ruts, rut_cell, surface=None) takes a pycvc.volume and field's values as keywords. It returns the field's id, an int.
    • velocity is None or three volumes.
    • set_field(id, ...) takes the same keywords and sets the whole field, as C++'s set_field does.
    • remove_field, field_count and field_load_on(body) (force, torque, immersed volume) work as in C++.
    • physics_binding.publish_field(name, id) names a field in the state tree.
  • Surfaces. still_surface(level, current=None) and wave_train_surface(level=0, depth=0, trains=[...], gravity=9.80665) are C++'s classes, held by shared_ptr.
    • trains is a list of dicts of wave_train's fields. A key a dict leaves out keeps the default; an unknown key raises.
    • Both have level, height, velocity and digest. A wave train also has train_count, train(i), wavenumber(i) and omega(i), with i range-checked.
    • A field shares its surface, so the surface outlives Python's name for it.
    • Python cannot subclass a surface: the step reads it from its own thread, without the GIL.
  • The time base.
    • follow(clock) takes a pycvc.world_clock and releases the GIL, as step does.
    • field_time() and set_field_time(t) are O6a's.

Python reads the same values as C++

  • New C++ test. PhysicsFluidSurface.CrossPlatformGoldenHash pins the swell scene's state hash, f0085b4212e1a8c0. The scene is a slab and a ball in a 0.2 m, 4 s wave train, 300 steps from field time 3 s.
    • The surface and the field step compute with det::, so a cross-platform deterministic Jolt should give that hash on every platform. This PR's Linux and macOS jobs are the first check of that.
  • test_pycvc_physics.py. It builds the same scene call for call through pycvc and requires that hash. It also checks:
    • the surfaces against Airy's formulas: deep-water k = ω²/g, η, orbital speed Aω decaying as e^{kz}, finite-depth dispersion, a still bottom, digests;
    • half draft on calm water at the surface's level;
    • the field time anchored to a clock that ran 123.45 s before the world joined it;
    • restore bringing back the field time and refusing another surface, or none;
    • a damping the tree sets through publish_field: set_field keeps the surface, and the run matches a world built with that damping;
    • the refusals: a medium with a surface, an unknown kind, and a velocity that is not volumes.

Checked locally (Windows Release, GL build with pycvc on)

  • pycvc_physics: 135 checks, including both golden hashes and the parity run.
  • Every other pycvc test (46).
  • Every Physics* gtest (134, plus 2 skipped by design), and physics_field_test (18).
  • git clang-format is clean.

Next

  • O7: the cvc::ocean-backed sea surface: the physics band's 64² CPU FFT, height at a world point by fixed-point iteration, orbital velocity and the shore layer. Plus debris in lsystem_coast.

…the same on every platform

Before O6 puts the sea into the physics state_hash, h0 and the shore layer must give the same
bits on every platform; they called libm, whose transcendentals each platform rounds its own
way (docs/roadmap/OCEAN-AND-WEATHER-ROADMAP.md, B1's open item).

- cvc::physics's private det_math moves to cvc::algo as cvc/algo/det_math.h (standard library
  only), and gains exp, log, pow, sinh, cosh, acos and hypot. pow carries log x as a double-double
  and multiplies it by y exactly, so it stays within 3 ULP of libm even where y log x is large;
  y = 1, 2, -1 and 0.5 are one correctly rounded operation each. physics/det_math.h is now a
  namespace alias, so the physics step is unchanged (its bit pins and physics_replay_test hold).
- cvc::ocean's spectrum, h0 and shore layer call det:: in place of std::, and are built without
  FMA contraction. cvc::ocean may now include cvc::algo (which depends on nothing).
- algo_det_math_test (was physics_det_math_test) measures each new function against libm over
  the ranges the ocean uses, checks libm's special cases (pow's C99 Annex F table), and pins
  bits. ocean_spectrum_test and ocean_shore_test pin digests of the spectrum, h0 and the shore
  layer's planes, evaluate() and swash(), measured on Windows, for CI to check elsewhere.
…me (O6a)

O6 of docs/roadmap/OCEAN-AND-WEATHER-ROADMAP.md, its B5 hook (decision D2, a virtual
interface) and B6's tests.

- cvc/physics/fluid_surface.h: fluid_surface (level, height, velocity, digest), still_surface
  (a level and a uniform current) and wave_train_surface (linear Airy trains, finite-depth
  dispersion, cosh/sinh decay, det_math throughout so it is the same on every platform).
- field::surface, on a fluid only: field_set::apply clips each cell's top to the surface's
  height over its clipped centre, and drag and damping use the surface's velocity in place of
  the velocity volumes.
- world::field_time(): t0 + (tick - tick0) dt. follow()'s first call anchors it to the clock's
  t(), so physics reads the surface at the time a renderer draws it; set_field_time sets it.
- With a free surface, save() appends a section with the field-time anchor and each surface's
  digest, so state_hash() covers them and restore() refuses other surfaces. Without one the
  format is unchanged: every existing hash and the replay trace hold.
- physics_field_test: half draft on calm water at two levels; heave in a 4 s swell in phase with
  the surface (correlation > 0.97), about as high, at the swell's period; the field time follows
  the clock; hashes agree for one surface and differ for another amplitude or field time; a save
  restores the field time and refuses another surface.
physics_world gains add_field / set_field (a pycvc.volume and field's values, with a surface),
remove_field, field_count, field_load_on, follow(clock), field_time and set_field_time;
still_surface and wave_train_surface are C++'s classes, shared with the field; and
physics_binding gains publish_field.

PhysicsFluidSurface.CrossPlatformGoldenHash pins the swell scene's state hash, and
test_pycvc_physics.py builds the same scene through pycvc and requires it.
@transfix
transfix enabled auto-merge (squash) November 11, 2026 01:19
…/ocean-fluid-surface-py

# Conflicts:
#	docs/roadmap/OCEAN-AND-WEATHER-ROADMAP.md
#	src/cvc/tests/physics_field_test.cpp
@transfix
transfix merged commit 225ccd6 into master Nov 11, 2026
13 of 34 checks passed
@transfix
transfix deleted the feat/ocean-fluid-surface-py branch November 11, 2026 04:02
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