# The methods of a plan Every value that `plan.method.kind` takes, with the parameters that stand beside it and the problems that get it, and the other parts of a plan: the grid, the times and the notes. ## The parts of a plan ```python import sympy as sp import pdemagic as pm x, t = sp.symbols("x t", real=True) u = sp.Function("u")(x, t) rod = pm.Problem( sp.Eq(u.diff(t), u.diff(x, 2)), domain=pm.Box({x: (0, 1)}), time=(t, 0, 0.1), initial={u: sp.sin(sp.pi * x)}, boundary=sp.Eq(u, 0), ) print(pm.plan(rod)) ``` ```text method: kind: mode_propagator steps: 1 grid: lower: [0.0] upper: [1.0] shape: [24] periodic: [False] rules: - chebyshev times: start: 0.0 end: 0.1 count: 21 notes: - The equation is of first order in time, with a linear operator of second order with constant coefficients in space, on a 1-dimensional box. - Boundary conditions: the value at x = 0, the value at x = 1. - Method: exact propagation in the modes of the box, with Chebyshev points along the axes with faces. - Grid: the coarsest candidate on which the spectrum of the solution and of what is given falls below 1e-10 at high frequencies. - Time: recorded at 21 times. Nothing that is given depends on time, so each of them is exact in time. ``` | Entry | Meaning | |---|---| | `method.kind` | The method: one of the kinds below. It must suit the problem. | | `method.` | The parameters of that kind. A kind without parameters has none. | | `grid.lower`, `grid.upper` | The first and the last point along each axis, in the coordinates of the domain. Along a periodic axis they are the ends of one period. | | `grid.shape` | The number of points along each axis. | | `grid.periodic` | Which axes are periodic. An empty list means none. | | `grid.rules` | How the points of each axis are placed. The entry is missing where every axis is uniform. | | `times.start`, `times.end`, `times.count` | For a problem in time: the solution is recorded at `count` times, evenly spaced from `start` to `end`. The planner chooses 21. A single time is `end`. A stationary problem has no `times`. | | `notes` | What the planner found and why it chose what it chose, in words. They have no effect on the solve. | Every entry is read and set as an attribute, as in `plan.grid.shape = (96, 96)` or `plan.times.count = 5`. Only the entries that a plan holds can be set: `plan.method.tolerance` exists for the kinds that have a tolerance. ### The rules of a grid | Rule | Where the points lie | Used along | |---|---|---| | `uniform` | Equally spaced. Along a periodic axis they start at `lower` and stop one step short of `upper`. Elsewhere both ends are included. | free and periodic axes, angles around an axis, the grid over a region | | `chebyshev` | Chebyshev points of the second kind: both ends are included, and the points crowd towards them. | an axis of a box that ends in faces, the axis of a cylinder with conditions | | `gauss` | The nodes of the Gauss–Legendre rule, strictly inside the bounds. | the radius of a disk, a ball and a cylinder with conditions, and of a disk and a ball with vacuum outside | | `gauss_cosine` | The angles whose cosines are the Gauss–Legendre nodes. | the polar angle of a ball | | `midpoint` | The midpoints of equal cells, half a step inside the bounds. | the radius and the axis of a cylinder with vacuum outside | ### What the grid means | Domain | The grid | |---|---| | free directions | A box that the planner puts around the sources, the initial state or the bound states. The diagnostics tell whether it was large enough. | | a box, a round domain | The domain itself, in its own coordinates. `grid.shape` sets the accuracy. | | a region | Equally spaced points over the rectangle that holds the region, where the solution is given: see [grids on a shape](../methods/element-grids.md). It does not affect the accuracy: `method.degree` and `method.spacing` do. | | bodies | Where the solution is evaluated. The accuracy depends on `method.panels`. | ## The kinds In free space and on periodic boxes: | Kind | Problems that get it | Parameters | How it works | |---|---|---|---| | `fourier` | Poisson, screened Poisson and Helmholtz with free and periodic directions. Any linear equation with constant coefficients, and stationary linear systems, on a domain that is periodic in every direction. | none | [Poisson](../methods/fourier-poisson.md), [other linear equations](../methods/linear-fourier.md), [Helmholtz](../methods/helmholtz.md), [systems](../methods/coupled.md) | | `fourier_iterative` | Linear stationary equations with coefficients that vary in space. | `tolerance`, `max_iterations` | [coefficients that vary](../methods/varying-coefficients.md) | | `fourier_newton` | Stationary equations with a term that is nonlinear in the unknown. | `tolerance`, `max_steps`, `max_iterations` | [Newton's method](../methods/newton.md) | | `fourier_propagator` | Linear equations and systems in time with constant coefficients. | `steps` | [exact propagation](../methods/propagator.md), [systems](../methods/coupled.md) | | `exponential_runge_kutta` | Equations and systems in time with nonlinear terms or coefficients that vary. Also on boxes and round domains with conditions. | `tolerance`, `max_steps` | [exponential time stepping](../methods/exponential.md) | | `fourier_subspace` | Eigenproblems. | `tolerance`, `max_iterations` | [the lowest eigenvalues](../methods/subspace.md) | | `boundary_elements` | Poisson's equation around conductors and dielectrics, in free space in three dimensions. | `panels` | [boundary elements](../methods/boundary-poisson.md) | On boxes with walls and on round domains with conditions: | Kind | Problems that get it | Parameters | How it works | |---|---|---|---| | `collocation` | Linear stationary equations of second order with constant coefficients. | none | [collocation](../methods/collocation.md), [round domains](../methods/round-domains.md) | | `collocation_iterative` | Stationary equations with coefficients that vary, and on a box with a mixed derivative. | `tolerance`, `max_iterations` | [the iteration between walls](../methods/iteration-between-walls.md) | | `collocation_newton` | Stationary equations with a term that is nonlinear in the unknown. | `tolerance`, `max_steps`, `max_iterations` | [the iteration between walls](../methods/iteration-between-walls.md) | | `collocation_split` | The plate equation on a box. | none | [the plate equation](../methods/plate-equation.md) | | `mode_propagator` | Linear equations of first and second order in time with constant coefficients. | `steps` | [collocation](../methods/collocation.md), [round domains](../methods/round-domains.md) | | `exponential_runge_kutta` | Equations in time with nonlinear terms or coefficients that vary: of first order, of second order on periodic domains and between walls, and systems of them. | `tolerance`, `max_steps` | [exponential time stepping](../methods/exponential.md), [systems](../methods/systems-between-walls.md) | | `collocation_modes` | Eigenproblems whose modes are products of the modes of the axes. | none | [the modes of a cavity](../methods/cavity-modes.md) | | `collocation_inverse_modes` | Every other eigenproblem: a medium, a potential of any form, a mixed derivative, a plate. | none | [modes that are no products](../methods/inverse-modes.md) | On round domains with vacuum outside: | Kind | Problems that get it | Parameters | How it works | |---|---|---|---| | `harmonics` | Poisson's equation in a disk or a ball. | none | [harmonics](../methods/harmonics-poisson.md) | | `finite_differences` | Poisson's equation in a cylinder. | none | [surface values and finite differences](../methods/cylinder-poisson.md) | On regions of the plane: | Kind | Problems that get it | Parameters | How it works | |---|---|---|---| | `spectral_elements` | Linear stationary equations and systems. | `degree`, `spacing`, `layers` | [spectral elements](../methods/spectral-elements.md), [corners](../methods/element-corners.md), [systems](../methods/element-systems.md) | | `element_newton` | Stationary equations and systems with nonlinear terms. | `degree`, `spacing`, `layers`, `tolerance`, `max_steps` | [nonlinear equations on a shape](../methods/element-newton.md) | | `element_propagator` | Linear equations of first and second order in time that are exact in the modes of the shape. | `degree`, `spacing`, `steps` | [elements in time](../methods/elements-in-time.md) | | `element_stepping` | Equations of first and second order in time with terms that are stepped, and systems of equations of first order. | `degree`, `spacing`, `tolerance`, `max_steps` | [elements in time](../methods/elements-in-time.md) | | `element_modes` | Eigenproblems. | `degree`, `spacing`, `layers` | [the modes of a shape](../methods/element-modes.md) | Which forms of an equation each kind takes is on the pages of [what is solved where](equations.md). ## The parameters "The planner's value" is what `pm.plan` returns. ### Iterations | Kind | Parameter | Meaning | The planner's value | |---|---|---|---| | `fourier_iterative`, `collocation_iterative` | `tolerance` | The iteration stops when the residual has fallen to this fraction of the right-hand side. | `1e-10` | | | `max_iterations` | The most steps before the iteration gives up. | 200 | | `fourier_subspace` | `tolerance` | The iteration stops when the residual of every eigenfunction has fallen to this fraction of the largest eigenvalue. | `1e-10` | | | `max_iterations` | The most iterations before it gives up. | 500 | ### Newton's method | Kind | Parameter | Meaning | The planner's value | |---|---|---|---| | `fourier_newton` | `tolerance` | The method stops when the residual of the equation has fallen to this fraction of the larger of the source and the effective source. | `1e-10` | | `collocation_newton`, `element_newton` | `tolerance` | The same, as a fraction of the larger of the source and the nonlinear term. | `1e-10` | | all three | `max_steps` | The most steps of Newton's method before it gives up. | 50 | | `fourier_newton`, `collocation_newton` | `max_iterations` | The most steps of the iteration within one step of Newton's method. On a region each step is solved directly. | 200 | ### Time | Kind | Parameter | Meaning | The planner's value | |---|---|---|---| | `fourier_propagator`, `mode_propagator`, `element_propagator` | `steps` | The number of steps between two recorded times. It only matters for a source or for boundary values that depend on time, which are interpolated in time within each step. | 1, and more where something that is given depends on time | | `exponential_runge_kutta`, `element_stepping` | `tolerance` | The error of a single step, relative to the size of the solution, that is accepted. | `1e-10` | | | `max_steps` | The most steps between two recorded times before the stepping gives up. | 1048576 | ### Elements and panels | Kind | Parameter | Meaning | The planner's value | |---|---|---|---| | `spectral_elements`, `element_newton`, `element_modes`, `element_propagator`, `element_stepping` | `degree` | The degree of the polynomials on each quadrilateral, in both directions. The accuracy is raised by it. | chosen for each problem | | | `spacing` | About how long the sides of the triangles are that the quadrilaterals are cut from, three from each. | chosen for each problem | | `spectral_elements`, `element_newton`, `element_modes` | `layers` | The number of layers of elements that shrink towards each corner of the boundary at which the solution has a singularity, each half the size of the one before. Zero for a mesh that takes no notice of corners. | chosen for each problem, zero for a shape without such a corner | | `boundary_elements` | `panels` | About how many triangles the surfaces of all bodies that are given as shapes are divided into, together. A body given as a mesh keeps its own triangles. | 1000 | What a plan may hold at most is on the page of [known limits](../dev/limits.md#limits-that-do-not-refuse), under "Size and speed". See also: [The planner and its plan](../topics/planner.md), [`pm.Plan`](plan-and-solve.md) and the [diagnostics](diagnostics.md) that each method reports.