Matlab Code For A Level Set-Based Topology Optimization Method Using A Reaction Diffusion Equation
Matlab Code For A Level Set-Based Topology Optimization Method Using A Reaction Diffusion Equation
DOI 10.1007/s00158-014-1190-z
EDUCATIONAL ARTICLE
Received: 10 March 2014 / Revised: 3 October 2014 / Accepted: 21 October 2014 / Published online: 19 November 2014
Springer-Verlag Berlin Heidelberg 2014
Abstract This paper presents a simple Matlab implementation for a level set-based topology optimization method in
which the level set function is updated using a reaction diffusion equation, which is different from conventional level
set-based approaches (Allaire et al. 2002, 2004; Wang et
al. 2003) that use the Hamilton-Jacobi equation to update
the level set function. With this method, the geometrical
complexity of optimized configurations can be easily controlled by appropriately setting a regularization parameter.
We explain the code in detail, and also the derivation of
the topological derivative that is used in the level set-based
topology optimization. Numerical results for stiffness maximization problems are provided to facilitate the readers
understanding. The presented code is intended for educational purposes only. This paper was inspired by previously published papers presenting Matlab code for a SIMP
method (Sigmund 2001; Andreassen et al. 2011), a level
set-based method (Challis 2010), and FreeFem++ code for
a structural optimization method (Allaire and Pantz 2006).
Readers can investigate results provided by these different
methods and discover the prominent aspects of each particular method. The code presented here can be downloaded
from http://www.osdel.me.kyoto-u.ac.jp/members/yamada/
codes.html.
Keywords Education Matlab code Topology
optimization Level set method Topological derivative
Reaction diffusion equation
1 Introduction
This paper presents Matlab code for a level set-based
topology optimization method incorporating a reaction diffusion equation for a compliance minimization problem.
Concerning level set-based structural optimization methods, many have been proposed since the pioneering works
by Allaire et al. (2002, 2004) and Wang et al. (2003).
Programming code for a level set approach is freely available: Scilab code (Allaire et al. 2004) can be downloaded
via http://www.cmap.polytechnique.fr/allaire/levelset en.
html. Also, Challis (2010) presented Matlab code for
a discrete level set approach, which is available in the
manuscript. The Matlab code discussed in this paper can be
used as an aid to understand the similarities and differences
between this level set-based method and other topology
optimization methods.
The level set method was first proposed by Osher and
Sethian (1988) as a method to implicitly represent the
evolution of interfaces. In such analyses, the evolution
of interface boundaries is tracked by solving a so-called
Hamilton-Jacobi equation, using an appropriate velocity
normal to the interface of the moving boundary. In level
set-based approaches, structural boundaries are represented
by the zero iso-surface of the level set function and the
level set function is defined so that the structural domain
is represented wherever the level set function has a positive
value. With respect to boundary representation methods,
we classify the method presented here as a level set-based
approach, which was developed by several of the authors
(Yamada et al. 2010).
In this method, the level set function is updated by
solving a reaction-diffusion equation based on the topological derivative of the objective functional. Therefore,
this method allows topological changes that generate new
1160
M. Otomori et al.
2 Formulation
2.1 Topology optimization
For structural optimization, optimization problems are formulated using a domain filled with a material domain, a
void domain, and boundaries , as follows:
inf F [] =
fd (x, x, x)d +
fb (x, x, x)d,
(1)
inf F [ ] =
fd (x, ) d +
D
fb (x, ) d,
(2)
(3)
1161
1 (x) > 0 x \
(x) = 0
x
(4)
0 > (x) 1 x D \ .
The above level set function is used to represent the
boundaries of the target structure; positive values represent
the material domain, negative values represent the void
domain, and zero represents the structural boundaries. The
level set function has upper and lower limits imposed for the
regularization term, used for regularizing the optimization
problem, which will be explained in the next subsection. To
avoid confusion concerning the sign of the level set function, we note that even though we define positive values of
the level set function as corresponding to points in the material domain, as in (Wang et al. 2003; Yamada et al. 2010),
an inverse definition where negative values correspond to
points in the material domain, as in (Allaire 2002; Allaire
et al. 2004; Challis 2010), is equally valid. We also note that
the level set function used in the method presented here is
not a signed distance function, such as is typically used in
many level set-based approaches. The optimization problem
that minimizes an objective functional F under an inequality
constraint G is then formulated as follows, using the level
set function defined above.
fd (x, )d + fb (x, )d
(5)
inf F [ ] =
D
subject to G[ ] =
g(x, ) d Gmax 0 ,
(6)
D
(8)
G = 0,
0,
G 0,
(9)
1162
M. Otomori et al.
= K F ,
t
(10)
where K > 0 is a coefficient of proportionality. The optimization problem as formulated above is an ill-posed problem, so it is regularized by adding a regularization term, as
follows.
= K F 2 ,
t
(11)
have excessive geometrical complexity, so that an optimized configuration that has a desired degree of geometrical
simplicity can be obtained.
Upper and lower limits are imposed on the level set function so that the smoothing effect only operates on points that
are close to the structural boundaries. Therefore, this regularization term functions implicitly as a kind of perimeter
control. That is, the complexity of the optimized configuration can be controlled by adjusting the value of the
regularization parameter . For relatively small values of ,
relatively complex optimized configurations are obtained,
and the converse is true. The details are provided in the
numerical examples. We note that adding the regularization term to (10) to obtain (11) makes it currently difficult
to guarantee that the objective functional monotonically
decreases, although the advection velocity is rigorously
guaranteed to decrease in a descent direction in Allaire et al.
(2004). We hope to address this issue in future research.
Setting appropriate boundary conditions for (11), the
following equations are obtained.
= K F 2 in D
t
=0
on D.
(12)
1163
settings. Other boundary conditions might work fine. However, we use the Dirichlet boundary condition = 0 on the
boundary of the design domain for simplicity on implementation. The optimized configuration can now be obtained by
solving the above time evolution problem. In this method,
topological derivative dt F is used for the F term.
The second term on the right-hand side in the above equation can be replaced using Greens formula, as follows:
F =
ti ui d + u i ti d
u i,j Cij kl uk,l d
+
d Vmax .
s.t. G =
d Vmax 0
(14)
(15)
div Cij kl uk,l = 0 on
ui = u i
ti = ti
(19)
in u
(16)
in t ,
(17)
(F + F ) F
0 meas( \ ) meas()
(20)
0 4
(21)
Aij kl
(1 14 + 15 2 )E
3(1 )
=
ij kl
2(1 + )(7 5)
(1 2)2
+ 5E(ik j l + il j k ) . (22)
3 Implementation
3.1 Reaction-diffusion equation
We now present a scheme for implementing the reactiondiffusion equation (Yamada et al. 2010). As discussed
above, the level set function is updated using a reaction diffusion equation, and the diffusive term 2 ensures that
the optimization has sufficient smoothness and numerical
stability.
First, we introduce a parameter C to normalize the sensitivities so that the value of can be chosen regardless of the
1164
M. Otomori et al.
= Cdt F 2 in D
t
(23)
=0
on D.
Here, K in (12) is set to 1. The effect of this term is explained
in Yamada et al. (2010). We note that the F term in (12)
is replaced by Cdt F . The opposite in sign is due to the
relationship between the definitions of topological derivative and the sign of level set function. C is defined so that
D d
.
(24)
C=
|
d
t F | d
D
Using the finite difference approach, the equations in (23)
are discretized in the time direction as follows:
(t)
(t + t)
2 (t + t) = Cdt F +
(25)
t
t
= 0 on D,
where t is the step for fictitious time t. Using the finite element approach, the above equations are expressed in weak
form as follows:
(t+t)
dD
+ D T (t + t) dD
D t
(26)
+ (t) dD
for
Cd
=
F
t
D
t
= 0 on D,
is the functional space defined such that
where
= (x)|(x) H 1 (D) with = 0 on D .
(27)
Y=
N
e=1 Ve
Cdt F +
(x, t)
NdVe ,
t
(30)
where N is the
number of elements and Ve is the volume
of an element. N
e=1 represents the union set of the elements, where e is the element number. N is the interpolation
function of the level set function.
After updating the level set function using (28), the level
set function is replaced based on the following rule, so that
the upper and lower limit constraints of the level set function
in (4) are satisfied.
if > 1
then = sign().
(31)
D dt F d
D
d
exp
G
+d
p Gmax
(32)
1165
where Vmax is the upper limit of the volume fraction and tau
is the regularization parameter .
i
0,
dVmax (V0 Vmax ) max 0, 1
nvol
D
(33)
G=
where i is the current iteration number and V0 is the volume fraction of the initial guess. The first term represents
the volume of the configuration at the current iteration. The
third term in the right-hand side of (33) is added to the primal volume constraint to relax the upper limit of the volume
constraint so that the constraint is gradually tightened during
nvol iterations. After nvol iterations, the constraint functional
(33) represents the original volume constraint.
4 Matlab code
The simple Matlab code for the mean compliance minimization problem is provided in Appendix A. The program
consists of four parts: parameter definitions (lines 313),
finite element analysis preparation (lines 1440), loads and
boundary settings (lines 4153), and the main loop (lines
5488). Figure 5 shows the design domain and boundary
conditions of the problem. Displacement is fixed at the left
boundary and a downward force is applied at the center of
the right boundary. The design domain is discretized using
a rectangular mesh. The numbers of elements are nelx in the
horizontal direction and nely in the vertical direction.
The Matlab code is evoked with the following call:
levelset88(nelx,nely,Vmax ,tau),
Table 1 Parameter definition
parameter
meaning
nelx
nely
Vmax
tau
E0
Emin
nu
nvol
dt
d, p
1166
M. Otomori et al.
Due to the similarity in the formulation of the topological derivative u 0i,j Aij kl u0k,l defined in (22), and the mutual
strain energy density u i,j Kij kl uk,l (Nishiwaki et al. 1998;
Howell 2001), the topological derivative can be computed
using the same procedure as that for computing the mutual
strain energy density, by replacing Youngs modulus E and
Poissons ratio as follows:
E
4A22
,
A1 + 2A2
(34)
A1
,
A1 + 2A2
(35)
where
3(1 ) 1 14 + 15 2
A1 =
E,
2(1 + )(7 5)(1 2)2
A2 =
15E(1 )
.
2(1 + )(7 5)
(36)
(37)
Fig. 6 Optimized configurations for design model 1 obtained using different meshes: a 8064; b 160128; c 320256
1167
Fig. 7 Optimized configurations for design model 1 obtained using different regularization parameter settings: a 2 104 ; b 6 104 ;
c 1 102
5 Numerical examples
5.1 Mesh independency
First, we examine three cases whose degree of discretization is subject to the following mesh parameters:
80 64, 160 128, and 320 256. The regularization
parameter is set to 2 104 and a volume fraction upper
limit of 0.5 is used in all cases. The Matlab code calls for
these three cases are respectively:
levelset88(80,64,0.5,2e-4),
levelset88(160,128,0.5,2e-4), and
levelset88(320,256,0.5,2e-4).
1168
M. Otomori et al.
Fig. 9 Optimized configurations for design model 2 obtained using different values for the regularization parameter : a 2 104 ; b 6 104
Line 45:
fixeddofs = [1:2:2*(nely+1) 2*(nely+1)*
(nelx+1-round(nelx/32)):2*(nely+1):2*
(nely+1)*(nelx+1)];
6 Conclusions
This paper presented Matlab code for a level set-based
topology optimization method that uses a reaction diffusion equation to update the level set function. A rigorous
derivation of the topological derivative for a compliance
minimization problem was provided. Although the term representing the effect of boundary conditions when a hole
is created in the design domain was ignored in previous
research (Yamada et al. 2010), this effect was considered in
the method presented here.
We hope that dissemination of this code will enable
readers to more easily understand the operation of this
topology optimization method and also allow them to
compare results obtained when using different topology
optimization methods. We believe that this code is very
compact, comprehensible, and computationally efficient. It
employs the loop vectorization and memory preallocation
detailed in Andreassen et al. (2011).
1169
1170
M. Otomori et al.
\
in
(38)
ui + ui = u i
ti + ti = ti
on u
(39)
on t
(40)
ti + ti = 0
on
(41)
.
\
F =
div Cij kl u k,l ui d +
(ti ti )ui d
\
t
+
(ui + u i )ti d +
u i,j Cij kl uk,l d
u
Cij kl u i,j nl uk d
d.
(45)
u t
(ti ui + ti ui + ti ui )d
u i (ti + ti )d +
u i (ti + ti )d
u t
(42)
\
on u
(47)
on t .
(48)
F =
u t
(ti ui + ti ui )d +
u t
d.
u i ti d
(43)
1171
on u
ti = 0
on t
(52)
ti = ti
on
.
(53)
(51)
on
,
(55)
)
u
ik
j
l
il
j
k
i,j k,l
1
(64)
A1
A1 + 2A2 A1
A1
A1 + 2A2 A1
A1
A1
A1 + 2A2
0
0
0
0
0
0
0
0
0
(57)
0 4
(65)
0
0
0
A2
0
0
0
0
0
0
A2
0
0
0
0
0
0
A2
11
22
33
12
23
31
(66)
(60)
A1
where c = A1 +2A
. Compare this with the following
2
formulation of the mutual strain energy density:
Namely,
3(1 ) 1 14 + 15 2
15E(1 )
.
A1 =
E, A2 =
2
2(1 + )(7 5)
2(1 + )(7 5)(1 2)
(61)
11
0
A1 + 2A2 A1
22
A1 + 2A2 0
=
11
22 12 A1
12
0
0
A2 0
1
c
0
11
= (A1 + 2A2 )
11
22 12 c 1 0
22 ,
12
0 0 1c
2
(67)
(63)
where ij is Kroneckers delta function. Finally, the topological derivative of the Lagrangian is given as
F
dt F = lim
= u 0i,j Aij kl u0k,l ,
(58)
3
where Aij kl is defined as follows:
3(1)
(114+15 2 )E
ij kl
Aij kl = 2(1+)(75)
(12)2
+5E(ik j l + il j k ) .
(62)
"
#
11
1 0
E
11
22 12 1 0
22 .
=
(1 )2
12
0 0 1
2
(68)
1172
M. Otomori et al.
(69)
References
Allaire G (2002) Shape optimization by the homogenization method.
Vol. 146 of applied mathematical sciences. Springer, New York
Allaire G, Pantz O (2006) Structural optimization with FreeFem++.
Struct Multidiscipl Optim 32:173181
Allaire G, Jouve F, Toader AM (2002) A level-set method for shape
optimization. C R Acad Sci Paris Ser I 334:11251130
Allaire G, Jouve F, Toader AM (2004) Structural optimization using
sensitivity analysis and a level-set method. J Comp Phys 194:363
393
Allaire G, de Gournay F, Jouve F, Toader AM (2005) Structural optimization using topological and shape sensitivity via a level set
method. Control Cybern 34:5980
Andreassen E, Clausen A, Schevenels M, Lazarov BS, Sigmund O
(2011) Efficient topology optimization in MATLAB using 88 lines
of code. Struct Multidiscipl Optim 43:116