Skip to content

Physics and numerics audit (2026-07-08)

Date 2026-07-08
Reviewed 0.10.0
Work packages WP-A (guards), WP-B (quadratures), WP-C (inductive stack), WP-D (layer 2), WP-E (n ≥ 3), WP-F (performance)
Released in 0.11.0 (2026-07-10)
Overview Audit history · Changelog

A physics, numerics and performance audit between review passes 8 and 9; it is not counted in the numbering of the review passes. Every work package shipped with 0.11.0, whose release notes are reproduced here.

Where this text comes from

This page was moved verbatim from CHANGELOG.md when the release notes were condensed in 2026.11.0 (source: commit 30a122d). Only the markup was adapted: reST roles are rendered as code or math, relative links point to the current pages, trailing whitespace is removed, and each block stands under a heading that names where it was published. Paths, test names and numbers are those of the time; the code has changed since.

Released in 0.11.0 (2026-07-10)

Fixed — discrete reciprocity and honest n ≥ 3 handling (audit 2026-07-08, WP-B3/WP-E)

  • Multiport Z is exactly reciprocal. The grounding matrix paired length-weighted excitation columns with an unweighted potential average, breaking Z[i, j] == Z[j, i] at the discretisation level for electrodes with unequal segment lengths (mesh electrodes with dx/nx != dy/ny, rods split at the layer interface). The row reduction now uses the Galerkin-consistent length-weighted average — symmetry to machine precision (regression test at 1e-13); results for uniform per-electrode segment lengths (every rod/ring/strip) are unchanged.
  • cim and bem reject n_layers >= 3. The historic complex-image kernel implemented an incomplete Green's function (single image family; missing the 2·h_1-reflected families and the surface–interface multiple-reflection denominator) and systematically underestimated the layered correction. Both backends now raise NotImplementedError pointing at mom_sommerfeld / fem; the corrected full kernel formula is documented in solver/_layered.py, and ADR-0002 carries an amendment revoking cim as the primary n ≥ 3 engine.
  • bem docstring no longer claims independence from mom for n ≤ 2 (they assemble the identical matrix — measured 4e-16; audit finding P4). Genuine layered cross-validation: mom_sommerfeld and fem.

Changed — vector fitting on the conjugate-pair real basis (audit 2026-07-08, WP-B4)

  • Complex pole pairs now carry genuinely complex residues. The historic real-stacked least squares used one real unknown per pole, silently removing the Im(r) degree of freedom for both the residues and the σ-residues that steer the pole relocation — a deviation from the cited Gustavsen & Semlyen algorithm. Both LS systems now use the standard conjugate-pair real basis (1/(s-p) + 1/(s-p̄) and j/(s-p) - j/(s-p̄) with two real coefficients per pair); residues at conjugate poles are exact conjugates by construction (the post-hoc repair is gone). Regression test: a synthetic resonant Z with Im(r) = 40 is now reproduced to rms 1e-6 relative (previously unfittable).
  • Convergence monitoring. The relocation loop tracks the relative pole displacement, breaks early below 1e-8 and emits a VectorFitConvergenceWarning when it is still above 1 % after n_iter iterations; diagnostics exposed as VectorFitResult.n_iter_used / pole_shift.
  • Optional weighting. vector_fit(..., weighting= "inverse_magnitude") weights samples by 1/|Z| — the standard remedy when |Z| spans decades.
  • Dead frequencies are masked. rho_f_from_field_result used to inject Z = 0 samples for frequencies where the electrode carries no current, silently pulling the fit through the origin; those samples are now excluded with a warning (all-dead input raises).

