Algorithm Search⌘K

Data structureadvanced

Hierarchical B-spline

Also called HB-spline.

Forsey and Bartels's spline built from nested levels of B-spline bases chosen by refinement regions, used by Vuong and coauthors for adaptive analysis.

Time
O(N p^2) worst · average · best
Space
O(k) extra
Where
N = the number of tensor B-splines of all levels together; k = the number of selected basis functions; p = the degree
Properties
deterministiciterative
Origin
David R. Forsey, Richard H. Bartels, 1988

A hierarchical B-spline space is built from a sequence of nested tensor product B-spline spaces, one per level, each finer than the last, and a nested sequence of domains Ω0⊇Ω1⊇⋯\Omega^0 \supseteq \Omega^1 \supseteq \cdots. The basis takes, from each level ℓ\ell, the B-splines whose support lies inside Ωℓ\Omega^\ell but not inside Ωℓ+1\Omega^{\ell+1}. So the functions are coarse where the domains stop and fine where they go on. Forsey and Bartels introduced hierarchical refinement in 1988 to edit surfaces locally. Kraft's selection rule of 1997 makes the functions linearly independent, and Vuong, Giannelli, Jüttler and Simeon used it in 2011 for adaptive isogeometric analysis.

In plain words

Start with a coarse grid of smooth bumps that covers the whole surface. In the places where you need more detail, mark a region and lay a second grid of bumps there, with half the spacing. Inside a smaller region you can lay a third grid, and so on.

You cannot keep every bump of every grid, because a coarse bump that sits inside a fine region is then just a sum of fine bumps. So the rule is: keep a bump of a grid if it fits inside the region of its own grid, and drop it if it fits inside the region of the next, finer grid.

The bumps that remain are independent, and together they can make every shape that the grids can make. They do not add up to 1.

The abstract type

A hierarchical B-spline space of degree pp with LL levels stores, for each level ℓ\ell, a tensor product knot vector and a domain Ωℓ\Omega^\ell. The operations are:

  • BASIS: the list of selected B-splines, as pairs (level, index).
  • EVALUATE(c,x,y)(c, x, y): the value ∑cββ(x,y)\sum c_\beta \beta(x, y) of a function given by coefficients on the selected B-splines.
  • REFINE(ℓ,R)(\ell, R): add a region RR to Ωℓ\Omega^\ell, where RR is a union of cells of level ℓ−1\ell - 1 inside Ωℓ−1\Omega^{\ell-1}.
  • FINEST(β)(\beta): the coefficients of a selected B-spline in the tensor B-splines of the finest level, by the two-scale relation.

Representation

Level ℓ\ell has, in each direction, the open uniform knot vector of degree pp on [0,n0][0, n_0] with spacing 2−ℓ2^{-\ell}: p+1p + 1 copies of 0, the points a 2−ℓa\, 2^{-\ell}, and p+1p + 1 copies of n0n_0. Its knots contain those of level ℓ−1\ell - 1, so by knot refinement each B-spline of level ℓ\ell is a combination of B-splines of level ℓ+1\ell + 1, the two-scale relation. A cell of level ℓ\ell is a square of side 2−ℓ2^{-\ell} between grid lines. The B-spline NiℓN^\ell_i is nonzero on the cells max⁡(i−p,0),…,min⁡(i,n02ℓ−1)\max(i - p, 0), \ldots, \min(i, n_0 2^\ell - 1) in each direction.

Each domain Ωℓ\Omega^\ell is a set of cells of level ℓ\ell, with Ω0\Omega^0 the whole square, Ωℓ\Omega^\ell a union of cells of level ℓ−1\ell - 1, and Ωℓ⊆Ωℓ−1\Omega^\ell \subseteq \Omega^{\ell-1}. Set ΩL=∅\Omega^L = \emptyset. "The support of β\beta lies in Ω\Omega" means that every cell of the support is a cell of Ω\Omega. The two-scale coefficients are stored as one sparse matrix per level and direction, computed once by Boehm insertion of all the midpoints.

Operations

  1. BASIS(levels, Ω) ▷ Kraft's selection
  2. 1for ℓ ← 0 to L − 1 do
  3. 2for each tensor B-spline β of level ℓ do
  4. 3if supp β ⊆ Ω^ℓ and not supp β ⊆ Ω^(ℓ+1) then
  5. 4add (ℓ, β) to H
  1. EVALUATE(c, x, y)
  2. 1s ← 0
  3. 2for each (ℓ, (i, j)) with coefficient c in the list do
  4. 3s ← s + c · N^ℓ_i(x) · N^ℓ_j(y) ▷ Cox-de Boor on the knots of level ℓ
  5. 4return s

