Algorithm Search⌘K

Algorithmresearch

Isogeometric boundary element method

Also called IGABEM.

Uses the spline basis of the CAD boundary for boundary integral equations, so only the surface needs a parameterization, as Politis and then Simpson and coauthors showed.

Time
O(n^2 g + n^3) worst
Space
O(n^2) extra
Where
g = Gauss points per element; n = number of boundary unknowns
Properties
deterministicnot exactiterative
Origin
Costas Politis, Alexandros I. Ginnis, Panagiotis D. Kaklis, Robert N. Simpson, Stéphane P. A. Bordas, Jon Trevelyan, Timon Rabczuk, 2009

The isogeometric boundary element method (IGABEM) solves a linear partial differential equation by an integral equation on the boundary of the domain, and it uses the NURBS basis of the CAD boundary both for the geometry and for the unknown fields. A CAD solid is stored by its boundary, so the method needs no volume mesh and no volumetric spline parameterization, which is the hard step of volume isogeometric analysis. Politis and coauthors (2009) used it for 2D potential flow, and Simpson, Bordas, Trevelyan and Rabczuk (2012) for 2D elasticity. No page of this site covers the boundary element method itself, so this page defines what it needs, for the 2D Laplace equation, with collocation at the Greville abscissae as in isogeometric collocation.

In plain words

For some equations, such as steady heat flow without sources, the values inside a region follow from the values and the fluxes on its border. A classic formula, built from the field of a point source, ties the two together. So you can solve for the unknown border data only, and the problem lives on a curve instead of on a whole area.

To solve the border problem, you need a way to describe functions on the border. The CAD model already describes the border with smooth spline pieces. The method uses those same pieces for the unknown data, so the shape is exact and no mesh has to be made. You ask the border formula to hold at one point per unknown, get a full linear system, and solve it. The values inside then follow from the same formula.

The problem

Let Ω⊂R2\Omega \subset \mathbb{R}^2 be a bounded domain with a smooth boundary Γ\Gamma and outward normal nn. Given gg on Γ\Gamma, find uu with

Δu=0 in Ω,u=g on Γ,\Delta u = 0 \text{ in } \Omega, \qquad u = g \text{ on } \Gamma,

that is, the Poisson equation with zero source. The unknown of the boundary method is the flux q=∂u/∂nq = \partial u / \partial n on Γ\Gamma.

The boundary integral equation. The fundamental solution of the 2D Laplace equation and its normal derivative at yy are

u∗(x,y)=−12πln⁡∣y−x∣,q∗(x,y)=∂u∗∂ny=−12π(y−x)⋅ny∣y−x∣2.u^*(x, y) = -\frac{1}{2\pi} \ln |y - x|, \qquad q^*(x, y) = \frac{\partial u^*}{\partial n_y} = -\frac{1}{2\pi} \frac{(y - x) \cdot n_y}{|y - x|^2}.

Green's second identity, applied on Ω\Omega minus a small disc around xx, gives for a harmonic uu and an interior point xx the representation formula u(x)=∫Γu∗q ds−∫Γq∗u dsu(x) = \int_\Gamma u^* q \, ds - \int_\Gamma q^* u \, ds. As xx moves to a smooth point of Γ\Gamma, the second integral jumps by half the value, and

12u(x)+∫Γq∗(x,y) u(y) dsy=∫Γu∗(x,y) q(y) dsy(x∈Γ).\tfrac12 u(x) + \int_\Gamma q^*(x, y) \, u(y) \, ds_y = \int_\Gamma u^*(x, y) \, q(y) \, ds_y \qquad (x \in \Gamma).

The right side is the single layer operator VqV q, with a weak singularity ln⁡∣y−x∣\ln |y - x|. On a smooth boundary q∗q^* is bounded, because (y−x)⋅ny(y - x) \cdot n_y is of order ∣y−x∣2|y - x|^2.

The isogeometric discretization. Γ\Gamma is a closed NURBS curve C(t)=∑jRj(t)PjC(t) = \sum_j R_j(t) P_j, t∈[0,1]t \in [0, 1], of degree pp, counterclockwise, with an open knot vector and P0=PnP_0 = P_n. The functions R0R_0 and RnR_n are merged into one, which gives nn functions that are continuous around the closed curve and sum to 1. Both fields use this basis, uh=∑jRjuju_h = \sum_j R_j u_j and qh=∑jRjqjq_h = \sum_j R_j q_j. The collocation points are xi=C(τi)x_i = C(\tau_i), i=1,…,ni = 1, \ldots, n, for the Greville abscissae τi\tau_i without the last one, which gives the same point as the first.

The algorithm

  1. IGABEM-DIRICHLET(C, g) ▷ C: closed NURBS curve, g: boundary values
  2. 1n ← number of control points − 1 ▷ first and last basis functions merged
  3. 2τ_i ← Greville abscissae of the knots, the last dropped; x_i ← C(τ_i)
  4. 3for i = 1 to n, for each element e = [t_a, t_b] of C do
  5. 4if τ_i ∈ e: split e at τ_i; graded Gauss rule t = τ_i ± d w^m for u*, plain Gauss on each part for q*
  6. 5else: the same g-point Gauss rule on e for both kernels
  7. 6for each rule point t with weight ω: add u*(x_i, C(t)) R_j(t) |C'(t)| ω to G[i, j] and the same with q* to H[i, j]
  8. 7H[i, j] ← H[i, j] + ½ R_j(τ_i) ▷ the free term
  9. 8solve Σ_j R_j(τ_i) u_j = g(x_i) for the coefficients u of the data
  10. 9solve G q = H u and return q

