Data and bodies

pm.GridData gives a term of a problem as an array in the place of a formula. pm.Conductor and pm.Dielectric put bodies with sharp surfaces into three-dimensional free space, and a solution reports on each of them with a pm.BodyResult.

Data from arrays

class pdemagic.GridData(values, lower=None, upper=None)

Values of a function on a uniform grid.

Use it to give a term of an equation as an array instead of a formula.

Parameters:
  • values (Any) – The values, with one axis per coordinate of the domain.

  • lower (Sequence[float] | None) – The coordinates of the first and the last grid point along each axis. Along a periodic coordinate the last point is one step short of the end of the period, as with numpy.linspace(..., endpoint=False). Leave them out for a Box, a Disk, a Ball or a Cylinder, whose grid points are fixed by the shape of the array: see Box.axes. On a Region they may be left out as well: the grid then lies over the rectangle that holds the region, as Region.axes says, and points that hold nan are not read.

  • upper (Sequence[float] | None) – The coordinates of the first and the last grid point along each axis. Along a periodic coordinate the last point is one step short of the end of the period, as with numpy.linspace(..., endpoint=False). Leave them out for a Box, a Disk, a Ball or a Cylinder, whose grid points are fixed by the shape of the array: see Box.axes. On a Region they may be left out as well: the grid then lies over the rectangle that holds the region, as Region.axes says, and points that hold nan are not read.

Examples

>>> import numpy as np
>>> xs = np.linspace(-1.0, 1.0, 5)
>>> GridData(xs**2, lower=[-1.0], upper=[1.0])
GridData(shape=(5,), lower=[-1.0], upper=[1.0])
>>> GridData.from_axes(xs**2, xs)
GridData(shape=(5,), lower=[-1.0], upper=[1.0])
classmethod from_axes(values, *axes)

Build grid data from the coordinates of the points along each axis.

Parameters:
  • values (Any) – The values, with one axis per coordinate of the domain.

  • *axes (Any) – One array per axis with the coordinates of its grid points. The points must be equally spaced.

Return type:

GridData

Bodies

The shapes that a body takes are in the module pdemagic.shapes.

class pdemagic.Conductor(shape, potential=None, flux=None, name=None)

A conducting body: the unknown is constant on it.

Give either the potential the conductor is held at, or, for a conductor that is not connected to anything, the flux through its surface. Without either, the conductor is grounded.

Parameters:
  • shape (Shape) – Where the body is: a shape from pdemagic.shapes.

  • potential (float | None) – The value of the unknown on the conductor.

  • flux (float | None) – The flux of -grad(u) out of the conductor. This is its charge in the units of the equation: for laplacian(u) = -rho, the charge itself, and for laplacian(u) = -rho / eps0, the charge divided by eps0. The potential then adjusts itself and is reported with the solution.

  • name (str | None) – A name to find the body by in the solution. By default bodies are named "body 1", "body 2" and so on, in their order in the problem.

Examples

>>> from pdemagic import Conductor, shapes
>>> Conductor(shapes.Sphere(radius=0.5), potential=1.0)
Conductor(Sphere(centre=(0.0, 0.0, 0.0), radius=0.5), potential=1.0)
>>> Conductor(shapes.Sphere(radius=0.5), flux=0.0, name="probe")
Conductor(Sphere(centre=(0.0, 0.0, 0.0), radius=0.5), flux=0.0, name='probe')
class pdemagic.Dielectric(shape, permittivity, name=None)

A dielectric body with a sharp surface.

Inside the body the equation holds with the coefficient inside the divergence multiplied by the permittivity: -div(grad(u)) = g becomes -div(permittivity * grad(u)) = g. At the surface the unknown and the normal component of permittivity * grad(u) are continuous.

Parameters:
  • shape (Shape) – Where the body is: a shape from pdemagic.shapes.

  • permittivity (float) – The permittivity of the body relative to the space around it.

  • name (str | None) – A name to find the body by in the solution. By default bodies are named "body 1", "body 2" and so on, in their order in the problem.

Examples

>>> from pdemagic import Dielectric, shapes
>>> Dielectric(shapes.Box(lower=(0, 0, 0), upper=(1, 1, 1)), permittivity=4)
Dielectric(Box(lower=(0.0, 0.0, 0.0), upper=(1.0, 1.0, 1.0)), permittivity=4.0)
class pdemagic.BodyResult(name, panels, flux, potential)

What a solve found out about one body.

Parameters:
  • name (str)

  • panels (int)

  • flux (float)

  • potential (float | None)

name

The name of the body.

Type:

str

panels

The number of triangles its surface was divided into.

Type:

int

flux

The flux of -grad(u) out of the body that the charge on its surface causes. For a conductor this is its charge in the units of the equation, for a dielectric the polarization charge on its surface.

Type:

float

potential

The value of the unknown on the body, if it is a conductor.

Type:

float or None

See also: Data from arrays and Bodies.