Domains

The classes that say where a problem lives: all of space with free and periodic directions, boxes with faces, and the round domains in their own coordinates. Shapes in the plane are on the page of regions, curves and shapes.

Class

The domain

Coordinates

Faces

pm.FreeSpace

all of space

Cartesian, any number

none

pm.Space

all of space, periodic along some coordinates

Cartesian, any number

none

pm.Box

an interval along each coordinate

Cartesian, any number

two along each coordinate that is not periodic

pm.Disk

a disk, or a ring with inner=

radius, angle

the rim, and the inner rim of a ring

pm.Ball

a ball, or a shell with inner=

radius, polar angle, azimuth

the surface, and the inner one of a shell

pm.Cylinder

a finite cylinder, hollow with inner=, without caps with periodic=True

distance from the axis, angle, position along the axis

the wall, the two caps, and the inner wall

A disk, a ball or a solid cylinder with caps that gets no boundary condition has vacuum outside.

Free and periodic directions

class pdemagic.Space(*coordinates, periodic=None)

All of space, optionally periodic along some coordinates.

Along a periodic coordinate the problem repeats with the given period. Along every other coordinate space is unbounded, and the vacuum condition holds there: every unknown is its free-space solution, the source convolved with the free-space Green’s function. In three and more free dimensions that is the solution that vanishes at infinity.

Parameters:
  • *coordinates (sp.Symbol) – The sympy symbols that span the space, in the order in which solution arrays are indexed.

  • periodic (Mapping[sp.Symbol, tuple[float, float]] | None) – The periodic coordinates, each with the two ends of one period.

Examples

A slab, periodic along x and y and free along z:

>>> import sympy as sp
>>> x, y, z = sp.symbols("x y z", real=True)
>>> Space(x, y, z, periodic={x: (0, 2), y: (0, 2)})
Space(x, y, z, periodic={x: (0.0, 2.0), y: (0.0, 2.0)})
class pdemagic.FreeSpace(*coordinates)

All of space, with the vacuum condition at infinity.

This is Space without periodic coordinates.

Parameters:

*coordinates (sp.Symbol) – The sympy symbols that span the space, in the order in which solution arrays are indexed.

Examples

>>> import sympy as sp
>>> x, y, z = sp.symbols("x y z", real=True)
>>> FreeSpace(x, y, z)
FreeSpace(x, y, z)

Boxes

class pdemagic.Box(sides, periodic=())

A box: an interval along each coordinate, with conditions on its faces.

Where a coordinate reaches an end of its interval the box has a face, and on each face the problem states a boundary condition: see the boundary argument of Problem. Along a periodic coordinate the box has no faces: the problem repeats there.

Parameters:
  • sides (Mapping[sp.Symbol, tuple[float, float]]) – The coordinates with the two ends of the box along each, as in {x: (0, 1), y: (0, 2)}. Their order is the order in which solution arrays are indexed.

  • periodic (Sequence[sp.Symbol]) – The coordinates along which the box is periodic.

Examples

>>> import sympy as sp
>>> x, y = sp.symbols("x y", real=True)
>>> box = Box({x: (0, 1), y: (0, 2)})
>>> box
Box({x: (0.0, 1.0), y: (0.0, 2.0)})
>>> box.faces
((x, 0.0), (x, 1.0), (y, 0.0), (y, 2.0))

A channel, periodic along x and with two walls across it:

>>> Box({x: (0, 4), y: (-1, 1)}, periodic=[x]).faces
((y, -1.0), (y, 1.0))
property faces: tuple[tuple[Symbol, float], ...]

The faces of the box, each as a coordinate and the end it lies at.

laplacian(expr)

Return the Laplacian of a formula in the coordinates of the domain.

Parameters:

expr (Expr)

Return type:

Expr

axes(shape)

Return the grid points along each coordinate for a grid of this shape.

Array data for a problem on this domain must be given at these points: Chebyshev points, which include both ends and crowd towards them, along the coordinates with faces, and equally spaced points along the periodic ones.

Parameters:

shape (Sequence[int]) – The number of points along each coordinate.

Return type:

tuple[ndarray, …]

Round domains

class pdemagic.Disk(*coordinates, radius=1.0, inner=0.0)

A disk around the origin, or a ring, in polar coordinates.

What holds on the rim of the disk is part of the problem. Without a boundary condition there is vacuum outside: the unknown is the free-space solution for a source that vanishes outside the disk. With one, the rim is a face: see the boundary argument of Problem. The source may reach right up to the rim in both cases.

With an inner radius the domain is a ring, which has two faces and needs a boundary condition on each.

Parameters:
  • r – The symbols for the radius and the angle.

  • phi – The symbols for the radius and the angle.

  • radius (float) – The radius of the disk.

  • inner (float) – The inner radius of a ring. Zero for a disk.

  • coordinates (sp.Symbol)

Examples

>>> import sympy as sp
>>> r, phi = sp.symbols("r phi", real=True)
>>> disk = Disk(r, phi, radius=2)
>>> disk
Disk(r, phi, radius=2.0)
>>> disk.cartesian
(r*cos(phi), r*sin(phi))
>>> disk.laplacian(r**2)
4
>>> disk.faces
((r, 2.0),)
>>> Disk(r, phi, radius=2, inner=1).faces
((r, 1.0), (r, 2.0))
property cartesian: tuple[Expr, Expr]

The Cartesian coordinates x and y as formulas in r and phi.

laplacian(expr)

Return the Laplacian of a formula in the coordinates of the domain.

Parameters:

expr (Expr)

Return type:

Expr

