knotflow Lessons PDF ↓ Deutsch Handbook Modeller ↗ Source

Lesson 3.13 · III Modelling

Growing: fields and a bone

What it's about: A shape that is not drawn but described: the outline of a thigh bone, the forces while walking, where it is held and how much bone there should be. The inner structure grows by a rule like the one living bone follows. The tools for it are fields, one number per cell of a grid in the plane, and a computation that says where material carries load.

Grown femur

How the structure grows: steps 0, 8, 15, 23, 30

1. Fields

For shapes in the plane there is the value type field: one number per cell of a grid, such as a density, a distance or an energy. You compute with fields as with numbers: d * 2, a + b, max(d, 0.01), clamp(…), sqrt(…) work cell by cell.

Isn't that the broadcasting the language deliberately lacks (Lesson 2.1)? No – and the difference is exactly the reason it lacks it: a field is one value, mathematically a function over the plane. For two functions, f + g is, in mathematics, the function x ↦ f(x) + g(x); there is no question of "one or many?" and no combination rules. A list of fields, on the other hand, is not processed automatically – that is why the model says fold(r.energy, 0 * d, (+)), the sum over all load cases (section 3).

Shapes as fields. sdf(curve, grid) gives, for every cell, the distance to the curve, negative inside (a signed distance field). Combining shapes then becomes arithmetic: the minimum of two distance fields is their union. With a smooth minimum they merge with a fillet – written in the language itself:

fn smin(a, b, k) = min(a, b) - h * h * k / 4
  where h = max(k - abs(a - b), 0) / k

let outline = smin(smin(smin(sdf(shaft, g), sdf(troch, g), 10),
                        smin(sdf(neck, g), sdf(head, g), 8), 10), sdf(small, g), 6)

For the bone below, shaft, greater trochanter, neck, head and lesser trochanter are described separately like this, the neck at the anatomical angle of 130° to the shaft, and together they make an organic outline.

A field becomes a solid with plate(field, level:, thickness:) (a plate where the field is above level) or relief(field, height:, base:) (a height per cell, Lesson 2.5). More tools: grid (an empty field over a rectangle), xs/ys (the coordinates of every cell), step, blur (soften) and mean.

2. What bone does

If you cut a thigh bone open lengthwise, you see a solid shell on the outside (the cortex), an empty marrow cavity in the shaft, and at the top, in the head and neck, a sponge of fine little struts (the cancellous bone, or spongiosa). The struts are not placed at random: they follow the lines along which the bone is pushed and pulled. In the 19th century the engineer Karl Culmann noticed that the stress lines of a crane look just the same; from this the surgeon Julius Wolff formulated Wolff's law in 1892: bone remodels itself so that it follows the loads.

How this works inside the bone is described by the model of Rik Huiskes and colleagues (1987–2000): bone cells sense the deformation around them. If the stimulus is large, bone is added; if it is small, bone is removed. Independently, the engineering world invented the same mathematics – topology optimisation (Bendsøe & Kikuchi 1988; the form common today, "SIMP", from 1989 on). An optimisation step there and a remodelling step in Huiskes' model are almost the same formula.

3. Declarative – and why that fits a functional language

The model examples/bone.kf has two parts. The first describes the problem and computes nothing:

let shape    = step(-outline)                       // the outline (see below)
let cortex   = shape * step(outline + wall)         // the cortex is fixed
let supports = shape * step(4 - ys(g))              // clamped at the bottom
let cases    = [case(2317, 24, 703, 28),            // standing on one leg
                case(1158, -15, 351, -8),           // abduction
                case(1548, 56, 468, 35)]            // adduction

The second part is the growth rule, and it is written in the language, not in the Rust core:

fn stimulus(d) = blur(fold(r.energy, 0 * d, (+)) / max(d, 0.01), sense, within: shape)
  where r = analyze_plane(d, shape, supports, cases)

fn remodel(d) = max(adapt(d, s, threshold(d, s, 1e-9, 1e9, 60)), cortex)
  where s = stimulus(d)

let states = history(start, steps, remodel)

This fits the functional style for three reasons:

4. What comes out – and what doesn't

Without any of this being drawn:

The shaft is not as empty as in a real bone – further up, a network of struts remains. Less bone overall makes it hollower, but then the rest turns truss-like again. An attempt with Huiskes' "set point" rule (exercise 2) also shifts the balance, but doesn't fully solve it.

5. Limits

In depth A: finite elements in the plane

analyze_plane computes how the plate deforms under the loads:

The loads come from bone research (Carter et al. 1989, Beaupré et al. 1990): three typical postures, each with the force in the hip joint and the pull of the abductor muscles on the greater trochanter.

In depth B: the remodelling rule in detail

  1. Stimulus: strain energy per bone mass, summed over all three postures and averaged over the sensing radius of the bone cells (blur – in Huiskes' model the "influence function"). Without this averaging, checkerboard patterns appear.
  2. Remodelling: every cell changes its density by the factor (stimulus / threshold)^speed – by at most 0.2 per step.
  3. Threshold: chosen so that the amount of bone stays the same – found by bisection, written as a function with two equations (the first one ends the search):
fn threshold(d, s, lo, hi, 0) = sqrt(lo * hi)
fn threshold(d, s, lo, hi, k) =
  if mean(adapt(d, s, mid), within: shape) > volume then threshold(d, s, mid, hi, k - 1)
                                                   else threshold(d, s, lo, mid, k - 1)
  where mid = sqrt(lo * hi)
  1. Porosity: the decisive building block. Without it you get a truss: a few thick struts, a big X in the shaft – the classic result of topology optimisation, because for a fixed amount of material a few thick bars are stiffest. But bone is porous everywhere. That is why each neighbourhood may contain at most a certain share of bone (after Wu, Aage, Westermann, Sigmund 2017, "approaching bone-like porous structures"). Then the material has to spread over many thin struts:
fn porous(d) = d * min(1, local / max(blur(d, pore, within: shape), 0.01))

One line, and the truss turns into cancellous bone.

How it is checked

The finite element computation is checked against cases whose result is known without it: an element moved or rotated as a whole produces no force; a uniform stretch stores exactly ½ E ε²; the stored energy is exactly half the work done by the loads; a cantilever bends a little less than beam theory says (bilinear square elements are known for being too stiff in bending). The whole model must grow with coarse settings and give a closed plate.

Try it yourself

cargo run --release -p kf -- render examples/bone.kf -o out/bone.png --view -90,89
cargo run --release -p kf -- render examples/bone.kf -D stages=5 -D cell=1.2 -o out/growth.png --view -90,89 --width 1100
cargo run --release -p kf -- render examples/bone.kf -o out/bone.stl

Exercises:

  1. Compute with the one-legged stance only (cases = [case(2317, 24, 703, 28)]). How does the pattern in the head change? (The crossed arches in a real femur only arise from several postures.)

  2. Replace the fixed amount of bone with a set point (Huiskes): the threshold is then not the result of a search but fixed, and the amount of bone adjusts itself:

    let setpoint_value = setpoint * mean(stimulus(start), within: shape)
    fn remodel(d) = max(porous(clamp(d * (stimulus(d) / setpoint_value) ^ speed,
                                     max(0.01, d - 0.2), min(1, d + 0.2)) * shape), cortex)

    (setpoint_value has to come after let start = …: values are computed in order, Lesson 2.2.)

  3. Change pore and local. When does the cancellous bone fall apart into fragments, and when does it turn back into a truss?

  4. Something to think about: why would the computation produce a checkerboard without blur in the stimulus?