Fixed — layer-2 field evaluation and cross-layer plumbing (audit 2026-07-08, WP-D)

  • Layer dispatch in the post-solve potential paths. FieldResult.potential and the solve_mutual_* probe kernels applied the upper-layer Tagg/Sunde image series to every probe and source point; for layer-2 points the measured error was +7 % at z = 7 m and +25 % at z = 12 m (K = +0.818, h_1 = 5 m). Pairs involving layer 2 now go through the rigorous spectral kernel (new coupling.layered_green.two_layer_probe_matrix, grouped by depth pair with one spectral-amplitude solve per group); pure upper-layer evaluation keeps the historic fast path bit-exact. Verified: potential continuity across the interface, homogeneous limit, exact agreement with the spectral reference at depth.
  • Interface-split discretiser (ADR-0007 step 1, previously documented but not implemented). Rod and sloped-strip segments are split at the layer interface so no segment straddles h_1 (historic mis-assignment: up to ds/2 of wire in the wrong layer); wired into every layered backend. A margin warning fires when the deepest segment ends within 2·segment_length of h_1 (the image-series self-terms degrade there).
  • mom accepts cross-layer worlds. The hard rejection is gone; the shared self-kernel factory dispatches to the ADR-0007 Sommerfeld path. mom is the engine that solves the per-segment current distribution — the audit's P5 uniform-leakage bias across the interface is now measurable inside the package (regression test pins mom below image_2layer for rho_2 > rho_1, and mom ≡ bem to 1e-6).
  • Cross-layer assembly grouped and cached (performance): the ADR-0007 reaction-matrix correction ran one scalar Sommerfeld BVP solve per matrix entry — O(n²) quadratures, prohibitively slow after the WP-B1 oscillation-resolved grids. Off-diagonals are now grouped by (z_i, z_j) with one spectral-amplitude solve per group (two_layer_layered_correction_group), identical diagonal entries are deduplicated, and the current-independent matrices are cached across the per-frequency/per-excitation kernel calls of one solve. Measured: 3-rod cross-layer world 33.7 s → 4.6 s on the audit sandbox (identical result).
  • New regression suite tests/test_audit_layer2.py (8 tests: interface continuity, pinned layer-2 anchor values, homogeneous limit, split invariants, margin warning, mom cross-layer).

Fixed — inductive earth-return stack consolidated (audit 2026-07-08, WP-C)

