Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Fast methods and what they converge to

The question. Games and films simulate soft bodies many times a second with methods that look far cheaper than a Newton search. What does each of them give when it is run to the end, how quickly does it get there, and can any of them give the arm’s balance faster than the simulator does?

A method is fast only with respect to a target. Real-time methods are built to give a plausible shape after a fixed, small amount of work each frame. The simulator’s target is different: a shape in which no free coordinate of any body carries more than 10 mN of unbalanced force. This chapter measures the fast methods against that target, and then turns the same test on the simulator’s own attempts to speed itself up.

By the end you will be able to tell the speed of an iteration from the accuracy of its answer, predict what a fixed number of sweeps leaves undone in a stiff body, say what projective dynamics, position-based dynamics, ADMM and model reduction solve when they are run to the end, and say why a speed-up must be judged on a whole run.

Two ways to be fast

An iteration can be fast in two senses. Each of its steps can be cheap, or it can need few steps to reach the target. The two are different, and only their product, the cost to reach the target, matters here.

An iteration has linear convergence when each step leaves a fixed fraction of the error. To cut the error by a factor it then needs

steps. In words: the steps grow with the number of digits wanted, and they grow without limit as approaches 1. At , eight digits take 27 steps. At they take 1833. Newton’s method, near a balance, has quadratic convergence: the digits it has right double each step, so eight digits from one take three steps. Each Newton step is dear, a whole linear solve; each step of a linearly converging method is cheap, and there may be thousands.

An answer taken after a fixed number of steps of a linearly converging method has the accuracy that number of steps happens to give. If is near 1, that may be very little.

Relaxing one corner at a time

Gauss–Seidel is the simplest iteration for a set of equations, one for each corner. It visits the corners in turn and moves each one to where the forces on it balance, with its neighbours held where they are at that moment. A sweep is one visit to every corner. Position-based dynamics, the method behind many real-time simulations, relaxes its constraints in exactly this way, one at a time (Macklin, Müller and Chentanez 2016, section 4.1).

A worked example

A soft spring of 100 N/m runs from a wall to a corner . A stiff spring of 10 000 N/m runs from to a second corner , which is pulled away from the wall with 1 N. Let and be how far the two corners move, in metres.

The balance. Each spring carries the whole 1 N. The soft one stretches m and the stiff one m, so mm and mm. The pair is as stiff as N/m.

One sweep. Corner balances when the soft spring’s pull back toward the wall equals the stiff spring’s pull toward : , so . Corner balances when the stiff spring carries the 1 N: mm. Starting from rest, the first sweep gives and mm. The second gives mm and mm. Each sweep does the same thing:

In words: the end keeps of where it was and gains another tenth of a millimetre. After sweeps it is at

SweepsEnd movedShare of the balanceStiffness the pair seems to have
10.100 mm1.0 %10 000 N/m
100.957 mm9.5 %1045 N/m
1006.37 mm63 %157 N/m
46310.0 mm99 %100 N/m

So : the stiff spring over the sum of the two. The stiff spring is satisfied at every sweep, so its corners move together, and the stretch the soft spring needs arrives a tenth of a millimetre at a time. After ten sweeps the pair behaves as if it were ten times stiffer than it is. Make the stiff spring 10 000 times the soft one instead of 100, and : 99 % then takes about 46 000 sweeps.

Newton’s method on this pair takes one step, because the forces are exactly in proportion to the moves, and its step is the balance.

Here the sweeps start from rest, so an unfinished answer has moved too little and looks too stiff. A real-time simulation starts each step from where the bodies would fly freely, and there an unfinished answer leaves the constraints stretched and looks too soft. Either way the result depends on the number of sweeps. Macklin and colleagues describe this for position-based dynamics: its constraints “become arbitrarily stiff as the iteration count increases, or as the time step decreases”, which makes the stiffness of one object depend on how many iterations are spent on the whole scene (Macklin, Müller and Chentanez 2016, section 1).

Try it: a fixed number of sweeps

