Efficient topology optimization in MATLAB using 88 lines of code

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 where students may be assigned to do extensions such as multiple load-cases, alternative mesh-independency schemes, passive areas, etc..


Details of the implementation are discussed in the paper Efficient topology optimization in MATLAB using 88 lines of code, E. Andreassen, A. Clausen, M. Schevenels, B. S. Lazarov and O. Sigmund, Struct Multidisc Optim, Volume 43, Issue 1, p.1 - 16, (2011) .

Uncorrected version of the paper can be downloaded here

Abstract: The paper presents an efficient 88 line MATLAB code for topology optimization. It has been developed using the 99 line code presented by Sigmund (Struct Multidisc Optim 21(2):120–127, 2001) as a starting point. The original code has been extended by a density filter, and a considerable improvement in efficiency has been achieved, mainly by preallocating arrays and vectorizing loops. A speed improvement with a factor of 100 is obtained for a benchmark example with 7,500 elements. Moreover, the length of the code has been reduced to a mere 88 lines. These improvements have been accomplished without sacrificing the readability of the code. The 88 line code can therefore be considered as a valuable successor to the 99 line code, providing a practical instrument that may help to ease the learning curve for those entering the field of topology optimization. The paper also discusses simple extensions of the basic code to include recent PDE-based and black-and-white projection filtering methods.

The 88 line code can be downloaded here top88.m (5K, Shift+click to save). Modified versions can be obtained by selecting the links below:

Implementation utilizing PDE filter top82.m

Implementation utilizing conv2 Matlab function top71.m

Implementation utilizing Heaviside projection top110.m

Design obtained using: top110(300,100,0.5,3,9,3)

Save the program and start Matlab in the same directory. Run the program by writing for example:

>> top88(120,40,0.5,3.0,3.5,1)

in the Matlab prompt. top88 should be replaced with the corresponding name for the modified versions.

Since November 22, 2010 the top88.m MATLAB code has been downloaded 24118 times by 7615 unique users.