Skip to content

Native spherical Kramer Stokes references, gravity kernels and real spherical harmonics - #1108

Merged
lmoresi merged 6 commits into
developmentfrom
feature/analytic-spherical-kramer-references
Nov 12, 2026
Merged

lmoresi merged 6 commits into
developmentfrom
feature/analytic-spherical-kramer-references

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 12, 2026

Copy link
Copy Markdown
Member

Native SymPy reference solutions for Stokes flow in a spherical shell (Kramer, Davies and Wilson 2021), with the gravity kernels and real spherical harmonics they use. This is @gthyagi's work, cut out of #1033 at 1b740463 as a unit of its own: it depends on nothing else in that PR and nothing in the solvers.

Until now the spherical Kramer cases were available only through the external assess package, as numbers. These are symbolic, so the conformance suite can check them against the equations they claim to solve, and they are finite at the poles.

What is added (gthyagi, one commit, authorship kept)

  • uw.analytic.KramerSphericalStokes: smooth and delta-sheet density, free-slip and zero-slip walls, any degree from 2, registered with the analytic family.
  • uw.analytic.spherical.gravity: analytical potential of spherical sheets and power-law volume densities, and the two-interface shell response with self-gravity.
  • uw.maths.spherical_harmonics: real orthonormal harmonics, numeric and as Cartesian polynomials.
  • KramerSphericalStokes.geoid_response: wall topography and geoid from the analytic wall stress.

What we changed, and why

  • A dangling import. The geoid adapter had cylindrical branches importing analytic.cylindrical.kramer and analytic.cylindrical.gravity, which are not in the repository. Only the spherical class uses the adapter, so the branches are removed. A new test, shown failing first, checks that every relative import in the analytic package names a module that exists.
  • Duplicated geoid functions removed. gravity.py carried GeoidResponse, SelfGravityResponse, spherical_shell_geoid_response and spherical_shell_self_gravity_response, which uw.postprocessing.geoid already provides with the same signatures. They gave identical numbers and nothing imported the copies.
  • Tests for code no test reached. Two mutants passed the suite: the geoid divided by the other wall's gravity, and a flipped sign of the outer topography. The shell response is now checked against the thin-sheet closed form with the self-gravity fixed point, and the adapter's topography against the wall normal stress.
  • Tier. The new Kramer test file is tier B, not tier A.

Verification (hyperion, PETSc int32, MPICH 5.0.1, head 40b5007)

check result
the two new test files 76 passed
development's analytic test files (1015 to 1030) all pass; the conformance, contract and parameter-sweep suites now include 16 Kramer cases
independent check of the fields, 56 cases across the four families: incompressibility, momentum balance, wall conditions, sheet jumps, rebuilt from velocity and pressure alone with scipy's harmonics worst relative residual 5.9e-13
native fields against assess at random points, four families, degrees 2 to 8 within 2.5e-13
on a shell mesh at np 1, 2, 3: named evaluators against the symbolic path, and integral norms 1e-14 at the nodes; integral norms equal to 11 digits
11 mutants (coefficient signs, normalisations, Condon-Shortley phase, kernel exponents, adapter signs) all killed; 9 of 11 before the added tests
import underworld3 time unchanged (4.6 s against 4.4 to 4.7 s)
CI reach, style gate all 433 test files reachable; gate passes

Conventions confirmed: div(sigma) + f = 0; smooth body force -g (r/R_outer)^k Y e_r; at the delta sheet the normal stress jumps by g Y (outer minus inner) with velocity and shear traction continuous.

Left open

  • No test here solves Stokes against these fields, so apply_forcing and apply_boundary_conditions are not exercised. That comparison belongs with the spherical convergence studies.
  • SphericalStokes is exported as a second name for KramerSphericalStokes.
  • About a third of the public functions in gravity.py still have no test (the potential operator, the quadrature variant, the volume-density radial derivative).
  • Not run: above np 3, degrees above 8, the full suite.

Checklist (UW3 Style Charter — docs/developer/UW3_STYLE_CHARTER.md)

  • I have read the Style Charter and followed it over the surrounding code (S2)
  • No drive-by refactors, renames, or "while I was here" cleanups (S9)
  • Bug fixes ship the regression test, written first, with level_* and tier_* markers (S8)
  • No hedging names (maybe_ / try_ / do_) and no commented-out code (S3, S4)
  • Every exception swallow states its sanctioned failure mode in a comment (S4)
  • New data access uses .array / mesh.X.coords — no with ....access(...), no mesh.data (S7)
  • Parallel safety considered — np2/np4 checked where swarm/mesh/solver dispatch is touched (S11)
  • No pixi.toml / pixi.lock or other dependency changes riding in an unrelated PR
  • AI-assisted work carries the attribution line below

Underworld development team with AI support from Claude Code

gthyagi and others added 6 commits November 12, 2026 20:49
…al spherical harmonics

Cut from #1033 at 1b74046 as a unit of its own, on development 01b06c9.
The files are as they stand at that head; they were written in f5b3f85
(Restore validated spherical Kramer and sheet-load dependencies), 0dd36aa
(Cover spherical gravity kernels with independent analytical oracles) and
efd48ff.

- analytic/spherical/kramer.py: Kramer, Davies and Wilson (2021) spherical
  shell solutions in SymPy, smooth and delta density, free-slip and zero-slip
  walls, registered as KramerSphericalStokes.
- analytic/spherical/gravity.py and analytic/_kramer_geoid.py: analytical
  gravity kernels and the stress-to-geoid adapter.
- maths/spherical_harmonics.py: real spherical harmonics.
- tests 1032 and 1033, and KramerSphericalStokes added to the 1028 sweep.

