Questions that come up

Short answers to what users ask first, each with a link to the page that says more.

Stating a problem

Why is there no boundary in free space?

Because the problem has none. pm.FreeSpace means all of space, with the condition at infinity that the solution is the one its sources produce. pdemagic does not cut the domain off and put a condition on the cut: the condition at infinity is built into the method. The box that a plan shows is where the solution is given, not a wall. See Free space and periodic directions.

Why is a symbol in my equation refused?

An equation may hold the coordinates of the domain, the time and the symbol of an eigenvalue, and no other symbol. A parameter must be a number when the problem is built: write equation.subs(k, 7), or give k a value in Python before you write the equation. A symbol that is left raises InvalidProblemError with the words “substitute a number for it”. See Problems, unknowns and equations.

Is the derivative in a boundary condition along the normal?

u.diff(x) in a condition is the derivative along the coordinate, not along the normal that points out of the domain. At an upper face the two agree, and at a lower face they differ in sign. pm.normal_derivative(u) is the derivative along the outward normal on every face, and on a shape in the plane it is the only way to write the slope. See Boundary conditions.

Why was my problem refused?

pdemagic raises one of four errors, and the message names what it found. InvalidProblemError means that the problem is inconsistent or incomplete, or has no solution: a face without a condition, a box that resonates. UnsupportedProblemError means that the problem is fine and pdemagic cannot solve it yet. InvalidPlanError means that a plan does not fit its problem, and ConvergenceError that an iteration or a time stepping did not reach its tolerance. See the errors, what is solved where and the known limits.

Why is a disk without boundary conditions not a drum?

A disk, a ball or a cylinder without boundary= has no wall. It is solved with vacuum outside: the source fills the shape, and the potential is the one that it produces in all of space. Only the plan says so. Give a condition on the rim, such as boundary=sp.Eq(u, 0), for a wall. See Disks, rings, balls, shells and cylinders.

Can I use my own data?

Yes. A source, a coefficient, a value on the boundary, an initial state and a starting value can each be an array, wrapped as pm.GridData. In free space the array brings a uniform grid of its own, and on other domains it lies at their points. Except on a shape in the plane, the solution lives on the grid of the data. See Use measured data as a source and Data from arrays.

The plan and the grid

What is a plan?

The record of every choice that pdemagic made for a problem: the method, the box, the grid, the times, the tolerances, with notes that say why. pm.plan(problem) returns it without solving, a solution carries the one that produced it, and you can change any entry and solve with it. See The planner and its plan.

Why did pdemagic choose this grid?

The notes of the plan say. In free space the planner takes a box on whose faces the source has fallen to \(10^{-12}\) of its maximum, and the coarsest grid on which the spectrum of the source falls below \(10^{-10}\). Between walls and on a shape in the plane it solves on one grid or degree after the other and takes the first that resolves the solution. See Read what was decided.

Can I use my own grid?

Yes: set plan.grid.shape, and in free space plan.grid.lower and plan.grid.upper, and solve with the plan. Between walls and on round domains the kind of points is fixed, and only their number can change. On a shape in the plane the grid is only where the solution is given. See Choose the grid yourself.

What does “NOT resolved” mean?

The planner tried its finest grid or its highest degree, and the spectrum of the solution, or of what is given, still had not decayed. The cause is most often a singularity: boundary values that disagree in a corner, a jump, a source that is not smooth. The solution is returned, with fewer digits than usual. See What to do when a plan says NOT resolved.

Results

How accurate is the result?

Most methods are spectral: the error falls faster than any power of the grid spacing, and ten digits are common on modest grids. Two are of second order: cylinders with vacuum outside, and bodies with sharp surfaces. Linear equations in time are propagated exactly, and only nonlinear terms are stepped, with an error that a tolerance bounds. Every solution carries diagnostics that tell whether its grid and its box were adequate. See How accurate it is and Get more digits.

Why is my solution complex?

An equation or a source that holds sp.I has a complex unknown, and so has the Helmholtz equation in free space, whose solution carries the amplitude and the phase of a wave that leaves. A plot shows the magnitude, and part="real" or part="imag" one of the parts. See Complex unknowns.

Why does my array hold nan?

The solution on a shape in the plane comes on a grid over the rectangle that holds the shape. A point of that grid outside the shape, or in a hole, holds no number. Use np.nanmax and its relatives, or the mask np.isfinite(values). See Shapes in the plane.

Why was a constant taken off my source?

A problem that is periodic in every direction, or gives the slope on every face, has a solution only if its source balances. pdemagic takes the excess off the source, returns the solution with zero mean, and reports what it took in the diagnostic removed_source_mean. See the diagnostics.

Why can I not call my solution at a point in free space?

solution(x, y) gives values between the points of the grid on boxes with walls, on disks, rings and cylinders with boundary conditions, on shapes in the plane and on domains that are periodic in every direction. Where a direction is free it does not yet: the grid is a cut out of all of space there. Choose the grid so that it holds your points. See Evaluate a solution at a point.

Does a result far in the future cost more?

Not for a linear equation with constant coefficients. pdemagic does not step through time there: it evaluates the exact solution for every wave or mode, so a late time costs no more than an early one and is no less accurate. In free space the box must still hold what has spread or travelled by then. Nonlinear terms and coefficients that vary are stepped, and those take longer for a longer span. See Problems in time.

Installing and running

Which Python and which platforms?

Python 3.11 and later, on Linux (x86-64 and ARM), macOS (Apple silicon and Intel) and Windows (x86-64). pip install "pdemagic[plot]" brings a finished package, and nothing has to be compiled. There is no package for Linux with musl, such as Alpine, for Windows on ARM, or for Python 3.10 and older. See Installation.

Can I solve a problem again from a saved file?

No. A file that solution.save writes holds the values, the plan and the diagnostics, and of the problem the domain and what the solver read, not the sympy expressions. Keep the script, and the plan if you changed it. See Save and load a solution and Reuse a plan.