REFINE adds the four children of each given cell to Ωℓ\Omega^\ell and checks that the cell is in Ωℓ−1\Omega^{\ell-1}; then BASIS runs again. FINEST applies the two-scale matrices of the levels ℓ,…,L−2\ell, \ldots, L - 2 to each index and multiplies the two results.

Example

Take p=2p = 2, n0=4n_0 = 4 and three levels, with Ω1=[0,2]2\Omega^1 = [0, 2]^2 and Ω2=[0,1]2\Omega^2 = [0, 1]^2. Level 0 has 6×6=366 \times 6 = 36 biquadratic B-splines. The four with i,j≤1i, j \le 1 have their support inside [0,2]2[0, 2]^2, so they are dropped, and 32 remain. Level 1 has 10×1010 \times 10 B-splines; the 16 with i,j≤3i, j \le 3 lie in Ω1\Omega^1, and 4 of them, with i,j≤1i, j \le 1, lie in Ω2\Omega^2, so 12 are kept. Level 2 keeps the 16 B-splines that lie in [0,1]2[0, 1]^2. The basis has 32+12+16=6032 + 12 + 16 = 60 functions, and their expansions in the finest level have rank 60.

The functions are not a partition of unity. At (12,12)(\tfrac12, \tfrac12) their sum is 12764\tfrac{127}{64}, because there the kept functions of all three levels overlap. Far from the refined region, at (3,3)(3, 3), only level 0 functions are nonzero, and the sum is 1. The constant 1 is still in the space, with other coefficients, because the space contains all the level 0 B-splines.

Correctness

The two-scale relation writes a B-spline of level ℓ\ell as a nonnegative combination of B-splines of level ℓ+1\ell + 1 whose supports lie inside its own. From this, by induction from the finest level down, every B-spline of level ℓ\ell whose support lies in Ωℓ\Omega^\ell is in the span of the selected functions: either the rule selects it, or its support lies in Ωℓ+1\Omega^{\ell+1} and its children do. Two facts follow. The space contains the whole level 0 spline space, and enlarging the domains gives a larger space, so refinement is nested. The selected functions are linearly independent: on a cell of Ωℓ\Omega^\ell outside Ωℓ+1\Omega^{\ell+1} only functions of levels up to ℓ\ell are nonzero, and B-splines of one level are linearly independent on each cell. The proofs are in the correctness proof.

Proof: Kraft's hierarchical basis is linearly independent, contains each level on its domain, and gives nested spacesfull

We use the representation of the page. Level ℓ\ell has the tensor B-splines β=Niℓ(x)Njℓ(y)\beta = N^\ell_i(x) N^\ell_j(y) of degree pp on the knot vector of level ℓ\ell, and its cells are the squares of side 2−ℓ2^{-\ell}. The support cells of β\beta are the cells of level ℓ\ell on which β\beta is not identically zero; they form a rectangle, and β>0\beta > 0 in the interior of each of them. The domains satisfy Ω0=[0,n0]2\Omega^0 = [0, n_0]^2, Ωℓ⊆Ωℓ−1\Omega^{\ell} \subseteq \Omega^{\ell-1}, each Ωℓ\Omega^\ell is a union of cells of level ℓ−1\ell - 1, and ΩL=∅\Omega^L = \emptyset. "β⊆Ω\beta \subseteq \Omega" means that all support cells of β\beta lie in Ω\Omega. HH is the output of lines L1 to L4, HℓH^\ell its functions of level ℓ\ell, and S(H)S(H) their span.

Lemma 1 (local linear independence). For a cell QQ of level ℓ\ell, the B-splines of level ℓ\ell that are not zero on QQ are linearly independent as functions on QQ.

Proof. In one direction, the p+1p + 1 B-splines of degree pp that are nonzero on a knot interval span the polynomials of degree at most pp there, a space of dimension p+1p + 1, by the Curry-Schoenberg theorem restricted to one interval; so they are independent on it. The tensor products of two independent families on two intervals are independent on the rectangle: if ∑ijcijNi(x)Nj(y)=0\sum_{ij} c_{ij} N_i(x) N_j(y) = 0, then for each yy the coefficients ∑jcijNj(y)\sum_j c_{ij} N_j(y) vanish, and then each cij=0c_{ij} = 0. □\square

