New optimized 99 line topology optimization code written in MATLAB

The Matlab codes presented in this page are intended for engineering education. Students and newcomers to the field of topology optimization can find the codes here and download them.
The codes may be used in courses in structural optimization. Compared to the previous TopOpt Matlab software, these new codes contain several speedups and the use of up-to-date Matlab capabilities, allowing to run larger Topology Optimization examples on a laptop. Moreover, the possibility to specify passive domain, filter boundary conditions, to apply continuation on penalization and projection parameters and the use of volume-preserving density projection are given by default in the present codes.

The 2D code can be downloaded from top99neo.m and the 3D code from top3D125.m (5K, Shift+click to save).

Save the programs and start Matlab in the same directory and run the programs by writing for example:
The 2D MBB beam example:
>> top99neo(300,100,0.5,3,8.75,3,'N',0.5,2,0.2,500);

The 3D cantilever beam example
>> top3D125(24,12,12,0.12,3,sqrt(3),1,'N',0.5,1,0.2,100);

NOTE: the codes contain the external function "fsparse" that is part of the "Fast" package by Stefan Engblom. The package can be downloaded here:
and installed in Matlab following the instructions in the README file.

Details of the implementation are discussed in the paper:

A new generation 99 line Matlab code for compliance topology optimization and its extension to 3D - Federico Ferrari, Ole Sigmund, Structural and Multidisciplinary Optimization (2020), doi:10.1007/s00158-020-02629-w

The ArXive version of the paper can be found here:

Abstract: Compact and efficient Matlab implementations of compliance Topology Optimization (TO) for 2D and 3D continua are given, consisting of 99 and 125 lines respectively. On discretizations ranging from $3\cdot 10^{4}$ to $4.8\cdot10^{5}$ elements, the 2D version, named top99neo, shows speedups from 2.55 to 5.5 times compared to the well-known top88 code. The 3D version, named top3D125, is the most compact and efficient Matlab implementation for 3D TO to date, showing a speedup of 1.9 times compared to the code of Amir etal. (2014), on a discretization with $2.2\cdot10^{5}$ elements. For both codes, improvements are due to much more efficient procedures for the assembly and implementation of filters and shortcuts in the design update step. The use of an acceleration strategy, yielding major cuts in the overall computational time, is also discussed, stressing its easy integration within the basic codes.
8 MARCH 2021