DfAM Practitioner Program › Module 6 › Lesson 30
Module 6 · Lesson 30 of 42 · about 1 hour
Topology Optimisation: Numerical Implementation
Sensitivities, filters, projection, optimality criteria and MMA; the 99- and 88-line codes
Why This Topic Matters
Where we are: Lesson 29 stated the problem. This topic shows how it is actually solved, at a level that lets you read and modify a research code.
Motivation: Commercial tools hide the algorithm, but their settings (filter radius, penalty, move limit) only make sense if you know what they do. Research requires changing the code itself.
Analogy: Learning to drive is easier in a simple car with the bonnet open. The short educational codes are that car.
Industry practice: The 99-line and 88-line MATLAB codes are the starting point for a large share of published research on topology optimisation.
State of the art: Robust length-scale control, efficient solvers for very large problems and differentiable programming frameworks are current implementation topics.
The Optimisation Loop
1. Analyse: assemble the stiffness matrix with the current densities and solve for the displacements.
2. Evaluate: compute the objective and the constraints.
3. Differentiate: compute the sensitivity of the objective and constraints with respect to every density. The adjoint method gives all of them for the cost of about one extra solution.
4. Regularise: filter the sensitivities or the densities to remove numerical artefacts and impose a minimum length scale.
5. Update: change the densities with an optimality-criteria rule or a mathematical-programming method.
6. Check: stop when the largest density change falls below a tolerance; otherwise repeat.
Checkerboards, Mesh Dependence and Filters
Without regularisation the solution shows checkerboard patterns, which are a numerical artefact of low-order elements that appear falsely stiff.
The solution also depends on the mesh: finer meshes give ever finer members, because the unregularised problem has no smallest length scale.
Sensitivity filter: each element's sensitivity is replaced by a weighted average over a neighbourhood of radius r_min (Sigmund). Simple and effective.
Density filter: the densities themselves are averaged, and the physical density used in the analysis is the filtered one.
Projection: a smoothed step function pushes filtered densities back towards zero and one, giving crisp boundaries while keeping the length scale.
The filter radius is therefore a design parameter: it sets the minimum member size in the result (used again in Lesson 31).
Updating the Design
Optimality criteria: at the optimum the ratio of stiffness gain to volume cost is the same for every intermediate element. The update multiplies each density by that ratio raised to a damping power.
The Lagrange multiplier of the volume constraint is found by bisection so that the volume limit is met exactly at every iteration.
A move limit restricts the change of each density per iteration, which stabilises the process.
Method of moving asymptotes (MMA): a general-purpose algorithm by Svanberg that handles many constraints of any sign. It is the usual choice beyond compliance problems.
Continuation: the penalty exponent or the projection sharpness is raised gradually, which helps to avoid poor local optima.
The problem is non-convex, so different starting points or settings can give different, similarly good, designs.
Reading the Educational Codes
- The 99-line code (Sigmund, 2001) solves the two-dimensional compliance problem with a sensitivity filter and the optimality-criteria update.
- The 88-line code (Andreassen et al., 2011) is a faster rewrite with vectorised assembly and a choice of sensitivity or density filter.
- A 169-line code (Liu and Tovar, 2014) extends the same structure to three dimensions.
- Inputs are the mesh size, volume fraction, penalty exponent, filter radius and filter type; loads and supports are edited in the code.
- Typical modifications for study: other load cases, passive solid or void regions, a different filter, an added constraint.
- Lab 8 uses the 88-line code; reading it line by line beside this topic is the most effective way to learn the method.
Key Relations: Filter, Projection and Update

Worked Example: One Filter Step and One Update Step by Hand

Revision Notes: Numerical Implementation
- The loop is analyse, evaluate, differentiate, regularise, update and check convergence.
- Checkerboards and mesh dependence are numerical artefacts removed by sensitivity or density filters.
- The filter radius sets the minimum member size; projection restores crisp boundaries.
- The optimality-criteria update scales each density by the ratio of stiffness gain to volume cost, within a move limit.
- MMA handles general constraints; continuation in penalty or projection sharpness improves results.
- The 99-, 88- and 169-line codes implement all of this compactly and are the basis for study and research.
Explore Further
Code paper: Sigmund, 'A 99 line topology optimization code written in Matlab', Structural and Multidisciplinary Optimization 21, 2001.
Code paper: Andreassen et al., 'Efficient topology optimization in MATLAB using 88 lines of code', Structural and Multidisciplinary Optimization 43, 2011.
3D code: Liu and Tovar, 'An efficient 3D topology optimization code written in Matlab', Structural and Multidisciplinary Optimization 50, 2014.
Projection: Wang, Lazarov and Sigmund, 'On projection methods, convergence and robust formulations in topology optimization', Structural and Multidisciplinary Optimization 43, 2011.
Coding exercise (Lab 8): Run the 88-line code for an MBB beam with filter radii of 1.5, 3 and 6 elements. Describe how the layout and the compliance change.
Quick Check
Pick an answer for each question, then check.