Techniqueadvanced
Summation-by-parts operators
Also called SBP-SAT method.
Difference operators D = H^-1 Q with Q + Q^T = B, a discrete form of integration by parts. With weak boundary terms (SAT) the energy method proves stability for the discrete scheme.
A summation-by-parts (SBP) operator is a difference approximation on the nodes of an interval that has the form , where is symmetric positive definite and
Then , which is the discrete form of . acts as a quadrature rule and defines a discrete norm . Because integration by parts holds exactly, the energy method that proves well-posedness of a PDE also proves stability of the semi-discrete scheme. Boundary conditions are imposed weakly with simultaneous approximation terms (SAT), penalty terms whose strength is chosen to make the energy estimate close. The SBP-SAT method gives provably stable high-order finite difference schemes on bounded domains, and the same structure appears in DG and spectral element methods on Gauss-Lobatto nodes.
In plain words
A key tool for proving that a wave or flow equation behaves well is integration by parts: it moves a derivative from one function to another and leaves only terms at the ends of the interval. Ordinary difference formulas do not obey an exact discrete version of this rule, so proofs for the equation do not carry over to the computer program, and schemes can blow up near boundaries. SBP operators are difference formulas built so that the rule holds exactly with a matching set of weights. Boundary values are not forced in. Instead, a correction term pulls the solution toward the boundary data, with a strength chosen so the total energy can only go down. Then the stability proof for the equation also works for the program.
When it applies
- Linear or linearized hyperbolic and parabolic problems on bounded domains where an energy estimate exists for the continuous problem: advection, wave equations, Maxwell's equations, the linearized Euler and Navier-Stokes equations.
- Nonlinear conservation laws, by combining SBP operators with split forms or two-point fluxes to get entropy stable schemes.
- Structured grids or multiblock grids. Blocks are coupled with interface SAT terms, the same way as boundary data.
- High-order finite differences that must be stable near boundaries. Diagonal is preferred because it keeps the energy estimate valid on curvilinear grids and for variable coefficients.
The template
SBP-SAT(PDE with an energy estimate, boundary data g)- 1
choose a positive diagonal norm H, a quadrature rule of the required order - 2
choose D = H⁻¹Q with Q + Qᵀ = B, exact for polynomials up to the boundary and interior orders - 3
replace each ∂/∂x by D to get the semi-discrete system - 4
add penalty terms τ H⁻¹ e_k (u_k - g_k) at each boundary node k where data enter - 5
apply the energy method to uᵀHu and choose τ so that all boundary terms are nonpositive
For on with and inflow , the scheme is
The energy method with gives (theorem)
which is nonpositive for , the same estimate as for the PDE once the boundary condition is used. The choice is the usual one. With the estimate bounds by the data.
Two standard diagonal-norm operators, with the grid spacing:
- (2,1): , the trapezoidal rule. is the central difference inside and one-sided and at the ends.
- (4,2): , the fourth-order central difference inside, and four special rows at each end, which are exact for quadratics only.
The first number is the interior order and the second the boundary order. For a hyperbolic problem the global order is the boundary order plus one, because the less accurate rows touch only a fixed number of nodes (see Svärd and Nordström 2014 for the theory; measured below).
Classic examples
- Advection equation: the model problem below, with one SAT term at the inflow boundary.
- Wave equation: in first-order form, two SAT terms per boundary give an energy estimate (exercise 2).
- Spectral element method: collocation on Gauss-Lobatto nodes is an SBP operator with the Lobatto weights.
- Discontinuous Galerkin method: with Lobatto nodes, the numerical fluxes act as SAT terms that couple the elements.
- Entropy stable schemes: SBP operators with two-point entropy conservative fluxes give entropy stability for nonlinear laws.
The (2,1) operator by hand. With and : and
so . For , , and : , the SAT term changes the first entry by , so . The energy rate is , and the formula gives .
Gauss-Lobatto collocation. On the three Lobatto nodes the Lagrange differentiation matrix and the Lobatto weights are
Then has rows , , , and . This holds for any number of Lobatto nodes, because the Lobatto rule integrates exactly for polynomials of degree . So the DG spectral element method with Lobatto nodes is an SBP method, and its numerical fluxes play the role of SAT terms.
Refinement study (measurement). on , , inflow , , classical RK4 with , error in the norm at :
| (2,1) | rate | (4,2) | rate | |
|---|---|---|---|---|
| 20 | 3.405e-2 | 4.767e-3 | ||
| 40 | 8.423e-3 | 2.02 | 5.709e-4 | 3.06 |
| 80 | 2.100e-3 | 2.00 | 7.006e-5 | 3.03 |
| 160 | 5.247e-4 | 2.00 | 8.687e-6 | 3.01 |
The (4,2) operator is fourth order inside but its global order is 3, one more than its boundary order.
Variations
- Dense and block norms. A full or block-diagonal allows higher boundary accuracy (up to the interior order), but the energy estimate then fails for variable coefficients and curvilinear grids unless extra care is taken.
- Second-derivative SBP operators with symmetric positive semidefinite, for diffusion and wave equations in second-order form.
- Upwind SBP operators, pairs and with , which add dissipation at high wavenumbers.
- Generalized SBP operators on nodes that do not include the boundary, such as Gauss nodes, with built from extrapolation vectors.
- Multidimensional SBP operators on triangles and tetrahedra, used in entropy stable DG methods.
- Interface SAT for multiblock grids and for coupling to other methods; the Nitsche method is the finite element relative of weak boundary conditions.
Pitfalls
- Strong boundary conditions. Overwriting with after each stage breaks the energy estimate and can make high-order schemes unstable. Use the SAT term.
- Penalty too weak. With the estimate fails, and the energy can grow; for example with the energy rate of on the (2,1) grid is positive.
- Penalty too strong. A very large is stable but makes the system stiff and shrinks the explicit time step.
- Expecting interior order globally. The low-order boundary rows limit the global order, so a "fourth-order" diagonal-norm operator gives third order for hyperbolic problems.
- Wrong norm in error measures. Report errors in the norm or the maximum norm, and note that the boundary weights differ from .
- Nonlinear problems. SBP alone does not give stability for nonlinear equations. It needs split forms or entropy conservative fluxes, because the product rule does not hold for .
Code
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/summation-by-parts-operators/. The authors are listed in prov/SK4AFB.jsonl.
"""Diagonal-norm summation-by-parts (SBP) first-derivative operators and SAT boundary terms.
An SBP operator on the n + 1 nodes x_i = i h of [0, L] is D = H^{-1} Q with H diagonal and
positive and Q + Q^T = B = diag(-1, 0, ..., 0, 1). Two operators are built here, with exact
rational entries when h is a Fraction:
sbp21: second order inside, first order at the boundary (H = h diag(1/2, 1, ..., 1, 1/2));
sbp42: fourth order inside, second order at the boundary (H = h diag(17/48, 59/48, 43/48,
49/48, 1, ...)), the classical diagonal-norm operator with these weights.
SAT: for u_t + a u_x = 0 with a > 0 and inflow data g at x = 0, the semi-discrete scheme
du/dt = -a D u - tau a H^{-1} e_0 (u_0 - g) is energy stable for tau >= 1/2.
Precondition: n >= 2 (sbp21) or n >= 8 (sbp42), h > 0. Cost: building D is Theta(n^2)
in this dense form (it has Theta(n) nonzeros); one product D u costs Theta(n) with the
sparse rows used by apply().
"""
from fractions import Fraction as Fr
from typing import List, Tuple
Matrix = List[List]
_D42 = [
[Fr(-24, 17), Fr(59, 34), Fr(-4, 17), Fr(-3, 34), 0, 0],
[Fr(-1, 2), 0, Fr(1, 2), 0, 0, 0],
[Fr(4, 43), Fr(-59, 86), 0, Fr(59, 86), Fr(-4, 43), 0],
[Fr(3, 98), 0, Fr(-59, 98), 0, Fr(32, 49), Fr(-4, 49)],
]
_H42 = [Fr(17, 48), Fr(59, 48), Fr(43, 48), Fr(49, 48)]
def sbp21(n: int, h) -> Tuple[List, Matrix]:
"""Norm weights H (a list) and dense D for the (2,1) operator on n + 1 nodes."""
if n < 2:
raise ValueError("need n >= 2")
H = [h / 2] + [h] * (n - 1) + [h / 2] # @line L1
D = [[0 * h] * (n + 1) for _ in range(n + 1)]
D[0][0], D[0][1] = -1 / h, 1 / h
D[n][n - 1], D[n][n] = -1 / h, 1 / h
for i in range(1, n):
D[i][i - 1], D[i][i + 1] = -1 / (2 * h), 1 / (2 * h) # @line L2
return H, D
def sbp42(n: int, h) -> Tuple[List, Matrix]:
"""Norm weights H and dense D for the diagonal-norm (4,2) operator on n + 1 nodes."""
if n < 8:
raise ValueError("need n >= 8")
H = [w * h for w in _H42] + [h] * (n - 7) + [w * h for w in reversed(_H42)]
D = [[0 * h] * (n + 1) for _ in range(n + 1)]
for i in range(4):
for j in range(6):
D[i][j] = _D42[i][j] / h
D[n - i][n - j] = -_D42[i][j] / h # mirror: D[n-i][n-j] = -D[i][j]
for i in range(4, n - 3):
for off, c in ((-2, Fr(1, 12)), (-1, Fr(-2, 3)), (1, Fr(2, 3)), (2, Fr(-1, 12))):
D[i][i + off] = c / h
return H, D
def q_matrix(H: List, D: Matrix) -> Matrix:
"""Q = H D."""
return [[H[i] * d for d in D[i]] for i in range(len(H))]
def apply(D: Matrix, u: List) -> List:
"""D u using only the nonzero entries of each row."""
return [sum(d * x for d, x in zip(row, u) if d != 0) for row in D]
def sat_advection_rhs(H: List, D: Matrix, u: List, a, g, tau=1) -> List:
"""du/dt = -a D u - tau a H^{-1} e_0 (u_0 - g) for u_t + a u_x = 0, a > 0."""
r = [-a * x for x in apply(D, u)] # @line L3
r[0] -= tau * a * (u[0] - g) / H[0] # @line L4
return r
def energy_rate(H: List, D: Matrix, u: List, a, g, tau=1):
"""d/dt (u^T H u) for the SAT scheme, computed from the right side."""
r = sat_advection_rhs(H, D, u, a, g, tau)
return 2 * sum(w * x * y for w, x, y in zip(H, u, r)) # @line L5
def solve_advection(op, n: int, a: float, T: float, cfl: float, u0, g) -> List[float]:
"""Classical RK4 for u_t + a u_x = 0 on [0, 1] with SAT inflow g(t) at x = 0."""
h = 1.0 / n
H, D = op(n, h)
H, D = [float(w) for w in H], [[float(d) for d in row] for row in D]
u = [u0(i * h) for i in range(n + 1)]
steps = max(1, int(round(T / (cfl * h / a))))
dt, t = T / steps, 0.0
f = lambda t, v: sat_advection_rhs(H, D, v, a, g(t))
for _ in range(steps):
k1 = f(t, u)
k2 = f(t + dt / 2, [x + dt / 2 * y for x, y in zip(u, k1)])
k3 = f(t + dt / 2, [x + dt / 2 * y for x, y in zip(u, k2)])
k4 = f(t + dt, [x + dt * y for x, y in zip(u, k3)])
u = [x + dt / 6 * (p + 2 * q + 2 * r + s) for x, p, q, r, s in zip(u, k1, k2, k3, k4)]
t += dt
return u
test_summation_by_parts_operators.py 85 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/summation-by-parts-operators/. The authors are listed in prov/SK4AFB.jsonl.
import math
import random
from fractions import Fraction as Fr
import pytest
from summation_by_parts_operators import (
apply, energy_rate, q_matrix, sat_advection_rhs, sbp21, sbp42, solve_advection,
)
@pytest.mark.parametrize("op,n", [(sbp21, 2), (sbp21, 7), (sbp42, 8), (sbp42, 15)])
def test_sbp_property_holds_exactly(op, n):
H, D = op(n, Fr(1, n))
Q = q_matrix(H, D)
for i in range(n + 1):
for j in range(n + 1):
b = -1 if i == j == 0 else 1 if i == j == n else 0
assert Q[i][j] + Q[j][i] == b
assert all(w > 0 for w in H)
assert sum(H) == 1 # H integrates constants exactly
@pytest.mark.parametrize("op,n,p_in,p_bd", [(sbp21, 9, 2, 1), (sbp42, 14, 4, 2)])
def test_accuracy_inside_and_at_the_boundary(op, n, p_in, p_bd):
H, D = op(n, Fr(1, n))
x = [Fr(i, n) for i in range(n + 1)]
nb = 1 if op is sbp21 else 4
for p in range(p_in + 1):
Du = apply(D, [xi ** p for xi in x])
for i in range(n + 1):
exact = p * x[i] ** (p - 1) if p else 0
if i < nb or i > n - nb:
assert (Du[i] == exact) == (p <= p_bd), (p, i)
else:
assert Du[i] == exact
def test_hand_example():
H, D = sbp21(2, Fr(1, 2))
assert H == [Fr(1, 4), Fr(1, 2), Fr(1, 4)]
u = [Fr(1), Fr(2), Fr(0)]
assert sat_advection_rhs(H, D, u, 1, 0) == [-6, 1, 4]
assert energy_rate(H, D, u, 1, 0) == -1
@pytest.mark.parametrize("op,n", [(sbp21, 6), (sbp42, 11)])
def test_energy_identity_with_sat_is_exact(op, n):
rng = random.Random(n)
h = Fr(1, n)
H, D = op(n, h)
for tau in (Fr(1, 2), Fr(1), Fr(3)):
for _ in range(5):
u = [Fr(rng.randint(-9, 9), rng.randint(1, 5)) for _ in range(n + 1)]
a = Fr(rng.randint(1, 4))
rate = energy_rate(H, D, u, a, 0, tau)
assert rate == -a * u[-1] ** 2 - a * (2 * tau - 1) * u[0] ** 2
assert rate <= 0
def test_too_weak_penalty_can_create_energy():
H, D = sbp21(4, Fr(1, 4))
u = [Fr(1), 0, 0, 0, 0]
assert energy_rate(H, D, u, 1, 0, Fr(1, 4)) > 0
@pytest.mark.parametrize("op,p_min", [(sbp21, 1.9), (sbp42, 2.85)])
def test_global_order_is_boundary_order_plus_one(op, p_min):
errs = []
for n in (20, 40, 80):
h = 1.0 / n
u = solve_advection(op, n, 1.0, 0.5, 0.5, lambda x: math.sin(2 * math.pi * x),
lambda t: math.sin(-2 * math.pi * t))
H, _ = op(n, h)
errs.append(math.sqrt(sum(float(w) * (x - math.sin(2 * math.pi * (i * h - 0.5))) ** 2
for i, (w, x) in enumerate(zip(H, u)))))
assert math.log2(errs[1] / errs[2]) > p_min, errs
def test_rejects_small_grids():
with pytest.raises(ValueError):
sbp42(5, 0.1)
Exercises
- Show that the (2,1) operator is the only SBP operator with that is the central difference inside and has a two-point stencil at each boundary.
- For the wave equation in first-order form , write the SBP-SAT scheme with the boundary condition at both ends and choose the penalty so that does not grow.
- Verify for the (4,2) operator using its first four rows and the symmetry .
References
- H.-O. Kreiss and G. Scherer, Finite element and finite difference methods for hyperbolic partial differential equations, in C. de Boor (ed.), Mathematical Aspects of Finite Elements in Partial Differential Equations, Academic Press, 1974, 195-212, the summation-by-parts property and the energy estimate for difference operators
- Magnus Svärd and Jan Nordström, Review of summation-by-parts schemes for initial-boundary-value problems, Journal of Computational Physics 268 (2014) 17-38, the definitions, the SAT boundary treatment, the energy method and the accuracy of SBP-SAT schemes
- David C. Del Rey Fernández, Jason E. Hicken and David W. Zingg, Review of summation-by-parts operators with simultaneous approximation terms for the numerical solution of partial differential equations, Computers and Fluids 95 (2014) 171-196, the general definition, diagonal and dense norms, generalized SBP operators and their link to DG and spectral element methods
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W3 standard |
|
Tag SK4AFB Edit this page History Report an error Markdown