Skip to content

Replace bundled AMOS complex Bessel with fortnum (6/8)#145

Draft
krystophny wants to merge 1 commit into
fortnum/k5-kilca-roots-utilfrom
fortnum/k6-complex-bessel
Draft

Replace bundled AMOS complex Bessel with fortnum (6/8)#145
krystophny wants to merge 1 commit into
fortnum/k5-kilca-roots-utilfrom
fortnum/k6-complex-bessel

Conversation

@krystophny

@krystophny krystophny commented Jun 14, 2026

Copy link
Copy Markdown
Member

Merge order

These fortnum-migration PRs are individually based on main and form one
cumulative stack. Merge them in this order:

#140 -> #141 -> #142 -> #143 -> #144 -> #145 -> #146 -> #147 -> #148 -> #149 -> #150

Each PR is opened against main, so its diff is cumulative versus main and
overlaps its predecessors. Merging in the order above keeps the history linear:
once a predecessor merges into main, the next PR's diff shrinks to just its
own increment.

Scope

The headline removal: replace the bundled AMOS complex-argument Bessel sources with the fortnum complex-Bessel core. A new common/math/fortnum_amos_compat module provides zbesj/zbesi/zbesk on the historical AMOS (ZR, ZI, FNU, KODE, N, CYR, CYI, NZ, IERR) ABI, so every caller compiles and links unchanged: the KiLCA wrappers (interface/bessel.f90, math/bessel/bessel.f90), the conductivity D-array kernels, the vacuum stitching (hmedium), the Maxwell start values, and the KIM dispersion solvers (fun_input, wkb_dispersion). The zbes* family and its AMOS helpers (and dgamln, used only by them) are deleted from common/math/slatec; the machine-constant and error routines stay for QUADPACK and ddeabm. The dead, never-compiled KiLCA/math/bessel/amos and /644 trees are deleted.

Dependency removed

Bundled AMOS zbesj/zbesi/zbesk (common/math/slatec z*.f) and the SLATEC zbesi used by KIM.

Verification

The fortnum-backed shim computes the AMOS sequences correctly through the original ABI:

$ gfortran -I.../fortnum/include fortnum_amos_compat.f90 probe.f90 libfortnum.a -o probe && ./probe
 zbesi I0..I2 re=   1.1798566  0.5124138  0.0885864  ierr= 0
 zbesk K0..K2 re=   0.3078189  0.3763245  0.5884542  ierr= 0
 zbesj J1(2)=  0.5767248  0.0  ierr= 0   (bessel_j1(2)=0.576725)

In the stack-tip build, nm over every shipped binary shows 0 defined AMOS implementation symbols (zbknu zbinu zseri zmlri zasyi zacai zacon zunhj zunik zuoik zwrsk zbuni zbunk zairy zbesh zbesy zbiry dgamln zabs all 0), while zbesi_/zbesj_/zbesk_ resolve to the fortnum-backed shim and pull fortnum_bessel_i_complex_array / __fortnum_special_complex_bessel_MOD_*. test_ampere_matrices and the integration tests pass (see K8). Draft: only the stack tip was built end to end.


Stack reconciliation (update)

The migration stack was rebuilt as a strictly linear cumulative chain on main 428a708:

k1 (+ golden CI fix) -> k2 -> k3 -> k4 -> k5 -> k6 -> k7 -> k8 -> z1 -> z2 -> z3

Every branch now pins fortnum to main 974dcf1 (all kernel fixes plus both new integrators). This branch's standalone golden result above stands. The cumulative tip (#150 z3) does not pass: the KiLCA background equilibrium ODE on #143 k4 cannot reproduce the GSL rk8pd golden with DOP853 at the unchanged 1e-8 bar. See #143 and #150. Tolerances were not weakened and the stored golden was not regenerated.

Merge order: #140 -> #141 -> #142 -> #143 -> #144 -> #145 -> #146 -> #147 -> #148 -> #149 -> #150.

Note: fortnum pin updated to current main (92de6e9) after a fortnum history rewrite; old shas no longer resolve.

@krystophny krystophny force-pushed the fortnum/k6-complex-bessel branch from 816ff96 to 174cbbb Compare June 15, 2026 19:27
@krystophny krystophny changed the base branch from main to fortnum/k5-kilca-roots-util June 15, 2026 19:29
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