Techniqueadvanced
Bezier extraction
Also called Bezier extraction operator.
Write the B-splines or NURBS on each element as N = C^e B, a small matrix times the Bernstein polynomials, so a standard finite element code can run isogeometric analysis.
Bezier extraction writes the B-splines of degree that are nonzero on one element as linear combinations of the Bernstein polynomials of that element. For the element it gives a matrix , the element extraction operator, with , where is the vector of the local B-splines and the vector of Bernstein polynomials in the local parameter . The Bernstein polynomials are the same on every element, so a finite element code can treat them as the shape functions of one reference element. The matrices carry all the information about the knots, and the usual element loop, assembly with a connectivity array and Gauss quadrature stay as they are. Borden, Scott, Evans and Hughes introduced this form for NURBS in 2011, and Scott and coauthors applied it to T-splines in the same year.
The notation is the one of the B-spline page: a clamped knot vector (here 1-based, as in the paper), degree , functions , and elements the nonempty spans . On the element with span only are nonzero, and they are the rows of in this order. The local parameter is . Borden and coauthors use the parent element . The matrix is the same for both choices, since only the parameter of changes.
In plain words
A spline is made of polynomial pieces, and each piece of each basis function is a polynomial on one element. A finite element code likes to use the same few polynomials on every element, the shape functions of a standard element. Bezier extraction finds, for each element, a small table of numbers that says how much of each standard polynomial each spline function contains there. The code keeps one table per element. It evaluates the standard polynomials once, multiplies by the table, and gets the spline functions. Everything else in the code, the loop over elements, the integration and the assembly, does not change. The tables come from cutting the spline into pieces at its knots, which is an exact operation.
When it applies
- You want to run isogeometric analysis inside an existing finite element code, with an element loop, element matrices and assembly by a connectivity array.
- The basis is a B-spline or NURBS basis, a tensor product of them, or a T-spline (with a different way to compute , see Variations). The basis must be piecewise polynomial on the elements, or a ratio of such functions.
- You evaluate the basis at many points per element, so the cost of the Bernstein values (shared by all elements of the same degree) and one small matrix product is lower than the Cox-de Boor recursion at each point.
- It is also the input format of Bezier based tools: element by element export of a spline model, Bezier projection and some refinement codes.
The template
The operators come from knot insertion. Insert each interior knot until it has multiplicity . Then each element has its own control points, the Bezier points of that piece. The loop below is the one-pass algorithm of Borden and coauthors. It does the insertions for one element at a time, on the matrix instead of on control points, and copies the overlap with the next element into the next operator. Here is a list of numbers, and "column " is a column of .
BEZIER-EXTRACT(u_1..u_m, p) ▷ clamped knots, interior multiplicities ≤ p- 1
a ← p + 1; b ← a + 1; e ← 1; C^1 ← I - 2
while b < m: - 3
C^{e+1} ← I; i ← b - 4
while b < m and u_{b+1} = u_b: b ← b + 1 - 5
mult ← b − i + 1 ▷ multiplicity of the knot u_b - 6
if mult < p: - 7
for j = p down to mult + 1: α_{j−mult} ← (u_b − u_a)/(u_{a+j} − u_a) - 8
r ← p − mult ▷ number of insertions of u_b - 9
for j = 1 to r: - 10
s ← mult + j - 11
for k = p + 1 down to s + 1: column k ← α_{k−s} · column k + (1 − α_{k−s}) · column k − 1 - 12
if b < m: rows r−j+1 .. r+1 of column r−j+1 of C^{e+1} ← rows p−j+1 .. p+1 of column p+1 of C^e - 13
e ← e + 1 - 14
if b < m: a ← b; b ← b + 1 - 15
return C^1, ..., C^{e−1}
Why . Let be the knot vector with every interior knot of multiplicity , and let be its B-splines. Knot insertion gives a matrix of size with the property: for every set of control points , the control points on of the same curve are . So for all . Take to be the unit vectors: , or . On each element has its own block of functions , and on the element they are the Bernstein polynomials in , because a B-spline whose knots are only the two ends of one element, each repeated, is a Bernstein polynomial. All other are zero on the element. Restrict to the element: , where is the block of with the rows of the functions that are nonzero on and the columns of the Bezier functions of . The algorithm computes these blocks. Line L11 is Boehm's formula for the new control points, applied to the columns, because the columns of are the coefficients of the current control points in terms of the original ones. Line L12 copies the new points that also belong to the next element.
Properties. Each column of sums to 1, because and on the element (partition of unity), and the Bernstein polynomials are linearly independent. The entries are nonnegative, because Boehm's coefficients are convex combinations. is invertible: both and are bases of the polynomials of degree on the element (the local B-splines are linearly independent there by the Curry-Schoenberg theorem on one span). The Bezier control points of the element are , where are the local control points, since .
NURBS. With weights for the local functions, the NURBS basis on the element is , where is the weight function in Bernstein form. So the same serves both the B-splines and the NURBS.
Tensor products. On a tensor product patch the element operator is the Kronecker product of the one-dimensional operators of the two (or three) directions, in the order that matches the numbering of the local functions.
Classic examples
A cubic with simple knots. Take and , so 7 functions and 4 elements. The algorithm gives
and , are , with the rows and the columns in reverse order. Here are the cubic Bernstein polynomials. Row 2 of says on . At , and , the value the Cox-de Boor recursion gives. The first column of holds the values of the local functions at the left end of the element, since only is nonzero at , and the last column holds the values at the right end. So the last column of is . In a longer uniform knot vector every interior element has the operator with first column and the same other columns as .
A quadratic. For and :
With the control points , the Bezier points of element 2 are .
Element routine. At a quadrature point of element the code does:
- take and from a table built once for degree ;
- form and , then the NURBS values with the weights;
- map with the geometry, , and build the element matrix as for any finite element;
- assemble with the connectivity array (IEN), the list of the global numbers of the local functions.
Variations
- T-splines and other local refinement. Scott, Borden, Verhoosel, Sederberg and Hughes (2011) extract T-splines: each blending function has its own local knot vectors, and the operator of an element is found by knot insertion into each function separately. The element operators are then rectangular in general, since the number of functions on an element is not fixed. The same idea is used for hierarchical and THB-splines and for LR B-splines.
- Global form. All the blocks together are , the transpose of the knot refinement matrix to the Bezier knot vector. It can also be computed with the Oslo algorithm.
- Inverse operators. maps Bernstein coefficients back to B-spline coefficients on one element. Bezier projection uses it to project a function element by element and then averages the results.
- Lagrange extraction. Instead of Bernstein polynomials, use the Lagrange polynomials of the element, so that an existing Lagrange element can be reused. The matrix is then times the change of basis from Bernstein to Lagrange.
Pitfalls
- Zero length elements. Repeated knots make spans of zero length. They are not elements, and the algorithm skips them in L4. A code that numbers elements by knot index gets empty elements and wrong connectivity.
- Discontinuous knots. As written, the algorithm assumes interior multiplicity at most , so the curve is at least. A knot of multiplicity breaks the overlap in L12 and needs its own handling.
- Parent domain. is the same on and , but the derivative gets a factor on , and the Jacobian of the map from the parent element to the element is instead of . Mixing the two conventions gives wrong element matrices.
- The weights are not in . For NURBS the weights enter in a separate step. The rational basis is not a linear combination of Bernstein polynomials with constant coefficients, so a code that uses as the shape functions of a NURBS model computes with the wrong basis.
- Storage. For a uniform knot vector the interior elements have the same . A code that stores one matrix per element can share them, which saves memory for large tensor product models.
Code
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/bezier-extraction/. The authors are listed in prov/5HN7GF.jsonl.
"""Bezier extraction of a clamped B-spline basis, after Borden, Scott, Evans and Hughes.
extract(U, p) returns one (p+1) x (p+1) matrix C^e per element. Row a of C^e
gives the local B-spline N_{k-p+a} (k the span of the element) as a
combination of the p + 1 Bernstein polynomials of the element:
N^e(u) = C^e B(s), s = (u - u_left) / (u_right - u_left).
The loop follows Algorithm 1 of the paper, with 1-based indices inside.
"""
from fractions import Fraction
from math import comb
def identity(n):
return [[Fraction(int(i == j)) for j in range(n)] for i in range(n)]
def extract(U, p):
"""Element extraction operators of a clamped knot vector U of degree p."""
m = len(U)
u = [None] + [Fraction(x) for x in U] # u[1..m]
one = lambda: [[None] * (p + 2)] + [[None] + row for row in identity(p + 1)]
a, b, nb = p + 1, p + 2, 1 # @line L1
C = {1: one()}
alphas = [None] * (p + 2)
while b < m: # @line L2
C[nb + 1] = one() # @line L3
i = b
while b < m and u[b + 1] == u[b]: # @line L4
b += 1
mult = b - i + 1 # @line L5
if mult < p: # @line L6
numer = u[b] - u[a]
for j in range(p, mult, -1): # @line L7
alphas[j - mult] = numer / (u[a + j] - u[a])
r = p - mult # @line L8
for j in range(1, r + 1): # @line L9
save = r - j + 1
s = mult + j # @line L10
for k in range(p + 1, s, -1): # @line L11
al = alphas[k - s]
for row in range(1, p + 2):
C[nb][row][k] = al * C[nb][row][k] + (1 - al) * C[nb][row][k - 1]
if b < m: # @line L12
for t in range(j + 1):
C[nb + 1][save + t][save] = C[nb][p - j + 1 + t][p + 1]
nb += 1 # @line L13
if b < m: # @line L14
a, b = b, b + 1
return [[row[1:] for row in C[e][1:]] for e in range(1, nb)] # @line L15
def elements(U):
"""The nonempty knot spans [u_k, u_{k+1}) with their span index k."""
return [(k, U[k], U[k + 1]) for k in range(len(U) - 1) if U[k] < U[k + 1]]
def bernstein(p, s):
return [comb(p, j) * s**j * (1 - s) ** (p - j) for j in range(p + 1)]
def local_basis(Ce, p, s):
"""N^e = C^e B(s) for the local parameter s in [0, 1]."""
B = bernstein(p, s)
return [sum(c * x for c, x in zip(row, B)) for row in Ce]
def rational_local_basis(Ce, w, p, s):
"""NURBS: R^e = W^e C^e B / W with the weight function W = (C^e^T w) . B."""
N = local_basis(Ce, p, s)
W = sum(wa * na for wa, na in zip(w, N))
return [wa * na / W for wa, na in zip(w, N)]
def bezier_points(Ce, P):
"""Bezier control points of an element: (C^e)^T applied to the local points."""
n = len(Ce)
return [tuple(sum(Ce[a][j] * P[a][c] for a in range(n)) for c in range(len(P[0]))) for j in range(n)]
test_bezier_extraction.py 130 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/bezier-extraction/. The authors are listed in prov/5HN7GF.jsonl.
import random
from fractions import Fraction as F
from bezier_extraction import bezier_points, elements, extract, local_basis, rational_local_basis
def cox_de_boor(t, i, p, u):
"""N_{i,p}(u) by the recursion, on half-open spans."""
if p == 0:
return F(int(t[i] <= u < t[i + 1]))
s = F(0)
if t[i + p] > t[i]:
s += (u - t[i]) / (t[i + p] - t[i]) * cox_de_boor(t, i, p - 1, u)
if t[i + p + 1] > t[i + 1]:
s += (t[i + p + 1] - u) / (t[i + p + 1] - t[i + 1]) * cox_de_boor(t, i + 1, p - 1, u)
return s
def random_knots(rng, p):
U = [F(0)] * (p + 1)
for x in range(1, rng.randint(2, 6)):
U += [F(x)] * rng.randint(1, p)
end = U[-1] + 1
return U + [end] * (p + 1)
def insert(t, p, P, x):
"""Boehm insertion on coefficient vectors (dicts), used as the reference."""
k = max(i for i in range(len(t) - 1) if t[i] <= x < t[i + 1])
Q = []
for i in range(len(P) + 1):
if i <= k - p:
Q.append(P[i])
elif i > k:
Q.append(P[i - 1])
else:
a = (x - t[i]) / (t[i + p] - t[i])
Q.append({j: (1 - a) * P[i - 1].get(j, 0) + a * P[i].get(j, 0) for j in set(P[i]) | set(P[i - 1])})
return t[: k + 1] + [x] + t[k + 1 :], Q
def global_extraction(U, p):
"""Reference: insert every interior knot up to multiplicity p over the whole basis."""
n = len(U) - p - 1
t, Q = list(U), [{i: F(1)} for i in range(n)]
for x in sorted(set(U))[1:-1]:
while t.count(x) < p:
t, Q = insert(t, p, Q, x)
out = []
for e, (k, _, _) in enumerate(elements(U)):
rows = range(k - p, k + 1)
out.append([[Q[e * p + j].get(i, F(0)) for j in range(p + 1)] for i in rows])
return out
def test_paper_example():
C = extract([0, 0, 0, 0, 1, 2, 3, 4, 4, 4, 4], 3)
assert len(C) == 4
assert C[0] == [[1, 0, 0, 0], [0, 1, F(1, 2), F(1, 4)], [0, 0, F(1, 2), F(7, 12)], [0, 0, 0, F(1, 6)]]
assert C[1] == [[F(1, 4), 0, 0, 0], [F(7, 12), F(2, 3), F(1, 3), F(1, 6)], [F(1, 6), F(1, 3), F(2, 3), F(2, 3)], [0, 0, 0, F(1, 6)]]
assert C[3] == [list(reversed(r)) for r in reversed(C[0])]
def test_against_cox_de_boor():
rng = random.Random(7)
for p in (1, 2, 3, 4):
for _ in range(3):
U = random_knots(rng, p)
C = extract(U, p)
spans = elements(U)
assert len(C) == len(spans)
for Ce, (k, lo, hi) in zip(C, spans):
for s in [F(0), F(1, 3), F(1, 2), F(5, 7), F(rng.randint(1, 99), 100)]:
u = lo + s * (hi - lo)
want = [cox_de_boor(U, i, p, u) for i in range(k - p, k + 1)]
assert local_basis(Ce, p, s) == want
def test_against_global_knot_insertion():
rng = random.Random(8)
for p in (1, 2, 3, 4):
for _ in range(3):
U = random_knots(rng, p)
assert extract(U, p) == global_extraction(U, p)
def test_columns_sum_to_one_and_entries_nonnegative():
rng = random.Random(9)
for p in (2, 3, 5):
U = random_knots(rng, p)
for Ce in extract(U, p):
for j in range(p + 1):
assert sum(Ce[a][j] for a in range(p + 1)) == 1
assert all(x >= 0 for row in Ce for x in row)
def test_bezier_points_give_the_curve():
rng = random.Random(10)
p = 3
U = random_knots(rng, p)
n = len(U) - p - 1
P = [(F(rng.randint(-5, 5)), F(rng.randint(-5, 5))) for _ in range(n)]
for Ce, (k, lo, hi) in zip(extract(U, p), elements(U)):
Bz = bezier_points(Ce, P[k - p : k + 1])
for s in (F(0), F(1, 4), F(2, 3)):
u = lo + s * (hi - lo)
want = tuple(sum(cox_de_boor(U, i, p, u) * P[i][c] for i in range(n)) for c in range(2))
# de Casteljau on the Bezier points
pts = [list(q) for q in Bz]
for r in range(1, p + 1):
pts = [[(1 - s) * x + s * y for x, y in zip(pts[j], pts[j + 1])] for j in range(p + 1 - r)]
assert tuple(pts[0]) == want
def test_rational_basis():
p = 2
U = [0, 0, 0, 1, 2, 2, 2]
w = [F(1), F(1, 2), F(2), F(1)]
for Ce, (k, lo, hi) in zip(extract(U, p), elements(U)):
for s in (F(0), F(1, 5), F(1, 2), F(1)):
u = lo + s * (hi - lo)
N = [cox_de_boor(U, i, p, u) if u < 2 else F(int(i == 3)) for i in range(4)]
W = sum(wi * ni for wi, ni in zip(w, N))
want = [w[i] * N[i] / W for i in range(k - p, k + 1)]
if u < 2:
assert rational_local_basis(Ce, w[k - p : k + 1], p, s) == want
assert sum(rational_local_basis(Ce, w[k - p : k + 1], p, s)) == 1
Exercises
- Compute the extraction operators for and . Explain why and are both identity matrices.
- Prove that the first column of the operator of an interior element in a uniform cubic knot vector is , the values of the uniform cubic B-splines at a knot.
- Show that , where is the length of the element. Use .
- Write the extraction operator of a tensor product element with on the knot vectors of the quadratic example in both directions, for the element . Check that its columns sum to 1.
- For a circle written as a quadratic NURBS with 9 control points and knots , show that every is the identity, and explain why.
References
- M. J. Borden, M. A. Scott, J. A. Evans and T. J. R. Hughes, Isogeometric finite element data structures based on Bézier extraction of NURBS, International Journal for Numerical Methods in Engineering 87(1-5), 2011, 15 to 47, the whole paper, the extraction operator in one dimension with its knot insertion algorithm, the tensor product case and the NURBS case
- M. A. Scott, M. J. Borden, C. V. Verhoosel, T. W. Sederberg and T. J. R. Hughes, Isogeometric finite element data structures based on Bézier extraction of T-splines, International Journal for Numerical Methods in Engineering 88(2), 2011, 126 to 156, the whole paper, extraction for T-splines
- J. A. Cottrell, T. J. R. Hughes and Y. Bazilevs, Isogeometric Analysis, Toward Integration of CAD and FEA, Wiley, 2009, Chapter 3 (NURBS as a basis for analysis, p. 69) and Appendix A (connectivity arrays, p. 313)
- Les Piegl and Wayne Tiller, The NURBS Book, 2nd edition, Springer, 1997, Chapter 5, the decomposition of a B-spline curve into Bezier pieces by knot insertion
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W3 standard |
|
Tag 5HN7GF Edit this page History Report an error Markdown