Algorithm Search⌘K

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
Properties
certifieddeterministicnot exactnot iterative
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 μ1,…,μr\mu_1, \ldots, \mu_r. The span of these solutions is the reduced space. For a new μ\mu it finds the Galerkin approximation in this space, which is a linear system of size rr. It also returns a bound Δ(μ)\Delta(\mu) that is at least the true error, computed from the residual and a lower bound of the coercivity constant. If the matrix depends on μ\mu in an affine way, all the work that involves the nn 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 nn. 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 μj\mu_j with the bound Δ\Delta, and the Kolmogorov width of the solution set says how small rr 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 XX be a finite element space of dimension nn with an inner product (u,v)X=uTXv(u, v)_X = u^T X v, where XX is now also its symmetric positive definite matrix. For each parameter μ\mu in a set P\mathcal{P}, a bilinear form a(⋅,⋅;μ)a(\cdot, \cdot; \mu) and a load FF define the truth solution u(μ)∈Xu(\mu) \in X by

a(u(μ),v;μ)=F(v)for all v∈X.a(u(\mu), v; \mu) = F(v) \quad \text{for all } v \in X .

The form is coercive and continuous in the XX norm, with constants α(μ)>0\alpha(\mu) > 0 and γ(μ)\gamma(\mu), so by the Lax-Milgram theorem u(μ)u(\mu) exists and is unique. The form is affine: a(u,v;μ)=∑q=1Qθq(μ) aq(u,v)a(u, v; \mu) = \sum_{q=1}^{Q} \theta_q(\mu)\, a_q(u, v), with matrices AqA_q that do not depend on μ\mu. A lower bound αLB(μ)\alpha_{LB}(\mu) with 0<αLB(μ)≤α(μ)0 < \alpha_{LB}(\mu) \le \alpha(\mu) is known and cheap to evaluate.

Given sample parameters μ1,…,μr\mu_1, \ldots, \mu_r with linearly independent truth solutions and a query μ\mu, the output is the reduced solution ur(μ)∈Xr=span⁡{u(μ1),…,u(μr)}u_r(\mu) \in X_r = \operatorname{span}\{u(\mu_1), \ldots, u(\mu_r)\} with a(ur,v;μ)=F(v)a(u_r, v; \mu) = F(v) for all v∈Xrv \in X_r, and a bound Δ(μ)≥∥u(μ)−ur(μ)∥X\Delta(\mu) \ge \|u(\mu) - u_r(\mu)\|_X.

The model problem of the example and the tests is −u′′+μu=1-u'' + \mu u = 1 on (0,1)(0, 1) with u(0)=u(1)=0u(0) = u(1) = 0 and μ∈[1,100]\mu \in [1, 100], in P1 finite elements on a uniform mesh with nn interior nodes and h=1/(n+1)h = 1/(n+1). Then A(μ)=K+μMA(\mu) = K + \mu M with the stiffness matrix KK and the mass matrix MM, so Q=2Q = 2, θ1=1\theta_1 = 1 and θ2=μ\theta_2 = \mu. The inner product is X=K+μˉMX = K + \bar{\mu} M with μˉ=10\bar{\mu} = 10. Since vTA(μ)v=vTKv+μ vTMv≥min⁡(1,μ/μˉ) vTXvv^T A(\mu) v = v^T K v + \mu\, v^T M v \ge \min(1, \mu/\bar{\mu})\, v^T X v, the min-theta bound αLB(μ)=min⁡(1,μ/μˉ)\alpha_{LB}(\mu) = \min(1, \mu/\bar{\mu}) is a valid lower bound, and in the same way γ(μ)≤max⁡(1,μ/μˉ)\gamma(\mu) \le \max(1, \mu/\bar{\mu}). The exact solution is u(x)=μ−1(1−cosh⁡(μ(x−1/2))/cosh⁡(μ/2))u(x) = \mu^{-1}\big(1 - \cosh(\sqrt{\mu}(x - 1/2)) / \cosh(\sqrt{\mu}/2)\big).

