Skip to content

fix(solver): boundary-consistent projection, reproject_every option, divergence test - #7

Merged
gfpinton merged 2 commits into
mainfrom
fix/projection-boundary-and-reproject
Sep 16, 2026
Merged

gfpinton merged 2 commits into
mainfrom
fix/projection-boundary-and-reproject

Conversation

@gfpinton

@gfpinton gfpinton commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to the 12 July projection fix (bc9429b), prompted by a residual-divergence diagnosis on the halle_dacc transcranial run in acoustoelastic_ultrasound_neurons.

  • Boundary-consistent projection. project_vector_field / project_vector_field_jax now zero the one-voxel boundary layer before taking the divergence. Taking the divergence first and masking afterwards left a residual f_boundary/(2h) in the layer next to the domain edge whenever the force is non-zero on the box faces (7.7 m⁻¹ relative divergence on the halle_dacc ARF; now at float32 roundoff). No effect on the existing tests (tapered fields) and a negligible effect on the focal field of the transcranial run.
  • opts["reproject_every"] = N in shear_fdtd (default 0 = off, NumPy solver only; the JAX solver raises NotImplementedError). Re-applies the Helmholtz projection to u_curr and u_prev every N steps. The zero-Dirichlet box wall is not solenoidal-preserving and is excited from step one because the projected force is non-local, so it injects divergence that travels inward at the shear speed. The option removes it at the cost of two CG solves per event.
  • tests/test_divergence_free.py asserts RMS(div u)/RMS(|curl u|) < 1e-4 for a homogeneous point-force run until the wall signal arrives (observed 1–4e-6; the pre-July projection gives ≈0.3 from step one), documents the wall mechanism, and checks that reproject_every bounds the ratio afterwards.

Test plan

  • pytest -q tests: 18 passed, 3 skipped (JAX not installed locally)
  • ruff check src tests and ruff format --check clean
  • Full halle_dacc re-run with and without reproject_every=60: identical focal field (peak von Mises 2.3134e-5 vs 2.3126e-5), interior divergence ratio 1.6e-5 vs 6.9e-4
  • JAX parity test for the masked projection: full suite with system Python (JAX 0.4.38, 2x RTX A6000): 29 passed, 0 skipped

🤖 Generated with Claude Code

gfpinton and others added 2 commits September 16, 2026 16:08
…on and divergence test

* project_vector_field / project_vector_field_jax now zero the one-voxel
  boundary layer *before* taking the divergence. Taking the divergence first
  and masking afterwards left a residual f_boundary/(2h) in the layer next to
  the domain edge whenever the input force was non-zero on the box faces
  (7.7 m^-1 relative divergence on the halle_dacc ARF, now at float32 roundoff).

* shear_fdtd gains opts["reproject_every"] = N (default 0, off): re-apply the
  Helmholtz projection to u_curr and u_prev every N steps. The zero-Dirichlet
  box wall is not solenoidal-preserving and is excited from step one because
  the projected force is non-local, so it injects divergence that travels
  inward at the shear speed; this option removes it at the cost of two CG
  solves per event. The JAX solver raises NotImplementedError if it is passed.

* tests/test_divergence_free.py asserts RMS(div u)/RMS(|curl u|) < 1e-4 for a
  homogeneous point-force run until the wall signal arrives, documents the wall
  mechanism, and checks that reproject_every bounds the ratio afterwards. The
  pre-July-2026 projection gives ~0.3 on this setup from the first step.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…able in ruff 0.16

CI installs the latest ruff, which now enables PLR0917 and flags 28 pre-existing
numeric-API signatures across src/, examples/ and tests/. The sibling rule
PLR0913 is already ignored for the same reason.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@gfpinton
gfpinton merged commit 6c6575c into main Sep 16, 2026
4 checks passed
@gfpinton
gfpinton deleted the fix/projection-boundary-and-reproject branch September 16, 2026 20:28
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