# Poisson's equation by Fourier convolution This page explains how pdemagic solves $$ -\nabla^2 \varphi = g \quad \text{in } \mathbb{R}^d, \qquad \varphi \to 0 \text{ at infinity}, $$ and what its automatic choices are based on. The method is described for three free dimensions first. Other dimensions, periodic directions, and the mix of both follow below. ## The method The solution is the convolution of the source with the free-space Green's function, $$ \varphi(\mathbf{x}) = \int G(\mathbf{x} - \mathbf{y})\, g(\mathbf{y})\, \mathrm{d}\mathbf{y}, \qquad G(r) = \frac{1}{4\pi r}. $$ A convolution is a product in Fourier space, which suggests the FFT. Two things stand in the way. The transform of $G$, $1/s^2$, is singular at zero frequency. And an FFT computes a periodic convolution, which is the solution of the periodic problem, not of the free one. pdemagic uses the method of Vico, Greengard and Ferrando[^vgf], which removes both obstacles with one observation. The source and the points where the potential is wanted all lie in the box of the grid. No two of them are further apart than the diagonal $D$ of the box. So $G$ can be replaced by $$ G_R(r) = \begin{cases} G(r), & r < R \\ 0, & \text{otherwise} \end{cases} \qquad \text{with } R > D, $$ without changing the result. The truncated function has a smooth transform in closed form, $$ \hat{G}_R(s) = \frac{1 - \cos(sR)}{s^2} = 2 \left( \frac{\sin(sR/2)}{s} \right)^{2}, \qquad \hat{G}_R(0) = \frac{R^2}{2}. $$ Because $G_R$ has compact support, the periodic convolution equals the free one as soon as the period along each axis holds the box and the reach $R$ of the kernel. The algorithm is therefore: 1. Sample the source on the grid and pad it with zeros to that period. 2. Transform, multiply by $\hat{G}_R$, transform back. 3. Keep the part that lies in the box. The padded array has about $(1 + \sqrt{3})^3 \approx 20$ times as many points as the grid. Sizes are rounded up to products of 2, 3 and 5, for which the transforms are fast. ## Other dimensions Only the Green's function and its truncated transform depend on the dimension $d$. With $x = sR$: | $d$ | $G(r)$ | $\hat{G}_R(s)$ | |---|---|---| | 1 | $-\lvert x \rvert / 2$ | $\dfrac{1 - \cos x}{s^2} - \dfrac{R \sin x}{s}$ | | 2 | $-\dfrac{\ln r}{2\pi}$ | $\dfrac{1 - J_0(x)}{s^2} - \dfrac{R \ln R \, J_1(x)}{s}$ | | $\ge 3$ | $\dfrac{\Gamma(d/2 - 1)}{4 \pi^{d/2}\, r^{d-2}}$ | $\dfrac{1 - \Lambda_{d/2-2}(x)}{s^2}$ | Here $\Lambda_\mu(x) = \Gamma(\mu + 1)\,(2/x)^{\mu} J_\mu(x)$ is the Bessel function normalized to $\Lambda_\mu(0) = 1$. In three dimensions it is $\cos x$, which gives the formula above; in five it is $\sin(x)/x$. In one and two dimensions $G$ does not decay, and the potential of a source with net charge grows at infinity. The "vacuum condition" then means exactly this convolution. In two dimensions the logarithm fixes the unit of length: $G$ vanishes at $r = 1$ in whatever units the coordinates are given. The padded array has $(1 + \sqrt{d})^d$ times as many points as the grid, which is 2 in one dimension, 6 in two, 20 in three and 81 in four. ## Periodic directions **Periodic in every direction.** No trick is needed: each Fourier coefficient of the source is divided by $\lvert \mathbf{k} \rvert^2$. The coefficient at $\mathbf{k} = 0$, the mean of the source, has no counterpart. A solution exists only if it vanishes, so it is dropped, the solution returned has zero mean, and the dropped value is reported as `removed_source_mean`. **Periodic in some directions, free in the others.** A Fourier series along the periodic directions leaves one problem per periodic wave vector $\mathbf{k}$, in the free directions only: $$ (\kappa^2 - \nabla_{\text{free}}^2)\, \varphi_{\mathbf{k}} = g_{\mathbf{k}}, \qquad \kappa = \lvert \mathbf{k} \rvert . $$ For $\kappa = 0$ this is the free problem in fewer dimensions, solved as above: a slab with net charge has the one-dimensional potential $-|z|/2$ per unit charge, a wire the logarithmic one. For $\kappa > 0$ the Green's function decays exponentially, but over the length of a period, which is not short compared with the box. Ignoring its tail would cost accuracy. It is therefore truncated at $R$ like the free one, and the transform is again known in closed form. With $x = sR$ and $D = \kappa^2 + s^2$: | Free dimensions | $G_\kappa(r)$ | $\hat{G}_{\kappa,R}(s)$ | |---|---|---| | 1 (slab) | $\dfrac{e^{-\kappa \lvert x \rvert}}{2\kappa}$ | $\dfrac{1 - e^{-\kappa R}\left(\cos x - \frac{s}{\kappa} \sin x\right)}{D}$ | | 2 (wire) | $\dfrac{K_0(\kappa r)}{2\pi}$ | $\dfrac{1 + R\left(s J_1(x) K_0(\kappa R) - \kappa J_0(x) K_1(\kappa R)\right)}{D}$ | | 3 | $\dfrac{e^{-\kappa r}}{4 \pi r}$ | $\dfrac{1 - e^{-\kappa R}\left(\cos x + \kappa R\, \frac{\sin x}{x}\right)}{D}$ | Only the free directions are padded, and the radius $R$ is the diagonal of the box along them. ## Accuracy For smooth sources the method is spectrally accurate: the error falls faster than any power of the grid spacing. For a Gaussian charge of unit width on a box of half-width 7.5, the largest error in the potential is: | Points per axis | Error | |---|---| | 16 | 2.4e-5 | | 20 | 4.3e-7 | | 24 | 4.1e-9 | | 28 | 2.8e-11 | | 32 | 7.5e-14 | The same holds in the other dimensions. For a unit Gaussian on a box of half-width 8.5, relative to the largest value of the potential: | Points per axis | 1D | 2D | 3D | |---|---|---|---| | 16 | 2.3e-5 | 6.6e-5 | 2.2e-4 | | 24 | 3.4e-7 | 2.0e-7 | 1.3e-7 | | 32 | 2.5e-12 | 1.6e-10 | 2.0e-11 | | 48 | 7.3e-16 | 2.4e-15 | 8.9e-16 | In four dimensions, on a box of half-width 6, the errors with 10, 14 and 18 points per axis are 3.5e-3, 2.1e-5 and 8.4e-8. With periodic directions, for a decaying wave plus the potential of a Gaussian charge that is uniform along the periodic directions: | Points per axis | Strip (2D) | Slab | Wire | |---|---|---|---| | 16 | 1.2e-2 | 4.6e-3 | 5.0e-2 | | 24 | 2.3e-4 | 1.6e-4 | 7.5e-4 | | 32 | 2.1e-6 | 1.8e-6 | 8.4e-6 | | 48 | 1.4e-11 | 1.3e-11 | 5.6e-11 | | 64 | 1.7e-15 | 2.0e-15 | 1.7e-15 | Fully periodic problems are exact to rounding as soon as the grid resolves the source. The tests assert this behaviour against the closed-form potentials. The accuracy rests on two assumptions, and the solution's diagnostics report on both: - **The source vanishes outside the box.** What is cut off is missing from the solution. `source_boundary_ratio` measures it. - **The grid resolves the source.** A source with features finer than the grid spacing is aliased. `spectral_tail` measures it. Sources with kinks or jumps are never resolved in this sense, and for them the method converges only algebraically. ## What the planner chooses **The box.** Along periodic directions the box is the period. Along the free ones the planner samples the source on a coarse grid around the origin and doubles the box until the source is below $10^{-12}$ of its maximum on the faces. It then tightens the box around the region where the source is larger than that. **The grid.** The planner tries 8, 12, 16, 24, 32, 48, 64, 96 and more points along the longest side, as far as its memory budget allows, with the same spacing along the other sides. It takes the coarsest grid on which the spectrum of the source is below $10^{-10}$ of its maximum in the upper third of the frequency range. This criterion is conservative: the table above shows the Gaussian is accurate to $10^{-13}$ with 32 points, where the planner picks 64. If no candidate qualifies, the planner takes the finest and says so in the plan's notes. Automatic grids are limited to about 320 MB for the padded transform. A grid set by hand is not limited. **Sources given as data.** There is nothing to choose: the planner takes the grid of the data. **Limits of the search.** The box is found by sampling, which can miss a source that is very narrow compared with its distance from the origin. The planner then reports that it could not find the source. Set the grid in the plan in that case. [^vgf]: F. Vico, L. Greengard, M. Ferrando, *Fast convolution with free-space Green's functions*, Journal of Computational Physics 323 (2016) 191–203.