Plot a section in three dimensions

Use this when a solution in three dimensions should be drawn on another plane than the one that plot takes by itself.

Steps

  1. Call solution.plot() for the section it chooses: the middle of the box along the last coordinate.

  2. For another one, name the coordinate that is held fixed and its value: solution.plot(cut={x: 1.0}).

  3. Use the axes that plot returns to change the figure.

Example

Two charges of opposite sign on the x axis:

import sympy as sp
import pdemagic as pm

x, y, z = sp.symbols("x y z", real=True)
V = sp.Function("V")(x, y, z)


def charge(centre):
    return sp.exp(-((x - centre) ** 2 + y**2 + z**2))


pair = pm.Problem(
    sp.Eq(pm.laplacian(V), -(charge(1) - charge(-1))),
    domain=pm.FreeSpace(x, y, z),
)
plan = pm.plan(pair)
plan.grid.shape = (32, 32, 32)  # coarse, for a quick picture
potential = pm.solve(pair, plan)

# The plane z = 0, through both charges.
through = potential.plot()
assert (through.get_xlabel(), through.get_ylabel()) == ("x", "y")

# The plane x = 1, through the positive charge and across the axis.
across = potential.plot(cut={x: 1.0})
assert (across.get_xlabel(), across.get_ylabel()) == ("y", "z")
The figure that the example above draws. The figure that the example above draws. The figure that the example above draws. The figure that the example above draws.

Notes

  • A section need not lie on a plane of the grid. Between two planes the field is taken to be linear.

  • A cut outside the box is refused, and so is a cut of a solution in one or two dimensions.

  • In a ball and in a cylinder the coordinate that is held fixed decides what the section is. The angle around the axis gives the plane through the axis, with both of its halves. In a ball the angle from the axis gives a cone, which at \(\pi/2\) is the plane of the equator, and the radius a sphere. In a cylinder the coordinate along the axis gives a disk, and the radius a tube that is unrolled.

  • No other plane can be drawn, and there is no view in space. For those, take the arrays, or write a VTK file for ParaView with solution.to_vtk(path).

  • For a problem in time add time=, and for an eigenproblem state=.

  • Plotting explains what plot draws, and Draw into your own figure puts several sections side by side.