A 2-d Scilab Code

for shape and topology optimization by the level set method

Grégoire Allaire, CMAP, Ecole Polytechnique, October 2009

(new release of January 25, 2012)

We propose a set of Scilab routines which perform shape and topology optimization of plane elastic structures. For the moment only compliance minimization is implemented in the single or multiple loads case. The proposed algorithm uses the level set method of S. Osher and J. Sethian. It is based on the work of G. Allaire, F. Jouve, A.-M. Toader, J. Comp. Phys. Vol 194/1, pp.363-393 (2004). It features the possiblity of using the notion of topological gradient to nucleate new holes, as implemented in the work of G. Allaire, F. de Gournay, F. Jouve, A.-M. Toader, Control and Cybernetics 34, pp.59-80 (2005). These routines have been written by G. Allaire, A. Karrman and G. Michailidis. Users are free to use this code as far as they acknowledge their source!

Warning : Although they have been written and tested with great care, these Scilab routines come with absolutely no warranty. Their authors decline any responsability linked to their use.

What is shape optimization ? In the context of solid mechanics it is also called structural optimization. It is the mathematical theory which makes possible the ''automatic'' optimization of shapes of mechanical structures. By ``automatic'' it is meant that these methods and algorithms can be implemented on a computer which can analyse and improve the designs of numerous successive configurations without any help from the engineer or designer. For more details on this topic we refer to the book Conception optimale de structures published by Springer in the series "Mathématiques et Applications", volume 58, 2007, 280 p., 91 illus., ISBN-10: 3-540-36710-1, ISBN-13: 978-3-540-36710-9. There are, of course, many more references on the topic!

What is Scilab ? Scilab is a free software developed and distributed by INRIA. You can freely download it on the web site www.scilab.org . It is very similar in spirit to Matlab.

List of Scilab computer programs to download

  • A set of various subroutines (functions in Scilab) functions.sci
  • The main routine optalg.sce
  • Parameters files for different test cases
  • Long cantilever long-cantilever.sce
    boundary condition for a long cantilever initial shape of a long cantilever final shape of a long cantilever
  • Short cantilever short-cantilever.sce
    boundary condition for a long cantilever initial shape of a short cantilever final shape of a short cantilever
  • Bridge bridge.sce
    boundary condition for a bridge initial shape of a bridge final shape of a bridge
  • L-beam L-beam.sce
    boundary condition for a L-beam initial shape of a L-beam final shape of a L-beam
  • Multiple loads case for a medium cantilever 2-force-cantilever.sce
    boundary condition for a bridge initial shape of a medium cantilever final shape of a medimum cantilever
  • L-beam (with the topological gradient) L-beam-top.sce
    initial shape of a L-beam iteration 20 of a L-beam final shape of a L-beam
  • A gzip tar archive of all these Scilab programs files.tar.gz
  • What this code does and doesn't...

    This Scilab code is inspired from the Fortran code used in the work of G. Allaire, F. Jouve, A.-M. Toader, J. Comp. Phys. Vol 194/1, pp.363-393 (2004). In a fixed computational domain the 2-d structure is parametrized by a level set function. The iterative algorithm of shape optimization alternates finite element analysis of the current structure and deformation of the structure by transport of the level set function. Its main features are the use of an explicit second-order finite difference upwind scheme for the transport Hamilton-Jacobi equation, a re-initialization process at fixed frequency (function mesh00), a regularization of the velocity field, a possibility of using the topological gradient to nucleate new holes (new !), a careful interpolation to project the structure on the fixed mesh (function FEdensity), a monitoring of the decrease of the objective function by varying the number of time steps in the transport Hamilton-Jacobi equation. We borrowed the finite element solver (functions FE and lk) from the famous '' 99 line topology optimization code written in Matlab'' of O. Sigmund (Struct. Multidisc. Optim. 21, pp.120-127, 2001) whose kind permission is greatefully acknowledged. The objective function to be minimized is the sum of three terms: the compliance, the volume and the perimeter. The two last ones are multiplied by fixed non-negative Lagrange multipliers. However, at the end of the manual, we have also given a function that can be added to the code in order to keep the total volume of the structure constant in each iteration (new !).

    The code is not optimized for minimal CPU cost: some routines are still not written in a vectorial form (shame on me). It works only in 2-d for square regular meshes. It performs only compliance minimization in the single or multiple loads case. There is no stopping criterion (not hard to add one). There are many small improvements in solving the level set equation which are implemented in the original Fortran code (cited above) and not reproduced in the Scilab code. Let us mention a few: narrow band, fast marching, Russo-Smereka correction for the re-initialization. One day maybe...

    I plan to deal with more general objective functions and to add an adjoint state in the process. In theory 3-d is easy to implement, but in practice Scilab is probably too slow...

    You may find more informations on this Scilab code in the report written by A. Karrman (from Caltech) after his internship at Ecole Polytechnique, as well as in a manual of the code written by G. Michailidis (Phd student at Ecole Polytechnique). Please send any bug report to gregoire.allaire_AT_polytechnique.fr and I will try to correct it as soon as possible.

    How to use this Scilab code

  • You must have first installed Scilab (version 4.1.2 or 5.1.1 at least) and start a Scilab Console.
  • To run one of the given example, say the long cantilever, you must load (i) functions.sci, (ii) long-cantilever.sce, (iii) optalg.sce. A graphic window will open and the iterations will run in the Console.
  • To create a new test case, you just have to write a file similar to long-cantilever.sce but with your own data... A priori, there is no need to change the other files (well, in theory!).
  • The important parameters at the user's disposal are:
  • Geometric parameters: mesh size dx=dy, length and height, the possibility of removing part of the working domain with the "passive" function (see the L-beam example).
  • Initialization: how many holes of which size ?
  • Numerical parameters: the value of the weak ersatz material filling holes, the frequency and the step number of re-initializations, the regularization coefficient for a smoother velocity field.
  • Optimization parameters: the total number of iteration, the allowance for a slight increase of the objective function, the Lagrange multipliers for the volume and perimeter constraints.
  • More explanations are given in the report written by A. Karrman and in the manual written by G. Michailidis.
  • Thanks. This work has partly been supported by many institutions, the support of which is gratefully acknowledged: Ecole Polytechnique, CNRS, INRIA Saclay Ile-de-France, the Chair ''Mathematical modelling and numerical simulation, F-EADS - Ecole Polytechnique - INRIA''.