Algorithmadvanced
Reduced basis method
For PDEs with parameters, builds a basis from solutions at a few chosen parameters, solves new cases by Galerkin projection, and certifies each answer with an a posteriori error bound.
- Time
- O(Q^2 r^2 n) offlineO(Q r^2 + r^3 + Q^2 r^2) online
- Space
- O(Q r n + Q^2 r^2) extra
- Where
- Q = the number of affine terms; n = the number of finite element unknowns, with banded matrices in 1D; r = the size of the reduced basis
- Model
- Real RAM
- Properties
- certifieddeterministicnot exactnot iterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Christophe Prud'homme, Dimitrios V. Rovas, Karen Veroy, Yvon Maday, Anthony T. Patera, Gabriel Turinici, 2002
The reduced basis method solves a parametrized PDE fast and many times, for example for a sweep of a material coefficient or for the samples of a Monte Carlo study. It solves the full finite element problem, the truth, at a few parameter values . The span of these solutions is the reduced space. For a new it finds the Galerkin approximation in this space, which is a linear system of size . It also returns a bound that is at least the true error, computed from the residual and a lower bound of the coercivity constant. If the matrix depends on in an affine way, all the work that involves the unknowns of the mesh is done once, in the offline stage. Each online query then costs a number of operations that does not depend on . The POD-Galerkin reduced-order model uses the same projection, but takes its basis from time snapshots of one run and has no certified bound. The weak greedy algorithm chooses the parameters with the bound , and the Kolmogorov width of the solution set says how small can be. The empirical interpolation method makes a non-affine problem affine.
In plain words
You must solve the same PDE for a thousand values of a parameter. Each solve on a fine mesh takes time. But the solutions for different parameters look alike, so a few of them, added with the right weights, describe the rest well. The reduced basis method solves the fine problem for a few parameters, keeps those solutions as building blocks, and finds the best weights for each new parameter from a tiny system.
The method also tells you how much to trust each answer. It puts the cheap answer back into the fine equation and measures how much is left over, the residual. A small residual means a small error, and a stability constant turns one into a bound on the other. With some care, both the weights and the bound come out of small precomputed tables, so a query does not touch the fine mesh.
The problem
Let be a finite element space of dimension with an inner product , where is now also its symmetric positive definite matrix. For each parameter in a set , a bilinear form and a load define the truth solution by
The form is coercive and continuous in the norm, with constants and , so by the Lax-Milgram theorem exists and is unique. The form is affine: , with matrices that do not depend on . A lower bound with is known and cheap to evaluate.
Given sample parameters with linearly independent truth solutions and a query , the output is the reduced solution with for all , and a bound .
The model problem of the example and the tests is on with and , in P1 finite elements on a uniform mesh with interior nodes and . Then with the stiffness matrix and the mass matrix , so , and . The inner product is with . Since , the min-theta bound is a valid lower bound, and in the same way . The exact solution is .
The algorithm
REDUCED-BASIS(A_1..A_Q, F, X, μ_1..μ_r; query μ)▷ offline stage, once- 1
solve A(μ_j) u_j = F for j = 1..r ▷ r truth solves - 2
Z ← [z_1 ... z_r], an X-orthonormal basis of span{u_1..u_r} by Gram-Schmidt - 3
A_q^r ← Z^T A_q Z for q = 1..Q; F_r ← Z^T F - 4
e_F ← X^(-1) F; e_qj ← X^(-1) A_q z_j; store G_FF = F^T e_F, g_qj = F^T e_qj, G_qp,ij = (A_q z_i)^T e_pj ▷ online stage, for each query μ- 5
solve (Σ_q θ_q(μ) A_q^r) c = F_r - 6
ρ² ← G_FF - 2 Σ_q θ_q Σ_j c_j g_qj + Σ_q Σ_p θ_q θ_p Σ_i Σ_j c_i c_j G_qp,ij - 7
Δ ← sqrt(max(ρ², 0)) / α_LB(μ) - 8
return u_r = Z c, Δ, the output s_r = F_r^T c and its bound Δ_s = ρ² / α_LB(μ)
Line L1 is the only place where the truth problem is solved, times. Line L2 orthonormalizes the snapshots in the inner product; the implementation runs Gram-Schmidt twice per vector and stops with an error if the snapshots are dependent. Line L3 projects each affine term once. Line L4 computes the Riesz representers of and of each , that is the solutions of and , and stores their inner products. These solves with and the tables are the price of the bound. Line L5 assembles the by matrix from small matrices. Line L6 expands for the residual vector , by the affine sum, so it uses only the tables. Line L7 divides by the stability lower bound. The compliance output in line L8 has its own bound. Lines L5 to L8 cost a number of operations that depends on and , not on , except for the lift , which a user who wants only can skip.
Example
The mesh has interior nodes (), the samples are , so , and . At the truth value at is ; the exact value is , so the finite element error is . The reduced basis method approximates the truth, not the exact solution. The table gives the online results (a measurement, from the test file).
| 2 | 0.2 | 5 | 4.90 | 0.0694652 | |||
| 3 | 0.3 | 3.33 | 3.28 | 0.0641482 | |||
| 10 | 1 | 1 | 0.0418882 | ||||
| 30 | 1 | 3 | 1.05 | 0.0212615 | |||
| 60 | 1 | 6 | 1.11 | 0.0123660 |
In each row the bound is above the error, and the effectivity is below , as the correctness section proves. You can check the second and third columns by hand: at , and . The effectivity grows as falls below , because the min-theta bound is then pessimistic: for the smoothest mode , the ratio is close to , which is 0.60 at , not 0.2. At the sample , the reduced solution is the truth up to rounding, but is , not : see the pitfalls. The output error is positive and about the square of the error, as the compliance lemma says. At , the error is with the two samples , with , and with .
Correctness
The proof file shows four facts, for a symmetric or non-symmetric coercive form. First, the reduced problem of line L5 has a unique solution, because is coercive on the subspace . Second, with and the Riesz representer of the residual (),
So the bound is reliable, and it is never worse than the error by more than a factor that does not depend on or . Third, the quantity of line L6 is exactly . Fourth, for a symmetric form and the compliance output, . The proof also shows that at each sample. For a symmetric form, is the best approximation of in in the energy norm of , by Cea's lemma.
Proof: The reduced basis solution exists, its error bound is reliable and effective, and the offline-online residual is exactfull
We assume exact arithmetic. has the inner product with a symmetric positive definite matrix , and the dual norm of a linear functional is . For a parameter , with , and . We assume
- coercivity: for all , with ;
- continuity: for all ;
- a lower bound .
Lemma 1 (the Riesz representer). For a vector , let . Then and .
Proof. by the Cauchy-Schwarz inequality, with equality for . And .
Lemma 2 (existence). Let be the by matrix of line L2, with -orthonormal columns. Then is invertible, so line L5 has a unique solution , and satisfies for all in the range of .
Proof. The sum identity holds because . For , , so . The equation says for each basis vector , and by linearity for all .
Lines L1 and L2 make the span of the snapshots: Gram-Schmidt in the inner product keeps the span of the first vectors at each step , and the snapshots are independent.
Theorem 1 (reliability and effectivity). Let , , and . Then
Proof. Since , we have , so for all . With : . If the first claim is clear; otherwise divide by to get . With : , so . Divide by .
Lemma 3 (the offline-online residual). The number of line L6 equals .
Proof. . By Lemma 1, . Expand the product. The term is . Each cross term is , and it appears twice, with a minus sign, because is symmetric. Each quadratic term is . These are the three sums of line L6, with the tables of line L4.
So line L7 returns the of Theorem 1.
Lemma 4 (reproduction). If for a sample , then and .
Proof. is in . Let . By Lemma 2 and the truth equation, for all , in particular for , and coercivity gives . Then and .
Theorem 2 (the compliance output). If is symmetric, and , then .
Proof. by symmetry and . Galerkin orthogonality (Lemma 2) gives , because . So . From the proof of Theorem 1, .
The model problem. For with symmetric positive semidefinite and whose sum is positive definite, and with : term by term, so . With the seminorms and and the Cauchy-Schwarz inequality, , so .
Complexity
In the real RAM model, the offline stage costs truth solves in line L1 and solves with in line L4. For a 1D problem with tridiagonal matrices each solve costs ; the implementation uses dense Gaussian elimination for simplicity. Lines L2 to L4 also cost for Gram-Schmidt and for the tables, with sparse and . The online stage costs to assemble the reduced matrix, to solve it and for line L6, with no dependence on . The tables need memory and the representers during the offline stage. The method pays off when the number of queries times the cost of a truth solve is much larger than the offline cost.
Properties
- Certified. Each answer comes with a bound that is proved to hold, if is a true lower bound and the arithmetic is exact.
- Effective. The bound overestimates by at most , independent of and .
- Interpolatory. At the sample parameters, the reduced solution equals the truth.
- Online cost independent of . This needs the affine form. Without it, line L5 must assemble on the mesh at each query.
- Approximates the truth. The bound is on the distance to the finite element solution, not to the solution of the PDE. The discretization error is separate.
- Intrusive. Lines L3 and L4 need the matrices of the finite element code.
Variants and improvements
- Greedy sampling. The weak greedy algorithm chooses where is largest over a training set, so the basis is built with truth solves only.
- POD sampling. Take many snapshots and keep their leading POD modes, as in the POD-Galerkin model. This costs more truth solves but needs no error bound.
- Successive constraint method. When no simple formula like min-theta gives , a small linear program per query gives a lower bound from the coercivity constants at a few parameters.
- Non-affine problems. The empirical interpolation method replaces a non-affine coefficient by an affine sum with terms, at the cost of an extra error.
- Time-dependent and non-coercive problems. Parabolic problems use a POD-greedy method in time and parameter. Non-coercive problems such as Helmholtz use the inf-sup constant in place of .
- Primal-dual outputs. For an output other than the compliance, a dual problem gives an output bound that is the product of the primal and dual residuals.
When to use it
Use the reduced basis method when a parametrized elliptic or parabolic PDE must be solved many times, in a real-time or many-query setting such as optimization, control, forward uncertainty propagation or Bayesian inversion, and when the solution set has a small Kolmogorov width, that is when a few solutions describe all of them. Smooth dependence on a few parameters is the good case. Do not use it when the parameter moves a shock or a front, when there are tens of parameters with no structure, or when you need only a few solves. If you cannot change the solver, use a non-intrusive model such as operator inference or a Gaussian process emulator, with no certified bound.
Pitfalls
- A lower bound that is not a lower bound. If line L7 uses an estimate of that is too large, for example the value at a nearby parameter, the bound can fall below the true error. The min-theta bound holds here because all and all are positive; it fails for a form with a term of either sign.
- The square root floor. Line L6 forms as a difference of numbers of size . Rounding errors of size give even when the error is 0. In the example, at a sample point. Tolerances in a greedy loop must be well above this floor, or the residual must be computed in a stable way.
- Clipping a negative value. Line L7 takes . A negative means rounding, not a negative error; do not take the absolute value of a large negative number, which is a sign of a bug in the tables.
- The wrong inner product. The bound is in the norm of . If line L2 orthonormalizes in the Euclidean product but line L4 uses , the tables do not match the norm of the bound. Use the same in both lines.
- Affine terms done online. If line L5 assembles on the mesh and then projects it, the online cost is per query or more, and the method is no faster than a good truth solver for small .
- Dependent snapshots. Two samples that are equal or very close make Gram-Schmidt in line L2 divide by a tiny norm. The implementation raises an error; a greedy choice avoids the problem in practice because the bound at a sample is near zero.
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
# Part of https://algorithm.tamnd.com/reduced-basis-method/. The authors are listed in prov/YM1D2Z.jsonl.
"""Reduced basis method with an offline-online split and a residual based error bound.
The model problem is -u'' + mu u = 1 on (0, 1) with u(0) = u(1) = 0, in P1 finite elements on a
uniform mesh. Its matrix is affine in the parameter: A(mu) = theta_1 K + theta_2 M with theta = (1, mu).
"""
import math
from scimat import matmul, matvec, solve, transpose
Matrix = list[list[float]]
Vector = list[float]
def fe_model(n: int) -> tuple[list[Matrix], Vector]:
"""Return ([K, M], F) for P1 elements with n interior nodes and h = 1/(n+1)."""
h = 1.0 / (n + 1)
k = [[0.0] * n for _ in range(n)]
m = [[0.0] * n for _ in range(n)]
for i in range(n):
k[i][i] = 2.0 / h
m[i][i] = 4.0 * h / 6.0
if i > 0:
k[i][i - 1] = k[i - 1][i] = -1.0 / h
m[i][i - 1] = m[i - 1][i] = h / 6.0
return [k, m], [h] * n
def theta(mu: float) -> Vector:
"""Return the affine coefficients (1, mu) of A(mu) = K + mu M."""
return [1.0, mu]
def assemble(aq: list[Matrix], mu: float) -> Matrix:
"""Return A(mu) = sum over q of theta_q(mu) A_q."""
th = theta(mu)
n = len(aq[0])
return [[sum(th[q] * aq[q][i][j] for q in range(len(aq))) for j in range(n)] for i in range(n)]
def truth_solve(aq: list[Matrix], f: Vector, mu: float) -> Vector:
"""Return the finite element solution u(mu) of A(mu) u = F."""
return solve(assemble(aq, mu), f)
def x_dot(x: Matrix, u: Vector, v: Vector) -> float:
"""Return the X inner product u^T X v."""
return sum(ui * xv for ui, xv in zip(u, matvec(x, v)))
def alpha_lb(mu: float, mu_bar: float) -> float:
"""Return the min-theta lower bound min(1, mu / mu_bar) of the coercivity constant in the norm of X = K + mu_bar M."""
return min(1.0, mu / mu_bar)
def offline(aq: list[Matrix], f: Vector, x: Matrix, samples: list[float]) -> dict:
"""Build the reduced basis from the snapshots at the sample parameters and all mu independent quantities."""
snaps = [truth_solve(aq, f, mu) for mu in samples] # @line L1: snapshots u(mu_1), ..., u(mu_r)
z: list[Vector] = []
for u in snaps: # @line L2: Gram-Schmidt in the X inner product, two passes
w = list(u)
for _ in range(2):
for zj in z:
c = x_dot(x, zj, w)
w = [wi - c * zi for wi, zi in zip(w, zj)]
nw = math.sqrt(x_dot(x, w, w))
if nw <= 1e-10 * math.sqrt(x_dot(x, u, u)):
raise ValueError("the snapshots are linearly dependent")
z.append([wi / nw for wi in w])
zt = z # rows of zt are the basis vectors
zm = transpose(zt) # n by r
aqr = [matmul(zt, matmul(a, zm)) for a in aq] # @line L3: A_q^r = Z^T A_q Z and F_r = Z^T F
fr = matvec(zt, f)
# @line L4: Riesz representers X^-1 F and X^-1 A_q z_j, and their Gram quantities
aqz = [transpose(matmul(a, zm)) for a in aq] # aqz[q][j] = A_q z_j
rhs = [f] + [v for q in range(len(aq)) for v in aqz[q]]
reps = transpose(solve(x, transpose(rhs)))
ef, eq = reps[0], reps[1:]
r = len(z)
gff = sum(a * b for a, b in zip(f, ef))
gf = [[sum(a * b for a, b in zip(f, eq[q * r + j])) for j in range(r)] for q in range(len(aq))]
gqq = [[[[sum(a * b for a, b in zip(aqz[q][i], eq[p * r + j])) for j in range(r)] for i in range(r)] for p in range(len(aq))] for q in range(len(aq))]
return {"Z": zm, "Aqr": aqr, "Fr": fr, "gff": gff, "gf": gf, "gqq": gqq}
def online(rb: dict, mu: float, mu_bar: float) -> tuple[Vector, float, float, float]:
"""Return (u_r, Delta, s_r, Delta_s) at mu, at a cost independent of n except for lifting u_r = Z c."""
th = theta(mu)
qn = len(th)
r = len(rb["Fr"])
ar = [[sum(th[q] * rb["Aqr"][q][i][j] for q in range(qn)) for j in range(r)] for i in range(r)]
c = solve(ar, rb["Fr"]) # @line L5: solve A_r(mu) c = F_r
res2 = rb["gff"] # @line L6: the dual norm of the residual, squared
for q in range(qn):
res2 -= 2.0 * th[q] * sum(c[j] * rb["gf"][q][j] for j in range(r))
for p in range(qn):
g = rb["gqq"][q][p]
res2 += th[q] * th[p] * sum(c[i] * g[i][j] * c[j] for i in range(r) for j in range(r))
res = math.sqrt(max(res2, 0.0))
a = alpha_lb(mu, mu_bar)
delta = res / a # @line L7
s_r = sum(fi * ci for fi, ci in zip(rb["Fr"], c))
return matvec(rb["Z"], c), delta, s_r, res * res / a # @line L8
scimat.py 227 lines
# 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)]
test_reduced_basis_method.py 93 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/reduced-basis-method/. The authors are listed in prov/YM1D2Z.jsonl.
import math
import random
import pytest
from reduced_basis_method import alpha_lb, assemble, fe_model, offline, online, truth_solve, x_dot
from scimat import matvec, solve
N = 99
MU_BAR = 10.0
AQ, F = fe_model(N)
X = [[AQ[0][i][j] + MU_BAR * AQ[1][i][j] for j in range(N)] for i in range(N)]
def x_norm(v):
return math.sqrt(x_dot(X, v, v))
def test_truth_matches_the_exact_solution():
mu = 10.0
u = truth_solve(AQ, F, mu)
exact_mid = (1.0 - 1.0 / math.cosh(math.sqrt(mu) / 2.0)) / mu
assert u[N // 2] == pytest.approx(exact_mid, abs=1e-5)
def test_min_theta_bound_by_hand():
assert alpha_lb(3.0, 10.0) == pytest.approx(0.3)
assert alpha_lb(30.0, 10.0) == 1.0
rng = random.Random(3)
for _ in range(20): # a(v, v; mu) >= alpha_lb ||v||_X^2 for random v
mu = rng.uniform(1.0, 100.0)
v = [rng.gauss(0, 1) for _ in range(N)]
a = assemble(AQ, mu)
assert sum(vi * avi for vi, avi in zip(v, matvec(a, v))) >= alpha_lb(mu, MU_BAR) * x_dot(X, v, v) * (1 - 1e-12)
def test_reproduces_the_snapshots():
rb = offline(AQ, F, X, [1.0, 10.0, 100.0])
for mu in (1.0, 10.0, 100.0):
ur, delta, s_r, ds = online(rb, mu, MU_BAR)
u = truth_solve(AQ, F, mu)
assert x_norm([a - b for a, b in zip(u, ur)]) < 1e-12
assert delta < 1e-6 # rounding in the offline-online sum sets a floor near sqrt(eps)
def test_example_values():
rb = offline(AQ, F, X, [1.0, 10.0, 100.0])
ur, delta, s_r, ds = online(rb, 3.0, MU_BAR)
u = truth_solve(AQ, F, 3.0)
err = x_norm([a - b for a, b in zip(u, ur)])
assert err == pytest.approx(1.1838e-05, rel=1e-3)
assert delta == pytest.approx(3.8780e-05, rel=1e-3)
assert delta / err <= 1.0 / 0.3
def test_bound_and_effectivity_on_random_parameters():
rng = random.Random(11)
for samples in ([1.0, 100.0], [1.0, 10.0, 100.0], [1.0, 4.0, 20.0, 100.0]):
rb = offline(AQ, F, X, samples)
for _ in range(6):
mu = math.exp(rng.uniform(0.0, math.log(100.0)))
ur, delta, s_r, ds = online(rb, mu, MU_BAR)
u = truth_solve(AQ, F, mu)
e = [a - b for a, b in zip(u, ur)]
err = x_norm(e)
assert err <= delta * (1 + 1e-9) + 1e-12
gamma = max(1.0, mu / MU_BAR)
if err > 1e-7:
assert delta <= gamma / alpha_lb(mu, MU_BAR) * err * (1 + 1e-6)
# the online residual norm equals the direct one, sqrt(R^T X^-1 R)
a = assemble(AQ, mu)
res = [fi - ai for fi, ai in zip(F, matvec(a, ur))]
direct = math.sqrt(max(sum(ri * yi for ri, yi in zip(res, solve(X, res))), 0.0))
assert delta * alpha_lb(mu, MU_BAR) == pytest.approx(direct, rel=1e-5, abs=1e-8)
# compliance output: 0 <= s - s_r <= Delta_s
s = sum(fi * ui for fi, ui in zip(F, u))
assert -1e-14 <= s - s_r <= ds * (1 + 1e-6) + 1e-14
def test_error_falls_as_the_basis_grows():
errs = []
for samples in ([1.0, 100.0], [1.0, 10.0, 100.0], [1.0, 4.0, 20.0, 100.0]):
rb = offline(AQ, F, X, samples)
ur, delta, s_r, ds = online(rb, 30.0, MU_BAR)
errs.append(x_norm([a - b for a, b in zip(truth_solve(AQ, F, 30.0), ur)]))
assert errs[0] > 10 * errs[1] > 100 * errs[2]
def test_repeated_parameter_is_rejected():
with pytest.raises(ValueError):
offline(AQ, F, X, [2.0, 2.0])
History
Reduced bases built from a few solutions were used in nonlinear structural analysis around 1980, by Almroth, Stern and Brogan and by Noor and Peters, to follow a load path. The modern method, with a global basis over the parameter domain, a rigorous a posteriori error bound and the offline-online split for affine problems, comes from Patera, Maday and their coworkers. Prud'homme, Rovas, Veroy, Machiels, Maday, Patera and Turinici published the output bound method in 2002. Rozza, Huynh and Patera wrote the standard review of the coercive case in 2008, with the min-theta and successive constraint lower bounds. The books of Hesthaven, Rozza and Stamm and of Quarteroni, Manzoni and Negri appeared in 2015 and 2016.
References
- Christophe Prud'homme, Dimitrios V. Rovas, Karen Veroy, Luc Machiels, Yvon Maday, Anthony T. Patera and Gabriel Turinici, Reliable real-time solution of parametrized partial differential equations, reduced-basis output bound methods, Journal of Fluids Engineering 124(1), 2002, 70-80, the affine parameter dependence, the offline-online computation and the output bounds
- Gianluigi Rozza, D. B. Phuong Huynh and Anthony T. Patera, Reduced basis approximation and a posteriori error estimation for affinely parametrized elliptic coercive partial differential equations, Archives of Computational Methods in Engineering 15(3), 2008, 229-275, the affine decomposition, the offline-online computation of the dual norm of the residual, and the error bounds with a lower bound of the coercivity constant (including the min-theta bound)
- Jan S. Hesthaven, Gianluigi Rozza and Benjamin Stamm, Certified Reduced Basis Methods for Parametrized Partial Differential Equations, SpringerBriefs in Mathematics, Springer, 2016, Chapter 3 (reduced basis methods, offline and online) and Chapter 4 (certified error control)
- Alfio Quarteroni, Andrea Manzoni and Federico Negri, Reduced Basis Methods for Partial Differential Equations, An Introduction, UNITEXT 92, Springer, 2016, Chapter 3 (basic principles and properties of reduced basis methods)
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 YM1D2Z Edit this page History Report an error Markdown