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 withdx/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. cimandbemrejectn_layers >= 3. The historic complex-image kernel implemented an incomplete Green's function (single image family; missing the2·h_1-reflected families and the surface–interface multiple-reflection denominator) and systematically underestimated the layered correction. Both backends now raiseNotImplementedErrorpointing atmom_sommerfeld/fem; the corrected full kernel formula is documented insolver/_layered.py, and ADR-0002 carries an amendment revokingcimas the primary n ≥ 3 engine.bemdocstring no longer claims independence frommomfor n ≤ 2 (they assemble the identical matrix — measured 4e-16; audit finding P4). Genuine layered cross-validation:mom_sommerfeldandfem.
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̄)andj/(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 withIm(r) = 40is 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
VectorFitConvergenceWarningwhen it is still above 1 % aftern_iteriterations; diagnostics exposed asVectorFitResult.n_iter_used/pole_shift. - Optional weighting.
vector_fit(..., weighting= "inverse_magnitude")weights samples by1/|Z|— the standard remedy when|Z|spans decades. - Dead frequencies are masked.
rho_f_from_field_resultused to injectZ = 0samples 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.potentialand thesolve_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 (newcoupling.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).
momaccepts 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.
sommerfeldis now a genuine Pollaczek kernel (ADR-0006 amendment). The historic kernel1/R + ∫Γ e^{-λ(z+z')}J0dropped the in-soil attenuatione^{-γR}of the primary term — which carries the buried-wire earth-return resistance — and producedRe Z' ≈ −ωμ0/8per 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)/Rin 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_seriesmatrix 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 reproducesz'·ℓindependent of segmentation.- Behaviour change: results with
earth_inductive_modelset 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_greenHankel 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 distancess >> min(h_1, depths)theJ0(λ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_gridkeeps 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_quadraturetruncated atmu_max = 30/pwith 64 fixed Gauss nodes; for buried-pair mutual geometries (theta -> 90°, small p) thecos(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 exacttheta = 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^-3term of Q was missing its1/sqrt(2)(~6e-4 absolute at a = 8); fortheta > 1.4 radthe asymptotic expansion degrades and now routes through the quadrature path. - New regression suite
tests/test_audit_quadratures.pypinning 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_currentspasses allN_aexcitation 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 ofN_atimes. - Multiport cache across the frequency loop. The grounding
matrix Z is frequency-independent;
image,image_2layerandcimnow assemble it once per solve and reuse it for every frequency (newmultiport_cacheparameter). - 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 inmom/bem/mom_sommerfeldvia_galerkin_solve, and infem).
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 passuse_image=False. - Thin-wire hard guard. The discretisers raise
ValueErrorwhen the resulting segment length is<= wire_radius— there the analytic self-termln(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.solvenow runscheck_segment_resolutionand emits each finding as aUserWarning(thin-wire ratio, electrode smaller than one segment, distributed-conductor ratio, segment budget). SeriesTruncationWarning. A truncated Tagg/Sunde series (image_max_termsreached before the tolerance) now emits a visible warning inimage_2layerandmominstead of a logger-only record;metadata['converged']is unchanged.- Concrete shells rejected loudly.
mom,cim,bem,mom_sommerfeldandfemraiseNotImplementedErrorfor worlds carryingconcrete_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, measuredI = 0through the conductor). It now falls back to a lumped finite branch, bit-identical to the equivalent lumped conductor. - Cross-layer consistency of
cim,bemand themom_sommerfelddiagonal. 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 withallow_cross_layer=True, dispatching the rigorous ADR-0007 cross-layer kernel — consistent withimage_2layer. Forn_layers >= 3cross-layer worlds,cim/bem/mom_sommerfeldnow raiseValueError(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|) < tolinstead of the per-term weight|K|^n < tol, which underestimated the neglected remainder by1/(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 theconvergedmetadata. Engine.image_max_termsdefault raised 100 → 300 so the AP1 corner contrast |K| = 0.94 converges under the new tail criterion (needs 277 terms). Same default increate_engine.- Engine truncation knobs reach all layered backends.
image_max_terms/image_series_tolare now forwarded tomom,cim,bemandmom_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-wireValueError(the workaround geometry is exactly what the guard rejects).