Systems of linear equations

This page explains how pdemagic solves several equations for several unknowns at once, when the equations are linear with constant coefficients:

\[\sum_j L_{ij}\, u_j = f_i \qquad\text{or}\qquad \sum_j \left( C^{(2)}_{ij}\, \partial_t^2 + C^{(1)}_{ij}\, \partial_t \right) u_j = \sum_j A_{ij}\, u_j + f_i .\]

The \(L_{ij}\) and \(A_{ij}\) are operators that act in space, and the \(C_{ij}\) are numbers. Maxwell’s equations in vacuum, the equations of linear elasticity, and coupled Schrödinger equations are of this kind.

One matrix per wave

An operator with constant coefficients multiplies each wave \(e^{i\mathbf{k}\cdot\mathbf{x}}\) by a number, its symbol (as for one equation). A system of \(n\) equations multiplies the vector of the \(n\) amplitudes by an \(n \times n\) matrix \(M(\mathbf{k})\). Everything that the methods for one equation do with a number is done here with that matrix.

Stationary systems

On a periodic box the system falls apart into one small linear system per wave,

\[M(\mathbf{k})\, \hat{\mathbf{u}}(\mathbf{k}) = \hat{\mathbf{f}}(\mathbf{k}),\]

which is solved by an LU factorization. If \(M\) is singular for a wave other than the constant one, the system has no unique solution, and pdemagic says so. For the constant wave a singular \(M\) is common: a system with derivatives only does not fix the mean of its unknowns. pdemagic then takes the smallest constant part that fits, and reports what it had to drop of the mean of the right-hand sides (removed_source_mean).

Systems in time

The system is first brought to first order in time. Its state \(\mathbf{y}\) holds every unknown, and for each unknown that an equation differentiates twice in time also its rate of change. The matrix of the highest derivatives in time is inverted once, which gives

\[\frac{\partial \mathbf{y}}{\partial t} = B\, \mathbf{y} + \mathbf{g}.\]

The equations need not be solved for their derivatives in time, and first and second order in time can be mixed. What is required is that the highest derivative in time of every unknown is determined. An equation without a derivative in time is a constraint, which is taken on periodic boxes: see below.

Each wave is then propagated exactly, as for one equation:

\[\hat{\mathbf{y}}(t + h) = e^{hB(\mathbf{k})}\, \hat{\mathbf{y}}(t) + \int_0^h e^{(h - s) B(\mathbf{k})}\, \hat{\mathbf{g}}(t + s)\, ds .\]

Without sources nothing is approximated in time. Sources that depend on time are replaced within each step by the cubic polynomial through their values at the four Gauss points of the step, and the integral of that polynomial is exact. It is a combination of the matrix functions \(\varphi_1(hB), \dots, \varphi_4(hB)\), with \(\varphi_k(Z) = \sum_n Z^n / (n + k)!\).

The matrix functions

The exponential and the \(\varphi_k\) are computed by scaling and squaring. \(Z\) is halved until its norm is below one half, the power series are summed there, and the result is doubled back:

\[\varphi_0(2Z) = \varphi_0(Z)^2, \qquad \varphi_k(2Z) = \frac{1}{2^k} \Big( \varphi_0(Z)\, \varphi_k(Z) + \sum_{j=1}^{k} \frac{\varphi_j(Z)}{(k - j)!} \Big).\]

No inverse of \(Z\) and no eigenvectors are needed. That matters: for the constant wave of every wave equation \(B\) is singular and has too few eigenvectors, and a method that relies on either fails exactly there.

Free directions

On an unbounded domain the transform is padded by the distance the solution travels, as for one equation. For a system that distance is known if the system is hyperbolic: its waves then travel with finite speeds, and the solution has a sharp front. Along an axis, a wave \(e^{ikx}\) evolves with the eigenvalues \(\lambda(k)\) of \(B\), and in a hyperbolic system these are \(\pm i c k\) for large \(k\), up to terms that do not grow with \(k\). The largest \(c\) is the speed of the fastest front along that axis. pdemagic reads it off the eigenvalues at two large wave numbers. Terms of lower order, such as a mass or a damping, do not change it.

Eigenvalues that grow faster than \(k\), as those of diffusion and of dispersion do, mean that there is no front. Such systems are solved on periodic boxes only. So are stationary systems.

Nonlinear terms