axes(shape)

Return the grid points along each coordinate for a grid of this shape.

Array data for a problem on this domain must be given at these points: Gauss points along the radius and the polar angle, equally spaced points along the azimuth.

Parameters:

shape (Sequence[int]) – The number of points along each coordinate.

Return type:

tuple[ndarray, …]

property faces: tuple[tuple[Symbol, float], ...]

The surface of the domain, and with an inner radius that one too.

class pdemagic.Ball(*coordinates, radius=1.0, inner=0.0)

A ball around the origin, or a spherical shell, in spherical coordinates.

What holds on the surface of the ball is part of the problem. Without a boundary condition there is vacuum outside: the unknown is the free-space solution for a source that vanishes outside the ball, the solution that vanishes at infinity. With one, the surface is a face: see the boundary argument of Problem. The source may reach right up to the surface in both cases.

With an inner radius the domain is a shell, which has two faces and needs a boundary condition on each.

Parameters:
  • r – The symbols for the radius, the polar angle measured from the positive z axis, and the azimuth.

  • theta – The symbols for the radius, the polar angle measured from the positive z axis, and the azimuth.

  • phi – The symbols for the radius, the polar angle measured from the positive z axis, and the azimuth.

  • radius (float) – The radius of the ball.

  • inner (float) – The inner radius of a shell. Zero for a ball.

  • coordinates (sp.Symbol)

Examples

>>> import sympy as sp
>>> r, theta, phi = sp.symbols("r theta phi", real=True)
>>> ball = Ball(r, theta, phi, radius=2)
>>> ball
Ball(r, theta, phi, radius=2.0)
>>> ball.cartesian
(r*sin(theta)*cos(phi), r*sin(phi)*sin(theta), r*cos(theta))
>>> ball.laplacian(r**2)
6
>>> ball.faces
((r, 2.0),)
>>> Ball(r, theta, phi, radius=2, inner=1).faces
((r, 1.0), (r, 2.0))
property cartesian: tuple[Expr, Expr, Expr]

The Cartesian coordinates x, y and z as formulas in r, theta and phi.

laplacian(expr)

Return the Laplacian of a formula in the coordinates of the domain.

Parameters:

expr (Expr)

Return type:

Expr

axes(shape)

Return the grid points along each coordinate for a grid of this shape.

Array data for a problem on this domain must be given at these points: Gauss points along the radius and the polar angle, equally spaced points along the azimuth.

Parameters:

shape (Sequence[int]) – The number of points along each coordinate.

Return type:

tuple[ndarray, …]

property faces: tuple[tuple[Symbol, float], ...]

The surface of the domain, and with an inner radius that one too.

class pdemagic.Cylinder(rho, phi, z, *, radius=1.0, z_range=(-1.0, 1.0), inner=0.0, periodic=False)

A finite cylinder around the z axis.

What holds on the surface of the cylinder is part of the problem. Without a boundary condition there is vacuum outside: the unknown is the free-space solution for a source that vanishes outside the cylinder, the solution that vanishes at infinity. With boundary conditions, the wall and the two caps are faces: see the boundary argument of Problem.

With an inner radius the cylinder is hollow and has an inner wall too. A cylinder that is periodic along its axis has no caps. Both need boundary conditions.

Parameters:
  • rho (sp.Symbol) – The symbols for the distance from the axis, the angle around it, and the position along it.

  • phi (sp.Symbol) – The symbols for the distance from the axis, the angle around it, and the position along it.

  • z (sp.Symbol) – The symbols for the distance from the axis, the angle around it, and the position along it.

  • radius (float) – The radius of the cylinder.

  • z_range (tuple[float, float]) – The two ends of the cylinder along its axis, or of one period.

  • inner (float) – The inner radius of a hollow cylinder. Zero for a solid one.

  • periodic (bool) – Whether the cylinder repeats along its axis.

Examples

>>> import sympy as sp
>>> rho, phi, z = sp.symbols("rho phi z", real=True)
>>> cylinder = Cylinder(rho, phi, z, radius=2, z_range=(-1, 3))
>>> cylinder
Cylinder(rho, phi, z, radius=2.0, z_range=(-1.0, 3.0))
>>> cylinder.cartesian
(rho*cos(phi), rho*sin(phi), z)
>>> cylinder.laplacian(rho**2 + z**2)
6
>>> cylinder.faces
((rho, 2.0), (z, -1.0), (z, 3.0))
>>> Cylinder(rho, phi, z, radius=2, inner=1, periodic=True).faces
((rho, 1.0), (rho, 2.0))
property faces: tuple[tuple[Symbol, float], ...]

The walls of the cylinder, and its two caps if it has them.

property cartesian: tuple[Expr, Expr, Expr]

The Cartesian coordinates x, y and z as formulas in rho, phi and z.

laplacian(expr)

Return the Laplacian of a formula in the coordinates of the domain.

Parameters:

expr (Expr)

Return type:

Expr

axes(shape, boundary=False)

Return the grid points along each coordinate for a grid of this shape.

Array data for a problem on this domain must be given at these points. With vacuum outside they are cell centres along the radius and the axis, and equally spaced points along the angle. A problem with boundary conditions has another grid: Gauss points along the radius, which lie inside, and Chebyshev points along the axis, which include the two caps.

Parameters:
  • shape (Sequence[int]) – The number of points along each coordinate.

  • boundary (bool) – Whether the problem has boundary conditions.

Return type:

tuple[ndarray, …]

See also: Domains: the families, and how to choose, Free space and periodic directions, Boxes with walls and Disks, rings, balls, shells and cylinders.