Line L4 handles the log singularity of u∗u^*. On each side of τi\tau_i, of length dd, the substitution t=τi±d wmt = \tau_i \pm d \, w^m with w∈[0,1]w \in [0, 1] turns ln⁡∣t−τi∣\ln |t - \tau_i| into mln⁡w+ln⁡dm \ln w + \ln d and multiplies it by md wm−1m d \, w^{m-1}, which is bounded and smooth enough for Gauss rules in ww. The code uses m=4m = 4 and 16 points. The element test checks both τi\tau_i and τi+1\tau_i + 1, because the collocation point at t=0t = 0 also ends the last element at t=1t = 1. Line L8 takes the Dirichlet data into the basis by interpolation at the same points, so that HuH u is the left side of the integral equation. For a Neumann problem, qq is given and lines L8 and L9 change roles. For mixed data the columns of known and unknown values are swapped.

Geometry refinement. The basis is refined by knot insertion with Boehm's algorithm applied to the homogeneous control points (wjPj,wj)(w_j P_j, w_j), which leaves the curve exactly unchanged.

Example

The circle. Take the circle of radius R=2R = 2 as the exact quadratic NURBS with 9 control points, the knots (0,0,0,14,14,12,12,34,34,1,1,1)(0, 0, 0, \tfrac14, \tfrac14, \tfrac12, \tfrac12, \tfrac34, \tfrac34, 1, 1, 1) and the weights 1,22,1,…1, \tfrac{\sqrt2}{2}, 1, \ldots. On the circle, (y−x)⋅ny=∣y−x∣2/(2R)(y - x) \cdot n_y = |y - x|^2 / (2R), so q∗=−1/(4πR)q^* = -1/(4\pi R) is constant, and ∫Γq∗ ds=−12\int_\Gamma q^* \, ds = -\tfrac12.

  • Constant data. For u=1u = 1, each row of HuH u is 12−12=0\tfrac12 - \tfrac12 = 0, so qh=0q_h = 0. The code returns ∣qj∣<10−7|q_j| < 10^{-7}.
  • Data in the space. For u=x+2yu = x + 2y, the flux is q=(x+2y)/Rq = (x + 2y)/R. Both are NURBS of the basis, because xx and yy are. The code returns the exact control values of qq to about 7×10−97 \times 10^{-9}, the error of the quadrature.
  • A smooth solution not in the space. For u=x2−y2=R2cos⁡2θu = x^2 - y^2 = R^2 \cos 2\theta, the flux is q=2Rcos⁡2θ=4cos⁡2θq = 2R \cos 2\theta = 4 \cos 2\theta. Uniform knot insertion gives:
elements unknowns nn max error of qhq_h error of uu at (0.5,0.3)(0.5, 0.3)
4 8 5.3×10−15.3 \times 10^{-1} 1.5×10−21.5 \times 10^{-2}
8 12 6.4×10−26.4 \times 10^{-2} 2.5×10−42.5 \times 10^{-4}
16 20 1.5×10−21.5 \times 10^{-2} 9.2×10−59.2 \times 10^{-5}
32 36 1.7×10−31.7 \times 10^{-3} 5.5×10−65.5 \times 10^{-6}
64 68 2.1×10−42.1 \times 10^{-4} 3.4×10−73.4 \times 10^{-7}

From 16 to 64 elements the flux error falls by about 8 per halving of the element size, an observed order 3, and the interior error by about 16, an observed order 4. These are measurements on this problem. The interior value comes from the representation formula with uhu_h and qhq_h, which smooths the boundary error.

An ellipse. The same circle scaled by (1,0.75)(1, 0.75) is an ellipse, still an exact NURBS with the same weights. There q∗q^* is not constant, and for u=x2−y2+12xy+xu = x^2 - y^2 + \tfrac12 xy + x the flux error falls from 2.4×10−22.4 \times 10^{-2} to 2.7×10−32.7 \times 10^{-3} when the elements go from 16 to 32.

Correctness

Three things are proved on the proof page. First, the integral equation holds for the exact solution, and on the circle the operators are diagonal in Fourier modes: V1=−Rln⁡RV 1 = -R \ln R and Veikθ=R2∣k∣eikθV e^{ik\theta} = \frac{R}{2|k|} e^{ik\theta} for k≠0k \ne 0. So the single layer operator of a circle is invertible if and only if R≠1R \ne 1. Second, the discrete system is consistent: if the exact uu and qq are both in the spline space, they satisfy the collocation equations exactly, so if the matrices of lines L8 and L9 are non-singular, the method returns them. This is what the test with u=x+2yu = x + 2y checks. Third, u=1u = 1 gives qh=0q_h = 0 for every closed smooth curve, from ∫Γq∗ ds=−12\int_\Gamma q^* \, ds = -\tfrac12.

The non-singularity of the discrete matrix GG and the convergence order are not proved here. The table measures them.

Proof: The boundary integral equation on a circle, its degenerate scale, and the consistency of IGABEM collocationfull

We use the notation of the page: u∗(x,y)=−12πln⁡∣y−x∣u^*(x, y) = -\frac{1}{2\pi} \ln |y - x|, q∗=∂u∗/∂nyq^* = \partial u^* / \partial n_y, (Vq)(x)=∫Γu∗(x,y)q(y) dsy(V q)(x) = \int_\Gamma u^*(x, y) q(y) \, ds_y and (Ku)(x)=∫Γq∗(x,y)u(y) dsy(K u)(x) = \int_\Gamma q^*(x, y) u(y) \, ds_y. The boundary integral equation is 12u+Ku=Vq\tfrac12 u + K u = V q on a smooth closed curve Γ\Gamma. We take it as known from Green's second identity, as derived on the page.

Lemma 1 (the double layer of a constant). For a smooth closed curve Γ\Gamma and x∈Γx \in \Gamma, ∫Γq∗(x,y) dsy=−12\int_\Gamma q^*(x, y) \, ds_y = -\tfrac12.

