# Poisson's equation in disks and balls This page explains how pdemagic solves $$ -\nabla^2 u = g \quad \text{with } g = 0 \text{ outside a disk or a ball}, $$ when the problem is stated in polar or spherical coordinates and gives no condition on the surface. The solution is the free-space one, as for the [Fourier method](fourier-poisson.md), but the grid follows the shape of the domain, and the source may reach right up to its surface without loss of accuracy. ## The method In these coordinates the free-space Green's function separates. In a ball, $$ \frac{1}{4\pi \lvert \mathbf{x} - \mathbf{y} \rvert} = \sum_{l,m} \frac{1}{2l+1}\, \frac{r_<^{\,l}}{r_>^{\,l+1}}\, Y_{lm}(\Omega_x)\, Y_{lm}^*(\Omega_y), $$ with $r_<$ and $r_>$ the smaller and the larger of the two radii. Expanding source and solution in spherical harmonics therefore leaves one one-dimensional integral per harmonic: $$ u_{lm}(r) = \frac{1}{2l+1} \int_0^R \frac{r_<^{\,l}}{r_>^{\,l+1}}\; g_{lm}(s)\, s^2\, \mathrm{d}s . $$ In a disk the harmonics are $e^{im\varphi}$, and $$ u_m(r) = \frac{1}{2\lvert m \rvert} \int_0^R \left( \frac{r_<}{r_>} \right)^{\lvert m \rvert} g_m(s)\, s\, \mathrm{d}s \quad (m \ne 0), \qquad u_0(r) = -\int_0^R \ln(r_>)\, g_0(s)\, s\, \mathrm{d}s . $$ The integrals run over the domain only. The vacuum outside is built into the Green's function, so no boundary condition is imposed, approximated or iterated. This is the exact vacuum condition on the surface. The steps are: 1. Transform along the azimuth with an FFT. In the ball, project onto the associated Legendre functions with Gauss–Legendre quadrature in the cosine of the polar angle. 2. Apply the radial integral to each coefficient. The source coefficient is interpolated by a polynomial through the radial Gauss points and integrated with Gauss–Legendre quadrature. Inside a point one panel is exact. Outside it, where the integrand falls steeply for high orders, panels that double in length keep the quadrature accurate to rounding for every order. 3. Transform back. The radial integral is a matrix per order $l$ or $\lvert m \rvert$, computed once per solve. ## Accuracy Polynomial sources are reproduced to rounding on the coarsest grids. For example, a uniformly charged ball of radius $R$ has the potential $(3R^2 - r^2)/6$ inside. For smooth sources the method is spectrally accurate. For a Gaussian charge of width 0.08 at a distance 0.27 from the centre of a unit disk or ball, relative to the largest value of the potential: | Points along the radius | Disk | Ball | |---|---|---| | 16 | 1.3e-4 | 2.2e-4 | | 24 | 4.2e-7 | 1.4e-6 | | 32 | 8.7e-10 | 4.7e-9 | | 48 | 1.8e-15 | 5.5e-15 | The grids have as many points along the polar angle as along the radius, and twice as many along the azimuth. A source with a jump inside the domain, or with a kink, is not resolved by any grid, and the method then converges only algebraically. A jump at the surface is no obstacle: it is where the domain ends. ## What the planner chooses There is no box to find: the domain is given. The planner tries grids with 8, 12, 16, 24, 32, 48, 64 and 96 points along the radius, and takes the coarsest one on which the expansion of the source has decayed to $10^{-10}$ of its largest coefficient, both in the upper third of the angular orders and in the upper third of the radial polynomial degrees. ## Limits - Poisson's equation only, and nothing in time. With a condition on the surface, other equations and equations in time are solved by [collocation](round-domains.md). - The domain is the full disk or ball around the origin. Rings and shells are solved with a condition on each surface, by [another method](round-domains.md), and not with vacuum outside. Sectors are not handled. - Array data must be given at the points of the method's grid, which `Disk.axes` and `Ball.axes` return. Data on other grids would have to be interpolated first. - The spherical harmonic transform costs a number of operations that grows with the fourth power of the number of points along the radius. It is fast for the grids the planner chooses, and would need a faster transform far beyond them.