The algorithm

  1. REDUCED-BASIS(A_1..A_Q, F, X, μ_1..μ_r; query μ)
  2. ▷ offline stage, once
  3. 1solve A(μ_j) u_j = F for j = 1..r ▷ r truth solves
  4. 2Z ← [z_1 ... z_r], an X-orthonormal basis of span{u_1..u_r} by Gram-Schmidt
  5. 3A_q^r ← Z^T A_q Z for q = 1..Q; F_r ← Z^T F
  6. 4e_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
  7. ▷ online stage, for each query μ
  8. 5solve (Σ_q θ_q(μ) A_q^r) c = F_r
  9. 6ρ² ← G_FF - 2 Σ_q θ_q Σ_j c_j g_qj + Σ_q Σ_p θ_q θ_p Σ_i Σ_j c_i c_j G_qp,ij
  10. 7Δ ← sqrt(max(ρ², 0)) / α_LB(μ)
  11. 8return 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, rr times. Line L2 orthonormalizes the snapshots in the XX 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 FF and of each AqzjA_q z_j, that is the solutions of Xe=FX e = F and Xe=AqzjX e = A_q z_j, and stores their inner products. These 1+Qr1 + Q r solves with XX and the tables are the price of the bound. Line L5 assembles the rr by rr matrix from QQ small matrices. Line L6 expands ρ2=RTX−1R\rho^2 = R^T X^{-1} R for the residual vector R=F−A(μ)ZcR = F - A(\mu) Z c, by the affine sum, so it uses only the tables. Line L7 divides by the stability lower bound. The compliance output s(μ)=F(u(μ))s(\mu) = F(u(\mu)) in line L8 has its own bound. Lines L5 to L8 cost a number of operations that depends on rr and QQ, not on nn, except for the lift ZcZ c, which a user who wants only srs_r can skip.

Example

The mesh has n=99n = 99 interior nodes (h=0.01h = 0.01), the samples are μj=1,10,100\mu_j = 1, 10, 100, so r=3r = 3, and μˉ=10\bar{\mu} = 10. At μ=10\mu = 10 the truth value at x=1/2x = 1/2 is 0.06052530.0605253; the exact value is 0.06052290.0605229, so the finite element error is 2.4×10−62.4 \times 10^{-6}. The reduced basis method approximates the truth, not the exact solution. The table gives the online results (a measurement, from the test file).

μ\mu αLB\alpha_{LB} γ/αLB\gamma / \alpha_{LB} ∥u−ur∥X\|u - u_r\|_X Δ\Delta Δ/∥u−ur∥X\Delta / \|u - u_r\|_X srs_r s−srs - s_r
2 0.2 5 7.528×10−67.528 \times 10^{-6} 3.690×10−53.690 \times 10^{-5} 4.90 0.0694652 5.6×10−115.6 \times 10^{-11}
3 0.3 3.33 1.184×10−51.184 \times 10^{-5} 3.878×10−53.878 \times 10^{-5} 3.28 0.0641482 1.4×10−101.4 \times 10^{-10}
10 1 1 5.4×10−155.4 \times 10^{-15} 5.3×10−95.3 \times 10^{-9} 0.0418882 1.1×10−151.1 \times 10^{-15}
30 1 3 7.795×10−57.795 \times 10^{-5} 8.157×10−58.157 \times 10^{-5} 1.05 0.0212615 6.4×10−96.4 \times 10^{-9}
60 1 6 9.115×10−59.115 \times 10^{-5} 1.012×10−41.012 \times 10^{-4} 1.11 0.0123660 9.2×10−99.2 \times 10^{-9}

