# Diagnostics Every key of `solution.diagnostics`, with what it measures, when it is set, and what a good value is. `solution.diagnostics` is a dictionary that always holds the same fourteen keys. A key that does not apply to the method that was used holds `None`. A ratio or a tail is a fraction of a largest value, and "tiny" means near what the planner aims at: $10^{-10}$ for a spectrum, and $10^{-12}$ for a source on the faces of a box. ## The keys at a glance | Key | About | Good values | |---|---|---| | [`spectral_tail`](#spectral_tail) | whether the grid resolves what is given | tiny | | [`source_boundary_ratio`](#source_boundary_ratio) | whether the box holds the source | tiny | | [`padded_shape`](#padded_shape) | the size of the transform | for information | | [`removed_source_mean`](#removed_source_mean) | what was taken off the source | zero, unless you rely on it | | [`coefficient_boundary_ratio`](#coefficient_boundary_ratio) | whether the box holds the coefficients | tiny | | [`iterations`](#iterations) | the steps of an iteration | below `method.max_iterations` | | [`residual`](#residual) | what an iteration reached | at or below `method.tolerance` | | [`newton_steps`](#newton_steps) | the steps of Newton's method | for information | | [`solution_boundary_ratio`](#solution_boundary_ratio) | whether the solution has reached the faces of the box | for information | | [`steps`](#steps-and-rejected_steps), [`rejected_steps`](#steps-and-rejected_steps) | the steps of a time stepping | for information | | [`solution_tail`](#solution_tail) | whether the grid resolves the solution | tiny | | [`bodies`](#bodies) | the charge and the potential of each body | | | [`source_surface_ratio`](#source_surface_ratio) | whether free charge reaches a body | tiny | ## Each key ### `spectral_tail` How far the spectrum of what is given has decayed at high frequencies, as a fraction of its largest coefficient: the source, the initial state, coefficients that vary, and on a box with conditions the values on the faces as well. A value that is not tiny means that the grid is too coarse for what is given. Set for every solve. It is zero where nothing is given to judge, as in an eigenproblem between walls. In a cylinder with vacuum outside it covers the angle only. ### `source_boundary_ratio` The largest magnitude of the source on the faces of the box along its free directions, as a fraction of its largest magnitude overall. The Fourier methods take the source to vanish outside the box, so this should be tiny. With coefficients that vary and with a nonlinear term it covers the effective source as well, and a value that is not tiny then means that the solution has outgrown the box. Set by `fourier`, `fourier_iterative`, `fourier_newton`, `fourier_propagator` and `exponential_runge_kutta` on domains with free or periodic directions, where it also covers the initial state, and by `boundary_elements` if there is a free charge. On a domain that is periodic in every direction it is zero. ### `padded_shape` The size of the zero-padded transform that the method worked on. On a domain that is periodic in every direction it is the shape of the grid. Set together with `source_boundary_ratio`. ### `removed_source_mean` What was taken off the source so that the problem has a solution. - `fourier`: the mean of the source of Poisson's equation on a domain that is periodic in every direction. It is zero for a problem with a free direction, and `None` for the Helmholtz equation. - `fourier_iterative`, on a periodic domain, for an equation in which the unknown appears in derivatives only: what was taken off is this number times the coefficient of the highest derivatives, relative to its mean. - `collocation` and `spectral_elements`: the constant that was taken off the source where the whole boundary gives the slope and no term holds the unknown, so that the source balances what flows through the boundary. `None` for every other problem there. ### `coefficient_boundary_ratio` How far the coefficients of the equation are from the constants that they settle to, on the faces of the box along its free directions, as a fraction of how far they are from them at most. The method takes the coefficients to be constant outside the box, so this should be tiny. Set by `fourier_iterative` and `fourier_newton`, and by `exponential_runge_kutta` for coefficients that vary on a domain with free directions. ### `iterations` The number of steps that an iteration took. - `fourier_iterative`, `collocation_iterative`: the steps of the iteration for coefficients that vary. - `fourier_newton`, `collocation_newton`: the steps of that iteration in all steps of Newton's method together. - `fourier_subspace`, `element_modes`, `collocation_inverse_modes`: the iterations for the eigenfunctions. `None` for `element_newton`, where each step of Newton's method is solved directly. ### `residual` What an iteration reached. - `fourier_iterative`, `collocation_iterative`: the residual, as a fraction of the right-hand side. - `fourier_newton`, `collocation_newton`, `element_newton`: the residual of the nonlinear equation, as a fraction of the larger of the source and the effective source or the nonlinear term. - `fourier_subspace`, `element_modes`: the residual of the eigenfunctions. - `collocation_inverse_modes`: how far the stationary solve is from mapping a mode to a multiple of itself, relative to the size of the mode, for the worst of the modes. - `collocation_split`: how far the conditions on the faces of a plate are from holding. It should be at or below `method.tolerance`. For the plate equation it should be tiny. ### `newton_steps` The number of steps that Newton's method took. Set by `fourier_newton`, `collocation_newton` and `element_newton`. ### `solution_boundary_ratio` For a problem in time with free directions: the largest magnitude of the solution on the faces of the box at the last recorded time, as a fraction of its largest magnitude then. A value that is not tiny means that the solution has spread beyond the box. What the box shows is still right. Set by `fourier_propagator` and by `exponential_runge_kutta` on domains with free or periodic directions, where it is zero on a domain that is periodic in every direction. `fourier_subspace` sets it for an eigenproblem with free directions: there it should be tiny, since a bound state has faded on the faces. ### `steps` and `rejected_steps` For time stepping: the number of steps that were taken, and the number that were tried and rejected because their error was above the tolerance. Set by `exponential_runge_kutta` and `element_stepping`. ### `solution_tail` How far the solution itself has decayed at high frequencies. A value that is not tiny means that the grid is too coarse for the solution, or that the solution has a singularity, as it often does at the corners of a box. - Time stepping: how much of the solution at the last recorded time lies in the highest waves that the stepping keeps. A nonlinear equation can create finer structures than its initial state has. - On boxes and round domains with conditions, for every method: how far the coefficients of the solution have decayed, as a fraction of the largest one. In time it is taken at the last recorded time. - On a region, for every method: the same for the polynomials of the elements. The remedy there is `method.degree` or `method.spacing`, not the grid. - `fourier_iterative`, `fourier_newton`: the same for the effective source, which holds the waves of the solution, the short ones with more weight. - `fourier_subspace`: the same for the eigenfunctions. `None` for `fourier`, `fourier_propagator`, `harmonics`, `finite_differences` and `boundary_elements`. ### `bodies` For `boundary_elements`: what was found out about each body, in the order of the problem, each with its `name`, the number of `panels` on its surface, the `flux` of $-\nabla u$ out of it, and the `potential` of a conductor. The flux is the charge on the surface in the units of the equation. `solution.bodies` holds the same by name, as [`pm.BodyResult`](data-and-bodies.md). ### `source_surface_ratio` For `boundary_elements` with a free charge: the largest magnitude of the source on the surfaces of the bodies, as a fraction of its largest magnitude overall. The grid cannot follow the jump of a charge density at the surface of a body, so this should be tiny. `None` if there is no free charge. ## Which method sets which keys `spectral_tail` is set by every method. | `method.kind` | Keys beside `spectral_tail` | |---|---| | `fourier` | `source_boundary_ratio`, `padded_shape`, `removed_source_mean` | | `fourier_iterative` | those of `fourier`, `coefficient_boundary_ratio`, `iterations`, `residual`, `solution_tail` | | `fourier_newton` | `source_boundary_ratio`, `padded_shape`, `coefficient_boundary_ratio`, `iterations`, `residual`, `newton_steps`, `solution_tail` | | `fourier_subspace` | `iterations`, `residual`, `solution_tail`, and with free directions `solution_boundary_ratio` | | `fourier_propagator` | `source_boundary_ratio`, `padded_shape`, `solution_boundary_ratio` | | `exponential_runge_kutta`, free and periodic | `source_boundary_ratio`, `padded_shape`, `solution_boundary_ratio`, `steps`, `rejected_steps`, `solution_tail`, and with free directions `coefficient_boundary_ratio` | | `exponential_runge_kutta`, boxes and round domains | `steps`, `rejected_steps`, `solution_tail` | | `collocation` | `solution_tail`, and with slopes on every face `removed_source_mean` | | `collocation_iterative` | `iterations`, `residual`, `solution_tail` | | `collocation_newton` | `iterations`, `residual`, `newton_steps`, `solution_tail` | | `collocation_split` | `residual`, `solution_tail` | | `collocation_modes`, `mode_propagator` | `solution_tail` | | `collocation_inverse_modes` | `iterations`, `residual`, `solution_tail` | | `harmonics`, `finite_differences` | none | | `boundary_elements` | `bodies`, and with a free charge `source_boundary_ratio`, `padded_shape`, `source_surface_ratio` | | `spectral_elements` | `solution_tail`, and with slopes on the whole boundary `removed_source_mean` | | `element_newton` | `residual`, `newton_steps`, `solution_tail` | | `element_modes` | `iterations`, `residual`, `solution_tail` | | `element_propagator` | `solution_tail` | | `element_stepping` | `steps`, `rejected_steps`, `solution_tail` | ## When a diagnostic is not small | What is not small | Remedy in the plan | |---|---| | `source_boundary_ratio`, `coefficient_boundary_ratio` | a wider box: `grid.lower`, `grid.upper` | | `spectral_tail`, `solution_tail` | a finer grid: `grid.shape`. On a region: a higher `method.degree` or a smaller `method.spacing` | | `residual` | more steps: `method.max_iterations`, `method.max_steps` | | `source_surface_ratio` | keep the free charge away from the surfaces of the bodies | See also: [Accuracy and diagnostics](../topics/accuracy.md), [the methods of a plan](methods-of-a-plan.md) and [how accurate it is](accuracy.md).