Give one condition for all faces¶
Use this when the same condition holds on the whole boundary: a membrane that is fixed along its edge, a room whose walls let nothing through.
Steps¶
Write the condition as one equation.
sp.Eq(u, 0)gives the value.sp.Eq(pm.normal_derivative(u), 0)gives the slope along the normal that points out of the domain.Pass that equation alone as
boundary=. It then holds on every face.Solve. The plan lists the condition that each face got.
Example¶
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)
box = pm.Box({x: (0, 1), y: (0, 1)})
# A membrane under an even load, fixed along all four sides.
fixed = pm.Problem(sp.Eq(-pm.laplacian(u), 1), domain=box, boundary=sp.Eq(u, 0))
sagging = pm.solve(fixed)
sagging.plot()
assert abs(sagging(0.5, 0.5) - 0.07367135328) < 1e-9
assert sagging.plan.notes[1].startswith("Boundary conditions: the value at x = 0")
# A source between four walls that let nothing through.
closed = pm.Problem(
sp.Eq(-pm.laplacian(u) + u, sp.cos(sp.pi * x)),
domain=box,
boundary=sp.Eq(pm.normal_derivative(u), 0),
)
between = pm.solve(closed)
X, Y = between.mesh()
assert abs(between[u] - np.cos(np.pi * X) / (1 + np.pi**2)).max() < 1e-12
Notes¶
A derivative along a coordinate, such as
u.diff(x), belongs to the faces across that coordinate only. As the one condition of a box in the plane it is refused.pm.normal_derivative(u)fits every face.The same works on a disk, a ring, a ball, a shell, a cylinder and a shape in the plane. A disk, a ball or a cylinder without
boundaryhas no wall: it is solved with vacuum outside.If every face gives the slope and the equation has no term with the unknown itself, the solution is fixed up to a constant. pdemagic returns the one with zero mean, and reports in the diagnostic
removed_source_meanwhat it took off the source to make the problem solvable.A box that is periodic along a coordinate has no faces there. The one condition holds on the faces that are left.
The plate equation takes two conditions on each face: see Clamp a plate.
For faces that differ, see Give each face its own condition. Boundary conditions explains the kinds of conditions, and pm.Problem lists what
boundary=takes.