In each row the bound is above the error, and the effectivity Δ/∥u−ur∥X\Delta / \|u - u_r\|_X is below γ/αLB\gamma / \alpha_{LB}, as the correctness section proves. You can check the second and third columns by hand: at μ=3\mu = 3, αLB=min⁡(1,3/10)=0.3\alpha_{LB} = \min(1, 3/10) = 0.3 and γ≤max⁡(1,0.3)=1\gamma \le \max(1, 0.3) = 1. The effectivity grows as μ\mu falls below μˉ\bar{\mu}, because the min-theta bound is then pessimistic: for the smoothest mode v=sin⁡(πx)v = \sin(\pi x), the ratio a(v,v;μ)/∥v∥X2a(v, v; \mu) / \|v\|_X^2 is close to (π2+μ)/(π2+μˉ)(\pi^2 + \mu)/(\pi^2 + \bar{\mu}), which is 0.60 at μ=2\mu = 2, not 0.2. At the sample μ=10\mu = 10, the reduced solution is the truth up to rounding, but Δ\Delta is 5.3×10−95.3 \times 10^{-9}, not 10−1510^{-15}: see the pitfalls. The output error s−srs - s_r is positive and about the square of the error, as the compliance lemma says. At μ=30\mu = 30, the error is 2.49×10−32.49 \times 10^{-3} with the two samples 1,1001, 100, 7.79×10−57.79 \times 10^{-5} with 1,10,1001, 10, 100, and 8.90×10−78.90 \times 10^{-7} with 1,4,20,1001, 4, 20, 100.

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 aa is coercive on the subspace XrX_r. Second, with e=u−ure = u - u_r and the Riesz representer e^\hat{e} of the residual (Xe^=RX \hat{e} = R),

∥e∥X≤∥e^∥Xα(μ)≤∥e^∥XαLB(μ)=Δ(μ),Δ(μ)∥e∥X≤γ(μ)αLB(μ).\|e\|_X \le \frac{\|\hat{e}\|_X}{\alpha(\mu)} \le \frac{\|\hat{e}\|_X}{\alpha_{LB}(\mu)} = \Delta(\mu), \qquad \frac{\Delta(\mu)}{\|e\|_X} \le \frac{\gamma(\mu)}{\alpha_{LB}(\mu)} .

