Boxes with walls

A box is an interval, a rectangle, or its like in any number of dimensions, with a wall at each end. This page is about the box itself: its faces, its periodic directions and its grid. What you state on the faces is on the page about boundary conditions.

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)

A box and its faces

A Box is given by its sides: each coordinate with the two ends of the box along it.

box = pm.Box({x: (0, 1), y: (0, 1)})
assert box.faces == ((x, 0.0), (x, 1.0), (y, 0.0), (y, 1.0))

A face is named by the coordinate that is constant on it and the end it lies at: (x, 0) is the face where x is 0. The order of the coordinates is the order in which the arrays of a solution are indexed.

Every face needs a condition. This plate is kept at zero on three faces and heated along the fourth:

conditions = dict.fromkeys(box.faces, sp.Eq(u, 0))
conditions[y, 1] = sp.Eq(u, sp.sin(sp.pi * x))

plate = pm.Problem(sp.Eq(pm.laplacian(u), 0), domain=box, boundary=conditions)
heated = pm.solve(plate)
heated.plot()

X, Y = heated.mesh()
exact = np.sin(np.pi * X) * np.sinh(np.pi * Y) / np.sinh(np.pi)
assert abs(heated[u] - exact).max() < 1e-10
The figure that the example above draws. The figure that the example above draws.

Walls and periodic directions

A box can be periodic along some of its coordinates. It has no faces there. This channel repeats along x and has a wall at y = 0 and at y = 1:

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)},
)
pm.solve(flow).plot()
The figure that the example above draws. The figure that the example above draws.

A box that is periodic along every coordinate has no walls at all. It is solved as a periodic domain, which pm.Space states as well.

The grid

Along a coordinate with faces the grid points are Chebyshev points. They include both ends and crowd towards them. solution.axes returns them:

xs, ys = heated.axes
assert xs[0] == 0.0 and xs[-1] == 1.0
assert xs[1] - xs[0] < xs[len(xs) // 2] - xs[len(xs) // 2 - 1]

The planner solves the problem on one grid after the other and takes the coarsest one on which the solution is resolved. A smooth solution needs few points. One with a kink in a corner needs more, and the plan says how well it was resolved.

Values between the points

Call the solution with coordinates for its value anywhere in the box. The value comes from the polynomial through the points of the grid, which is what the method solved with, so it is as accurate as the values on the grid:

middle = heated(0.5, 0.5)
along_a_line = heated(np.linspace(0, 1, 7), 0.25)
assert along_a_line.shape == (7,)
assert np.isnan(heated(1.5, 0.5))  # outside the box

heated.integral() is the integral of the solution over the box, by the weights of the same points. Solutions has more on both.

Arrays on a box

An array, in the source or on a face, is given at the points of the grid, which the box tells you for any shape:

grid_x, grid_y = box.axes((16, 16))
assert grid_x[0] == 0.0 and grid_x[-1] == 1.0

An array for a face is given like any other: on the whole grid. Only its values on the face are read. Data from arrays shows how.

What is solved on a box

A box takes equations of second order, and the plate equation, which is of fourth:

The full list is in the reference: what is solved on boxes with walls.

What does not work yet

  • A box that is bounded along some directions and free along others.

  • Stationary systems of equations on a box. In time a system is solved.

  • An array for one face alone: it is given on the whole grid.

See also