Proof. The function u=1u = 1 is harmonic with q=0q = 0. The boundary integral equation gives 12⋅1+∫Γq∗(x,y) dsy=0\tfrac12 \cdot 1 + \int_\Gamma q^*(x, y) \, ds_y = 0. □\square

Lemma 2 (the circle). Let Γ\Gamma be the circle of radius RR about the origin, with x=Reiθx = R e^{i\theta} and y=Reiφy = R e^{i\varphi}. Then

  1. q∗(x,y)=−14πRq^*(x, y) = -\dfrac{1}{4\pi R} for y≠xy \ne x, so (Ku)(x)=−12uˉ(K u)(x) = -\tfrac12 \bar u, where uˉ\bar u is the mean of uu over Γ\Gamma;
  2. V1=−Rln⁡RV 1 = -R \ln R, and Veikφ=R2∣k∣eikθV e^{ik\varphi} = \dfrac{R}{2|k|} e^{ik\theta} for each integer k≠0k \ne 0.

Proof. (1) The outward normal at yy is ny=y/Rn_y = y / R, and ∣x∣=∣y∣=R|x| = |y| = R, so (y−x)⋅ny=(R2−x⋅y)/R(y - x) \cdot n_y = (R^2 - x \cdot y)/R and ∣y−x∣2=2R2−2x⋅y|y - x|^2 = 2R^2 - 2 x \cdot y. So (y−x)⋅ny=∣y−x∣2/(2R)(y - x) \cdot n_y = |y - x|^2 / (2R), and q∗=−12π⋅12Rq^* = -\frac{1}{2\pi} \cdot \frac{1}{2R}. With dsy=R dφds_y = R \, d\varphi, (Ku)(x)=−14πR∫02πu R dφ=−12uˉ(K u)(x) = -\frac{1}{4\pi R} \int_0^{2\pi} u \, R \, d\varphi = -\tfrac12 \bar u.

(2) ∣y−x∣=R ∣1−ei(φ−θ)∣|y - x| = R \, |1 - e^{i(\varphi - \theta)}|, and for α∉2πZ\alpha \notin 2\pi\mathbb{Z} the Fourier series ln⁡∣1−eiα∣=−∑m≥1cos⁡mαm\ln |1 - e^{i\alpha}| = -\sum_{m \ge 1} \frac{\cos m\alpha}{m} holds, as the real part of ln⁡(1−z)=−∑mzm/m\ln(1 - z) = -\sum_m z^m / m on ∣z∣=1|z| = 1, z≠1z \ne 1, with convergence in L2(0,2π)L^2(0, 2\pi). So

ln⁡∣y−x∣=ln⁡R−∑m≥1cos⁡m(φ−θ)m.\ln |y - x| = \ln R - \sum_{m \ge 1} \frac{\cos m(\varphi - \theta)}{m}.

Multiply by −12πeikφR-\frac{1}{2\pi} e^{ik\varphi} R and integrate over φ∈(0,2π)\varphi \in (0, 2\pi); the L2L^2 convergence allows term by term integration against the bounded function eikφe^{ik\varphi}. For k=0k = 0 only the constant term remains, and it gives −12π⋅2πRln⁡R=−Rln⁡R-\frac{1}{2\pi} \cdot 2\pi R \ln R = -R \ln R. For k≠0k \ne 0 only the term m=∣k∣m = |k| remains, with ∫02πcos⁡(∣k∣(φ−θ))eikφ dφ=πeikθ\int_0^{2\pi} \cos(|k|(\varphi - \theta)) e^{ik\varphi} \, d\varphi = \pi e^{ik\theta}, which gives 12π⋅R∣k∣⋅πeikθ=R2∣k∣eikθ\frac{1}{2\pi} \cdot \frac{R}{|k|} \cdot \pi e^{ik\theta} = \frac{R}{2|k|} e^{ik\theta}. □\square

Theorem 1 (solvability on the circle and the degenerate scale). On the circle of radius RR, VV is injective on L2(Γ)L^2(\Gamma) if and only if R≠1R \ne 1. For R≠1R \ne 1 and the Dirichlet data gg, the equation Vq=12g+KgV q = \tfrac12 g + K g has the unique solution with the Fourier coefficients q^0=0\hat q_0 = 0 and q^k=∣k∣Rg^k\hat q_k = \frac{|k|}{R} \hat g_k for k≠0k \ne 0, which is the exact flux ∂u/∂n\partial u / \partial n.

Proof. By Lemma 2, VV multiplies the Fourier coefficient of index kk by R2∣k∣>0\frac{R}{2|k|} > 0 for k≠0k \ne 0 and by −Rln⁡R-R \ln R for k=0k = 0. A multiplier operator is injective if and only if no multiplier is zero, and −Rln⁡R=0-R \ln R = 0 exactly for R=1R = 1. For the right side, Lemma 2 gives 12g+Kg=12(g−gˉ)\tfrac12 g + K g = \tfrac12 (g - \bar g), whose coefficients are 00 for k=0k = 0 and 12g^k\tfrac12 \hat g_k for k≠0k \ne 0. Dividing by the multipliers gives the stated q^\hat q. The harmonic function with boundary values gg is u=∑kg^k(r/R)∣k∣eikθu = \sum_k \hat g_k (r/R)^{|k|} e^{ik\theta}, and ∂u/∂r\partial u / \partial r at r=Rr = R has the coefficients ∣k∣Rg^k\frac{|k|}{R} \hat g_k, so the solution is the exact flux. □\square