The laboratory solves a linear system two ways and stops each after a fixed number of sweeps, which each press of Step raises, from 1 to 2000: Gauss–Seidel, and conjugate gradients with the corner-by-corner preconditioner of Solving many equations at once. Beside them is the answer solved to the end.

  1. Check the worked example. With the two springs and the ratio at 100, the first frame shows one sweep: the end has moved 0.100 mm of its 10.100. Press Step three times: ten sweeps, 0.957 mm, and a pair that seems to be 1045 N/m stiff instead of 99.0. Conjugate gradients have had the answer since their second iteration: two unknowns, two steps.
  2. Predict, then check. How many sweeps reach 99 % of the movement? The table says 463. Press on to 500 sweeps: 99.3 %.
  3. Predict, then check. Set the ratio to 10 000. What share will 2000 sweeps reach? , about 18 %. Press Play and read it.
  4. The block. Choose the pushed block of tissue, with its bulk modulus 100 times its shear modulus. After 2000 sweeps Gauss–Seidel has moved the end 0.43 mm of 3.32: 13 %. Conjugate gradients, which take each new direction so as to undo nothing done before, had the answer by 200 iterations.
  5. Predict, then check. Set the ratio to 10 000, close to the arm’s muscle. After 2000 sweeps the block has moved 0.6 % of the way and seems about 170 times stiffer than it is. Conjugate gradients finish within 500 iterations.
  6. Set the ratio to 1. Even a block that squeezes as easily as it shears is only two thirds of the way after 2000 sweeps. Its long, slender shape alone makes the factor of each sweep close to 1, and conjugate gradients finish within 50 iterations.

What the fast methods solve

Each of the methods below was built for speed at a small, fixed amount of work per frame. Run to the end, each converges to the answer of some set of equations, and that set is not always the simulator’s.

Projective dynamics. It takes implicit time steps with “specially designed energy potentials that can be solved efficiently using an alternating optimization approach” (Bouaziz et al. 2014). Run to the end, it gives the time step of those special energies. The arm’s fibres, with their active force that depends on length and speed (The fibre as a force generator), are not of that form, so the material itself would have to be replaced by an approximation of it. A quasi-Newton method takes steps like Newton’s but solves each with a cheaper stand-in for the stiffness matrix, often improved from step to step by how the forces changed. Projective dynamics is one, and it can be accelerated by such updates (L-BFGS); that version is “typically more than 10 times faster than one iteration of Newton’s method” (Liu, Bouaziz and Kavan 2017). That comparison is against a single Newton iteration per frame of a real-time animation, not against a search to a force tolerance.

ADMM. The alternating direction method of multipliers, applied to the same alternation, permits general nonlinear materials and hard constraints while keeping the matrix it solves with the same from step to step (Overby et al. 2017). Run to the end it gives the time step of the true material. How many of its iterations a balance to 10 mN would need, at a bulk modulus times the shear modulus, is not reported in what has been read of it.

Position-based dynamics and XPBD. XPBD gives position-based dynamics a stiffness that does not depend on the iteration count. To do so it drops parts of the stiffness matrix, an approximation that “omits the geometric stiffness and constraint Hessian terms”, and its authors are explicit about what it does not do: “XPBD does not converge faster than PBD, simply that behavior remains consistent at different iteration counts” (Macklin, Müller and Chentanez 2016, sections 3, 4 and 6). Its Gauss–Seidel and Jacobi iterations converge linearly, as the worked example did. A later finding is that many small time steps of one iteration each do better than one large step of many iterations (Macklin et al. 2019). That turns the method toward explicit dynamics. A static balance is then reached only by simulating a motion until it comes to rest.

Model reduction. Instead of moving every corner, the body is allowed only a few tens or hundreds of chosen shapes, and the solve finds how much of each. For one simple material the forces in such a subspace can be written as precomputed cubic polynomials of its coordinates (Barbič and James 2005); for others, a few well-chosen sample points stand in for the whole body (An, Kim and James 2008). A related idea makes coarse bricks behave like many fine ones: a coarse model with eight times fewer elements matched the fine one, at , about 60 times faster, with bases built at rest that “may fail to capture very large and highly nonlinear deformation” (Chen et al. 2018, figures 1 and 9 and section 4.4). In every case the answer is the subspace’s, not the body’s. What a reduced model loses first is what is local: contact, folds and the stress near an attachment.

None of the four reaches a 10 mN balance of the arm’s energy faster than Newton’s method with a factorisation, and projective dynamics and XPBD also change the equations. They answer a different question well: what looks right within a frame’s budget.

The simulator’s own speed-ups

The same test applies to the simulator. Over the whole 2 kg curl its tissue search takes 17.2 Newton iterations a time step, and 72 % of those steps use a stand-in for the stiffness with its negative curvature removed, because the true stiffness fails to factorise far from the balance. That count looked like the place to save time, and several ways of cutting it were built, each switched off unless asked for:

