Professional Documents
Culture Documents
s00158-020-02498-3
s00158-020-02498-3
https://doi.org/10.1007/s00158-020-02498-3
EDUCATIONAL PAPER
Received: 16 May 2019 / Revised: 16 November 2019 / Accepted: 7 January 2020 / Published online: 18 February 2020
# Springer-Verlag GmbH Germany, part of Springer Nature 2020
Abstract
In this article, we present a simple FreeFEM++ code to represent high-resolution boundaries of the optimal shape using
reaction-diffusion equation–based topology optimization and adaptive mesh refinement. The design algorithm is divided
into two parts to achieve a high quality of the boundary. In the first part, loop 1, the ordinary method for a reaction-
diffusion equation–based topology optimization, is applied to obtain the optimal shape. In the second part, loop 2, a
modified reaction-diffusion equation combined with a double well potential, is employed as an optimizer and the adaptive
mesh refinement is used with a gradual decrease of the diffusion coefficient. Because the code is intended for educational
purposes, this paper provides background knowledge for understanding of the finite element method and topology opti-
mization. Various numerical examples are discussed to confirm the robustness of the proposed design algorithm. The
corresponding code may be downloaded from the website http://ssd.yonsei.ac.kr.
Keywords Education . FreeFEM++ . Topology optimization . Reaction-diffusion equation . Double-well potential . Adaptive
mesh refinement
phases using the sensitivity of shape change to the design allows any topological change of the interface to be automat-
variable. The diffusion term includes the Laplacian of the ically permitted.
design variable that allows to get the numerical stability by Therefore, the concept of the phase field method to simu-
mitigating the optimal shape. late the microstructural change is similar to that of structural
However, due to regularization by the diffusion term, the topology optimization method, which obtains the optimal ma-
gray area inevitably appears at the boundary of the resultant terial distribution to maximize the structural performance by
shape. The fixed mesh used at the beginning of the design has permitting the topological change in the design domain. Based
a limit to reduce the gray area and determine clear boundaries. on the concept, the phase field method was first introduced in
Thus, the dense mesh is required to overcome such limitation, structural topology optimization by Bourdin and Chambolle
and this can be effectively achieved by applying an AMR. (2003). Later, Zhou and Wang (2007) used the fourth-order
Maute and Ramm (1995) first proposed applying AMR to Cahn-Hilliard equation as update scheme, and Takezawa et al.
topology optimization, and the method separates the design (2010) introduced the Allen-Cahn equation in which the ob-
variable and analysis mesh to improve the quality of the result jective function is integrated with the DWP, which restricts
layout. The design variable mesh is mapped onto an adaptive topological change in the design domain by inducing the sen-
mesh for analysis. The code provided in this paper also in- sitivity not to be applied at ϕ = 0 and ϕ = 1. Inspired by the
cludes the AMR and the DWP (Takezawa et al. 2010) to work of Yamada et al. (2010), Choi et al. (2011) proposed an
reduce the gray area of the optimal shape from the RDE- RDE-based topology optimization scheme. By combining
based design method. with the DWP, the method has been evolved to the phase-
The phase field method was originally developed as a tool field design method (Lim et al. 2014b). Recently, phase
to simulate the formation process of the microstructure, which field–based topology optimization or the phase field design
is the spatial structure of interfaces in the field of computa- method has been applied to the multidisciplinary topology
tional materials. Due to the versatility of the model, it has been optimization such as stress problem (Lee et al. 2016), fracture
extended to tools for predicting almost all types of microstruc- resistance of composites (Xia et al. 2018), load uncertainty
ture appearing in materials such as dendritic pattern simulation problem (Jeong et al. 2019), fluid problem (Garcke et al.
(McFadden et al. 1993; Wheeler et al. 1993), eutectic growth, 2015), and electromagnetic problems (Lim et al. 2014a; Lim
and (Karma 1994) multiphase transformation (Steinbach and et al. 2014b; Seong and Yoo 2017).
Pezzolla 1999). The important factors in the microstructure FreeFEM++ is a free open source program developed
formation process are diffusion of alloying elements or latent for solving nonlinear partial differential equation (PDE)
heat, interfacial energy effect, interfacial kinetics effect, and by the finite element method (Hecht 2012). To use
stress effect (Langer 1980; Flemings 1974; Kurz and Fisher FreeFEM++, one must know the variational formulation
1989). However, among them, diffusion and interfacial energy for the derivation of the weak form from the strong form
effects are the most fundamental roles in the phase transfor- of the PDE. FreeFEM ++ was developed to easily handle
mation. The phase transformation process is determined by the complex and tedious processes required for finite
competition and balance between the intrinsic effect of diffu- element analysis with a few commands. The boundary
sion to reduce the characteristic distance and the interfacial shape can be easily modeled by using the parameter,
energy effect (or the Gibbs-Thomson effect) which reduces and the mesh generation and the connectivity setting of
the total energy by decreasing the area of the interface each node are automatically conducted by the program.
(Langer 1980). Such interaction of diffusion and interfacial Also, boundary conditions can also be easily implement-
energy plays a key role in the formation of solidification ed. In this respect, there is an advantage that the time for
microstructure. the code development of the finite element analysis can
The fundamental ideas of the phase field model method are be shortened compared with other mathematical pro-
as follows: (1) The phase field variable ϕ, which is a contin- grams. In addition, FreeFEM ++ is compatible with var-
uous variable defined in the entire system, is introduced. (2) ious external programs such as Tetgen, Gmsh, Mmg, and
The interface is regarded as a region having a finite thickness ParaView.
in which the fraction of two phases continuously changes. In This article provides detailed derivations of the weak forms
other words, ϕ changes continuously according to the position required to implement FreeFEM++ code for structural analy-
in the interface. The existing Gibbs-Thomson equation (Gibbs sis and topology optimization. Beginners can study the fun-
1928) is difficult to be handled because it must be applied only damentals of finite element analysis and topology optimiza-
to the interface, but the phase field equation is easy for the tion through the provided code. Furthermore, it is expected for
numerical calculation because it is applied to the whole sys- them to be able to develop the code and conduct in-depth
tem. Therefore, the phase field model has the advantage such research using the strength of open-source programs.
that the numerical calculation code is very simple, and not The remainder of this paper is organized as follows: For
only it is easy to be expanded from 2-D to 3-D, but it also FreeFEM ++ code implementation, Section 2 explains the
FreeFEM++ code for reaction-diffusion equation–based topology optimization: for high-resolution boundary... 441
derivation of weak forms for structural analysis and reaction- ΓN and the Dirichlet boundary ΓD, which do not overlap each
diffusion equation and the AMR. A detailed description of the other so that ∂Ω = ΓN ∪ ΓD and ΓN ∩ ΓD = 0. g is the body
FreeFEM++ code implementation for structural optimization force per unit mass, f is the traction vector (or stress vector) on
is given in Section 3. Finally, numerical examples and conclu- ΓN, and n is the normal unit vector to the boundary.
sions are discussed in Section 4 and 5, respectively. In the finite element method, the weighted residual
method based on the Galerkin approximation is generally
used to convert the differential equation of a strong form
2 Theoretical backgrounds into the integral equation of a weak form. Here, if the
strong form is 2p-th-order derivative, then the weak form
In this section, we explained the theoretical backgrounds to is p-th-order derivative. Therefore, the order decrease in
understand optimization procedure of compliance problem. the derivative of the weak form is advantageous to find
The equations derived in this chapter will be written as the solution.
FreeFEM++ idiom in Section 3. By employing the virtual displacement v (also called as a
test function) and performing integration by parts using
2.1 Structural analysis Green’s identity, the weak form of the linear elastic problem
is defined as follows (Bathe 2006):
The isotropy linear elastic material is represented by only two
material properties of Young’s modulus and Poisson’s ratio,
∫Ω σ : εðvÞ dx ¼ ∫Ω g⋅v dx þ ∫ΓN f⋅v ds
and those properties can be replaced with Lamé constants. As ð9Þ
for u∈U ; ∀v∈U
a result, the constitutive equation of the isotropy linear elastic
material is defined as where the admissible linear space U is defined as
n o
σ ¼ λð∇⋅uÞI þ 2μεðuÞ ð1Þ
U ¼ v∈H 1 ðΩÞd j v ¼ 0 on ΓD : ð10Þ
or
where d is the dimension of the space. We substitute the
σ ¼ CεðuÞ ð2Þ constitutive (1) into (9) and obtain
1
εðuÞ ¼ ∇u þ ð∇uÞT ð3Þ
2
∫Ω ½λð∇⋅uÞð∇⋅vÞ þ 2μεðuÞ : εðvÞ dx
where σ is the stress tensor, C is the 4th-order elasticity
tensor, ε is the infinitesimal strain tensor, and u is the displace- ¼ ∫Ω g⋅v dx þ ∫ΓN f⋅v ds: ð11Þ
ment vector (also called as a state variable). Also, Lamé con-
stants λ and μ are defined as follows: Using the elasticity tensor C, (9) can be expressed as
follows:
Ev
λ¼ ð4Þ
ð1 þ vÞð1−2vÞ ∫Ω ðCεðuÞÞ : εðvÞ dx ¼ ∫Ω g⋅v dx þ ∫ΓN f⋅v ds ð12Þ
E
μ¼ ð5Þ or
2ð 1 þ v Þ
where v is Poisson’s ratio. According to the equilibrium aðu; vÞ ¼ l ðvÞ u∈U ; ∀v∈U ð13Þ
condition, the governing equation and boundary conditions
of the linear elastic problem are defined by the partial differ- where a(u, v) and l(v) are called the bilinear and the load
ential equations as follows: linear form, respectively. The Neumann boundary condition
(7) is implicitly contained in the weak form (13). On the other
hand, the Dirichlet boundary condition (8) on the boundary
−∇⋅σ ¼ g in Ω ð6Þ ΓD must be explicitly satisfied in (13) and it is directly con-
σ⋅n ¼ f on ΓN ð7Þ sidered in definition of U. However, because the finite element
spaces used in FreeFEM++ do not include the Dirichlet
u ¼ 0 on ΓD ð8Þ
boundary condition, FreeFEM++ employs the penalty method
where Ω ⊂ Rd(d = 2 or 3) is a bounded domain. The bound- to impose this boundary condition. It is covered in detail in
ary ∂Ω of Ω is divided into two parts, the Neumann boundary Section 3.4.
442 C. Kim et al.
2.2 Topology optimization based on RDE-based where the objective functional J is the strain energy density
design method and the state variable u is the function of design variable ϕ. |Ω|
= ∫Ω1 dx is the area of the design domain in 2-D. Note that the
2.2.1 Material property smaller strain energy means that the stiffness of the structure
becomes greater, so the problem is equivalent to the design for
The RDE-based design method intends to find the optimal dis- maximizing stiffness. With the constrains of (18), the optimi-
tribution of the phase-field parameter ϕ by updating using the zation problem must follow the governing equations satisfy-
RDE to maximize the desired design performance. It is noted ing the boundary condition and the volume fraction constraint.
that the parameter ϕ is a design variable for the optimization First, the Lagrangian L that does not yet take into account
problem. Therefore, the material property, i.e., the Young mod- the volume constraint is defined as
ulus, is represented by ϕ based on the SIMP interpolation.
L ϕ; u ; p ¼ J ðϕÞ þ ∫Ω Cε u : ε p −ϕg⋅pdx−∫ΓN f⋅pds ð19Þ
E ðϕÞ ¼ E min þ ðE0 −E min Þϕp ð14Þ
In (19), ðu ; pÞ∈U are vector-valued functions; p is the
where p is a penalization factor (typically = 3). Here, ϕ Lagrange multiplier for the governing equation and the
works as a material density. Likewise, Lamé constants and Neumann boundary condition at ΓN.
the elasticity tensor are defined by ϕ as follows: To obtain the adjoint equation, the partial derivative of the
v Lagrangian L with respect to u in the direction δu at a station-
λðϕÞ ¼ E ðϕÞ ð15Þ ary point (u, p) ∈ U leads to
ð1 þ vÞð1−2vÞ
* +
1 ∂L
μðϕÞ ¼ E ðϕ Þ ð16Þ ðϕ; u; pÞ; δu ¼ ∫Ω g⋅δuϕ dx þ ∫ΓN f⋅δu ds
2ð 1 þ v Þ ∂u ð20Þ
þ ∫Ω Cε δu : εðpÞ dx ¼ 0:
CðϕÞ ¼ Cmin þ ðC0 −Cmin Þϕp ð17Þ
As a result, the RDE-based design method can be regarded In the third term on the right hand side of (20), δu can
as the density method of updating design variables with the commute with p due to the symmetric property of the bilinear
reaction-diffusion equation. form. Namely,
Cε δu : εðpÞ ¼ ðCεðpÞÞ : ε δu : ð21Þ
2.2.2 Compliance minimization
Substituting (21) into (20) and taking integration by parts
The compliance minimization problem shown in Fig. 1 is lead to the following equation:
formulated as * +
∂L
min J ðϕÞ ¼ ∫Ω g⋅uϕ dx þ ∫ΓN f⋅u ds ðϕ; u; pÞ; δu ¼ −∫Ω ½divðCεðpÞÞ−gϕ⋅δu dx
ϕ
∂u ð22Þ
s:t: −divðCðϕÞεðuÞÞ ¼ gϕ in Ω
u ¼ 0 on ΓD þ ∫ΓN ½ððCεðpÞÞnÞ þ f ⋅δu ds
ðCðϕÞεðuÞÞn ¼ f on ΓN ð18Þ þ ∫ΓD ððCεðpÞÞnÞ⋅δu ds ¼ 0:
∫Ω ϕ dx
GðϕÞ ¼ −V req ≤ 0 With the arbitrary function δu and the fundamental
jΩ j
lemma of calculus of variations, the following adjoint
0 ≤ ϕ ≤1
equation holds:
8
< divðCεðpÞÞ ¼ gϕ in Ω
p¼0 on ΓD ð23Þ
:
−ðCεðpÞÞ⋅n ¼ f on ΓN :
8
> 1
< qGðϕÞ þ rG2 ðϕÞ
q
dJ dC if G ≥ −
¼ ∫Ω g⋅u−g⋅p þ εðuÞ : εðpÞdx: ð25Þ e ðϕ; q; rÞ ¼ ηJ ðϕÞ þ
L 2 r ð31Þ
dϕ dϕ >
: q2 q
− if G < − :
2r r
Taking p = − u, we obtain
The above approach leads to a procedure based on a se-
quence of optimization sub-problems as the following mini-
dJ dC mization problem:
¼ ∫Ω 2g⋅u− εðuÞ : εðuÞdx: ð26Þ
dϕ dϕ
or
qkþ1 ¼ qk þ rk max½GðϕÞ; −ðqk =rk Þ ð33Þ
dJ dλðϕÞ dμðϕÞ rkþ1 ¼ γrk ; γ > 1 ð34Þ
¼− ð∇⋅uÞð∇⋅uÞ þ 2 εðuÞ : εðuÞ : ð28Þ
dϕ dϕ dϕ
As mentioned earlier, the convergence rate of the multiplier
in (33) to the Lagrange multiplier is faster than that of the
primal-dual method. Also, the multiplier method can mitigate
2.2.3 Augmented Lagrangian for inequality-constrained the ill-conditioning problem because it has the advantage of
problem convergence without increasing r to infinity. Because of those
advantages, the augmented Lagrangian is employed in this
The multiplier method proposed by Hestenes (1969) and study.
Powell (1969) is one of the ways to convert a constrained
optimization problem into an unconstrained optimization
problem. The transformed unconstrained optimization prob- 2.2.4 Reaction-diffusion equation for the update scheme
lem is represented by a single augmented Lagrangian. The
multiplier method solves the issues of the slow convergence In the RDE-based topology optimization, the RDE is used as a
of a primal-dual method and an ill-conditioning of a penalty design variable update scheme, such as the method of moving
method by combining both methods. asymptotes (MMA) and the optimality criteria method
The structural optimization problem for the above, the (Bendsøe and Sigmund 2003). The RDE has the advantage
Lagrangian in (24) can be reformulated as follows: of being able to simultaneously update the design variables
and alleviate the overestimation of optimal shapes such as
checkerboard patterns. This study introduces two types of
min J ðϕÞ s:t: GðϕÞ ¼ ∫Ω ϕdx −V req ≤ 0; 0 ≤ ϕ ≤ 1 ð29Þ
RDE: one is a conventional RDE and the other is a modified
ϕ
jΩj one combined with the DWP.
Firstly, the conventional RDE is defined as follows in the
Therefore, the augmented Lagrangian for the inequality design domain Ω ⊂ Rd(d = 2 or 3) and the pseudo-time interval
constraint is defined as (Bertsekas 2014): t (Choi et al. 2011):
∂ϕ e
∂L
¼ κ∇2 ϕ− ϕt1 ; qt1 ; rt1 in Ω ðt 1 ≤ t ≤ t 2 Þ ð35Þ
e ðϕ; q; rÞ ¼ ηJ ðϕÞ þ qGþ ðϕ; q; rÞ þ 1 rjGþ ðϕ; q; rÞj2
L ∂t ∂ϕ
2
where Gþ ðϕ; q; rÞ ¼ max½GðϕÞ; −ðq=rÞ ð30Þ ∂ϕ
¼ 0 on ∂Ω ðt 1 ≤ t ≤ t 2 Þ ð36Þ
jΩj ∂n
η¼
kdJ =dϕkL2 ðΩÞ
where ∂Ω is the boundary of Ω, and κ is a diffusion coef-
ficient. The right-hand side of (35) is composed of a diffusion
where the positive scalar q is the Lagrange multiplier for and a reaction term. The Laplacian in the diffusion term plays
the inequality constraint, and r is the penalty parameter. η is a the role of preventing the checkerboard pattern like a filtering
normalization factor introduced to stabilize the results of sen- scheme, and κ determines the thickness of the interfacial layer
sitivity analysis. An alternative expression of (30) is given by and the complexity of the resultant structure (Bourdin and
444 C. Kim et al.
Chambolle 2003). According to the previous research (Kim by using (38). Therefore, removing 30 ⋅ w(ϕ) from the
et al. 2019), the value of κ is suggested as κ > h2/2, where h is second term in the brace of (40) may not cause any
the mesh size. In the reaction term, the partial derivative of the significant change in the final shape. However, it can
augmented Lagrangian function L e with respect to ϕ is formu- produce small particles around the boundary or grayscale
lated as follows: parts inside the shape. As a result, putting it in (40) is
necessary for the boundary tracking property.
8 In addition, similar to the derivation of (39), the following
e >
< dG ðq þ rGÞ q
if G ≥ − equation can be obtained from (40):
∂L dJ
ðϕ; q; rÞ ¼ η ðϕÞ þ dϕ r ð37Þ
∂ϕ dϕ >
: 0 if G < −
q
r
ϕn −ϕn−1 e
∫Ω ϕ þ κ ∇ϕn ⋅∇ϕe
δt !
where dG/dϕ is |Ω|−1. e
∂L ð41Þ
0
þ aw ðϕn Þ þ 30⋅wðϕn Þ ϕ ; q ; rn−1 ϕdxe ¼ 0:
To implement the RDE in FreeFEM ++, the weak form ∂ϕ n−1 n−1
must be derived. Multiplying both sides of (35) by the test
function ϕ e and taking the integration by parts using Green’s In the code provided, (39) and (41) are represented by the
identity, the weak form can be derived as names RDE and DWP, respectively.
∂ϕ e e
∫Ω e þ ∂L ϕt ; qt ; rt ϕdx−∫
ϕ þ κ ∇ϕ⋅∇ϕ e ∂Ω
∂ϕ e
ϕds ¼ 0: ð38Þ
∂t ∂ϕ 1 1 1
∂n 3 FreeFEM++ implementation
Here, the second term in the left-side hand can be canceled This section describes the FreeFEM++ code for the com-
out due to (36). Applying the implicit Euler finite difference pliance minimization of a cantilever beam under a plane
approximation with respect to the pseudo time, (38) can be stress condition. As shown in Fig. 1, the left side is fixed
rewritten as and the negative y-direction force is applied on the mid-
dle right side. Its dimension is 2 m × 1 m, and the
" # design domain is discretized with symmetric structural
ϕn −ϕn−1 e e
∫Ω e þ ∂L ϕn−1 ; qn−1 ; rn−1 ϕ
ϕ þ κ ∇ϕn ⋅∇ϕ e dx ¼ 0: ð39Þ meshes as displayed in Fig. 2.
δt ∂ϕ
The provided code consists of four parts in overall: param-
The modified RDE combined with the DWP allows to eter definition (lines 1–14), border and mesh (lines 15–27),
obtain the narrow gray region as well as to restrict the shape setting the problem (lines 28–59), and optimization loops
change only along boundaries (Lim et al. 2014b). Therefore, (lines 60–108). Detailed descriptions of each part are given
the modified RDE limits the topological change during the in the following subsections.
optimization process. It is given by
3.1 Optimization algorithm
( )
∂ϕ 0
e
∂L
¼ κ∇2 ϕ− aw ðϕÞ þ 30⋅wðϕÞ ϕ ; q ; rt Figure 3 shows the whole algorithm of the provided code. The
∂t ∂ϕ t1 t1 1 algorithm consists of loop 1 and loop 2. In loop 1, the optimal
in Ω ðt 1 ≤ t ≤ t 2 Þ ð40Þ shape is obtained by the RDE-based design method. Loop 1
∂ϕ
¼ 0 on ∂Ω ðt 1 ≤ t ≤ t 2 Þ
∂n
where wðϕÞ ¼ ϕ2 ð1−ϕÞ2 :
terminates if the maximum change in design variables is less the interfacial area. In that case, the AMR may automat-
than the value of TOL as ically generate the dense mesh in those areas. It is useful
for resolving local and extreme variation of the solution
ϕtþΔt −ϕt ∞ < TOL ð42Þ such as the stress concentration and sharp change of a
L ðΩÞ
structural geometry. In this paper, the AMR is applied
where TOL is set to 1% in this study. based on ϕ to improve the quality of the boundary.
When entering loop 2, the AMR is conducted with the Through the AMR, the refined mesh in 2-D is adaptive
DWP and the diffusion coefficient is decreased at each to the Hessian defined as
iteration. In general, because of predicting the resulting
optimal shape in the beginning, the analysis result from
the pre-determined mesh may be inaccurate, especially at ∂2 ϕ ∂ 2 ϕ ∂2 ϕ
HðϕÞ ¼ ∇ð∇ϕÞ ¼ ; ; : ð43Þ
∂x2 ∂x∂y ∂y2
Table 1 Parameter explanation Therefore, nodes generated by the AMR are concentrated
Parameter Explanation in the vicinity of the boundary since ϕ changes from 0 to 1 in
the gray area.
E0 Young’s modulus 200 GPa, E0 in (14)
Emin Void value 0.001, Emin in (14)
nu Poisson’s ratio 0.3, v in (15), (16)
p Penalization factor 3, p in (14)
InitVol Initial volume fraction set as 0.5
Volreq Volume constraint, Vreq in (18)
k Diffusion coefficient, κin (39), (41)
eta Normalized value of the sensitivity, η in (30)
r Penalty parameter, r in (33), (34)
gamma Increasing rate of penalty parameter 1.025,γin (34)
q Lagrange multiplier, q in (33)
dt Pseudo time step 0.1, δtin (39), (41)
AMRnode Maximum number of nodes
Fig. 4 Rectangle and label number of the cantilever model
446 C. Kim et al.
The AMR is introduced in loop 2 for two reasons. 3.3 Shape and mesh (lines 15–27)
Firstly, in the density-based topology optimization where
the gray region of the material interface inevitably exists, The ‘square’ command is used to model a rectangular shape
the AMR helps to represent physical phenomena at the with the triangular mesh in 2-D. For example, the rectangle Th
interfacial area. For example, multi-material topology op- of [x0, x1] × [y0, y1]with n by m grid can be represented as
timization considering the interfacial behavior between follows:
materials (Lawry and Maute 2015; Liu et al. 2016) re-
quires enough nodes at the interface, in matters where mesh Th = square (N, M, [x0 + (x1 − x0) * x, y0 + (y1 − y0) * y])
the interface behavior between materials must be consid-
ered. In that case, the AMR can generate sufficient num- ‘square’ labels each boundary by default that label numbers
ber of nodes at the interface. Secondly, for the education- are assigned counterclockwise from the bottom. For the conve-
al purpose, it is intended to show that the AMR can be nience of imposing boundary conditions, the label numbers are
easily implemented in the topology optimization using modified by the array in lines 20–22. To apply a force on the
FreeFEM ++ by using only one subroutine function center of the right boundary, we define three rectangles which are
“adaptmesh.” bottom (Th1), middle (Th2), and top (Th3) as shown in Fig. 4
The criteria of loop 2 is based on the measure of discrete- with their label numbers. Here, label 2 and label 3 mean the fixed
ness in lines 73 and 96 (Sigmund 2007). condition and the load condition, respectively. Each rectangle of
Th1,∙Th2, and∙Th3 is easily combined by using the operator “+”
∫Ω 4ϕð1−ϕÞdx in line 26. The ‘plot’ command in line 27 visualizes the mesh of
M nd ¼ : ð44Þ Th. Here, the ‘wait’ command is used for the debug. If its value is
∫Ω 1 dx
1 or true, the program is stopped at the line. On the contrary, if it
has a value of 0 or false, the program continues.
3.2 Parameter definition (lines 1–14)
3.4 Setting problem (lines 28–59)
Table 1 explains the meaning of each parameter and the
corresponded equation in which the parameter is used. In lines 30–35, the tensors used repeatedly are defined by
Those equations are directly used in the FreeFEM++ code. the ‘macro’ command. u, v, f, e(u), div(u), and grad(phi)
FreeFEM++ code for reaction-diffusion equation–based topology optimization: for high-resolution boundary... 447
are the displacement vector, the virtual displacement vec- 39, ‘P2’ is the command for piecewise quadratic continu-
tor, the external force vector, the infinitesimal strain vec- ous finite element analysis. In line 40, phi, vphi, and
tor, divergence, and gradient, respectively. dx and dy oldphi correspond to the design variable ϕn, the test func-
mean the partial derivative of x and y. u[0] and u[1] are tion of the design variable ϕ, e and the design variable of
u1 and u2 as the first and second components of array u. the previous iteration ϕn − 1 in (39), respectively. phierror
In lines 36–40, finite element spaces and approximated is declared to calculate the change of the design variable
solutions are defined for the structural analysis and optimiza- in lines 79 and 102.
tion. fespace Vh(Th, [P1,P1]) defines the finite element space In lines 41–44, the total volume of the design domain
Vh having the approximated solution of the vector type on the Voltot, the volume fraction Vol, and the diffusion coefficient
nodes of Th as follows: k are defined. The ‘Int2d’ command conducts the numerical
n o integration based on the Gauss quadrature. Thus,
VhðTh; ½P1; P1Þ ¼ ðu1 ; u2 Þju1 ∈Vh Th; P1 ; u2 ∈Vh Th; P1 int2d(Th)(1.) in line 42 is the same with |Ω| = ∫Ω1 dx. In line
M 44, the reason for multiplying the diffusion coefficient by the
VhðTh; P1Þ ¼ uðx; yÞju x; y ¼ ∑ uk ϕk x; y
k total volume of the design area is to maintain the effect of
regularization according to the dimension change of the de-
where ‘P1’ is the command for piecewise linear contin- sign domain.
uous finite element analysis. ϕk and uk are called the shape Lines 45–59 define the functions and the weak forms. E,
functions and nodal values of the mesh, respectively. Also, lambda, and mu are defined in (14), (15), and (16), respective-
M indicates the number of the degree of freedom. In line ly. Lines 49–51 are the partial derivatives of (14), (15), and
448 C. Kim et al.
5.0E-03
4.0E-03 Before entering the while loop, parameters are initialized and
declared. oldphi = InitVol in line 62 means to set the gray
3.0E-03
value of 0.5 for whole design variables in the initial design.
2.0E-03 In line 70, the elasticity solves the elasticity problem defined
in line 57. After solving the elasticity problem, objective, eta,
1.0E-03
and Mnd are calculated by (18), (30), and (44), respectively.
0.0E+00 Through solving RDE in line 76, phi is updated from oldphi.
0 20 40 60 80 100 120 140 In lines 77–78, phi less than 0 or greater than 1 is forced to be
Iteration 0 and 1, respectively, using the max function. Line 80 calcu-
lates the L-infinity norm of change of design variable to de-
b Loop 1 Loop 2 termine the stopping criterion of loop 1. Then, lines 82–83
1 update the Lagrange multiplier and the penalty parameter with
(33) and (34).
0.8
Vo l u m e f r act i o n
0.6 3.5.2 Loop 2 including DWP and AMR loop (lines 85–108)
Table 2 Mesh independence according to different mesh densities and non-structural mesh
Figure 7 shows each of convergence histories for the // Shape & Mesh
compliance, the volume fraction, and the gray area (de- int n = 8; // mesh density
real L = 2, H = 1; // Dimension of the Shape
fined by the Mnd value in (44)). Plots of the compliance
real x0= 0 , x1= L ;
and the volume fraction maintain the continuity as well as real y0=-H/2 , y1= -H/10 , y2= H/10 , y3= H/2 ;
the smoothness even when entering loop 2. In addition, we
can observe that compliance value is getting smaller in // right boundary of the mesh
loop 2. On the other hand, the gray area plot shows an border bd1(t=y0,y1) { x=L; y=t; label=1; };
border bd2(t=y1,y2) { x=L; y=t; label=3; };
abrupt decrease as it enters loop 2. It is due to the intro-
border bd3(t=y2,y3) { x=L; y=t; label=1; };
duction of the DWP and the reduction of the diffusion // left boundary of the mesh
coefficient with the adaptive meshing. border bg(t=y3,y0){ x=0; y=t; label=2; };
// upper boundary of the mesh
border bs(t=L,0) { x=t; y=H/2; label=1; };
// lower boundary of the mesh
border bi(t=0,L) { x=t; y=-H/2; label=1; };
4 Numerical examples
// label meanings: 1=Free, 2=Fixed(Dirichlet), 3=Applied
In this section, mesh independence, the influence of the diffu- force(Neumann)
sion coefficient, and other boundary condition problems are
mesh Th= buildmesh (bd1(2*n)+bd2(1*n)+bd3(2*n) +
discussed.
bg(5*n)+bs(10*n)+bi(10*n));
plot(Th, boundary = 0, WindowIndex = 0,wait=0);
Table 3 Effect of different diffusion coefficient values of 5×10−4, 1×10−4, and 5×10−5
FreeFEM++ code for reaction-diffusion equation–based topology optimization: for high-resolution boundary... 451
// left boundary
border bdl (t=H,0) {x=-L/2; y=t; label = 1;} ;
// right boundary
border bdr (t=0,H) {x=L/2; y=t; label = 1;} ;
// upper boundary
border bdu (t=L/2,-L/2) {x=t; y=H; label = 1;} ;
// lower boundary
border bdl1 (t =-L/2,-L/2+L/40) {x=t; y=0; label = 2;} ;
border bdl2 (t =L/2-L/40,L/2) {x=t; y=0; label = 4;} ;
border bdl3 (t =-L/40,L/40) {x=t; y=0; label = 3;} ;
border bdl4 (t =-L/2+L/40,-L/40) {x=t; y=0; label = 1;} ;
border bdl5 (t =L/40,L/2-L/40) {x=t; y=0; label = 1;} ;
Fig. 9 Other boundary conditions for the design problems of a bridge and // label meanings: 1=Free, 2=Fixed(Dirichlet), 3= Applied force
b half-MBB beam
mesh Th= buildmesh
(bdl(20*n)+bdr(20*n)+bdu(40*n)+bdl1(1*n)+bdl2(1*n)+bdl3(2*n)
+bdl4(18*n)+bdl5(18*n));
coefficient decreases, the optimal shape becomes more compli- plot(Th, boundary = 0, WindowIndex = 0,wait=0);
cated and the value of the total variation increases. Also, the gray
area decreases because the effect of regularization is reduced. In Listing 2 Shape and mesh definition for the bridge design
the case of κ = 5 × 10−5, we set the nbvx = 60,000 instead of problem
40,000 because the smaller the diffusion coefficient, the greater
the length of the boundary and the need for more mesh nodes.
// Elasticity system //
When using the adaptmesh, if the number of nodes in problem elasticity(u,v)=
FreeFEM++ is limited and the number of additional node points int2d(Th)(lambda*div(v)*div(u)+2.*mu*(e(v)'*e(u)))
is not enough, then the following error message would be -int1d(Th,3)(f'*v)
displayed: +on(2,u1=0,u2=0)
+on(4,u2=0);
// Elasticity system //
problem elasticity(u,v)=
int2d(Th)(lambda*div(v)*div(u)+2.*mu*(e(v)'*e(u)))
-int1d(Th,3)(f'*v)
+on(2,u1=0)
+on(4,u2=0);
Loop 1
Iteration 54 53
Compliance 4.48086 e-05 3.03715 e-05
Gray 0.98 % 0.99 %
# of element 79,254 triangles 77,916 triangles
Loop 2
FreeFEM++ code for reaction-diffusion equation–based topology optimization: for high-resolution boundary... 453
Lee K, Ahn K, Yoo J (2016) A novel P-norm correction method for Sigmund O (2001) A 99 line topology optimization code written in
lightweight topology optimization under maximum stress con- Matlab. Struct Multidiscip Optim 21:120–127
straints. Comput Struct 171:18–30 Sigmund O (2007) Morphology-based black and white filters for topolo-
Lim D, Shin D, Shin H, Kim K, Yoo J (2014a) A systematic approach to gy optimization. Struct Multidiscip Optim 33:401–424
enhance off-axis directional electromagnetic wave by two- Steinbach I, Pezzolla F (1999) A generalized field method for multiphase
dimensional structure design. Opt Express 22:6511–6518 transformations using interface fields. Physica D 134:385–393
Lim H, Yoo J, Choi JS (2014b) Topological nano-aperture configuration Takezawa A, Nishiwaki S, Kitamura M (2010) Shape and topology op-
by structural optimization based on the phase field method. Struct timization based on the phase field method and sensitivity analysis. J
Multidiscip Optim 49:209–224 Comput Phys 229:2697–2718
Liu P, Luo Y, Kang Z (2016) Multi-material topology optimization con- Wheeler AA, Murray BT, Schaefer RJ (1993) Computation of dendrites
sidering interface behavior via XFEM and level set method. Comput using a phase field model. Physica D 66:243–262
Methods Appl Mech Eng 308:113–133 Xia L, Da D, Yvonnet J (2018) Topology optimization for maximizing the
Maute K, Ramm E (1995) Adaptive topology optimization. Struct Optim fracture resistance of quasi-brittle composites. Comput Methods
10:100–112 Appl Mech Eng 332:234–254
McFadden G, Wheeler A, Braun R, Coriell S, Sekerka R (1993) Phase- Yamada T, Izui K, Nishiwaki S, Takezawa A (2010) A topology optimi-
field models for anisotropic interfaces. Phys Rev E 48:2016 zation method based on the level set method incorporating a ficti-
Otomori M, Yamada T, Izui K, Nishiwaki S (2015) Matlab code for a tious energy. Comput Methods Appl Mech Eng 199:2876–2891
level set-based topology optimization method using a reaction dif- Zhou S, Wang MY (2007) Multimaterial structural topology optimization
fusion equation. Struct Multidiscip Optim 51:1159–1172 with a generalized Cahn–Hilliard model of multiphase transition.
Powell MJ (1969) A method for nonlinear constraints in minimization Struct Multidiscip Optim 33:89
problems. Optimization 283–298
Seong HK, Shin H, Yoo J, Yamada T, Nishiwaki S (2018) Reaction-diffusion
equation based topology optimization combined with the modified con- Publisher’s Note Springer Nature remains neutral with regard to jurisdic-
jugate gradient method. Finite Elem Anal Des 140:84–95 tional claims in published maps and institutional affiliations.
Seong HK, Yoo J (2017) Probability distribution function inspired struc-
tural optimization for frequency response problems. Comput
Methods Appl Mech Eng 318:783–802