Underworld development team with AI support from Claude Code
…e that exists

The geoid adapter defers imports of analytic.cylindrical.kramer and
analytic.cylindrical.gravity, which are not in the repository; this test fails
on them (2 missing).

Underworld development team with AI support from Claude Code
… that do not exist

_KramerGeoidMixin is used by the spherical solution only. Its cylindrical
branches imported analytic.cylindrical.kramer and analytic.cylindrical.gravity,
neither of which is in the repository, so they could only fail if reached. The
adapter now says it is spherical. The cylindrical geoid response already lives
in underworld3.postprocessing.geoid.

Underworld development team with AI support from Claude Code
Tier A is for tests that have been hardened and reviewed; a new proven test
starts at tier B.

Underworld development team with AI support from Claude Code
…closed forms

Neither was reached by a test: mutants that divided the geoid by the other
wall's gravity, or flipped the sign of the outer topography, passed the suite.
The shell response is now checked against the thin-sheet superposition for
two interfaces and an internal sheet, with the self-gravity fixed point; the
adapter's topography against the wall normal stress read from the Cartesian
stress field.

Underworld development team with AI support from Claude Code
…vity kernels

gravity.py carried GeoidResponse, SelfGravityResponse,
spherical_shell_geoid_response and spherical_shell_self_gravity_response,
which underworld3.postprocessing.geoid already provides with the same
signatures. The two gave identical numbers on a probe case, and nothing in
this unit or in #1033 imports the copies. The physical kernels and
spherical_physical_shell_response, which are new, stay.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 12, 2026 10:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@lmoresi

lmoresi commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

Review of #1108 (H3, second review desk)

Verdict: READY at 40b5007. The analytic fields solve the equations they claim to, and agree with the published implementation. The tests catch small coefficient errors, and the import cost is small. The only CI failure is the pre-existing test_1152[zone] (#1096/#1101), which this PR does not touch.

Built at 40b5007 on hyperion. Probes are in runs/2026-11-12-h3review/1108/: kcheck.py, kassess.py, mut1108.py.

Findings

  1. Low. For order m > 0, the real_orthonormal fields are √2 times assess's.
    • A best fit of the native velocity to assess.SphericalStokesSolution* gives a factor of exactly 1.414214, for (l, m) = (2, 1) smooth zero-slip and (3, 2) delta zero-slip, on both sides of the sheet. After the fit the residual is below 2e-13.
    • The native harmonics are the orthonormal ones. A Gauss–Legendre quadrature gives ∫Y² dΩ = 1.000000000000 for (2,0), (3,2) cos, (3,2) sin and (4,1), with cross terms at rounding.
    • So the difference is assess's real-part convention, not an error. The docstring could say so, since the PR body cites agreement with assess. For m = 0 the agreement is exact (below).
  2. Low. import underworld3 now loads five more modules eagerly: analytic._kramer_geoid, analytic.spherical, .gravity, .kramer and maths.spherical_harmonics.
    • Measured with -X importtime: the analytic modules take about 1 ms in all. maths.spherical_harmonics takes 0.14 s cumulative.
    • The whole import takes 1.79 s against development's 1.73 s (+3%, three runs each).
    • Not heavy, but the harmonics module could be loaded lazily.

Attacks that failed

  • The equations, independently, on the PR's own evaluators. Central differences (h = 1e-4) at 20 random points per case, away from the sheet, for:

    • smooth free-slip l=3 (k=3);
    • smooth zero-slip l=2 (k=4);
    • delta free-slip l=4;
    • smooth free-slip l=3 m=2.

    Results:

    • |div u| / |u| is 3e-8 to 1.3e-7;
    • the momentum residual of lap u − grad p + f (ν = 1) is 1.2e-8 to 4.2e-8 of its terms' scale, at the truncation level of the stencil;
    • u·n on both free-slip walls is 4e-17 to 3e-16.
  • Against the published implementation (assess), real_orthonormal, m = 0, at 15 random points: velocity and pressure agree to 1.2e-14 to 2.2e-14 for smooth free-slip l=3, and for delta free-slip l=4 inside and outside the sheet (assess sign +1 and −1).

  • Mutants, beyond the PR's 11:

    • one smooth free-slip radial coefficient off by 1e-6 fails 6 tests;
    • the delta zero-slip forcing halved fails 4.
  • Tests: the two new files give 76 passed. Development's analytic files (solcx, contract, transcription, inclusion, the conformance and parameter sweeps) give 363 passed.

  • Resonance guard: k=2, l=3 raises NotImplementedError, as documented, since (k+1)(k+2) = l(l+1).

Not checked

Degrees above 4 in our own probes; the gravity kernels beyond the PR's tests; apply_forcing and apply_boundary_conditions against a solve (the PR leaves that open).

Underworld development team with AI support from Claude Code

@lmoresi lmoresi closed this Nov 12, 2026
@lmoresi lmoresi reopened this Nov 12, 2026
@lmoresi lmoresi closed this Nov 12, 2026
@lmoresi lmoresi reopened this Nov 12, 2026
@lmoresi
lmoresi merged commit 264400a into development Nov 12, 2026
21 of 30 checks passed
jcgraciosa pushed a commit to jcgraciosa/underworld3 that referenced this pull request Nov 17, 2026
…y body force

underworldcode#1108 added KramerSphericalStokes to the family but not to this file's SWEEP,
and its default (a density sheet at r_int) carries no body force, so the
negative control flipped a zero vector. The sweep now covers smooth density
and two non-axisymmetric modes (real_orthonormal harmonics, which m > 0
requires), and the flip test flips the smooth-density case.

Underworld development team with AI support from Claude Code
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.

4 participants