Lemma 2 (two-scale relation). Each β\beta of level ℓ<L−1\ell < L - 1 is ∑γcγγ\sum_\gamma c_\gamma \gamma over B-splines γ\gamma of level ℓ+1\ell + 1 with cγ≥0c_\gamma \ge 0, and every γ\gamma with cγ≠0c_\gamma \ne 0 has its support inside the support of β\beta.

Proof. Work in one direction; the tensor product of the two directions then gives the claim. The knots of level ℓ+1\ell + 1 contain those of level ℓ\ell, so inserting the new knots one at a time by Boehm's rule writes NiℓN^\ell_i in the B-splines of level ℓ+1\ell + 1. Each new coefficient is αck+(1−α)ck−1\alpha c_k + (1 - \alpha) c_{k-1} with 0≤α≤10 \le \alpha \le 1, and the start vector is a unit vector, so all coefficients are nonnegative. The support [a,b][a, b] of NiℓN^\ell_i runs between two knots of level ℓ\ell, which are knots of level ℓ+1\ell + 1, so [a,b][a, b] is a union of fine knot intervals. A fine B-spline γ\gamma whose support is not inside [a,b][a, b] is nonzero on some fine interval II outside [a,b][a, b]. On II the sum ∑cγγ\sum c_\gamma \gamma equals Niℓ=0N^\ell_i = 0, and the fine B-splines that are nonzero on II are independent there by Lemma 1, so cγ=0c_\gamma = 0. □\square

Lemma 3 (each level on its domain). Every B-spline β\beta of level ℓ\ell with β⊆Ωℓ\beta \subseteq \Omega^\ell lies in S(H)S(H).

Proof. By downward induction on ℓ\ell. If β⊈Ωℓ+1\beta \not\subseteq \Omega^{\ell+1}, line L3 selects β\beta. This always happens for ℓ=L−1\ell = L - 1, since ΩL\Omega^L is empty. Otherwise β⊆Ωℓ+1\beta \subseteq \Omega^{\ell+1} and ℓ+1≤L−1\ell + 1 \le L - 1. By Lemma 2, β=∑cγγ\beta = \sum c_\gamma \gamma with each γ\gamma of level ℓ+1\ell + 1 and support inside that of β\beta, so γ⊆Ωℓ+1\gamma \subseteq \Omega^{\ell+1}, and by induction γ∈S(H)\gamma \in S(H). So β∈S(H)\beta \in S(H). □\square

Theorem 1 (linear independence). The functions of HH are linearly independent.