So the bound is reliable, and it is never worse than the error by more than a factor that does not depend on rr or nn. Third, the quantity ρ2\rho^2 of line L6 is exactly ∥e^∥X2\|\hat{e}\|_X^2. Fourth, for a symmetric form and the compliance output, 0≤s−sr=a(e,e;μ)≤ρ2/αLB(μ)0 \le s - s_r = a(e, e; \mu) \le \rho^2 / \alpha_{LB}(\mu). The proof also shows that ur(μj)=u(μj)u_r(\mu_j) = u(\mu_j) at each sample. For a symmetric form, uru_r is the best approximation of uu in XrX_r in the energy norm of μ\mu, 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. X=RnX = \mathbb{R}^n has the inner product (u,v)X=uTXv(u, v)_X = u^T X v with a symmetric positive definite matrix XX, and the dual norm of a linear functional ℓ(v)=LTv\ell(v) = L^T v is ∥ℓ∥X′=sup⁡v≠0ℓ(v)/∥v∥X\|\ell\|_{X'} = \sup_{v \ne 0} \ell(v) / \|v\|_X. For a parameter μ\mu, a(u,v;μ)=vTA(μ)ua(u, v; \mu) = v^T A(\mu) u with A(μ)=∑q=1Qθq(μ)AqA(\mu) = \sum_{q=1}^{Q} \theta_q(\mu) A_q, and F(v)=FTvF(v) = F^T v. We assume

  • coercivity: a(v,v;μ)≥α(μ)∥v∥X2a(v, v; \mu) \ge \alpha(\mu) \|v\|_X^2 for all vv, with α(μ)>0\alpha(\mu) > 0;
  • continuity: ∣a(u,v;μ)∣≤γ(μ)∥u∥X∥v∥X|a(u, v; \mu)| \le \gamma(\mu) \|u\|_X \|v\|_X for all u,vu, v;
  • a lower bound 0<αLB(μ)≤α(μ)0 < \alpha_{LB}(\mu) \le \alpha(\mu).

Lemma 1 (the Riesz representer). For a vector RR, let e^=X−1R\hat{e} = X^{-1} R. Then ∥RT⋅∥X′=∥e^∥X\|R^T \cdot\|_{X'} = \|\hat{e}\|_X and ∥e^∥X2=RTX−1R\|\hat{e}\|_X^2 = R^T X^{-1} R.

Proof. RTv=e^TXv=(e^,v)X≤∥e^∥X∥v∥XR^T v = \hat{e}^T X v = (\hat{e}, v)_X \le \|\hat{e}\|_X \|v\|_X by the Cauchy-Schwarz inequality, with equality for v=e^v = \hat{e}. And ∥e^∥X2=RTX−1XX−1R=RTX−1R\|\hat{e}\|_X^2 = R^T X^{-1} X X^{-1} R = R^T X^{-1} R. □\square

Lemma 2 (existence). Let ZZ be the nn by rr matrix of line L2, with XX-orthonormal columns. Then Ar(μ)=ZTA(μ)Z=∑qθq(μ)AqrA_r(\mu) = Z^T A(\mu) Z = \sum_q \theta_q(\mu) A_q^r is invertible, so line L5 has a unique solution cc, and ur=Zcu_r = Z c satisfies a(ur,v;μ)=F(v)a(u_r, v; \mu) = F(v) for all vv in the range XrX_r of ZZ.

Proof. The sum identity holds because ZT(∑qθqAq)Z=∑qθqZTAqZZ^T(\sum_q \theta_q A_q) Z = \sum_q \theta_q Z^T A_q Z. For c≠0c \ne 0, cTArc=a(Zc,Zc;μ)≥α(μ)∥Zc∥X2=α(μ)∣c∣2>0c^T A_r c = a(Z c, Z c; \mu) \ge \alpha(\mu) \|Z c\|_X^2 = \alpha(\mu) |c|^2 > 0, so Arc≠0A_r c \ne 0. The equation Arc=ZTFA_r c = Z^T F says (Zei)TA(μ)Zc=FTZei(Z e_i)^T A(\mu) Z c = F^T Z e_i for each basis vector ZeiZ e_i, and by linearity for all v∈Xrv \in X_r. □\square

Lines L1 and L2 make XrX_r the span of the snapshots: Gram-Schmidt in the XX inner product keeps the span of the first jj vectors at each step jj, and the snapshots are independent.

Theorem 1 (reliability and effectivity). Let e=u(μ)−ur(μ)e = u(\mu) - u_r(\mu), R=F−A(μ)urR = F - A(\mu) u_r, e^=X−1R\hat{e} = X^{-1} R and Δ=∥e^∥X/αLB(μ)\Delta = \|\hat{e}\|_X / \alpha_{LB}(\mu). Then

∥e∥X≤Δ≤γ(μ)αLB(μ)∥e∥X.\|e\|_X \le \Delta \le \frac{\gamma(\mu)}{\alpha_{LB}(\mu)} \|e\|_X .

Proof. Since A(μ)u=FA(\mu) u = F, we have A(μ)e=RA(\mu) e = R, so a(e,v;μ)=RTv=(e^,v)Xa(e, v; \mu) = R^T v = (\hat{e}, v)_X for all vv. With v=ev = e: α(μ)∥e∥X2≤a(e,e;μ)=(e^,e)X≤∥e^∥X∥e∥X\alpha(\mu) \|e\|_X^2 \le a(e, e; \mu) = (\hat{e}, e)_X \le \|\hat{e}\|_X \|e\|_X. If e=0e = 0 the first claim is clear; otherwise divide by ∥e∥X\|e\|_X to get ∥e∥X≤∥e^∥X/α(μ)≤Δ\|e\|_X \le \|\hat{e}\|_X / \alpha(\mu) \le \Delta. With v=e^v = \hat{e}: ∥e^∥X2=a(e,e^;μ)≤γ(μ)∥e∥X∥e^∥X\|\hat{e}\|_X^2 = a(e, \hat{e}; \mu) \le \gamma(\mu) \|e\|_X \|\hat{e}\|_X, so ∥e^∥X≤γ(μ)∥e∥X\|\hat{e}\|_X \le \gamma(\mu) \|e\|_X. Divide by αLB(μ)\alpha_{LB}(\mu). □\square

Lemma 3 (the offline-online residual). The number ρ2\rho^2 of line L6 equals ∥e^∥X2\|\hat{e}\|_X^2.

Proof. R=F−∑qθq∑jcjAqzjR = F - \sum_q \theta_q \sum_j c_j A_q z_j. By Lemma 1, ∥e^∥X2=RTX−1R\|\hat{e}\|_X^2 = R^T X^{-1} R. Expand the product. The term FTX−1FF^T X^{-1} F is GFFG_{FF}. Each cross term is θqcjFTX−1Aqzj=θqcjgqj\theta_q c_j F^T X^{-1} A_q z_j = \theta_q c_j g_{qj}, and it appears twice, with a minus sign, because X−1X^{-1} is symmetric. Each quadratic term is θqθpcicj(Aqzi)TX−1Apzj=θqθpcicjGqp,ij\theta_q \theta_p c_i c_j (A_q z_i)^T X^{-1} A_p z_j = \theta_q \theta_p c_i c_j G_{qp,ij}. These are the three sums of line L6, with the tables of line L4. □\square

So line L7 returns the Δ\Delta of Theorem 1.

Lemma 4 (reproduction). If μ=μj\mu = \mu_j for a sample jj, then ur(μ)=u(μ)u_r(\mu) = u(\mu) and Δ=0\Delta = 0.

Proof. u(μj)u(\mu_j) is in XrX_r. Let w=u(μj)−ur(μj)∈Xrw = u(\mu_j) - u_r(\mu_j) \in X_r. By Lemma 2 and the truth equation, a(w,v;μj)=0a(w, v; \mu_j) = 0 for all v∈Xrv \in X_r, in particular for v=wv = w, and coercivity gives w=0w = 0. Then R=0R = 0 and Δ=0\Delta = 0. □\square

Theorem 2 (the compliance output). If A(μ)A(\mu) is symmetric, s=FTus = F^T u and sr=FTur=FrTcs_r = F^T u_r = F_r^T c, then 0≤s−sr=a(e,e;μ)≤∥e^∥X2/αLB(μ)0 \le s - s_r = a(e, e; \mu) \le \|\hat{e}\|_X^2 / \alpha_{LB}(\mu).

Proof. s−sr=FTe=uTAes - s_r = F^T e = u^T A e by symmetry and Au=FA u = F. Galerkin orthogonality (Lemma 2) gives urTAe=urTR=0u_r^T A e = u_r^T R = 0, because ZTR=ZTF−Arc=0Z^T R = Z^T F - A_r c = 0. So FTe=(u−ur)TAe=a(e,e;μ)≥0F^T e = (u - u_r)^T A e = a(e, e; \mu) \ge 0. From the proof of Theorem 1, a(e,e;μ)=(e^,e)X≤∥e^∥X∥e∥X≤∥e^∥X2/α(μ)≤∥e^∥X2/αLB(μ)a(e, e; \mu) = (\hat{e}, e)_X \le \|\hat{e}\|_X \|e\|_X \le \|\hat{e}\|_X^2 / \alpha(\mu) \le \|\hat{e}\|_X^2 / \alpha_{LB}(\mu). □\square

The model problem. For A(μ)=K+μMA(\mu) = K + \mu M with symmetric positive semidefinite KK and MM whose sum is positive definite, and X=K+μˉMX = K + \bar{\mu} M with μˉ>0\bar{\mu} > 0: vTKv+μvTMv≥min⁡(1,μ/μˉ)(vTKv+μˉvTMv)v^T K v + \mu v^T M v \ge \min(1, \mu/\bar{\mu})(v^T K v + \bar{\mu} v^T M v) term by term, so αLB(μ)=min⁡(1,μ/μˉ)≤α(μ)\alpha_{LB}(\mu) = \min(1, \mu/\bar{\mu}) \le \alpha(\mu). With the seminorms ∣v∣K|v|_K and ∣v∣M|v|_M and the Cauchy-Schwarz inequality, ∣uTKv+μuTMv∣≤∣u∣K∣v∣K+μ∣u∣M∣v∣M≤max⁡(1,μ/μˉ)(∣u∣K∣v∣K+μˉ∣u∣M∣v∣M)≤max⁡(1,μ/μˉ)∥u∥X∥v∥X|u^T K v + \mu u^T M v| \le |u|_K |v|_K + \mu |u|_M |v|_M \le \max(1, \mu/\bar{\mu}) (|u|_K |v|_K + \bar{\mu} |u|_M |v|_M) \le \max(1, \mu/\bar{\mu}) \|u\|_X \|v\|_X, so γ(μ)≤max⁡(1,μ/μˉ)\gamma(\mu) \le \max(1, \mu/\bar{\mu}). ■\blacksquare

Complexity

In the real RAM model, the offline stage costs rr truth solves in line L1 and 1+Qr1 + Q r solves with XX in line L4. For a 1D problem with tridiagonal matrices each solve costs O(n)O(n); the implementation uses dense Gaussian elimination for simplicity. Lines L2 to L4 also cost O(nr2)O(n r^2) for Gram-Schmidt and O(Q2r2n)O(Q^2 r^2 n) for the tables, with sparse AqA_q and XX. The online stage costs O(Qr2)O(Q r^2) to assemble the reduced matrix, O(r3)O(r^3) to solve it and O(Q2r2)O(Q^2 r^2) for line L6, with no dependence on nn. The tables need O(Q2r2)O(Q^2 r^2) memory and the representers O(Qrn)O(Q r n) 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 αLB\alpha_{LB} is a true lower bound and the arithmetic is exact.
  • Effective. The bound overestimates by at most γ/αLB\gamma / \alpha_{LB}, independent of rr and nn.
  • Interpolatory. At the sample parameters, the reduced solution equals the truth.
  • Online cost independent of nn. This needs the affine form. Without it, line L5 must assemble A(μ)A(\mu) 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 AqA_q of the finite element code.

Variants and improvements

  • Greedy sampling. The weak greedy algorithm chooses μj+1\mu_{j+1} where Δ\Delta is largest over a training set, so the basis is built with rr 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 αLB\alpha_{LB}, 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 QQ 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 α\alpha.
  • 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 α(μ)\alpha(\mu) 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 θq\theta_q and all aqa_q are positive; it fails for a form with a term of either sign.
  • The square root floor. Line L6 forms ρ2\rho^2 as a difference of numbers of size ∥F∥2\|F\|^2. Rounding errors of size εmach∥F∥X′2\varepsilon_{mach} \|F\|_{X'}^2 give ρ≈εmach∥F∥X′\rho \approx \sqrt{\varepsilon_{mach}} \|F\|_{X'} even when the error is 0. In the example, Δ=5.3×10−9\Delta = 5.3 \times 10^{-9} 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 max⁡(ρ2,0)\max(\rho^2, 0). A negative ρ2\rho^2 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 XX. If line L2 orthonormalizes in the Euclidean product but line L4 uses XX, the tables do not match the norm of the bound. Use the same XX in both lines.
  • Affine terms done online. If line L5 assembles A(μ)A(\mu) on the mesh and then projects it, the online cost is O(nr)O(n r) per query or more, and the method is no faster than a good truth solver for small nn.
  • 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.

reduced_basis_method.pyI0RawGitHub
# 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

  1. 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
  2. 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)
  3. 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)
  4. 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.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.offline
  • a full proof of time.online
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example