The audit's headline physics finding: the inductive coupling stack (earth_inductive_model) had three structural defects that made quantitative Z(f) statements above ~100 Hz unreliable. All three are fixed; the galvanic (resistive) results are unaffected.

  • sommerfeld is now a genuine Pollaczek kernel (ADR-0006 amendment). The historic kernel 1/R + ∫Γ e^{-λ(z+z')}J0 dropped the in-soil attenuation e^{-γR} of the primary term — which carries the buried-wire earth-return resistance — and produced Re Z' ≈ −ωμ0/8 per metre (Carson's value with the wrong sign); it also applied the soil-side reflection +Γ to overhead conductors (air side requires −Γ). The kernel now dispatches per segment pair (buried/overhead/mixed), keeps the mirror deduplication −1/R' and the direct attenuation (e^{-γR}−1)/R in closed form, and integrates only the smooth remainder. Validated against Pollaczek's analytic K0 mutual (Im to ~1 %, Re to a few % chain truncation, correct positive sign) and the σ-limits: σ→0 → free space (no image), σ→∞ → screened (buried) / anti-parallel PEC image (overhead).
  • Spectral part interpolated over ρ instead of the historic (16,16,nλ) tensor evaluation: distant segment pairs drop from ~2 s to milliseconds per pair (the smooth Hankel integral is evaluated on 24 log-spaced ρ-nodes and interpolated).
  • carson_series matrix is mesh-convergent (tiling convention): collinear same-wire segment pairs no longer receive a pseudo-mutual term (with the axial midpoint distance misread as Carson's perpendicular wire separation — the assembled correction grew ~linearly with the segment count; measured branch-current drift of ~2.5× between dsl = 50 m and 6.25 m, now < 1e-3). Near-parallel pairs on distinct axes tile the per-metre mutual by their axial overlap length at the perpendicular axis separation — the assembled block reproduces z'·ℓ independent of segmentation.
  • Behaviour change: results with earth_inductive_model set to "sommerfeld" or "carson_series" change (they were wrong); "perfect_mirror" remains bit-stable and stays the default, but is now documented as a frequency-independent baseline whose additive image is far from the f < 1 kHz physics of buried conductors — use "sommerfeld" for quantitative Z(f).
  • New regression suite tests/test_audit_inductive_stack.py (Pollaczek K0 reference, σ-limit semantics, Carson mesh convergence at matrix and solver level).

Fixed — quadrature defects in the coupling kernels (audit 2026-07-08, WP-B)

  • layered_green Hankel grid resolves the Bessel oscillations. The cross-layer kernels (two_layer_real_space_kernel, two_layer_layered_correction_real_space) integrated the linear λ-region with a single fixed 96-node Gauss panel; for radial distances s >> min(h_1, depths) the J0(λs) oscillations were unresolved — measured errors of 2.5 % at s = 100 m and 46 % at s = 200 m for cross-layer pairs (live in AP1 via the ADR-0007 path). The new _hankel_lambda_grid keeps the historic single panel while it holds ≥ 8 nodes per oscillation (bit-compatible for small s), splits into one 16-node panel per J0 period beyond that, and caps the log-region below the first oscillation (lambda_break <= pi/(4 s)). Verified to ~1e-9 against adaptive scipy references up to s = 200 m.
  • Carson intermediate regime handles near-perpendicular geometries. _p_q_quadrature truncated at mu_max = 30/p with 64 fixed Gauss nodes; for buried-pair mutual geometries (theta -> 90°, small p) the cos(q·mu) oscillation was unresolved — measured errors up to −36 % in P and +67 % in Q (a = 0.44–1.6, θ ≈ 89°), squarely inside the AP1 parameter space. Oscillatory cases now use QUADPACK's Fourier integrator (quad(..., weight='cos')), which also covers the exact theta = 90° limit (the former small-a fallback there was invalid for a > 0.25 and is gone). Verified to 1e-11 against an independent composite-panel/Euler-accelerated reference.
  • Large-a asymptote: the a^-3 term of Q was missing its 1/sqrt(2) (~6e-4 absolute at a = 8); for theta > 1.4 rad the asymptotic expansion degrades and now routes through the quadrature path.
  • New regression suite tests/test_audit_quadratures.py pinning the audit's failing points with independent reference values; ADR-0005 regime section rewritten to describe the implemented quadrature (the previously documented σ-series never existed).

Changed — Tier-1 performance: one-shot multiport assembly (audit 2026-07-08, WP-F)

Profiling of AP1-sized worlds showed 97 % of Engine.solve wall time inside _self_corrected_kernel, called once per electrode column and per frequency — each call rebuilding the full (N, N) geometry tensors. Three changes (ADR-0010 Tier 0a/1, results numerically identical to FP rounding):

  • Batched multiport-Z assembly. _solve_cluster_currents passes all N_a excitation columns to the self-kernel in one call as an (n_segments, N_a) matrix; the O(N²) kernel tensors are built exactly once instead of N_a times.
  • Multiport cache across the frequency loop. The grounding matrix Z is frequency-independent; image, image_2layer and cim now assemble it once per solve and reuse it for every frequency (new multiport_cache parameter).
  • Batched potential evaluation + multi-RHS solves. The per-frequency segment potentials are evaluated in one stacked kernel call for the whole frequency set; the real DC-path linear systems solve [b_re, b_im] with a single LU factorisation (also in mom/bem/mom_sommerfeld via _galerkin_solve, and in fem).

Measured (sandbox, 4 cores): 50-building TN world, ds = 0.5 m (N = 1476): 22.0 s → 0.18 s; 100 buildings (N = 2926): ≈ 2 min → 0.85 s; two-rod world with distributed inductive PEN at 7 frequencies: 7 ms. Solver output verified identical against the pre-change audit reference values (galvanic and inductive paths).

Added — guard rails against silently wrong results (audit 2026-07-08, WP-A)

The physics/numerics audit of 2026-07-08 (report in audit-report-2026-07-08/) identified a class of configurations that solved to physically wrong numbers without any diagnostic. This patch converts them into hard errors or visible warnings:

  • Surface-laid inductive conductors raise. build_inductance_matrix(use_image=True) rejects segments lying in the soil-surface plane (2·|z_mid| <= wire_radius): the perfect-mirror image coincides with the segment and the partial self-inductance diverges (observed ~4.7 H instead of ~55 µH for a 25 m segment at z = 0, silently blocking the branch current). Bury the conductor or pass use_image=False.
  • Thin-wire hard guard. The discretisers raise ValueError when the resulting segment length is <= wire_radius — there the analytic self-term ln(L/a) flips sign and the solve returns nonsense currents. The advisory quality criterion (L >= 5a) remains a warning (see below).
  • Pre-flight diagnostics on every solve. Engine.solve now runs check_segment_resolution and emits each finding as a UserWarning (thin-wire ratio, electrode smaller than one segment, distributed-conductor ratio, segment budget).
  • SeriesTruncationWarning. A truncated Tagg/Sunde series (image_max_terms reached before the tolerance) now emits a visible warning in image_2layer and mom instead of a logger-only record; metadata['converged'] is unchanged.
  • Concrete shells rejected loudly. mom, cim, bem, mom_sommerfeld and fem raise NotImplementedError for worlds carrying concrete_shell_coefficient_ohm_m != 0 (ADR-0012) instead of silently solving the bare-metal problem — as the electrode documentation always promised.
  • Non-current sources warn. Every backend warns when it drops non-current sources; a world driven solely by voltage sources no longer solves to all-zero silently.
  • Clamp diagnostic. The reaction-matrix assembly warns when distinct segments fall below the 1 mm singularity clamp (coincident/overlapping conductors).

Fixed

  • Single-segment distributed conductors no longer vanish. A distributed conductor with discretize_segment_length >= length (n_segments == 1) was skipped by both the distributed topology builder and the lumped-branch builder and disappeared from the nodal system entirely (open circuit, measured I = 0 through the conductor). It now falls back to a lumped finite branch, bit-identical to the equivalent lumped conductor.
  • Cross-layer consistency of cim, bem and the mom_sommerfeld diagonal. For two-layer worlds with electrodes crossing the layer interface these backends silently applied the upper-layer Tagg/Sunde series. The shared self-kernel factory is now created with allow_cross_layer=True, dispatching the rigorous ADR-0007 cross-layer kernel — consistent with image_2layer. For n_layers >= 3 cross-layer worlds, cim/bem/mom_sommerfeld now raise ValueError (previously: warning followed by wrong physics).

Changed

  • Series truncation criterion. The Tagg/Sunde stop test now uses the geometric tail bound |K|^(n+1)/(1-|K|) < tol instead of the per-term weight |K|^n < tol, which underestimated the neglected remainder by 1/(1-|K|) (a factor 17 at the AP1 corner soil |K| = 0.94). Applied consistently in the solver, the post-processing potential kernels (FieldResult.potential, solve_mutual_*) and the converged metadata.
  • Engine.image_max_terms default raised 100 → 300 so the AP1 corner contrast |K| = 0.94 converges under the new tail criterion (needs 277 terms). Same default in create_engine.
  • Engine truncation knobs reach all layered backends. image_max_terms / image_series_tol are now forwarded to mom, cim, bem and mom_sommerfeld (previously hard-coded 100/200 terms in those paths).

Removed

  • _layered.image_series_offsets (dead code, never called by any backend): its higher-order expansion terms dropped the required Γ^{m+1} powers and would have produced wrong n ≥ 3 image series had it ever been consumed.

Internal

  • New regression suite tests/test_audit_guards.py (21 tests) covering every guard above end-to-end.
  • tests/test_strip.py: the degenerate-mesh workaround comparison now asserts the thin-wire ValueError (the workaround geometry is exactly what the guard rejects).