For g=x2−y2=R2cos⁡2θg = x^2 - y^2 = R^2 \cos 2\theta this gives q=2RR2cos⁡2θ=2Rcos⁡2θq = \frac{2}{R} R^2 \cos 2\theta = 2R \cos 2\theta, the value used in the test. For R=1R = 1, V1=0V 1 = 0, so the constant density is in the kernel and the Dirichlet problem cannot be solved through VV alone. This is the degenerate scale of the Pitfalls.

Theorem 2 (consistency of the collocation). Let Γ\Gamma be a smooth closed NURBS curve and let the collocation points xix_i be smooth points of Γ\Gamma. Suppose the exact solution has u∣Γ=∑jRju~ju|_\Gamma = \sum_j R_j \tilde u_j and q=∑jRjq~jq = \sum_j R_j \tilde q_j in the merged basis. If the matrix C=(Rj(τi))C = (R_j(\tau_i)) of line L8 and the matrix GG of line L9 are non-singular, and the integrals of lines L3 to L7 are exact, then IGABEM-DIRICHLET returns q=q~q = \tilde q.

Proof. Line L8 solves Cu=(g(xi))iC u = (g(x_i))_i. The vector u~\tilde u satisfies it, because g(xi)=u(xi)=∑jRj(τi)u~jg(x_i) = u(x_i) = \sum_j R_j(\tau_i) \tilde u_j, and CC is non-singular, so u=u~u = \tilde u. With exact integrals, row ii of Hu~H \tilde u is 12u(xi)+(Ku)(xi)\tfrac12 u(x_i) + (K u)(x_i) and row ii of Gq~G \tilde q is (Vq)(xi)(V q)(x_i), by linearity of the integrals in the coefficients. The boundary integral equation holds at every smooth point of Γ\Gamma, so Gq~=Hu~=HuG \tilde q = H \tilde u = H u. GG is non-singular, so line L9 returns q~\tilde q. □\square

On the circle, x=∑jRj(t)Xjx = \sum_j R_j(t) X_j and y=∑jRj(t)Yjy = \sum_j R_j(t) Y_j for the control points (Xj,Yj)(X_j, Y_j), because a NURBS curve is the weighted sum of its control points. The function u=ax+byu = a x + b y is harmonic, and its flux is q=(ax+by)/Rq = (a x + b y)/R by n=(x,y)/Rn = (x, y)/R. Both lie in the space, so Theorem 2 applies: the method returns the control values (aXj+bYj)/R(a X_j + b Y_j)/R of qq. The test checks this with a=1a = 1, b=2b = 2, R=2R = 2, where the only error left is that of the quadrature.

Corollary (constant data). For g=1g = 1 on any smooth closed curve, u=(1,…,1)u = (1, \ldots, 1) by the partition of unity, and with exact integrals (Hu)i=12+∫Γq∗(xi,y) dsy=0(H u)_i = \tfrac12 + \int_\Gamma q^*(x_i, y) \, ds_y = 0 by Lemma 1. So if GG is non-singular, q=0q = 0. ■\blacksquare

What is not proved here. The non-singularity of the discrete GG for R≠1R \ne 1 and the rate of convergence when qq is not in the spline space are not proved. The page measures an order of about 3 for the largest flux error and about 4 at an interior point, for quadratic NURBS on the circle.

Complexity

In the real RAM model, with nn unknowns, about nn elements and gg Gauss points per element:

  • Assembly. Each pair (collocation point, element) costs gg kernel evaluations, each adding to p+1p + 1 entries. The regular rules do not depend on the point, so the curve is evaluated once per element. The total is O(n2gp)O(n^2 g p), with two extra graded rules per row. The code evaluates full basis rows, an extra factor nn in that step, which is fine for the tests.
  • Solve. GG is dense and not symmetric, so Gaussian elimination costs O(n3)O(n^3) time and the matrices O(n2)O(n^2) space.

A 3D problem has nn unknowns on a surface, against about n3/2n^{3/2} for a volume mesh of the same resolution, but the dense matrix makes plain BEM cost O(n2)O(n^2) memory. Large problems use fast methods, such as the fast multipole method or hierarchical matrices, which reduce this to nearly O(n)O(n).

Properties

  • Exact geometry and boundary only. The analysis uses the CAD boundary without change. A trimmed CAD solid also only needs its boundary, see trimmed isogeometric analysis.
  • Dense, non-symmetric matrix. Every point sees every element.
  • Exterior problems (unbounded domains) need no truncation, because the fundamental solution has the right behavior at infinity.
  • Singular integrals. The diagonal blocks need special rules, and their accuracy limits the whole method.
  • Linear, constant coefficient equations only. The method needs a fundamental solution.

Variants and improvements

  • Galerkin BEM. Test the integral equation against the basis instead of collocating. The matrix of VV is then symmetric, and positive definite when the logarithmic capacity of Γ\Gamma is below 1 (for a circle, R<1R < 1), at the cost of double integrals.
  • Other equations. Elastostatics (Simpson and coauthors 2012), Helmholtz for acoustics, and Stokes flow, each with its fundamental solution.
  • T-spline and trimmed boundaries. 3D IGABEM works directly on T-spline surfaces and on trimmed NURBS surfaces.
  • Fast methods. Fast multipole methods and hierarchical matrices compress the dense blocks.

When to use it

Use it for linear problems with a known fundamental solution when the model comes from CAD and a volume mesh is costly: exterior acoustics and potential flow, electrostatics, and elasticity of solids when only the boundary is of interest. Use volume isogeometric or finite element analysis for nonlinear materials, variable coefficients and volume sources, which need a volume integral.

