  This paper presents an educational code written using FEniCS, based on the
level set method, to perform compliance minimization in structural
optimization. We use the concept of distributed shape derivative to compute a
descent direction for the compliance, which is defined as a shape functional.
The use of the distributed shape derivative is facilitated by FEniCS, which
allows to handle complicated partial differential equations with a simple
implementation. The code is written for compliance minimization in the
framework of linearized elasticity, and can be easily adapted to tackle other
functionals and partial differential equations. We also provide an extension of
the code for compliant mechanisms. We start by explaining how to compute shape
derivatives, and discuss the differences between the distributed and boundary
expressions of the shape derivative. Then we describe the implementation in
details, and show the application of this code to some classical benchmarks of
topology optimization. The code is available at
http://antoinelaurain.com/compliance.htm, and the main file is also given in
the appendix.
