Refinement

using TinyGismousing TinyGismo: knots, degree, basis, component

Refinement enlarges a spline space without changing what it currently represents. That is the property isogeometric analysis relies on: refine the geometry, and the geometry is unchanged while the discretization gets richer.

There are three independent ways to enlarge the space, and they are worth keeping apart:

operationknotsdegreecontinuity
knot insertion / uniform refinementmoreunchangedunchanged at old knots
degree elevationmultiplicities raisedhigherunchanged
degree increaseends onlyhigherraised in the interior

All of them are in-place — the ! suffix is not decoration.

Knot insertion

insertKnot! adds a single knot, optionally with a multiplicity. Start from a quadratic basis with one interior knot:

kv = KnotVector([0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0])b = BSplineBasis(kv)knotContainer(knots(b))
7-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.5
 1.0
 1.0
 1.0
insertKnot!(b, 0.25)knotContainer(knots(b))
8-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.25
 0.5
 1.0
 1.0
 1.0

A multiplicity greater than one lowers the continuity at that knot. Inserting 0.75 twice into a quadratic basis leaves only $C^0$ there:

insertKnot!(b, 0.75, 2)knotContainer(knots(b))
10-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.25
 0.5
 0.75
 0.75
 1.0
 1.0
 1.0

insertKnots! does a batch, and removeKnot! undoes an insertion:

insertKnots!(b, [0.1, 0.9])knotContainer(knots(b))
12-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.1
 0.25
 0.5
 0.75
 0.75
 0.9
 1.0
 1.0
 1.0
removeKnot!(b, 0.1)knotContainer(knots(b))
11-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.25
 0.5
 0.75
 0.75
 0.9
 1.0
 1.0
 1.0

Every inserted copy adds one basis function, but only a new knot value adds an element — the two insertions of 0.75 above added two functions and a single element:

Int(size(b)), Int(numElements(b)), Int(uSize(knots(b)))
(8, 5, 6)

Uniform refinement

uniformRefine! splits every element, which is the usual way to build a convergence study. The default inserts one knot per span, so the element count doubles:

b = BSplineBasis(kv)before = (Int(numElements(b)), Int(size(b)))uniformRefine!(b)before, (Int(numElements(b)), Int(size(b))), knotContainer(knots(b))
((2, 4), (4, 6), [0.0, 0.0, 0.0, 0.25, 0.5, 0.75, 1.0, 1.0, 1.0])

The first argument after the basis is the number of knots inserted per span, so a value of 3 quadruples the element count in one step:

uniformRefine!(b, 3)Int(numElements(b))
16

uniformCoarsen! reverses it:

uniformCoarsen!(b)Int(numElements(b))
8

Refining a geometry keeps its shape

This is the point of the whole exercise. Refining a geometry — rather than a bare basis — recomputes the control points so that the mapping is preserved exactly.

controlpoints = [0.0  0.0                 1.0  1.5                 2.0 -0.5                 3.0  1.0]curve = BSpline(BSplineBasis(kv), controlpoints)x = gsMatrix()eval!(curve, [0.3], x)before = toMatrix(x)
2×1 Matrix{Float64}:
 1.02
 0.8999999999999998
uniformRefine!(curve)eval!(curve, [0.3], x)after = toMatrix(x)before ≈ after
true

The control net, however, is completely different — there are now six control points instead of four, and none of the interior ones sit where they used to:

Int(coefsSize(curve)), toMatrix(coefs(curve))
(6, [0.0 0.0; 0.5 0.75; … ; 2.5 0.25; 3.0 1.0])

Refining a bare basis and its coefficients

If you are carrying coefficients separately rather than in a geometry object, uniformRefine_withCoefs! does the same job: it refines the basis in place and returns the matching refined coefficients. They cannot be updated in place, because refinement adds control points.

b = BSplineBasis(kv)newcoefs = toMatrix(uniformRefine_withCoefs!(b, controlpoints))Int(size(b)), size(newcoefs)
(6, (6, 2))

The refined pair represents exactly the same curve:

eval!(BSpline(b, newcoefs), [0.3], x)toMatrix(x) ≈ before
true

Degree elevation and degree increase

Both raise the polynomial degree, but they differ in what happens to the interior knots, and therefore to the continuity of the space.

degreeElevate! raises the multiplicity of every interior knot along with the degree, so the continuity at each knot is preserved:

