Spherical harmonic decomposition on a cubic grid

A method is described by which a function defined on a cubic grid (as from a finite difference solution of a partial differential equation) can be resolved into spherical harmonic components at some fixed radius. This has applications to the treatment of boundary conditions imposed at radii larger than the size of the grid, following Abrahams et al (1998 Phys. Rev. Lett. 80 1812–5). In the method described here, the interpolation of the grid data to the integration 2-sphere is combined in the same step as the integration to extract the spherical harmonic amplitudes, which become sums over grid points. Coordinates adapted to the integration sphere are not needed.