Free space and periodic directions¶
A domain without walls: all of space, a box that repeats, or a mix of the two. You state no boundary condition on it. The examples on this page use Poisson’s equation, and start from these lines:
import numpy as np
import sympy as sp
import pdemagic as pm
x, y, z = sp.symbols("x y z", real=True)
Free space in any dimension¶
pm.FreeSpace takes the coordinates. The same code works in one, two,
four and more dimensions. Only the coordinates change.
u = sp.Function("u")(x, y)
plane = pm.Problem(
sp.Eq(pm.laplacian(u), -sp.exp(-(x**2) - y**2)),
domain=pm.FreeSpace(x, y),
)
in_the_plane = pm.solve(plane)
assert in_the_plane[u].ndim == 2
in_the_plane.plot()
The solution is the one that the source produces, with nothing coming in from infinity. In three dimensions that is the potential that vanishes at infinity. In one and two dimensions no solution vanishes there unless the source has zero net charge, and the solution is the convolution of the source with the free-space Green’s function, \(-|x|/2\) in one dimension and \(-\ln(r)/(2\pi)\) in two.
The box of the grid¶
The solution comes on a grid, and the grid needs a box. The planner chooses it so that it holds the source. The box is a cut out of all of space, not a wall:
grid = in_the_plane.plan.grid
assert grid.periodic == [False, False]
assert in_the_plane.diagnostics["source_boundary_ratio"] < 1e-11
The diagnostic says how much of the source reaches the faces of the box,
against its maximum. To see more of the solution, widen the box in the
plan: plan.grid.lower and plan.grid.upper.
The planner and its plan says how.
Periodic directions¶
pm.Space is the general domain. Name the periodic coordinates with
their period, and the remaining ones are free. A strip that repeats along
x and is open along y:
w = sp.Function("w")(x, y)
strip = pm.Problem(
sp.Eq(pm.laplacian(w), -sp.cos(sp.pi * x) * sp.exp(-(y**2))),
domain=pm.Space(x, y, periodic={x: (0, 2)}),
)
on_the_strip = pm.solve(strip)
assert on_the_strip.plan.grid.periodic == [True, False]
In three dimensions a slab is periodic along two directions
(periodic={x: (0, 2), y: (0, 2)}), a wire along one, and a crystal
along all three. pm.FreeSpace(x, y, z) is pm.Space(x, y, z) without
periodic coordinates.
Along a periodic coordinate the grid starts at the lower end of the
period and stops one step short of the upper end, which is the same
point. solution.axes returns exactly these points:
along_x, along_y = on_the_strip.axes
assert along_x[0] == 0.0 and along_x[-1] < 2.0
A box that repeats in every direction¶
A problem that is periodic in every direction has a solution only if the source has zero mean. pdemagic removes the mean, as is customary, returns the solution with zero mean, and reports what it removed:
v = sp.Function("v")(x)
ring = pm.Problem(
sp.Eq(-sp.diff(v, x, 2), sp.cos(sp.pi * x) + 5),
domain=pm.Space(x, periodic={x: (-1, 1)}),
)
on_the_ring = pm.solve(ring)
assert abs(on_the_ring.diagnostics["removed_source_mean"] - 5) < 1e-12
On such a domain the solution has a value at any point, not only on its grid: call it with coordinates. The value is that of the trigonometric sum which the method solved with, and a point outside the period is taken into it.
assert abs(on_the_ring(0.3) - np.cos(0.3 * np.pi) / np.pi**2) < 1e-12
assert abs(on_the_ring(2.3) - on_the_ring(0.3)) < 1e-12
What is solved here¶
Free space takes Poisson’s equation in any dimension, and its screened form and the Helmholtz equation in up to three. A box that repeats in every direction takes more: any linear equation with constant coefficients, of any order. Both take coefficients that vary, nonlinear terms and problems in time, each with its conditions. The pages on the equations say which:
The full list is in the reference: what is solved in free space and on periodic boxes.
What does not work yet¶
Where a direction is free, the solution has values on its grid only. The grid is then a cut out of all of space, and the sum of the method is not one over that cut.
Beyond three dimensions memory limits the grids severely. The planner still finds a box, but it may report that it cannot resolve the source within its memory budget.
Periodic cells that are not rectangular, and periodic directions together with more than three free ones.
A box that is free along some directions and has walls along others.
See also¶
Domains: the other families, and how to choose.
Gallery: two charges, a screened charge, heat that spreads.
Methods: Poisson’s equation by Fourier convolution and linear equations with constant coefficients.
Recipe: make one direction periodic.