b = BSplineBasis(kv)degreeElevate!(b)degree(b), knotContainer(knots(b)), Int(numElements(b))
(3, [0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 1.0, 1.0, 1.0, 1.0], 2)

The interior knot 0.5 is now doubled: at degree 3 with multiplicity 2 the space is still $C^1$ there, as it was at degree 2 with multiplicity 1.

degreeIncrease! touches only the end knots, so the interior continuity goes up along with the degree:

b = BSplineBasis(kv)degreeIncrease!(b)degree(b), knotContainer(knots(b)), Int(numElements(b))
(3, [0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0, 1.0], 2)

degreeReduce! and degreeDecrease! are the corresponding inverses. Elevating and then reducing returns the original knot vector:

b = BSplineBasis(kv)degreeElevate!(b)degreeReduce!(b)knotContainer(knots(b)) ≈ knotContainer(kv)
true

Degree elevation on a geometry preserves the shape in the same way knot insertion does, at the cost of more control points:

rect = createBSplineRectangle(0.0, 0.0, 2.0, 1.0)beforedeg = (degree(rect, 1), degree(rect, 2), Int(coefsSize(rect)))degreeElevate!(rect)beforedeg, (degree(rect, 1), degree(rect, 2), Int(coefsSize(rect)))
((2, 2, 9), (3, 3, 16))

Continuity without changing the degree

elevateContinuity! and reduceContinuity! move continuity at fixed degree, by removing or repeating interior knots. Elevating continuity on the quadratic basis above removes the single interior knot altogether, collapsing the two elements into one Bézier segment:

b = BSplineBasis(kv)elevateContinuity!(b)degree(b), Int(numElements(b)), knotContainer(knots(b))
(2, 1, [0.0, 0.0, 0.0, 1.0, 1.0, 1.0])

Refining tensor product geometries

On a tensor product geometry the same calls apply to all directions at once:

rect = createBSplineRectangle(0.0, 0.0, 2.0, 1.0)rb = basis(rect)(ncoefs = Int(coefsSize(rect)), nelements = Int(numElements(rb)))
(ncoefs = 9, nelements = 1)
uniformRefine!(rect, 2)rb = basis(rect)(ncoefs = Int(coefsSize(rect)), nelements = Int(numElements(rb)))
(ncoefs = 25, nelements = 9)

Both directions went from one element to three, giving nine elements in total.

Working one direction at a time

Directional calls take a 1-based direction index, with 0 meaning "all directions". For insertKnot! on a geometry the third argument is the direction and the fourth the multiplicity:

insertKnot!(rect, 0.5, 1)   # value 0.5, direction 1knotContainer(knots(rect, 1))
9-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.3333333333333333
 0.5
 0.6666666666666666
 1.0
 1.0
 1.0

The second direction is untouched:

knotContainer(knots(rect, 2))
8-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.3333333333333333
 0.6666666666666666
 1.0
 1.0
 1.0

Anything outside 0:parDim is rejected:

try    degreeElevate!(rect, 1, -1)catch err    errend
ErrorException("degreeElevate!: direction must be 0 (= all directions) or in 1:2, got -1")

To read the per-direction element counts, go through TinyGismo.component, which returns the univariate basis for one direction:

rb = basis(rect)(    dir1 = Int(numElements(component(rb, 1))),    dir2 = Int(numElements(component(rb, 2))),    total = Int(numElements(rb)),)
(dir1 = 4, dir2 = 3, total = 12)

The mesh is now anisotropic — four elements across, three up, twelve in total.

Do not reach for the two-argument numElements here. Its second argument is a box side in the G+Smo numbering (1/2 west and east, 3/4 south and north), so it returns the number of elements along that boundary edge. Sides 1 and 2 run up the $v$ direction and give 3, while sides 3 and 4 run along $u$ and give 4:

[Int(numElements(rb, s)) for s in 1:4]
4-element Vector{Int64}:
 3
 3
 4
 4

Directional degree operations follow the same convention: the second argument of degreeElevate! is the number of levels and the third is the direction.

degreeElevate!(rect, 1, 1)   # elevate once, direction 1 onlydegree(rect, 1), degree(rect, 2)
(3, 2)

uniformRefine! on a geometry accepts the same trailing direction argument, after the knot count and the multiplicity:

square = createBSplineRectangle()uniformRefine!(square, 1, 1, 2)   # one knot per span, multiplicity 1, direction 2sb = basis(square)Int(numElements(component(sb, 1))), Int(numElements(component(sb, 2)))
(1, 2)