Pitfalls

  • The degenerate scale. In 2D, VV is not invertible when the logarithmic capacity of Γ\Gamma is 1, and for a circle that means R=1R = 1: then V1=−Rln⁡R=0V 1 = -R \ln R = 0. The test with R=1R = 1 shows that the constant vector is in the kernel of the discrete GG to 10−910^{-9}. Scale the geometry, or add the condition ∫Γq ds=0\int_\Gamma q \, ds = 0 with an extra unknown.
  • Singular quadrature. Plain Gauss on the element that holds the collocation point converges slowly on ln⁡∣t−τi∣\ln |t - \tau_i|. Use a graded rule, subtraction of the singularity, or a special log rule.
  • Points at corners. At a corner the free term is not 12\tfrac12 but the inner angle over 2π2\pi, and the normal jumps. Do not collocate at corners with the smooth formula, or move the point inside an element.
  • The seam of a closed curve. The parameter t=0t = 0 and t=1t = 1 are the same point. Merge the two basis functions and treat the singular element on both sides.
  • Nearly singular integrals. Interior points close to the boundary need refined rules, as in line L4.

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.

ig2kit.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Shared helper of the ig2 cad pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Small numerical helpers: B-spline basis with derivatives, Greville points,
Gauss-Legendre points and a dense linear solver.

Every function works with float, and the spline and solver functions also work
with fractions.Fraction, so that a test can check an exact identity.
"""

from __future__ import annotations

import math
from typing import List, Sequence, Tuple


def open_uniform_knots(p: int, ne: int, a=0, b=1) -> List:
    """Open knot vector of degree p with ne equal elements on [a, b].

    The ends have multiplicity p + 1 and the interior knots are simple.
    With Fraction inputs the knots are Fractions.
    """
    inner = [a + (b - a) * k / ne for k in range(1, ne)]
    return [a] * (p + 1) + inner + [b] * (p + 1)


def find_span(knots: Sequence, p: int, x) -> int:
    """Index s with knots[s] <= x < knots[s + 1], and the last non-empty span for x = knots[-1]."""
    n = len(knots) - p - 1  # number of basis functions
    if x >= knots[n]:
        s = n - 1
        while knots[s] == knots[s + 1]:
            s -= 1
        return s
    lo, hi = p, n
    while hi - lo > 1:
        mid = (lo + hi) // 2
        if x < knots[mid]:
            hi = mid
        else:
            lo = mid
    return lo


def basis_ders(knots: Sequence, p: int, s: int, x, nd: int) -> List[List]:
    """Values and derivatives of the p + 1 B-splines that are non-zero on span s.

    Returns d with d[k][j] = the k-th derivative of N_{s - p + j} at x, for
    k = 0..nd. This is algorithm A2.3 of Piegl and Tiller.
    """
    one = x - x + 1
    zero = x - x
    ndu = [[zero] * (p + 1) for _ in range(p + 1)]
    ndu[0][0] = one
    left = [zero] * (p + 1)
    right = [zero] * (p + 1)
    for j in range(1, p + 1):
        left[j] = x - knots[s + 1 - j]
        right[j] = knots[s + j] - x
        saved = zero
        for r in range(j):
            ndu[j][r] = right[r + 1] + left[j - r]
            temp = ndu[r][j - 1] / ndu[j][r]
            ndu[r][j] = saved + right[r + 1] * temp
            saved = left[j - r] * temp
        ndu[j][j] = saved
    ders = [[zero] * (p + 1) for _ in range(nd + 1)]
    for j in range(p + 1):
        ders[0][j] = ndu[j][p]
    for r in range(p + 1):
        s1, s2 = 0, 1
        a = [[zero] * (p + 1) for _ in range(2)]
        a[0][0] = one
        for k in range(1, nd + 1):
            dval = zero
            rk, pk = r - k, p - k
            if r >= k:
                a[s2][0] = a[s1][0] / ndu[pk + 1][rk]
                dval = a[s2][0] * ndu[rk][pk]
            j1 = 1 if rk >= -1 else -rk
            j2 = k - 1 if r - 1 <= pk else p - r
            for j in range(j1, j2 + 1):
                a[s2][j] = (a[s1][j] - a[s1][j - 1]) / ndu[pk + 1][rk + j]
                dval += a[s2][j] * ndu[rk + j][pk]
            if r <= pk:
                a[s2][k] = -a[s1][k - 1] / ndu[pk + 1][r]
                dval += a[s2][k] * ndu[r][pk]
            ders[k][r] = dval
            s1, s2 = s2, s1
    fac = p
    for k in range(1, nd + 1):
        for j in range(p + 1):
            ders[k][j] = ders[k][j] * fac
        fac *= p - k
    return ders


def all_basis(knots: Sequence, p: int, x, nd: int = 0) -> List[List]:
    """Full rows: out[k][i] = k-th derivative of N_i at x, for all n basis functions."""
    n = len(knots) - p - 1
    s = find_span(knots, p, x)
    d = basis_ders(knots, p, s, x, nd)
    zero = x - x
    out = [[zero] * n for _ in range(nd + 1)]
    for k in range(nd + 1):
        for j in range(p + 1):
            out[k][s - p + j] = d[k][j]
    return out


def greville(knots: Sequence, p: int) -> List:
    """Greville abscissae tau_i = (knots[i+1] + ... + knots[i+p]) / p."""
    n = len(knots) - p - 1
    return [sum(knots[i + 1 : i + p + 1]) / p for i in range(n)]


def solve_dense(a: List[List], b: List) -> List:
    """Solve a x = b by Gaussian elimination with partial pivoting.

    Works with float and with Fraction (then the result is exact).
    Raises ValueError if the matrix is singular (an exact zero pivot).
    Cost O(n^3) operations.
    """
    n = len(a)
    m = [list(row) + [bi] for row, bi in zip(a, b)]
    for c in range(n):
        piv = max(range(c, n), key=lambda r: abs(m[r][c]))
        if m[piv][c] == 0:
            raise ValueError("singular matrix")
        m[c], m[piv] = m[piv], m[c]
        for r in range(c + 1, n):
            f = m[r][c] / m[c][c]
            if f != 0:
                row_r, row_c = m[r], m[c]
                for k in range(c, n + 1):
                    row_r[k] -= f * row_c[k]
    x = [0] * n
    for r in range(n - 1, -1, -1):
        acc = m[r][n]
        for k in range(r + 1, n):
            acc -= m[r][k] * x[k]
        x[r] = acc / m[r][r]
    return x


def gauss_legendre(n: int) -> Tuple[List[float], List[float]]:
    """Nodes and weights of the n-point Gauss-Legendre rule on [-1, 1]."""
    xs, ws = [], []
    for i in range(1, n + 1):
        x = math.cos(math.pi * (i - 0.25) / (n + 0.5))
        for _ in range(100):
            p0, p1 = 1.0, x
            for k in range(2, n + 1):
                p0, p1 = p1, ((2 * k - 1) * x * p1 - (k - 1) * p0) / k
            dp = n * (x * p1 - p0) / (x * x - 1)
            dx = p1 / dp
            x -= dx
            if abs(dx) < 1e-16:
                break
        p0, p1 = 1.0, x
        for k in range(2, n + 1):
            p0, p1 = p1, ((2 * k - 1) * x * p1 - (k - 1) * p0) / k
        dp = n * (x * p1 - p0) / (x * x - 1)
        xs.append(x)
        ws.append(2.0 / ((1 - x * x) * dp * dp))
    return xs, ws
isogeometric_boundary_element_method.py 193 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/isogeometric-boundary-element-method/. The authors are listed in prov/JQY36Z.jsonl.
"""Isogeometric boundary element method for the 2D Laplace equation.