WayModelled time over 12 stepsOver the whole curl
Try a shifted stiffness before the stand-in, starting from the last shift that worked0.74 ×1.17 × slower
Add a small stiffness to every coordinate of the stand-in0.78 ×1.61 × slower
Let time steps grow where the motion is slow—1.17 × slower
Reuse the last factorisation for a few steps1.21 ×—
Start each search from a prediction of the next shape1.37 ×—
Eliminate in nested-dissection order5.8 × slower per factorisation—

The times are modelled from counts of the work done, factorisations, assemblies and trial steps, each priced at its measured cost, because the computer was shared and its clock times were unreliable. With every way switched off, the curl’s recording came out the same byte for byte as before any of them existed.

None was faster over the whole curl. The two that looked best over twelve steps were slower over 340. The reason is the one met at the end of Pressure as an unknown, and multigrid: each way follows a slightly different path, a body of tissue squeezed among others can settle into more than one balance, and the cost of the next step depends on which balance the last one found. Even a change of rounding alone, eliminating the same equations in another order, moved the tissue’s surface by 0.002 mm after the first balance and by 0.61 mm after twelve steps. Twelve steps are too few to average that out.

Every way still met the curl’s stated tolerances. The two Newton ways run over the whole curl differed from the default by at most 0.11° and 0.13° of elbow angle and 0.20 and 0.29 N·m of joint torque, within the spread that different paths give anyway. Letting the time steps grow took 22 % fewer steps but 13 % more Newton iterations, since a longer step starts its search further from its balance. It moved the result by up to 0.21° and 0.52 N·m, more than that spread though within the curl’s limit of 2° of stray: it moved the answer more than it saved.

The multigrid’s own steps reached the arm’s first balance in four times the factorisation’s time, and in a different balance, 35 mm away for one body. So the simulator keeps the factorisation’s steps, and runs the multigrid beside it only to compare.

What the fast methods are good for

  • Previews. An interactive view of the arm at a frame’s budget, labelled as a preview, where a plausible shape now is worth more than the balance later.
  • Predictors. A cheap first guess from which Newton’s method finishes to the same 10 mN test. The answer is then the simulator’s, though the path to it changes. A first guess from the last two steps is what the simulator uses; the tangent prediction tried above cost 1.37 times as much on twelve steps.
  • Coarse spaces. The coarse levels of the multigrid are a reduced model: each aggregate of corners moves only by its six rigid motions. Used inside a solver, a reduced model changes how fast the answer is found, not what it is.

Check against published results

Macklin and colleagues show that both Gauss–Seidel and Jacobi iterations converge linearly on their test problems, and that hanging cloth simulated by position-based dynamics becomes progressively stiffer and more heavily damped as the iteration count rises from 20 to 160 (Macklin, Müller and Chentanez 2016, figures 3 and 6). The laboratory’s Gauss–Seidel converges linearly, with exactly the factor the worked example derives, and its apparent stiffness depends on the number of sweeps, in the opposite direction because it starts from rest.

What this model leaves out

  • Time. The laboratory solves the linear equations of one shape, without inertia. The fast methods step through time, and their bodies have mass.
  • Nonlinear materials. Gauss–Seidel on a linear system shows the cost of relaxation; on the arm’s fibre law each corner’s balance would itself be a small nonlinear solve.
  • The fast methods themselves. The simulator has no projective dynamics, ADMM, XPBD or reduced model; what each converges to is taken from its authors, not measured here.
  • A quiet computer. The comparisons above rest on counts of work, which do not depend on how busy the computer was. Times measured on a quiet machine would rank close cases more surely.

Summary

  • Fast at a fixed number of iterations is not accurate. A linearly converging method needs steps without limit as its factor approaches 1, and the stiffer the stiff part, the nearer is to 1.
  • Gauss–Seidel on a soft spring and a stiff one leaves of the error a sweep at a ratio of 100; after ten sweeps the pair seems ten times too stiff. Newton’s method finds its balance in one step.
  • Projective dynamics and XPBD converge to the answer of changed equations; ADMM to the true one, at a rate not reported for a balance as tight as the arm’s; model reduction to the best answer in its subspace.
  • None of the simulator’s own speed-ups was faster over the whole curl, although two looked faster over twelve steps: each changes the path, and the path decides the next step’s cost.
  • The fast methods’ honest uses are previews, first guesses for Newton’s method, and coarse levels inside a solver.

Next: with the methods and their limits in hand, the book turns to the surfaces that bodies meet on, beginning with the triangles they are drawn with: Even triangles.