Make one direction periodic¶
Use this when the domain repeats along one coordinate: a channel between two walls, a slab, a wire, a pipe without ends.
Steps¶
For a box with walls, name the coordinates that repeat in
periodic=:pm.Box({x: (0, 2), y: (0, 1)}, periodic=[x]). The ends ofxare then its period.Give conditions for the faces that are left. The box has none along a periodic coordinate.
Solve. Along the 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.
Example¶
A channel that repeats along x, with a wall at y = 0 and at y = 1:
import numpy as np
import sympy as sp
import pdemagic as pm
x, y = sp.symbols("x y", real=True)
u = sp.Function("u")(x, y)
channel = pm.Box({x: (0, 2), y: (0, 1)}, periodic=[x])
assert channel.faces == ((y, 0.0), (y, 1.0))
flow = pm.Problem(
sp.Eq(pm.laplacian(u), 0),
domain=channel,
boundary={(y, 0): sp.Eq(u, sp.cos(sp.pi * x)), (y, 1): sp.Eq(u, 0)},
)
repeating = pm.solve(flow)
repeating.plot()
xs, ys = repeating.axes
assert xs[0] == 0.0 and xs[-1] < 2.0 # one step short of the period
assert ys[0] == 0.0 and ys[-1] == 1.0 # from wall to wall
X, Y = repeating.mesh()
exact = np.cos(np.pi * X) * np.sinh(np.pi * (1 - Y)) / np.sinh(np.pi)
assert abs(repeating[u] - exact).max() < 1e-12
# A point outside the period is taken into it.
assert abs(repeating(2.3, 0.5) - repeating(0.3, 0.5)) < 1e-12
Notes¶
Without walls the domain is a
pm.Space. Name the periodic coordinates with their period, and the others are free:pm.Space(x, y, z, periodic={x: (0, 2), y: (0, 2)})is a slab, and with every coordinate periodic it is a crystal.A cylinder repeats along its axis with
periodic=True, and has no caps then.An array for a periodic coordinate holds the points of the grid: from the lower end, without the upper one, as
numpy.linspace(..., endpoint=False)gives them.A problem that is periodic in every direction has a solution only if the source has zero mean. pdemagic removes the mean and reports it in the diagnostic
removed_source_mean.A box cannot be bounded along some directions and free along others.
Free space and periodic directions and Boxes with walls explain the two kinds of domains, and the reference lists their arguments.