The boundary is a closed NURBS curve, counterclockwise, with an open knot
vector on [0, 1] whose first and last control points coincide. The same
NURBS basis, with the first and last functions merged into one, carries the
boundary values u and the normal derivatives q = du/dn. Collocation at the
images of the Greville abscissae gives the square system H u = G q of the
boundary integral equation

    (1/2) u(x) + int q*(x, y) u(y) ds_y = int u*(x, y) q(y) ds_y,

with u* = -(1/2 pi) ln r and q* = -(1/2 pi) (r . n_y) / r^2, r = y - x.
"""

from __future__ import annotations

import math
from typing import Callable, List, Sequence, Tuple

from ig2kit import all_basis, gauss_legendre, greville, solve_dense

Point = Tuple[float, float]


def circle_nurbs(radius: float, sx: float = 1.0, sy: float = 1.0):
    """Exact quadratic NURBS of the circle of this radius (an ellipse if sx != sy).

    Returns (degree, knots, control points, weights), counterclockwise from (radius sx, 0).
    """
    r = radius
    pts = [(r, 0), (r, r), (0, r), (-r, r), (-r, 0), (-r, -r), (0, -r), (r, -r), (r, 0)]
    pts = [(sx * x, sy * y) for x, y in pts]
    h = math.sqrt(0.5)
    w = [1, h, 1, h, 1, h, 1, h, 1]
    knots = [0, 0, 0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1, 1, 1]
    return 2, [float(k) for k in knots], [(float(x), float(y)) for x, y in pts], [float(v) for v in w]


def insert_knot(p: int, knots: List[float], pts: List[Point], w: List[float], t: float):
    """Boehm insertion of one knot t, done on the homogeneous points (w x, w y, w)."""
    k = max(i for i in range(len(knots) - 1) if knots[i] <= t < knots[i + 1])
    hom = [(wi * x, wi * y, wi) for (x, y), wi in zip(pts, w)]
    new = []
    for i in range(len(hom) + 1):
        if i <= k - p:
            new.append(hom[i])
        elif i >= k + 1:
            new.append(hom[i - 1])
        else:
            a = (t - knots[i]) / (knots[i + p] - knots[i])
            new.append(tuple(a * hom[i][c] + (1 - a) * hom[i - 1][c] for c in range(3)))
    knots = knots[: k + 1] + [t] + knots[k + 1 :]
    return knots, [(X / W, Y / W) for X, Y, W in new], [W for _, _, W in new]


def refine(p, knots, pts, w, per_span: int):
    """Insert per_span - 1 equally spaced knots in each non-empty knot span."""
    spans = [(knots[i], knots[i + 1]) for i in range(len(knots) - 1) if knots[i] < knots[i + 1]]
    for a, b in spans:
        for k in range(1, per_span):
            knots, pts, w = insert_knot(p, knots, pts, w, a + (b - a) * k / per_span)
    return knots, pts, w


class Curve:
    """A closed NURBS curve with the periodic (merged) basis."""

    def __init__(self, p, knots, pts, w):
        self.p, self.knots, self.pts, self.w = p, knots, pts, w
        self.n = len(pts) - 1  # number of unknowns after merging the first and the last function

    def eval(self, t: float):
        """(point, unit tangent speed |C'|, outward normal, merged basis row) at parameter t."""
        d = all_basis(self.knots, self.p, t, 1)
        wn = [wi * v for wi, v in zip(self.w, d[0])]
        wd = [wi * v for wi, v in zip(self.w, d[1])]
        W, Wd = sum(wn), sum(wd)
        R = [v / W for v in wn]
        Rd = [(a * W - b * Wd) / (W * W) for a, b in zip(wd, wn)]
        x = sum(r * P[0] for r, P in zip(R, self.pts))
        y = sum(r * P[1] for r, P in zip(R, self.pts))
        dx = sum(r * P[0] for r, P in zip(Rd, self.pts))
        dy = sum(r * P[1] for r, P in zip(Rd, self.pts))
        jac = math.hypot(dx, dy)
        row = R[:-1]
        row[0] += R[-1]
        return (x, y), jac, (dy / jac, -dx / jac), row

    def elements(self) -> List[Tuple[float, float]]:
        k = self.knots
        return [(k[i], k[i + 1]) for i in range(len(k) - 1) if k[i] < k[i + 1]]


def kernels(x: Point, y: Point, ny: Point) -> Tuple[float, float]:
    """(u*, q*) of the 2D Laplace equation for the source x and the field point y."""
    rx, ry = y[0] - x[0], y[1] - x[1]
    r2 = rx * rx + ry * ry
    return -math.log(r2) / (4 * math.pi), -(rx * ny[0] + ry * ny[1]) / (2 * math.pi * r2)


def _rule(a: float, b: float, gx, gw):
    return [(0.5 * (a + b) + 0.5 * (b - a) * s, 0.5 * (b - a) * v) for s, v in zip(gx, gw)]


def _graded(ts: float, d: float, m: int, gx, gw):
    """Rule on [ts, ts + d] (d of either sign) with t = ts + d w^m, w in (0, 1): it removes the log singularity at ts."""
    out = []
    for s, v in zip(gx, gw):
        u = 0.5 * (s + 1)
        out.append((ts + d * u**m, abs(d) * m * u ** (m - 1) * 0.5 * v))
    return out


def assemble(curve: Curve, ng: int = 12, ngs: int = 16, m: int = 4):
    """Collocation points and the matrices H and G of the boundary integral equation."""
    n = curve.n
    gx, gw = gauss_legendre(ng)
    sx, sw = gauss_legendre(ngs)
    tau = greville(curve.knots, curve.p)[:-1]  # @line L2
    src = [curve.eval(t) for t in tau]
    els = curve.elements()
    # The regular rule of each element does not depend on the source: evaluate it once.
    regular = [[(curve.eval(t), wt) for t, wt in _rule(a, b, gx, gw)] for a, b in els]
    H = [[0.0] * n for _ in range(n)]
    G = [[0.0] * n for _ in range(n)]
    for i, (ts, (xi, _, _, rowi)) in enumerate(zip(tau, src)):  # @line L3
        for e, (a, b) in enumerate(els):
            hits = [s for s in (ts, ts + 1.0) if a <= s <= b]
            if hits:  # @line L4
                s0 = hits[0]
                qu = []  # rule for u*: graded toward s0
                qq = []  # rule for q*: plain Gauss on both sides of s0
                for d in (a - s0, b - s0):
                    if d != 0:
                        qu += _graded(s0, d, m, sx, sw)
                        qq += _rule(s0, s0 + d, gx, gw) if d > 0 else _rule(s0 + d, s0, gx, gw)
                pts_u = [(curve.eval(t), wt) for t, wt in qu]
                pts_q = [(curve.eval(t), wt) for t, wt in qq]
            else:
                pts_u = pts_q = regular[e]  # @line L5
            for (y, jac, ny, row), wt in pts_u:
                us, _ = kernels(xi, y, ny)
                c = us * jac * wt
                for j, rj in enumerate(row):
                    if rj:
                        G[i][j] += c * rj  # @line L6
            for (y, jac, ny, row), wt in pts_q:
                _, qs = kernels(xi, y, ny)
                c = qs * jac * wt
                for j, rj in enumerate(row):
                    if rj:
                        H[i][j] += c * rj
        for j in range(n):
            H[i][j] += 0.5 * rowi[j]  # @line L7
    return tau, src, H, G


def solve_dirichlet(curve: Curve, g: Callable[[float, float], float], **quad):
    """Given u = g on the boundary, return (coefficients of u, coefficients of q, tau, src, H, G)."""
    n = curve.n  # @line L1
    tau, src, H, G = assemble(curve, **quad)
    C = [s[3] for s in src]
    u = solve_dense(C, [g(*s[0]) for s in src])  # @line L8
    rhs = [sum(H[i][j] * u[j] for j in range(n)) for i in range(n)]
    q = solve_dense(G, rhs)  # @line L9
    return u, q, tau, src, H, G


def flux_at(curve: Curve, q: Sequence[float], t: float) -> float:
    """q_h(t) = sum_j R_j(t) q_j."""
    return sum(r * c for r, c in zip(curve.eval(t)[3], q))


def interior_value(curve: Curve, u: Sequence[float], q: Sequence[float], x: Point, ng: int = 24) -> float:
    """Representation formula u(x) = int u* q - int q* u for an interior point x."""
    gx, gw = gauss_legendre(ng)
    total = 0.0
    for a, b in curve.elements():
        for t, wt in _rule(a, b, gx, gw):
            y, jac, ny, row = curve.eval(t)
            us, qs = kernels(x, y, ny)
            uh = sum(r * c for r, c in zip(row, u))
            qh = sum(r * c for r, c in zip(row, q))
            total += (us * qh - qs * uh) * jac * wt
    return total


def refined_circle(radius: float, per_span: int, sx: float = 1.0, sy: float = 1.0) -> Curve:
    p, k, P, w = circle_nurbs(radius, sx, sy)
    k, P, w = refine(p, k, P, w, per_span)
    return Curve(p, k, P, w)
test_isogeometric_boundary_element_method.py 95 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/isogeometric-boundary-element-method/. The authors are listed in prov/JQY36Z.jsonl.

import math
import random

from isogeometric_boundary_element_method import (
    flux_at,
    interior_value,
    refined_circle,
    solve_dirichlet,
)


def flux_error(curve, q, grad, samples=400):
    """Largest |q_h - dg/dn| over equally spaced parameters."""
    worst = 0.0
    for k in range(samples):
        t = k / samples
        (x, y), _, n, _ = curve.eval(t)
        gx, gy = grad(x, y)
        worst = max(worst, abs(flux_at(curve, q, t) - (gx * n[0] + gy * n[1])))
    return worst


def test_refined_geometry_is_exact() -> None:
    rng = random.Random(5)
    for per_span in (1, 3, 8):
        c = refined_circle(2.0, per_span)
        for _ in range(200):
            (x, y), _, n, row = c.eval(rng.random())
            assert abs(math.hypot(x, y) - 2.0) < 1e-12
            assert abs(n[0] * x + n[1] * y - 2.0) < 1e-12  # outward unit normal
            assert abs(sum(row) - 1.0) < 1e-12  # partition of unity of the merged basis


def test_single_layer_of_a_constant() -> None:
    """On a circle of radius R, int u*(x, y) ds_y = -R ln R for x on the circle."""
    for radius in (2.0, 0.5):
        c = refined_circle(radius, 4)
        _, _, _, _, _, G = solve_dirichlet(c, lambda x, y: 0.0)
        for row in G:
            assert abs(sum(row) + radius * math.log(radius)) < 1e-7


def test_degenerate_scale_radius_one() -> None:
    """Pitfall: for R = 1 the constant is in the kernel of the single layer, so G is (nearly) singular."""
    c = refined_circle(1.0, 4)
    _, _, _, _, _, G = solve_dirichlet(c, lambda x, y: 0.0)
    assert max(abs(sum(row)) for row in G) < 1e-7
    assert max(abs(v) for row in G for v in row) > 1e-2


def test_constant_data_gives_zero_flux() -> None:
    c = refined_circle(2.0, 4)
    _, q, _, _, _, _ = solve_dirichlet(c, lambda x, y: 1.0)
    assert max(abs(v) for v in q) < 1e-7


def test_exact_when_data_and_flux_are_in_the_space() -> None:
    """u = x + 2 y on the circle of radius 2 has q = (x + 2 y) / 2, and both are NURBS of the basis."""
    for per_span in (1, 2, 4):
        c = refined_circle(2.0, per_span)
        u, q, _, _, _, _ = solve_dirichlet(c, lambda x, y: x + 2 * y)
        for uj, qj, (px, py) in zip(u, q, c.pts):
            assert abs(uj - (px + 2 * py)) < 1e-12
            assert abs(qj - (px + 2 * py) / 2) < 1e-7  # only the quadrature error is left


def test_circle_against_exact_solution() -> None:
    """u = x^2 - y^2 on the circle of radius 2: q = 2 R cos(2 theta)."""
    g = lambda x, y: x * x - y * y
    grad = lambda x, y: (2 * x, -2 * y)
    errs = []
    for per_span in (4, 8, 16):
        c = refined_circle(2.0, per_span)
        u, q, _, _, _, _ = solve_dirichlet(c, g)
        errs.append(flux_error(c, q, grad))
        if per_span == 8:
            assert abs(interior_value(c, u, q, (0.5, 0.3)) - 0.16) < 1e-5
    assert errs[1] < 3e-3
    rates = [math.log2(errs[k] / errs[k + 1]) for k in range(2)]
    assert all(r > 2.7 for r in rates), rates


def test_ellipse_against_exact_solution() -> None:
    g = lambda x, y: x * x - y * y + 0.5 * x * y + x
    grad = lambda x, y: (2 * x + 0.5 * y + 1, -2 * y + 0.5 * x)
    errs = []
    for per_span in (4, 8):
        c = refined_circle(2.0, per_span, 1.0, 0.75)
        u, q, _, _, _, _ = solve_dirichlet(c, g)
        errs.append(flux_error(c, q, grad))
    assert errs[1] < 5e-3 and errs[0] / errs[1] > 6
    assert abs(interior_value(c, u, q, (0.5, 0.3)) - g(0.5, 0.3)) < 1e-4

History

Boundary integral equations for potential problems go back to the nineteenth century, and the boundary element method as a numerical method developed from the 1960s. Politis, Ginnis, Kaklis, Belibassakis and Feurer (2009) used the NURBS basis of the boundary curve for a 2D exterior potential flow BEM. Simpson, Bordas, Trevelyan and Rabczuk (2012) gave a 2D IGABEM for elastostatics with collocation at the Greville abscissae, and later work extended the idea to 3D with T-splines and to trimmed surfaces. Marussig and Hughes (2018) list boundary methods among the ways to analyze trimmed CAD models without a volume parameterization.

References

  1. R. N. Simpson, S. P. A. Bordas, J. Trevelyan and T. Rabczuk, A two-dimensional isogeometric boundary element method for elastostatic analysis, Computer Methods in Applied Mechanics and Engineering 209-212, 2012, 87 to 100, the whole paper (the NURBS basis of the boundary for both the geometry and the fields, collocation at the Greville abscissae, the singular integrals and the comparison with Lagrange BEM)
  2. C. Politis, A. I. Ginnis, P. D. Kaklis, K. Belibassakis and C. Feurer, An isogeometric BEM for exterior potential-flow problems in the plane, 2009 SIAM/ACM Joint Conference on Geometric and Physical Modeling, 2009, 349 to 354, the whole paper, the first use of the NURBS basis of the boundary in a BEM
  3. T. J. R. Hughes, J. A. Cottrell and Y. Bazilevs, Isogeometric analysis, CAD, finite elements, NURBS, exact geometry and mesh refinement, Computer Methods in Applied Mechanics and Engineering 194(39-41), 2005, 4135 to 4195, the isogeometric idea of one basis for geometry and analysis, and the NURBS circle
  4. B. Marussig and T. J. R. Hughes, A review of trimming in isogeometric analysis, challenges, data exchange and simulation aspects, Archives of Computational Methods in Engineering 25(4), 2018, 1059 to 1127, the part on boundary methods, which need only the boundary representation of a trimmed CAD model

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.worst
  • 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