Algorithmadvanced
Symmetric interior penalty Galerkin method
Also called SIPG, interior penalty discontinuous Galerkin.
A discontinuous Galerkin method for elliptic problems with symmetric consistency terms and a penalty on jumps that must exceed a known bound.
- Solves
- Poisson equation
- Time
- Θ(m^3 k^3) worst
- Space
- Θ(m^2 k^2) extra
- Where
- k = the polynomial degree; m = the number of cells
- Model
- Real RAM
- Properties
- consistentdeterministiclocally conservativepositive definite above penalty boundsymmetric matrix
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Douglas N. Arnold, Mary F. Wheeler, 1982
The symmetric interior penalty Galerkin method (SIPG) solves elliptic problems such as with piecewise polynomials that may jump across the faces of the mesh. It starts from the Galerkin method on each cell and adds three face terms: a consistency term with the average flux, a symmetric copy of it, and a penalty on the jumps. The result is a symmetric bilinear form that the exact solution satisfies, and it is positive definite when the penalty parameter exceeds a bound that depends on the polynomial degree and the mesh. Boundary values enter weakly, as in Nitsche's method, and the method has the optimal orders in and in the broken energy norm.
In plain words
Picture a curve built from separate pieces, one per interval, where the pieces do not have to meet at their ends. Each piece is a simple polynomial. The method asks every piece to obey the equation in its own interval, and at every meeting point it adds two kinds of terms. The first kind lets the slopes on the two sides talk to each other, so that the pieces act as one curve for a correct answer. The second kind is a spring that pulls the two ends together, and its strength is the penalty. If the spring is too weak, the system can have no single answer. If it is strong enough, the problem is well behaved, and the gaps that remain at the meeting points shrink as the pieces get shorter.
The problem
Input. A domain with a mesh , a source , Dirichlet data , a degree and a penalty parameter . The reference code takes , , , , and cells of width .
Output. in the broken space with for all , where
On an interior face is the difference of the two traces and the mean; on a boundary face is the trace and the one-sided value. In 1D with the orientation of the code, inside, at and at .
The algorithm
SIPG(f, m, k, sigma, g0, g1) ▷ -u'' = f on (0, 1), degree k, m cells, h = 1/m- 1
for each cell K_j do ▷ local basis phi_r = xi^r, xi = (x - x_j)/h - 2
A[(j, r), (j, s)] += (phi_s', phi_r')_K = r s / (h (r + s - 1)) for r, s >= 1 - 3
b[(j, r)] += (f, phi_r)_K by quadrature - 4
for each node x_e, e = 0 to m do ▷ sides: (cell, end, weight of the mean, sign of the jump) - 5
for each pair of sides (trial, test): A[test, trial] += -{phi_s'}[phi_r] - {phi_r'}[phi_s] + (sigma/h)[phi_s][phi_r] - 6
if e = 0 or e = m then b[test] += -{phi_r'} [g] + (sigma/h) [g][phi_r] ▷ [g] = -g0 at 0, g1 at 1 - 7
c <- SOLVE(A, b) ▷ symmetric positive definite if sigma is above the bound - 8
return the coefficients c, k + 1 per cell
Lines L1 to L3 are the usual cell assembly, with no coupling between cells. Lines L4 and L5 couple the two cells that meet at a node: a node has two sides inside the domain and one side on the boundary, and the products of the mean and jump functionals of the sides give a block of size for each pair. Line L6 puts the boundary data into the load, which is how the method imposes without fixing any unknown. A penalty of is always enough in this 1D setting, and the code takes by default.
Example
Take with , so , and , , , . The unknowns are with on cell . Each step adds the following to the matrix and the load:
| step | what it adds |
|---|---|
| L2, cell 0 and cell 1 | at and at |
| L3 | , since and |
| L5, node | one side (cell 0, left end); the penalty gives at , and the flux terms give at and its mirror |
| L5, node | two sides with weights ; penalty block and flux blocks between cells 0 and 1 |
| L5, node | one side (cell 1, right end), the mirror image of node |
| L6 | nothing, because |
The assembled system is
and line L7 gives on and on . The two pieces meet at , which is exact, but the boundary values are in place of . For this mesh exactly, so gives and gives . A larger penalty pulls the boundary values toward the data, and the error still goes to zero as for any fixed above the bound.
Convergence (measurement). For the reference code gives, at :
| errors | order | broken errors | order | |
|---|---|---|---|---|
| 1 | , , , | 1.99 | , , , | 1.00 |
| 2 | , , , | 3.03 | , , , | 2.03 |
| 3 | , , , | 4.00 | , , , | 3.00 |
The orders shown are those of the last refinement, and they match and .
Correctness
The full proof is in the correctness proof. It first shows that lines L1 to L6 compute the matrix of and the vector of : at each node the mean and the jump are sums over the sides with the weights and signs of line L4, and line L5 expands their products. Integration by parts on each cell then shows consistency: for , the cell terms give plus , which the first face term cancels, and the other terms reduce to the boundary data of . The form is symmetric by construction. With the trace inverse inequality for polynomials of degree , which follows from the Legendre basis, the face term is bounded by the cell terms, and for with () or () the form is bounded below by a positive multiple of . So the matrix is symmetric positive definite and the solution is unique. Polynomials of degree are reproduced exactly.
Proof: SIPG assembles a symmetric consistent form that is positive definite above the penalty boundfull
Setting. The problem is on with and . The mesh has the nodes , , , and the cells . The space holds the functions whose restriction to each cell is a polynomial of degree at most , with no continuity between cells. For the jump and the average at a node are
Let , and for . For the SIPG forms are
The basis of is on with and elsewhere, for .
Claim 1 (assembly). The matrix and the vector built by lines L1 to L6 are and , when the quadrature of line L3 is exact for .
Proof. The volume part: is zero unless , and on it equals , so its integral is for and otherwise. Line L2 adds exactly these values. Line L3 adds , which is since vanishes off .
The node part: at node the code lists the sides of the node as tuples (cell, end, weight , sign ). An interior node has the left cell at its right end with and the right cell at its left end with ; node has only the left cell with ; node has only the right cell with . Comparing with the definitions, for every
where is the polynomial of that cell. A basis function is nonzero on one cell only, so it contributes to these sums only through the side of its own cell. Line L5 loops over all pairs (trial side, test side) and adds , with the values and derivatives from local_traces. Summing over the pairs gives the products , because each product of two sums is the sum over all pairs. The values in local_traces are those of : at the left end the value is for and the derivative is for , all others ; at the right end the value is and the derivative is . Line L6 adds at and , using the single side there. Summing over all nodes gives and .
Claim 2 (consistency). If is the exact solution, then for all .
Proof. In one dimension means and are continuous, so and at interior nodes, and at the two boundary nodes. Integration by parts on each cell gives . Summing over and collecting the terms at each node,
because at an interior node the two terms give , at the term is and at it is . So the first two sums of add up to . The remaining terms only involve , which is inside and at the boundary, so they equal . Together this is .
Claim 3 (symmetry). , so the matrix of Claim 1 is symmetric.
Proof. Each of the three sums is unchanged when and are exchanged: the first and the third are symmetric products, and the middle sum contains both and .
Lemma 4 (trace inverse inequality). For a polynomial of degree at most on an interval of length and an end point of , .
Proof. Map to by an affine map that sends to ; then and . The Legendre polynomials satisfy and , so for form an orthonormal basis of the polynomials of degree at most . Write . By the Cauchy-Schwarz inequality, . Then .
Claim 5 (positive definiteness). Let if and if . If , then for all
and only for . So the matrix is symmetric positive definite.
Proof. . For , . At an interior node , and at a boundary node is the square of the one-sided value. So is at most a sum over the cell ends of , with at an interior node and at a boundary node. The two weights of one cell add up to at most : to for a cell with two interior ends, to for a cell with one boundary end, and to only when . By Lemma 4 with , . Hence and
Take . Then and , both positive, which gives the bound. If , then on every cell and every jump is . So is one constant on , and makes it .
Conclusion. By Claim 1 the code builds the matrix of and the vector of in the basis . By Claims 3 and 5 the matrix is symmetric positive definite when , in particular for the default of the code, so it is nonsingular, Gaussian elimination in line L7 finds the unique solution, and line L8 returns its coefficients cell by cell. By Claim 2 the exact solution satisfies the same equations, so the error satisfies for all . In particular, if is a polynomial of degree at most , then solves the discrete problem, and by uniqueness .
Complexity
There are unknowns. Line L2 does work per cell and line L3 does five evaluations of per basis function, so the cell loop costs . Each node has at most two sides and four side pairs, each a block of entries, so lines L4 to L6 cost . The matrix is block tridiagonal with blocks of size . The reference code stores it densely, which takes memory, and solves it with Gaussian elimination in time, the bound in the front matter. A block tridiagonal solver costs time and memory. In several dimensions, the matrix is sparse with one dense block per cell and one per pair of neighbors, and conjugate gradients with a good preconditioner applies because the matrix is symmetric positive definite.
Properties
- Consistency and adjoint consistency (theorem). The exact solution satisfies the discrete equations, and because the form is symmetric, the solution of the dual problem does too. The second fact gives the order by the Aubin-Nitsche argument.
- Coercivity above a bound (theorem). In 1D, for and for are sufficient. For these bounds are sharp: the reference code finds the thresholds for and for . For the measured thresholds are smaller, for example about for and for at , against the sufficient bounds and .
- Optimal orders (theorem). For , the broken energy error is and the error is , with constants that depend on and the shape regularity.
- Local conservation. Testing with on one cell gives a flux balance on that cell with the numerical flux .
- Weak boundary values. The discrete solution does not take the boundary values exactly, as the example shows.
- More unknowns than continuous elements. For degree there are unknowns in place of , and the gap is larger in several dimensions.
Variants and improvements
- NIPG and IIPG. The nonsymmetric interior penalty method changes the sign of the term , so the two flux terms cancel in and the form is coercive for every . It loses adjoint consistency, so the proved order is only , and computations show the lost order for some degrees. The incomplete method drops that term. The alias "interior penalty discontinuous Galerkin" often refers to the whole family, not only to SIPG.
- Explicit penalty bounds. Shahbazi gave explicit values of for simplices based on the sharp trace inverse inequality, and many codes use them in place of a guess.
- Weighted averages. For a coefficient that jumps across faces, averages weighted by and a penalty with the harmonic mean of keep the method robust.
- Local discontinuous Galerkin and Bassi-Rebay. Use a lifting of the jumps in place of the penalty, which gives a stability parameter that does not need to be large.
- Hybridizable discontinuous Galerkin. Introduces a trace unknown on faces, which gives a smaller global system after local elimination.
- Time-dependent and convection problems. The SIPG form of the diffusion combines with upwind fluxes for the convection in the discontinuous Galerkin method.
When to use it
Use SIPG when a discontinuous Galerkin code must also handle diffusion terms, when the mesh has hanging nodes or the degree changes from cell to cell as in hp methods, or when local conservation matters. It keeps a symmetric positive definite matrix, which allows conjugate gradients and multigrid. Continuous elements have fewer unknowns for the same degree and need no penalty, so they are the cheaper choice for a smooth problem on a conforming mesh. If the choice of is a problem, NIPG, LDG or HDG avoid a large penalty.
Pitfalls
- A penalty below the bound. With too small in line L5, the matrix is indefinite: for and , makes the Cholesky factorization fail, and the solution can be wrong without any warning in a general solver. Use above the bound for the degree, which grows like .
- Wrong scaling of the penalty. The penalty is , not . A code that uses alone in line L5 loses coercivity on fine meshes and the error stops decreasing.
- Forgetting the boundary terms of the load. Line L6 must add both and . With only the penalty part, the method is not consistent and the order drops.
- Inconsistent jump signs. The mean and jump in line L5 must use the same orientation on both sides of a face. A sign error in one side makes the matrix nonsymmetric and the method inconsistent.
- Too large a penalty. A huge is safe for coercivity but increases the condition number in proportion to , which slows iterative solvers.
Implementations
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
# Shared helper of the scientific-computing pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Small dense linear algebra and error norms for the scientific-computing pages.
A matrix is a list of rows and a vector is a list. Entries may be int,
float or fractions.Fraction. The routines that do not take a square root
(solve, inv, det and the arithmetic) keep Fraction entries exact.
cholesky, cholesky_solve and norm2 take square roots and return floats.
API (fixed; other pages copy this file byte for byte):
zeros(m, n=None) m by n zero matrix (n = m if not given)
eye(n) n by n identity
add(A, B), sub(A, B) entrywise sum and difference (vectors or matrices)
scale(c, A) c times A (vector or matrix)
matmul(A, B) matrix product
matvec(A, x) matrix times vector
transpose(A) transpose
dot(x, y) inner product of two vectors
norm2(x) Euclidean norm of a vector, as a float
outer(x, y) outer product x y^T
solve(A, b) Gaussian elimination with partial pivoting;
b is a vector or a matrix of right sides
inv(A) inverse of A
det(A) determinant of A
cholesky(A) lower triangular L with A = L L^T (floats)
cholesky_solve(L, b) solve L L^T x = b for a vector b
err_l1(e, dx=1) sum |e_j| dx
err_l2(e, dx=1) sqrt(sum e_j^2 dx), as a float
err_linf(e, dx=1) max |e_j| (dx is not used)
observed_order(errors) [log2(E_i / E_(i+1)) for successive errors]
"""
import math
def zeros(m, n=None):
"""Return an m by n matrix of zeros (n = m if n is None)."""
if n is None:
n = m
return [[0] * n for _ in range(m)]
def eye(n):
"""Return the n by n identity matrix."""
out = zeros(n, n)
for i in range(n):
out[i][i] = 1
return out
def _is_matrix(a):
return len(a) > 0 and isinstance(a[0], list)
def add(a, b):
"""Return a + b for two vectors or two matrices of the same shape."""
if _is_matrix(a):
return [[x + y for x, y in zip(ra, rb)] for ra, rb in zip(a, b)]
return [x + y for x, y in zip(a, b)]
def sub(a, b):
"""Return a - b for two vectors or two matrices of the same shape."""
if _is_matrix(a):
return [[x - y for x, y in zip(ra, rb)] for ra, rb in zip(a, b)]
return [x - y for x, y in zip(a, b)]
def scale(c, a):
"""Return c times a, for a vector or a matrix a."""
if _is_matrix(a):
return [[c * x for x in row] for row in a]
return [c * x for x in a]
def transpose(a):
"""Return the transpose of the matrix a."""
return [list(col) for col in zip(*a)]
def matmul(a, b):
"""Return the matrix product a b."""
bt = transpose(b)
return [[sum(x * y for x, y in zip(row, col)) for col in bt] for row in a]
def matvec(a, x):
"""Return the product of the matrix a and the vector x."""
return [sum(aij * xj for aij, xj in zip(row, x)) for row in a]
def dot(x, y):
"""Return the inner product of the vectors x and y."""
return sum(a * b for a, b in zip(x, y))
def norm2(x):
"""Return the Euclidean norm of the vector x, as a float."""
return math.sqrt(float(dot(x, x)))
def outer(x, y):
"""Return the outer product x y^T as a matrix."""
return [[a * b for b in y] for a in x]
def _eliminate(a, rhs):
"""Reduce a to upper triangular form with partial pivoting.
a is a copy of the square matrix, rhs a list of right side rows (one
row per row of a) that receives the same row operations. Return the
number of row swaps. Raise ValueError if a pivot is zero.
"""
n = len(a)
swaps = 0
for k in range(n):
p = max(range(k, n), key=lambda i: abs(a[i][k]))
if a[p][k] == 0:
raise ValueError("matrix is singular")
if p != k:
a[k], a[p] = a[p], a[k]
rhs[k], rhs[p] = rhs[p], rhs[k]
swaps += 1
for i in range(k + 1, n):
f = a[i][k] / a[k][k]
if f == 0:
continue
for j in range(k, n):
a[i][j] -= f * a[k][j]
for j in range(len(rhs[i])):
rhs[i][j] -= f * rhs[k][j]
return swaps
def solve(a, b):
"""Solve a x = b by Gaussian elimination with partial pivoting.
b is a vector (the result is a vector) or a matrix with one column per
right side (the result is a matrix). Fraction entries stay exact.
Raise ValueError if a is singular.
"""
n = len(a)
work = [list(row) for row in a]
vector = not _is_matrix(b)
rhs = [[v] for v in b] if vector else [list(row) for row in b]
_eliminate(work, rhs)
m = len(rhs[0]) if n else 0
x = [[0] * m for _ in range(n)]
for i in range(n - 1, -1, -1):
for j in range(m):
s = rhs[i][j]
for k in range(i + 1, n):
s -= work[i][k] * x[k][j]
x[i][j] = s / work[i][i]
if vector:
return [row[0] for row in x]
return x
def inv(a):
"""Return the inverse of the square matrix a."""
return solve(a, eye(len(a)))
def det(a):
"""Return the determinant of the square matrix a (0 if singular)."""
work = [list(row) for row in a]
rhs = [[] for _ in a]
try:
swaps = _eliminate(work, rhs)
except ValueError:
return 0
d = -1 if swaps % 2 else 1
for i in range(len(a)):
d *= work[i][i]
return d
def cholesky(a):
"""Return the lower triangular L with a = L L^T, in floats.
Raise ValueError if a is not symmetric positive definite.
"""
n = len(a)
low = [[0.0] * n for _ in range(n)]
for j in range(n):
s = float(a[j][j]) - sum(low[j][k] ** 2 for k in range(j))
if s <= 0.0:
raise ValueError("matrix is not positive definite")
low[j][j] = math.sqrt(s)
for i in range(j + 1, n):
t = float(a[i][j]) - sum(low[i][k] * low[j][k] for k in range(j))
low[i][j] = t / low[j][j]
return low
def cholesky_solve(low, b):
"""Solve L L^T x = b, with L from cholesky, for a vector b."""
n = len(low)
y = [0.0] * n
for i in range(n):
y[i] = (float(b[i]) - sum(low[i][k] * y[k] for k in range(i))) / low[i][i]
x = [0.0] * n
for i in range(n - 1, -1, -1):
x[i] = (y[i] - sum(low[k][i] * x[k] for k in range(i + 1, n))) / low[i][i]
return x
def err_l1(e, dx=1):
"""Return the discrete L1 norm sum |e_j| dx."""
return sum(abs(v) for v in e) * dx
def err_l2(e, dx=1):
"""Return the discrete L2 norm sqrt(sum e_j^2 dx), as a float."""
return math.sqrt(float(sum(v * v for v in e) * dx))
def err_linf(e, dx=1):
"""Return the max norm max |e_j|. dx is accepted for a uniform call and not used."""
return max(abs(v) for v in e)
def observed_order(errors):
"""Return [log2(E_i / E_(i+1))] for a list of errors on meshes h, h/2, h/4, ..."""
return [math.log2(float(errors[i]) / float(errors[i + 1])) for i in range(len(errors) - 1)]
symmetric_interior_penalty_galerkin.py 111 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/symmetric-interior-penalty-galerkin/. The authors are listed in prov/Z6FE5T.jsonl.
"""SIPG for -u'' = f on (0, 1) with u(0) = g0 and u(1) = g1, imposed weakly.
The mesh is uniform with m cells x_j = j h, h = 1/m. On each cell the
discrete solution is a polynomial of degree k, written in the local
monomial basis phi_r(x) = xi^r with xi = (x - x_j) / h, r = 0, ..., k.
The unknown of (cell j, power r) has the global index j (k + 1) + r.
Jumps and averages at a node x_e: [v] = v(x_e-) - v(x_e+) and
{v'} = (v'(x_e-) + v'(x_e+)) / 2 inside; [v] = v(1-), {v'} = v'(1-) at
x = 1 and [v] = -v(0+), {v'} = v'(0+) at x = 0. The bilinear form is
a(u, v) = sum_K (u', v')_K - sum_e ({u'}[v] + {v'}[u]) + sum_e (sigma / h) [u][v].
With Fraction data the matrix and the solution are exact.
"""
from fractions import Fraction
import scimat
BOOLE = [(Fraction(0), Fraction(7, 90)), (Fraction(1, 4), Fraction(32, 90)),
(Fraction(1, 2), Fraction(12, 90)), (Fraction(3, 4), Fraction(32, 90)),
(Fraction(1), Fraction(7, 90))]
def local_traces(k, h, side):
"""Return (values, derivatives) of phi_0..phi_k at the left (side=0) or right (side=1) end."""
if side == 0:
val = [1 if r == 0 else 0 for r in range(k + 1)]
der = [1 / h if r == 1 else 0 for r in range(k + 1)]
else:
val = [1] * (k + 1)
der = [r / h for r in range(k + 1)]
return val, der
def sipg_system(f, m, k, sigma, g0=0, g1=0):
"""Return the SIPG matrix A and load vector b, of size m (k + 1).
Precondition: m >= 1, k >= 1. sigma is the penalty parameter; the
penalty on a node is sigma / h. Cost: Theta(m k^2) entries.
"""
exact_data = isinstance(sigma, Fraction)
h = Fraction(1, m) if exact_data else 1.0 / m
n = k + 1
size = m * n
A = scimat.zeros(size)
b = [0] * size
for j in range(m): # @line L1
off = j * n
for r in range(n):
for s in range(n):
if r >= 1 and s >= 1:
# (phi_s', phi_r')_K = r s / (h (r + s - 1))
A[off + r][off + s] += Fraction(r * s, r + s - 1) / h if exact_data else r * s / (h * (r + s - 1)) # @line L2
for xi, w in BOOLE:
b[off + r] += w * h * f(j * h + xi * h) * xi ** r # @line L3
# node e = 0..m; each side is (cell, end, weight of the average, sign of the jump)
for e in range(m + 1): # @line L4
sides = []
if e > 0:
sides.append((e - 1, 1, Fraction(1, 2) if e < m else 1, 1)) # left cell, its right end
if e < m:
sides.append((e, 0, Fraction(1, 2) if e > 0 else 1, -1)) # right cell, its left end
for (cu, eu, wu, su) in sides:
vu, du = local_traces(k, h, eu)
for (cv, ev, wv, sv) in sides:
vv, dv = local_traces(k, h, ev)
for r in range(n): # test function row
for s in range(n): # trial function column
term = -wu * du[s] * sv * vv[r] # -{u'}[v]
term -= wv * dv[r] * su * vu[s] # -{v'}[u]
term += sigma / h * su * vu[s] * sv * vv[r] # (sigma/h)[u][v]
A[cv * n + r][cu * n + s] += term # @line L5
# weak Dirichlet data: the exact [u] is g1 at x = 1 and -g0 at x = 0
if e == 0 or e == m:
gj = -g0 if e == 0 else g1
cv, ev, wv, sv = sides[0]
vv, dv = local_traces(k, h, ev)
for r in range(n):
b[cv * n + r] += -wv * dv[r] * gj + sigma / h * sv * vv[r] * gj # @line L6
return A, b
def sipg(f, m, k, sigma=None, g0=0, g1=0):
"""Solve the SIPG problem; return the coefficients, one list of k + 1 per cell.
sigma=None takes sigma = 2 k^2 + 1, above the coercivity bound 2 k^2.
Cost: assembly Theta(m k^2); the dense solve here costs Theta((m k)^3),
and a banded solver would cost Theta(m k^3).
"""
if sigma is None:
sigma = 2 * k * k + 1
A, b = sipg_system(f, m, k, sigma, g0, g1)
c = scimat.solve(A, b) # @line L7
n = k + 1
return [c[j * n:(j + 1) * n] for j in range(m)] # @line L8
def evaluate(coef, m, x):
"""Value and derivative of the discrete solution at x (from the right at a node, left at 1)."""
h = 1.0 / m
j = min(int(x * m), m - 1)
xi = (x - j * h) / h
c = coef[j]
val = sum(float(cr) * xi ** r for r, cr in enumerate(c))
der = sum(float(cr) * r * xi ** (r - 1) for r, cr in enumerate(c) if r >= 1) / h
return val, der
test_symmetric_interior_penalty_galerkin.py 126 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/symmetric-interior-penalty-galerkin/. The authors are listed in prov/Z6FE5T.jsonl.
import math
import random
from fractions import Fraction as F
import pytest
import scimat
from symmetric_interior_penalty_galerkin import evaluate, sipg, sipg_system
# 5-point Gauss-Legendre rule on [-1, 1], independent of the code under test
GX = [-0.9061798459386640, -0.5384693101056831, 0.0, 0.5384693101056831, 0.9061798459386640]
GW = [0.2369268850561891, 0.4786286704993665, 0.5688888888888889, 0.4786286704993665, 0.2369268850561891]
def errors(coef, m, u, du):
h = 1.0 / m
e0 = e1 = 0.0
for j in range(m):
c = coef[j]
for xg, wg in zip(GX, GW):
xi = (xg + 1) / 2
x = j * h + xi * h
v = sum(float(cr) * xi ** r for r, cr in enumerate(c))
d = sum(float(cr) * r * xi ** (r - 1) for r, cr in enumerate(c) if r) / h
e0 += wg * h / 2 * (v - u(x)) ** 2
e1 += wg * h / 2 * (d - du(x)) ** 2
return math.sqrt(e0), math.sqrt(e1)
def local_coefficients(p, x0, h):
"""Coefficients of p(x0 + xi h) in powers of xi, for p given by its coefficients in powers of x."""
out = [F(0)] * len(p)
for n, pn in enumerate(p):
# (x0 + xi h)^n = sum_r C(n, r) x0^(n - r) h^r xi^r
for r in range(n + 1):
out[r] += pn * math.comb(n, r) * x0 ** (n - r) * h ** r
return out
def test_page_example_two_cells() -> None:
A, b = sipg_system(lambda x: F(2), 2, 1, F(3))
assert A == [[12, 7, -6, -1], [7, 6, -5, -1], [-6, -5, 12, 5], [-1, -1, 5, 4]]
assert b == [1, F(1, 2), 1, F(1, 2)]
c = sipg(lambda x: F(2), 2, 1, F(3))
assert c == [[F(1, 8), F(1, 8)], [F(1, 4), F(-1, 8)]]
# the boundary value is only imposed weakly: u_h(0+) = 1 / (4 (sigma - 1))
for s in (F(3), F(10), F(100)):
c = sipg(lambda x: F(2), 2, 1, s)
assert c[0][0] == 1 / (4 * (s - 1))
assert sum(c[0]) == F(1, 4) == c[1][0]
def test_matrix_is_symmetric_exactly() -> None:
for m, k in ((1, 1), (3, 2), (4, 3)):
A, _ = sipg_system(lambda x: F(0), m, k, F(2 * k * k + 1))
n = len(A)
assert all(A[i][j] == A[j][i] for i in range(n) for j in range(n))
def test_spd_above_bound_and_not_spd_below() -> None:
for m in (1, 2, 5):
for k in (1, 2, 3):
A, _ = sipg_system(lambda x: 0.0, m, k, 2.0 * k * k + 0.01)
scimat.cholesky(A) # raises if not positive definite
# k = 1: the bounds 2 (one cell) and 3/2 (two or more cells) are sharp
for m, s in ((1, 2.0), (2, 1.5)):
with pytest.raises(ValueError):
scimat.cholesky(sipg_system(lambda x: 0.0, m, 1, s - 0.01)[0])
scimat.cholesky(sipg_system(lambda x: 0.0, m, 1, s + 0.01)[0])
with pytest.raises(ValueError):
scimat.cholesky(sipg_system(lambda x: 0.0, 6, 2, 1.0)[0])
def test_polynomials_of_degree_k_are_reproduced_exactly() -> None:
# u = x^2 with k = 2, Fraction arithmetic: the discrete solution is u itself
m, k = 3, 2
c = sipg(lambda x: F(-2), m, k, F(9), F(0), F(1))
h = F(1, m)
assert c == [local_coefficients([0, 0, 1], j * h, h) for j in range(m)]
def test_random_polynomials_against_closed_form() -> None:
# oracle: the exact solution, a random polynomial of degree <= k
rng = random.Random(11)
for _ in range(500):
k = rng.randint(1, 3)
m = rng.randint(1, 4)
p = [rng.randint(-5, 5) for _ in range(k + 1)]
# f = -p''
f2 = [-(n + 2) * (n + 1) * p[n + 2] for n in range(k - 1)]
def f(x, f2=f2):
return sum(cn * x ** n for n, cn in enumerate(f2))
def u(x, p=p):
return sum(cn * x ** n for n, cn in enumerate(p))
sigma = 2.0 * k * k + rng.uniform(0.5, 10.0)
coef = sipg(f, m, k, sigma, u(0.0), u(1.0))
h = F(1, m)
for j in range(m):
want = local_coefficients([F(v) for v in p], j * h, h)
assert all(abs(float(a) - float(b)) < 1e-8 for a, b in zip(coef[j], want))
def test_convergence_rates() -> None:
u = lambda x: math.sin(math.pi * x)
du = lambda x: math.pi * math.cos(math.pi * x)
f = lambda x: math.pi ** 2 * math.sin(math.pi * x)
for k in (1, 2, 3):
e = [errors(sipg(f, m, k), m, u, du) for m in (8, 16)]
assert abs(math.log2(e[0][0] / e[1][0]) - (k + 1)) < 0.15
assert abs(math.log2(e[0][1] / e[1][1]) - k) < 0.15
def test_evaluate_and_weak_boundary_values() -> None:
f = lambda x: math.pi ** 2 * math.sin(math.pi * x)
coef = sipg(f, 8, 2)
v, d = evaluate(coef, 8, 0.5)
assert abs(v - 1.0) < 1e-3 and abs(d) < 1e-2
# the boundary value is close to 0 but not equal to it
v0, _ = evaluate(coef, 8, 0.0)
assert 0 < abs(v0) < 1e-3
History
Joachim Nitsche imposed Dirichlet data in 1971 with a symmetric boundary term and a penalty, which is SIPG restricted to the boundary. Garth Baker used interior penalties for fourth-order problems in 1977, Jim Douglas and Todd Dupont used them for continuous elements in 1976, and Mary Wheeler combined collocation with interior penalties in 1978. Douglas Arnold analyzed the method with fully discontinuous elements in 1982, and this is the SIPG method used today. Interest returned at the end of the 1990s with the nonsymmetric methods of Oden, Babuška and Baumann and of Rivière, Wheeler and Girault, and in 2002 Arnold, Brezzi, Cockburn and Marini put these methods and LDG into one framework of numerical fluxes.
References
- Douglas N. Arnold, An interior penalty finite element method with discontinuous elements, SIAM Journal on Numerical Analysis 19(4) (1982) 742-760, the symmetric interior penalty method, its coercivity for a large enough penalty and the error estimates
- Mary Fanett Wheeler, An elliptic collocation-finite element method with interior penalties, SIAM Journal on Numerical Analysis 15(1) (1978) 152-161, interior penalty terms on the jumps of the normal derivative
- Douglas N. Arnold, Franco Brezzi, Bernardo Cockburn and L. Donatella Marini, Unified analysis of discontinuous Galerkin methods for elliptic problems, SIAM Journal on Numerical Analysis 39(5) (2002) 1749-1779, the flux formulation of SIPG, NIPG, IIPG, LDG and related methods, with their consistency, adjoint consistency and stability
- Béatrice Rivière, Discontinuous Galerkin Methods for Solving Elliptic and Parabolic Equations, SIAM Frontiers in Applied Mathematics 35, 2008, Chapter 1 (the one-dimensional problem with SIPG, NIPG and IIPG, the penalty bound and a code) and Chapter 2 (higher dimensions)
Where this leads
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 | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag Z6FE5T Edit this page History Report an error Markdown