Disks, rings, balls, shells and cylinders¶
Round domains are stated in polar, spherical and cylindrical coordinates, and the grid follows their shape. Each is used in one of two ways: with vacuum outside, or with a boundary condition on its surface.
import numpy as np
import sympy as sp
import pdemagic as pm
r, phi = sp.symbols("r phi", real=True)
s = sp.Function("s")(r, phi)
The domains and their coordinates¶
Domain |
Coordinates |
With |
|---|---|---|
|
the radius and the angle |
a ring |
|
the radius, the polar angle and the azimuth |
a shell |
|
the distance from the axis, the angle and the height |
a hollow cylinder |
The unknown is a function of these coordinates. Write the equation with
pm.laplacian(s): without coordinates it is the Laplacian as an
operator, which takes its meaning from the domain. On a round domain it
is the only way to write the equation.
A source is a formula in the coordinates of the domain. disk.cartesian
gives x and y as formulas in them, which is often the easier way to
write it.
With vacuum outside¶
Without a boundary, a disk, a ball or a cylinder holds a source and has
vacuum outside, as in free space. The source may reach
right up to the surface. Two charges of opposite sign inside a disk:
disk = pm.Disk(r, phi, radius=1)
dx, dy = disk.cartesian
blobs = sp.exp(-8 * ((dx - 0.4) ** 2 + dy**2)) - sp.exp(-8 * ((dx + 0.4) ** 2 + dy**2))
in_the_disk = pm.solve(pm.Problem(sp.Eq(-pm.laplacian(s), blobs), domain=disk))
in_the_disk.plot()
A ball works the same way. A uniformly charged ball of radius 2 has the potential \((12 - r^2)/6\) inside:
rho, theta = sp.symbols("rho theta", real=True)
V = sp.Function("V")(rho, theta, phi)
ball = pm.Ball(rho, theta, phi, radius=2)
in_the_ball = pm.solve(pm.Problem(sp.Eq(-pm.laplacian(V), 1), domain=ball))
radii, _, _ = in_the_ball.mesh()
assert np.allclose(in_the_ball[V], (12 - radii**2) / 6)
Only Poisson’s equation is solved this way. In a disk and a ball the
method is spectral. In a cylinder it is of second order: halving the cell
size divides the error by four, and the planner’s default grid gives
about three digits. For more, refine plan.grid.shape.
With a condition on the surface¶
With a boundary, the surface is a wall. A disk has one face, the radius
at which it ends:
assert disk.faces == ((r, 1.0),)
skin = pm.Problem(sp.Eq(-pm.laplacian(s), 1), domain=disk, boundary=sp.Eq(s, 0))
sagging = pm.solve(skin)
R, _ = sagging.mesh()
assert abs(sagging[s] - (1 - R**2) / 4).max() < 1e-12
A condition gives the value, the derivative along the radius, or a mix of both, and what is given may change along the rim. Boundary conditions has all of it.
With an inner radius the disk is a ring. It has two rims, and each needs its condition. This is the wall of a pipe that is warm inside, with a temperature outside that changes around it:
ring = pm.Disk(r, phi, radius=2, inner=0.5)
assert ring.faces == ((r, 0.5), (r, 2.0))
wall = pm.Problem(
sp.Eq(pm.laplacian(s), 0),
domain=ring,
boundary={(r, 0.5): sp.Eq(s, 1), (r, 2): sp.Eq(s, sp.cos(3 * phi) / 4)},
)
pm.solve(wall).plot()
A ball works like a disk. Its face is its surface, and with an inner
radius it is a shell between two spheres: pm.Ball(rho, theta, phi, radius=2, inner=0.5) has the faces (rho, 0.5) and (rho, 2).
Cylinders¶
A cylinder has a wall and two caps, and each takes its condition. This can is heated from below, cooled from above, and insulated around:
d, zeta = sp.symbols("d zeta", real=True)
can = pm.Cylinder(d, phi, zeta, radius=1, z_range=(0, 2))
assert can.faces == ((d, 1.0), (zeta, 0.0), (zeta, 2.0))
K = sp.Function("K")(d, phi, zeta)
standing = pm.Problem(
sp.Eq(pm.laplacian(K), 0),
domain=can,
boundary={
(d, 1): sp.Eq(K.diff(d), 0),
(zeta, 0): sp.Eq(K, 1),
(zeta, 2): sp.Eq(K, 0),
},
)
layered = pm.solve(standing)
_, _, heights = layered.mesh()
assert abs(layered[K] - (1 - heights / 2)).max() < 1e-12
With inner= the cylinder is hollow and has an inner wall. With
periodic=True it repeats along its axis and has no caps: a pipe without
ends.
pipe = pm.Cylinder(d, phi, zeta, radius=1.5, z_range=(0, 2), inner=0.5, periodic=True)
assert pipe.faces == ((d, 0.5), (d, 1.5))
The grid¶
A disk and a ball have Gauss points along the radius and the polar angle, and equally spaced points along the azimuth. The Gauss points lie inside the domain: the rim is not a grid point. The domain tells you the points for any shape, which is where array data must be given:
grid_radii, grid_angles = disk.axes((8, 12))
assert 0 < grid_radii[0] and grid_radii[-1] < 1
An array for the rim is read off the outermost ring of grid points.
Call the solution with coordinates for its value anywhere, also on the rim. That works on disks, rings and cylinders with boundary conditions, in their own coordinates:
assert abs(sagging(1.0, 0.3)) < 1e-12 # on the rim
assert abs(sagging(0.5, 0.3) - 3 / 16) < 1e-12
sagging.integral() is the integral over the area of the disk, and in a
ball and a cylinder over the volume: the coordinates bring their own
measure.
A cylinder with conditions has another grid than one with vacuum
outside: ask for it with can.axes(shape, boundary=True). Its points
along the axis include the two caps. With vacuum outside, a cylinder
gives its solution at the centres of cells.
What is solved on a round domain¶
With boundary conditions the operator is \(a\,\nabla^2 u + c\,u\), written
with pm.laplacian: Laplace’s and Poisson’s equation, screened ones and
the Helmholtz equation. The coefficient \(c\) may
vary, and the equation may hold a
nonlinear term. In time the same operator
gives heat, waves and the Schrödinger equation, and the
modes of a disk, a ball and a cylinder are eigenproblems.
The full list is in the reference:
what is solved on round domains.
What does not work yet¶
With vacuum outside: any equation but Poisson’s, and any problem in time. A ring, a shell and a hollow cylinder need a condition on each surface.
With boundary conditions: operators other than a Laplacian and a term with the unknown itself, and stationary systems. A disk with another equation of second order can be drawn as a region. In time a system is solved.
Values between the points of the grid in a ball, and in a cylinder with vacuum outside.
Sectors of a disk as round domains, and parts of a ball other than shells.