Shapes in the plane, in time¶
This page explains how pdemagic solves an equation in time on a region of the plane: heat, waves, the Schrödinger equation, and equations with terms that are stepped. The mesh, the elements and the weak form are those of a stationary equation, which are explained under spectral elements.
In time: the modes of the shape¶
A linear equation in time,
is propagated on a region as it is on a box (propagation, collocation): in the modes of the operator \(L\) with the conditions of the boundary. Each mode evolves by itself, and its evolution is known in closed form. A box has its modes axis by axis. A shape has them only as a whole.
The density \(\rho\), the medium \(\varepsilon\) and the potential \(c\) may vary in space: a membrane whose density or tension varies, heat in a body whose capacity varies, a wave function in a well. The operator stays symmetric with them, which is all that the modes need. They may carry one complex factor in common, as in the Schrödinger equation, and besides that \(\rho\) and \(\varepsilon\) must be real and positive and \(c\) real, up to a constant. The density may be written in front of the derivative in time, \(\rho\,u_{tt} = \dots\), or as a coefficient in front of the second derivatives. A potential that does not fit, or that changes in time, is stepped in an equation of first order in time. A medium that does not fit is refused.
One eigenproblem¶
At the points of the elements the weak form is a system of ordinary differential equations,
with the diagonal matrix \(M\) of the quadrature, the symmetric matrix \(K\) of \(\int \varepsilon\,\nabla u \cdot \nabla v\), the diagonal matrix \(B\) that a mix of value and slope leaves on the boundary, and the diagonal matrix \(C\) of the potential at the points. The points whose value is given are not unknowns. Written for \(w = M^{1/2} u\), the operator is the symmetric matrix
What flows through the boundary is \(\varepsilon\,\partial u/\partial n\), so a condition on the slope enters with the medium at the boundary.
With a density the equation is \(\rho\,M\,\dot u = \dots\): every point weighs its area times the density, and \(M\) stands for that product in the symmetric matrix. The modes are then orthogonal in the weighted sum, as the modes of a membrane with a density are.
One dense eigendecomposition of it, by faer, gives every mode that the elements hold: the eigenvalues are real, and the modes are orthogonal. Their matrix turns values at the points into coefficients of modes and back.
A mix \(\alpha u + \beta\,\partial u/\partial n = g\) needs a real ratio \(\alpha/\beta\) for that. Otherwise the matrix is not symmetric, and the problem is refused.
What is given¶
In the basis of the modes the equation is one ordinary differential equation per mode, with the eigenvalue as its rate. The source is turned into that basis. What is given on the boundary acts as one more source: given values act through the entries of \(K\) that join them to their neighbours, and a given slope through its integral over the boundary.
If nothing that is given depends on time, the solution at each recorded time is exact in time: no steps are taken. If the source or the boundary values do depend on time, each interval between two recorded times is cut into steps. Within a step, what is given is replaced by the cubic polynomial through four of its values, and that polynomial is integrated exactly, as on a box.
Accuracy in time¶
For the heat equation on the unit square with zero on its sides, started from two of its modes, on 24 elements and up to the time 0.1, on one core:
Degree |
Points |
Largest error |
Solve |
|---|---|---|---|
4 |
417 |
\(4.7 \cdot 10^{-4}\) |
0.05 s |
6 |
913 |
\(3.5 \cdot 10^{-6}\) |
0.2 s |
8 |
1 601 |
\(1.6 \cdot 10^{-8}\) |
0.6 s |
10 |
2 481 |
\(4.8 \cdot 10^{-11}\) |
2.4 s |
12 |
3 553 |
\(2.1 \cdot 10^{-10}\) |
6.8 s |
14 |
4 817 |
\(3.7 \cdot 10^{-12}\) |
16 s |
The error falls as for a stationary problem, down to about \(10^{-10}\). There rounding takes over: the largest eigenvalue of the matrix grows with the fourth power of the degree, and the eigendecomposition is right to a rounding error of that size, not of the small eigenvalues that matter.
The time grows with the cube of the number of points, and the memory with its square. That is the price of having every mode, and it bounds what this method reaches: the modes of 6 000 points take more than half a minute and 1.2 gigabytes, and a plan with more is refused.
Waves need more points than heat for the same accuracy. Heat forgets
detail. A wave carries all of it across the region for good, including the
kink that a start leaves at the boundary when it does not fit the
condition there. Three or four digits are typical for a drum, and the
diagnostic solution_tail says what was reached.
Terms that are stepped¶
An equation in time may hold more than the symmetric operator above: terms that are nonlinear in the unknown, terms with a first derivative, and terms with coefficients that vary in time. They are stepped by the exponential scheme of domains with walls, in the modes of the shape: the operator is exact, what the boundary is given is integrated exactly, and only the rest is approximated in time, to fourth order, with a step that follows a tolerance.
A potential that varies in space alone is not stepped: it is part of the modes. The ground state of a harmonic well on a disk, followed for two units of time, is right to \(4\cdot10^{-11}\) after 1.8 s that way. Stepped, as it was before the modes took the potential, it took 320 steps and 9.9 s for \(8\cdot10^{-10}\). A plan that asks for stepping is still taken.
The scheme needs the terms in the basis of the modes. Each evaluation turns the coefficients of the modes into values at the points of the elements, evaluates the terms there, with the source, and turns the result back, together with what the boundary contributes. Those two products with the matrix of the modes are the cost of a step: for a population that spreads and grows on the unit disk, \(p_t = \tfrac{1}{20}\nabla^2 p + p\,(1 - p)\), on 913 points, 2 600 of them take four fifths of 1.5 s.
The terms may hold the unknown, the position and the time, and first derivatives of the unknown or of an expression in it: a drift \(\mathbf{b}\cdot\nabla u\), with coefficients that are constant or vary, and terms such as \(u\,u_x\) or \((u^2/2)_x\). A drift with constant coefficients is stepped only where it is strong: otherwise it is part of the modes.
A derivative is taken element by element, as the derivative of the polynomial of the element. At a point that elements share, their derivatives differ, and the mean is taken, weighted with the area that the point stands for in each element. That is the weak form of the term, tested with the polynomials of the elements and divided by the area of the point, so it fits the modes, and the error falls as fast as that of the elements: a front of Burgers’ equation that passes a hole in a disk is right to \(10^{-5}\) at degree 3 and to \(6\cdot10^{-7}\) at degree 4.
A term with a derivative makes the steps small. The points of an element crowd towards its sides, with the square of the degree, and the step follows the smallest distance and the strength of the term. Heat with a drift of 20 on a triangle, \(u_t = \nabla^2 u - 20\,u_x\), takes 20 500 steps at degree 8 and the tolerance \(10^{-10}\), which are 138 s. Where diffusion is weak the steps are few: a blob that a rotation carries a quarter turn, with a diffusion of 1/50, takes 170.
A derivative above the first order in a term that is stepped is refused, also written as a derivative of a derivative.
A drift in the modes¶
A drift makes the operator \(a\,\nabla^2 u + \mathbf{b}\cdot\nabla u\) non-symmetric, as it stands. With the density \(\rho = e^{\mathbf{b}\cdot\mathbf{x}/a}\) it is
an operator with a density and a medium, which is symmetric once the points are weighted with the density. So a drift with constant coefficients is propagated exactly, in an equation of first or of second order in time, with the conditions on the boundary as they are given: neither the unknown nor its slope is changed.
For \(u_t = \nabla^2 u - 2u_x\) on a triangle, with the solution \(e^{x + y/2 - 3t/4}\), the error falls from \(2.6\cdot10^{-3}\) at degree 2 over \(2\cdot10^{-6}\) at degree 4 to \(6\cdot10^{-10}\) at degree 6, and the planner’s choice takes 0.6 s. Stepped, as it was before, it took 5 100 steps and 37 s.
The density must be resolved by the elements like everything that is given, so a stronger drift takes a higher degree: 12 for a drift of 6 on that triangle, 16 for one of 12, which take 4 s and 22 s. And it spans a factor of \(e^{P}\) over the shape, where \(P = |\mathbf{b}|\,L/a\) compares the drift with the diffusion across the shape. Rounding errors grow with the square root of that span. Up to \(P = 24\), which leaves ten digits, the drift is part of the modes. Beyond that it is stepped in an equation of first order in time, and refused in one of second order. The ratio \(\mathbf{b}/a\) must be real, or the density is not: a drift in the Schrödinger equation that is written with an \(i\) in front is stepped.
Several unknowns¶
A system of equations in time, one for each unknown and of first or second order, is stepped as one equation is. Each equation is sorted: the terms with its own unknown alone are read as a single equation, and give a symmetric operator with the conditions of that unknown, whose modes that unknown is expanded in. The terms that hold another unknown are stepped, with whatever else the equation has stepped. The state of the scheme is the coefficients of all unknowns, one after another, and each evaluation of the terms turns every unknown into its values at the points, evaluates all terms there, and turns the results back, each into the modes of its own unknown.
Unknowns whose operators differ by a factor alone, with the same conditions, have the same modes with other eigenvalues: substances that differ in their rate of diffusion. They share one eigenproblem.
An unknown whose equation has no derivative in space, as the slow one of the model of FitzHugh and Nagumo, has no operator with modes and no condition on the boundary. The points of the elements are its modes: its coefficients are its values, and its linear part is a number.
An equation without a derivative in time is a constraint, and fixes an unknown that has no equation in time, as between walls: at every evaluation of the terms it is solved in the modes of that unknown, mode by mode. The planner needs that unknown at the start, to judge a mesh by the terms there, and computes its modes on every mesh that it tries.
On the unit square, \(u = e^{-t}\sin\pi x\,\sin\pi y\), which vanishes on the sides, and \(v = e^{-2t}\cos\pi x\,\cos\pi y\), whose slope does, solve \(u_t = \nabla^2 u - u v + f\) and \(v_t = \tfrac12\nabla^2 v + u^2 v + g\) for the right \(f\) and \(g\). On three elements, to the time 1/4:
Degree |
Error |
Tolerance |
Steps |
Error |
|
|---|---|---|---|---|---|
4 |
\(3\cdot10^{-3}\) |
\(10^{-4}\) |
1 |
\(1\cdot10^{-5}\) |
|
6 |
\(5\cdot10^{-5}\) |
\(10^{-6}\) |
4 |
\(5\cdot10^{-8}\) |
|
8 |
\(4\cdot10^{-7}\) |
\(10^{-8}\) |
16 |
\(2\cdot10^{-11}\) |
The error falls with the degree as for one equation, and with the steps to the fourth order: the columns on the right are at degree 12.
Values on the boundary that change in time cost the scheme orders, for one equation as for a system: they enter through the points next to the boundary, where the operator is largest. With the value of \(u\) given on the rim of a disk as \(e^{-t}\sin x\cos y\), a thousand times the accuracy takes sixteen times the steps, not six.
How the mesh, the degree and the steps are chosen in time¶
Nothing is solved while planning: the modes are too expensive to compute for one candidate after another. The planner looks at what is given. It starts with a mesh whose spacing is half the size of the region, coarser than for a stationary problem, since a high degree on few elements needs the fewest points. It takes the lowest degree from 8 on, in steps of 2 up to 16, at which the Legendre coefficients of the initial state, and of the source at a few instants, have fallen to \(10^{-8}\) of the largest in every element. It stays below 3 500 points, which take a few seconds, and says so when that leaves something unresolved. For a problem with terms that are stepped it counts those terms at the start with what is given, and stays below 1 700 points. A finer mesh is only taken where the coarse one folds.
The steps between two recorded times are the fewest, as a power of two up to 128, for which the cubic polynomial matches what is given to \(10^{-10}\) at the end of each step.
The solution may develop detail that what is given does not have. The
diagnostic solution_tail is measured on the solution at the last time.
Limits¶
In time, the exact part is \(\nabla\cdot(\varepsilon\nabla u)/\rho + c\,u\), with a density, a medium and a potential that keep the operator symmetric. Directions that differ and a mixed derivative are not taken in time on a region yet, nor is a density beside a damping. Neither is a mix of value and slope whose ratio is not real.
Stepped terms hold the unknown and its first derivatives. In an equation of second order in time the unknown and its rate of change are stepped together, with a matrix for each mode: see nonlinear equations in time. A drift with constant coefficients is part of the modes up to a strength of 24 against the diffusion across the shape, and stepped beyond. A drift whose coefficients vary is always stepped.
In time the equations of a system are coupled through terms without second derivatives.
In time, a few thousand points. The modes come from a dense eigenproblem. A pulse that is narrower than about a tenth of the region is beyond it.
No layers in time. The mesh of a problem in time takes no notice of corners: the points that layers add are more than the modes can hold. A corner with a singularity leaves three or four digits there.