Proof. Let ∑(ℓ,β)∈Hcββ=0\sum_{(\ell, \beta) \in H} c_\beta \beta = 0. We show by induction on kk that cβ=0c_\beta = 0 for every β∈Hk\beta \in H^k. Assume it for the levels below kk, so ∑ℓ≥k∑β∈Hℓcββ=0\sum_{\ell \ge k} \sum_{\beta \in H^\ell} c_\beta \beta = 0. Let β∈Hk\beta \in H^k. Since β⊈Ωk+1\beta \not\subseteq \Omega^{k+1}, it has a support cell QQ of level kk that is not in Ωk+1\Omega^{k+1}. Since Ωk+1\Omega^{k+1} is a union of cells of level kk, the interior of QQ does not meet Ωk+1\Omega^{k+1}. Every function of a level ℓ>k\ell > k in HH lies in Ωℓ⊆Ωk+1\Omega^\ell \subseteq \Omega^{k+1}, so it is zero on the interior of QQ. Hence ∑β′∈Hkcβ′β′=0\sum_{\beta' \in H^k} c_{\beta'} \beta' = 0 on QQ. By Lemma 1 every β′\beta' of level kk that is not zero on QQ has cβ′=0c_{\beta'} = 0, and β\beta is one of them. □\square

Theorem 2 (the space). S(H)S(H) contains every tensor product spline of level 0 and every B-spline of level ℓ\ell whose support lies in Ωℓ\Omega^\ell. In particular the constant 1 lies in S(H)S(H).

Proof. Every level 0 B-spline lies in Ω0\Omega^0, so Lemma 3 applies to it and to the other levels. The constant is the sum of the level 0 B-splines, by the partition of unity of B-splines on an open knot vector. □\square

Theorem 3 (nested spaces). Let Ω^ℓ⊇Ωℓ\hat\Omega^\ell \supseteq \Omega^\ell for every ℓ\ell, both sequences with the properties above, and let H^\hat H be the selection for Ω^\hat\Omega. Then S(H)⊆S(H^)S(H) \subseteq S(\hat H). So REFINE never loses a function of the old space.

Proof. Each (ℓ,β)∈H(\ell, \beta) \in H has β⊆Ωℓ⊆Ω^ℓ\beta \subseteq \Omega^\ell \subseteq \hat\Omega^\ell, so β∈S(H^)\beta \in S(\hat H) by Lemma 3 for H^\hat H. □\square

Correctness of the operations. Lines L1 to L4 test exactly the rule of Theorem 1 for each tensor B-spline of each level. Lines L5 to L8 sum the given coefficients times the values of the selected B-splines, computed by the Cox-de Boor recursion on the knot vector of their level. REFINE keeps Ωℓ⊆Ωℓ−1\Omega^\ell \subseteq \Omega^{\ell-1} and the alignment to cells of level ℓ−1\ell - 1, so the hypotheses above hold after every call. The tests check Theorem 1, the containment of Lemma 3 and Theorem 3 by exact ranks of the expansions in the finest level. ■\blacksquare

Complexity

Let NN be the number of tensor B-splines of all levels together and kk the number of selected ones. BASIS tests each of the NN B-splines against (p+1)2(p + 1)^2 cells of its support, with a hash set of cells, so it takes O(Np2)O(N p^2) time. EVALUATE as written takes O(kp2)O(k p^2) time, since each B-spline costs O(p2)O(p^2) by Cox-de Boor; with a cell index that lists the functions nonzero on each cell, only O(Lp2)O(L p^2) functions are touched. FINEST on level ℓ\ell costs O(22(L−ℓ)p2)O(2^{2(L - \ell)} p^2) for the output. The extra space is O(k)O(k) for the basis, besides the domains.

Variants

  • Truncated hierarchical B-splines. Giannelli, Jüttler and Speleers cut from each coarse function its part in the finer B-splines that are inside the next domain. The truncated basis spans the same space, is a partition of unity and has smaller supports.
  • Other refinements between levels. The construction needs only nested spaces of the same degree, so the levels may use nonuniform knots and different knot insertions in each direction.
  • Forsey and Bartels's overlays. The original hierarchical editing adds offsets on finer patches to the coarse surface. It is a representation for modelling, not a basis selection.
  • Admissible meshes. For analysis, the domains are often restricted so that only a bounded number of levels have functions that are nonzero on a cell.

When to use it

Use hierarchical B-splines for adaptive isogeometric analysis and local surface fitting when you want a simple data structure, the tensor product structure of each level, and nested spaces under refinement. If the method needs partition of unity or the overlap of supports matters, use the truncated form. For local refinement that is not dyadic, compare T-splines, LR B-splines and PHT-splines.

Pitfalls

  • Keeping functions that lie in the finer domain. Without the second test of line L3, a coarse function inside Ωℓ+1\Omega^{\ell+1} is a combination of fine ones, and the set is dependent.
  • Assuming partition of unity. The sum of the selected functions is not 1 near the refined regions. A rational form or a convex hull argument that needs it fails.
  • Domains that are not aligned. Ωℓ\Omega^\ell must be a union of cells of level ℓ−1\ell - 1. A domain that cuts a cell gives supports that are partly inside, and the rule is then ambiguous.
  • Overlap of many levels. A coarse function can stay in the basis while its whole interior is covered by fine functions, so the number of functions nonzero at a point grows with the number of levels.

Implementations

The Python module builds the open uniform knot vectors of the levels, the two-scale matrices by Boehm insertion of all midpoints, the domains as sets of cells, Kraft's selection of lines L1 to L4, EVALUATE by Cox-de Boor, the expansion in the finest level, and an exact sparse rank. The tests check that one level gives the tensor B-splines of a separate Cox-de Boor table, that the two-scale relation holds at random points with positive coefficients, the counts of the example, that the selected functions of random hierarchies of degree 2 and 3 are independent and contain every B-spline of level ℓ\ell that lies in Ωℓ\Omega^\ell, that enlarging the domains keeps the old space inside the new one, and that the sum of the functions is not 1 while the constant 1 is in the space.

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.

hierarchical_b_spline.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/hierarchical-b-spline/. The authors are listed in prov/4MZ00N.jsonl.

"""Bivariate hierarchical B-splines with Kraft's selection, in exact arithmetic.

Level l has the open uniform knot vector of degree p on [0, n0] with spacing
2^-l in each direction, so the spline spaces of the levels are nested. A
B-spline of level l is a pair (i, j) of indices into that knot vector. A cell
of level l is a pair (a, b) for the square [a, a + 1] x [b, b + 1] scaled by
2^-l.

The domains Omega^0 = [0, n0]^2 and Omega^1, ..., Omega^(L-1) are sets of
cells, Omega^l a union of cells of level l - 1 inside Omega^(l-1).
Omega^L is empty. The hierarchical basis has the B-splines of level l whose
support lies in Omega^l but not in Omega^(l+1).
"""

from fractions import Fraction


def open_knots(n0, p, level):
    k = 2**level
    return [Fraction(0)] * p + [Fraction(a, k) for a in range(n0 * k + 1)] + [Fraction(n0)] * p


def insert_knot(knots, coeffs, u, p):
    """Boehm's rule on a whole coefficient vector: the same spline with u added."""
    k = max(i for i in range(len(knots) - 1) if knots[i] <= u < knots[i + 1])
    new = []
    for i in range(len(coeffs) + 1):
        if i <= k - p:
            new.append(coeffs[i])
        elif i > k:
            new.append(coeffs[i - 1])
        else:
            a = (u - knots[i]) / (knots[i + p] - knots[i])
            new.append(a * coeffs[i] + (1 - a) * coeffs[i - 1])
    return sorted(knots + [u]), new


def two_scale(n0, p, level):
    """R[i] = {j: c}: B-spline i of the level is sum_j c N_j of the next level."""
    coarse = open_knots(n0, p, level)
    fine = open_knots(n0, p, level + 1)
    new = sorted(set(fine) - set(coarse))
    R = []
    for i in range(len(coarse) - p - 1):
        knots, c = list(coarse), [Fraction(int(r == i)) for r in range(len(coarse) - p - 1)]
        for u in new:
            knots, c = insert_knot(knots, c, u, p)
        assert knots == fine
        R.append({j: x for j, x in enumerate(c) if x})
    return R


def bspline(knots, i, p, x):
    """N_i of degree p on the knots at x, by Cox-de Boor; closed at the right end."""
    last = knots[-1]
    vals = [Fraction(int(knots[k] <= x < knots[k + 1] or (x == last and knots[k] < knots[k + 1] == last))) for k in range(i, i + p + 1)]
    for d in range(1, p + 1):
        vals = [
            ((x - knots[i + k]) / (knots[i + k + d] - knots[i + k]) * vals[k] if knots[i + k + d] != knots[i + k] else 0)
            + ((knots[i + k + d + 1] - x) / (knots[i + k + d + 1] - knots[i + k + 1]) * vals[k + 1] if knots[i + k + d + 1] != knots[i + k + 1] else 0)
            for k in range(len(vals) - 1)
        ]
    return vals[0]


class Hierarchy:
    def __init__(self, n0, p, levels):
        self.n0, self.p, self.L = n0, p, levels
        self.knots = [open_knots(n0, p, l) for l in range(levels)]
        self.R = [two_scale(n0, p, l) for l in range(levels - 1)]
        self.omega = [{(a, b) for a in range(n0) for b in range(n0)}] + [set() for _ in range(levels - 1)]

    def size(self, level):
        return self.n0 * 2**level + self.p

    def cells(self, level, i):
        """The cells of the level, in one direction, where N_i is not zero."""
        return range(max(i - self.p, 0), min(i, self.n0 * 2**level - 1) + 1)

    def support(self, level, B):
        i, j = B
        return [(a, b) for a in self.cells(level, i) for b in self.cells(level, j)]

    def inside(self, level, B, m):
        """Does the support of the level-`level` function B lie in Omega^m (m = level or level + 1)?"""
        if m >= self.L:
            return False
        if m == level:
            return all(c in self.omega[m] for c in self.support(level, B))
        return all((2 * a + x, 2 * b + y) in self.omega[m] for a, b in self.support(level, B) for x in (0, 1) for y in (0, 1))

    def refine(self, level, coarse_cells):
        """Add to Omega^level the given cells of level - 1, which must lie in Omega^(level-1)."""
        for a, b in coarse_cells:
            if (a, b) not in self.omega[level - 1]:
                raise ValueError("Omega^l must lie inside Omega^(l-1)")
            self.omega[level] |= {(2 * a + x, 2 * b + y) for x in (0, 1) for y in (0, 1)}

    def basis(self):
        """Kraft's selection: a list of (level, (i, j))."""
        H = []
        for l in range(self.L):  # @line L1
            for i in range(self.size(l)):  # @line L2
                for j in range(self.size(l)):
                    if self.inside(l, (i, j), l) and not self.inside(l, (i, j), l + 1):  # @line L3
                        H.append((l, (i, j)))  # @line L4
        return H

    def evaluate(self, coeffs, x, y):
        """sum of c * B(x, y) over a dict {(level, (i, j)): c}."""
        total = Fraction(0)  # @line L5
        for (l, (i, j)), c in coeffs.items():  # @line L6
            total += c * bspline(self.knots[l], i, self.p, x) * bspline(self.knots[l], j, self.p, y)  # @line L7
        return total  # @line L8

    def finest(self, level, B):
        """B as {(i, j): c} in the tensor B-splines of the finest level, by the two-scale relation."""
        cs, ct = {B[0]: Fraction(1)}, {B[1]: Fraction(1)}
        for l in range(level, self.L - 1):
            cs = _apply(self.R[l], cs)
            ct = _apply(self.R[l], ct)
        return {(a, b): x * y for a, x in cs.items() for b, y in ct.items()}


def _apply(R, c):
    out = {}
    for i, x in c.items():
        for j, y in R[i].items():
            out[j] = out.get(j, Fraction(0)) + x * y
    return out


def rank(vectors):
    """Exact rank of sparse vectors given as dicts, by incremental elimination."""
    pivots = {}
    for v in vectors:
        v = {k: x for k, x in v.items() if x}
        while v:
            k = min(v)
            if k not in pivots:
                pivots[k] = v
                break
            p = pivots[k]
            f = v[k] / p[k]
            for kk, x in p.items():
                v[kk] = v.get(kk, Fraction(0)) - f * x
            v = {kk: x for kk, x in v.items() if x}
    return len(pivots)
test_hierarchical_b_spline.py 117 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/hierarchical-b-spline/. The authors are listed in prov/4MZ00N.jsonl.

import random
from fractions import Fraction as F

from hierarchical_b_spline import Hierarchy, bspline, open_knots, rank


def all_basis(knots, p, x):
    """Reference: every B-spline of degree p at x by the triangular Cox-de Boor table."""
    n = len(knots) - p - 1
    if x == knots[-1]:
        return [F(int(i == n - 1)) for i in range(n)]
    N = [F(int(knots[i] <= x < knots[i + 1])) for i in range(len(knots) - 1)]
    for d in range(1, p + 1):
        N = [
            ((x - knots[i]) / (knots[i + d] - knots[i]) * N[i] if knots[i + d] > knots[i] else 0)
            + ((knots[i + d + 1] - x) / (knots[i + d + 1] - knots[i + 1]) * N[i + 1] if knots[i + d + 1] > knots[i + 1] else 0)
            for i in range(len(N) - 1)
        ]
    return N


def example(p=2):
    """Three levels on [0, 4]^2: Omega^1 = [0, 2]^2 and Omega^2 = [0, 1]^2."""
    H = Hierarchy(4, p, 3)
    H.refine(1, [(a, b) for a in range(2) for b in range(2)])
    H.refine(2, [(a, b) for a in range(2) for b in range(2)])
    return H


def random_hierarchy(rng, p):
    H = Hierarchy(4, p, 3)
    H.refine(1, rng.sample(sorted(H.omega[0]), 7))
    H.refine(2, rng.sample(sorted(H.omega[1]), 9))
    return H


def pts(rng, k):
    return [(F(rng.randint(0, 400), 100), F(rng.randint(0, 400), 100)) for _ in range(k)]


def test_one_level_is_the_tensor_b_spline_basis():
    H = Hierarchy(3, 2, 1)
    basis = H.basis()
    assert len(basis) == 25
    rng = random.Random(1)
    for x, y in pts(rng, 10):
        if x > 3 or y > 3:
            continue
        Nx, Ny = all_basis(H.knots[0], 2, x), all_basis(H.knots[0], 2, y)
        for _, (i, j) in basis:
            assert H.evaluate({(0, (i, j)): 1}, x, y) == Nx[i] * Ny[j]


def test_two_scale_relation_against_direct_evaluation():
    rng = random.Random(2)
    for p in (2, 3):
        H = Hierarchy(4, p, 2)
        fine = H.knots[1]
        for i, row in enumerate(H.R[0]):
            for _ in range(5):
                x = F(rng.randint(0, 400), 100)
                assert bspline(H.knots[0], i, p, x) == sum(c * bspline(fine, j, p, x) for j, c in row.items())
                assert all(c > 0 for c in row.values())


def test_kraft_selection_on_the_example():
    H = example()
    basis = H.basis()
    by_level = [sum(1 for l, _ in basis if l == k) for k in range(3)]
    # level 0: the 36 B-splines minus the 4 whose support [i-2, i+1] lies in [0, 2]
    assert by_level == [32, 12, 16]
    assert rank([H.finest(l, B) for l, B in basis]) == len(basis)


def test_basis_is_independent_and_contains_each_level_on_its_domain():
    rng = random.Random(3)
    for p in (2, 3):
        H = random_hierarchy(rng, p)
        basis = H.basis()
        vecs = [H.finest(l, B) for l, B in basis]
        r = rank(vecs)
        assert r == len(basis)
        for l in range(3):
            for i in range(H.size(l)):
                for j in range(H.size(l)):
                    if H.inside(l, (i, j), l):
                        assert rank(vecs + [H.finest(l, (i, j))]) == r


def test_enlarging_the_domains_gives_nested_spaces():
    rng = random.Random(4)
    H = random_hierarchy(rng, 2)
    old = [H.finest(l, B) for l, B in H.basis()]
    for _ in range(3):
        level = rng.choice([1, 2])
        H.refine(level, rng.sample(sorted(H.omega[level - 1]), 2))
        new = [H.finest(l, B) for l, B in H.basis()]
        assert rank(new) == len(new)
        assert rank(new + old) == len(new)
        old = new


def test_no_partition_of_unity_but_constants_are_in_the_space():
    H = example()
    basis = H.basis()
    total = {}
    for l, B in basis:
        for k, c in H.finest(l, B).items():
            total[k] = total.get(k, F(0)) + c
    ones = {(a, b): F(1) for a in range(H.size(2)) for b in range(H.size(2))}
    assert total != ones  # the plain sum is not 1
    assert H.evaluate({b: 1 for b in basis}, F(1, 2), F(1, 2)) > 1
    vecs = [H.finest(l, B) for l, B in basis]
    assert rank(vecs + [ones]) == len(vecs)  # but 1 is in the span

History

Forsey and Bartels introduced hierarchical B-spline refinement for interactive surface editing at SIGGRAPH 1988. Kraft defined the selection by nested domains and proved the functions linearly independent in 1997. Vuong, Giannelli, Jüttler and Simeon applied it to adaptive isogeometric analysis in 2011. Giannelli, Jüttler and Speleers introduced the truncated basis in 2012 and proved its stability in 2014.

References

  1. David R. Forsey and Richard H. Bartels, Hierarchical B-spline refinement, Computer Graphics 22(4) (SIGGRAPH 1988), 205 to 212, overlays of finer B-spline patches on a coarse surface for local editing (general locator)
  2. Rainer Kraft, Adaptive and linearly independent multilevel B-splines, in A. Le Méhauté, C. Rabut and L. L. Schumaker (editors), Surface Fitting and Multiresolution Methods, Vanderbilt University Press, 1997, the selection of B-splines of each level by the nested domains, and its linear independence (general locator)
  3. A.-V. Vuong, C. Giannelli, B. Jüttler and B. Simeon, A hierarchical approach to adaptive local refinement in isogeometric analysis, Computer Methods in Applied Mechanics and Engineering 200(49-52) (2011), 3554 to 3567, the definition of the hierarchical basis by Kraft's rule, its linear independence, the nested spaces under refinement, and adaptive isogeometric analysis with it (general locator)
  4. Carlotta Giannelli, Bert Jüttler and Hendrik Speleers, THB-splines, the truncated basis for hierarchical splines, Computer Aided Geometric Design 29(7) (2012), 485 to 498, the comparison of the hierarchical basis with the truncated basis, which spans the same space (general locator)

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.average
  • a full proof of time.best
  • 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)
WritingW4 complete
  • a review of the text: no review record reviews/4MZ00N/text.yaml