Skip to content

Replace GSL fixed-rule quadrature and error handler with fortnum (3/5)#31

Draft
krystophny wants to merge 6 commits into
mainfrom
drop-gsl-fortnum-c-quadrature
Draft

Replace GSL fixed-rule quadrature and error handler with fortnum (3/5)#31
krystophny wants to merge 6 commits into
mainfrom
drop-gsl-fortnum-c-quadrature

Conversation

@krystophny

@krystophny krystophny commented Jun 14, 2026

Copy link
Copy Markdown
Member

Merge order

Stack sequence: #29 -> #30 -> #31 -> #32 -> #33.

Each PR is now based on main individually, so its diff is cumulative against main and shares code with its stack neighbors. Merge in the sequence above. Once a predecessor merges into main, the next PR rebases onto it and its diff shrinks to its own increment.


Third in the fortnum migration stack (base: the hyper1F1 PR). Moves the remaining C-side GSL call sites over, after which no MEPHIT source references GSL.

Dependency removed: GSL fixed-rule Gauss-Legendre quadrature in src/mephit_fem.c (gsl_integration_glfixed_table_*) and the GSL error-handler path in src/mephit_util.c / src/mephit_util.h / src/mephit_run.c (gsl_errno_msg, gsl_set_error_handler, gsl_strerror). The Gauss-Legendre nodes and weights on the unit interval now come from fortnum_gauss_legendre_ab, which folds the table allocation and the [a, b] mapping into one call. fortnum reports failures through return codes rather than a global GSL handler, so the dedicated GSL message hook and its forward declaration are removed.

Verification

Build the shared library at this tip:

$ cmake -S . -B build -G Ninja && cmake --build build --target mephit
[16/19] Building C object CMakeFiles/mephit.dir/src/mephit_util.c.o
[17/19] Building C object CMakeFiles/mephit.dir/src/mephit_fem.c.o
[18/19] Linking CXX shared library lib/libmephit.so

After this PR the library resolves no GSL symbol at all, and fortnum's Gauss-Legendre routine is linked:

$ nm -DC build/lib/libmephit.so | grep -ic gsl
0
$ nm -DC build/lib/libmephit.so | grep -i fortnum_gauss_legendre
0000000000115980 T fortnum_gauss_legendre
00000000001158f0 T fortnum_gauss_legendre_ab

GSL is still on the link line (GSL::gsl) and still searched (find_package(GSL)); both are removed in PR 5 once nothing depends on them. As in earlier PRs, the .x executables link only after PR 4 removes the empty FFTW link.

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

Drop the gsl_sf_bessel_In_array C binding in mephit_pert and compute the
modified Bessel functions through fortnum's bessel_in_array. fortnum fills
I_0..I_nmax in one pass, so the orders |m|-1, |m|, |m|+1 are recovered with
the symmetry I_{-n}(x) = I_n(x); for pol_mode = 0 the order -1 maps to I_1.

Wire fortnum via CMake FetchContent at the pinned tag, guarded so a build that
also pulls fortnum transitively through libneo does not declare the target
twice. Add the fortnum include directory for the C/C++ sources and link the
fortnum target. GSL stays linked until the remaining call sites move over.
@krystophny krystophny marked this pull request as draft June 14, 2026 07:56
@krystophny krystophny force-pushed the drop-gsl-fortnum-hyper1f1 branch from 8024bf9 to 12048cb Compare June 14, 2026 09:33
@krystophny krystophny force-pushed the drop-gsl-fortnum-c-quadrature branch from fa2e524 to 6d6cc8b Compare June 14, 2026 09:33
Route the a = 1 confluent hypergeometric evaluation through the fortnum C ABI:
the boundary integral uses fortnum_integrate_qag with the Gauss-Kronrod 21
rule, and the Kummer-series acceleration uses fortnum_levin_u_accel. Both
fortnum routines take the integrand plus an opaque context, so the existing
quad_params struct is forwarded unchanged and no workspace is allocated. Add
float.h for DBL_EPSILON, which was previously pulled in transitively through a
GSL header.
Move the remaining C-side GSL call sites onto the fortnum C ABI. The
Gauss-Legendre nodes and weights on the unit interval now come from
fortnum_gauss_legendre_ab, which folds the table allocation and the [a, b]
mapping into one call. Drop gsl_errno_msg and the gsl_set_error_handler
registration: fortnum routines report failures through return codes rather than
a global GSL error handler, so the dedicated GSL message hook and its forward
declaration are no longer reachable. After this change libmephit.so resolves no
GSL symbols.
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