On a periodic box a system in time may have terms that are nonlinear in the unknowns, or linear with coefficients that vary:

\[\frac{\partial \mathbf{y}}{\partial t} = B\, \mathbf{y} + \mathbf{N}(\mathbf{y}, \mathbf{x}, t).\]

\(B\) stays exact, and \(\mathbf{N}\) is stepped by the exponential Runge–Kutta scheme of fourth order, as for one equation. The numbers \(e^{\sigma h}\) and \(\varphi_k(\sigma h)\) of that scheme become the matrices \(e^{hB}\) and \(\varphi_k(hB)\) of each wave. Step control, the 2/3 rule and the diagnostics are the same.

An equation of second order in time with a nonlinear term is such a system: its state holds the unknown and its rate of change. The rate may appear in the nonlinear term, as in a nonlinear friction.

Constraints

An unknown may have no derivative in time. It is then fixed, at every time, by an equation without one, a constraint:

\[K\, \mathbf{c} = \mathbf{R}(\mathbf{y}, \mathbf{x}, t).\]

\(K\) is a matrix of linear operators with constant coefficients that acts on the unknowns \(\mathbf{c}\) which the constraints fix, and \(\mathbf{R}\) may depend on the state in any way. A potential that obeys Poisson’s equation, with a charge density that depends on the other unknowns, is the standard example.

Whenever \(\mathbf{N}\) is evaluated, the constraints are solved first, wave by wave, for the state at hand. The \(\mathbf{c}\) are thus functions of the state, and what is stepped is a system in the state alone. Every term that contains a \(\mathbf{c}\) counts as part of \(\mathbf{N}\).

  • There must be as many constraints as unknowns without a derivative in time, and the constraints must be linear in those unknowns.

  • If \(K\) is singular for the constant wave, the smallest constant part is taken, as for stationary systems. For Poisson’s equation that drops the mean of the charge.

  • The unknowns \(\mathbf{c}\) take no initial values. They are part of the solution at every recorded time.

Accuracy

In space the method is spectral. Maxwell’s equations in the plane, started from a Gaussian pulse of the electric field, agree with the wave equation that this field obeys to 1e-12. A plane wave of light in a periodic box in three dimensions is exact to 1e-13 after one period.

In time there is an error only for sources that depend on time. For a system of second and first order in time with the solution \(u = \cos x \cos 3t\), \(v = \cos x \sin 3t\), over two units of time in two intervals:

Steps per interval

Error

1

1.5e-4

2

3.2e-7

4

1.1e-9

8

4.2e-12

With nonlinear terms the error is that of the steps, which the tolerance bounds. With the default tolerance of 1e-10 per step:

Problem

Error

A breather of the sine-Gordon equation, four units of time

< 1e-8

A soliton shared between two nonlinear Schrödinger equations

< 1e-8

Two species that diffuse and react, with sources

< 1e-8

A Schrödinger equation with the potential of its own density

< 1e-9

Systems that are refused

As for one equation, a system whose waves grow without bound in the wave number is ill-posed, and pdemagic refuses it: it finds the norm of \(e^{BT}\) for every wave on the grid, and refuses if any exceeds that of the constant wave by a factor of \(e^{36}\).

Cost

For every wave, the matrix functions of an \(N \times N\) matrix, where \(N\) is the size of the state, and then one product of a matrix with a vector per recorded time. The matrices are kept, which takes \(N^2\) complex numbers per wave. Maxwell’s equations in three dimensions, with their six unknowns on a 64³ grid in free space, take six seconds. A matrix whose unknowns are not coupled by the linear part, as in reaction–diffusion systems, is diagonal, and its functions are those of its entries.

A nonlinear system costs twelve evaluations of its terms per step, each with a few transforms per unknown. The pattern of the Gray–Scott model in the guide, 268 steps on a 96² grid, takes four seconds.

Limits

  • Nonlinear terms and constraints need a periodic box here. With free directions it is not known how far a nonlinear solution travels. Between walls, on round domains and on regions they are solved in the modes of the domain: see systems between walls.

  • Constraints are linear in what they fix.

  • Stationary systems are linear, and on periodic boxes only.

  • Hyperbolic, with free directions.

  • Cartesian coordinates, without bodies and without walls. Boxes and round domains with boundary conditions take systems in time in the modes of each unknown, and regions of the plane by spectral elements.