Abstract In planetary geodesy, shapes and gravitational fields of celestial bodies are often expressed in spherical harmonics. Observing these quantities with ever-increasing spatial resolution challenges numerical implementations of spherical harmonics in aspects such as accuracy, efficiency, memory consumption or runtimes. In this paper, we present CHarm, a C library for spherical harmonic transforms centred around gravitational field and planetary topography modelling. CHarm implements forward transforms by means of the exact Gauss–Legendre and Driscoll–Healy quadratures. Backward transforms are possible up to the second-order potential derivatives, allowing to model quantities encountered in gravimetry and satellite gradiometry. Among features unique to CHarm are spectral gravity-forward modelling routines. They compute gravitational fields implied by topographic masses following constant, lateral and 3D-variable density distributions while supporting global and cap integrations. CHarm can be compiled in single, double and quadruple precision. We demonstrate numerical stability of double precision transforms up to degree 100,000, which corresponds to the 200-m resolution at the Earth’s surface. To boost performance, CHarm exploits three parallelisation techniques: (i) vectorised instructions, (ii) OpenMP for shared-memory parallelisation and (iii) the Message-Passing Interface for parallelisation on shared- and distributed-memory platforms. Besides parallelisation, we discuss and benchmark further strategies to optimise spherical harmonic transforms such as the use of the fast Fourier transform, the Chebyshev recurrences, the equatorial symmetry of Legendre functions, the polar optimisation and processing latitudes in small blocks of a fixed length. The library is accompanied by a Python wrapper called PyHarm. CHarm is available at https://www.github.com/blazej-bucha/charm .
Blažej Bucha (Sat,) studied this question.