Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Structural and Multidisciplinary Optimization (2020) 62:439–455

https://doi.org/10.1007/s00158-020-02498-3

EDUCATIONAL PAPER

FreeFEM++ code for reaction-diffusion equation–based topology


optimization: for high-resolution boundary representation using
adaptive mesh refinement
Cheolwoong Kim 1 & Mingook Jung 1 & Takayuki Yamada 2 & Shinji Nishiwaki 2 & Jeonghoon Yoo 3

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

1 Introduction intended for the educational purposes. The code is inspired


by the first MATLAB code based on the solid isotropic mate-
This paper presents a compact FreeFEM++ implementation of rial penalization (SIMP) method (Sigmund 2001),
reaction-diffusion equation (RDE)–based topology optimiza- FreeFEM++ code for a structural topology optimization
tion for minimizing the compliance of a 2-D isotropic linear (Allaire and Pantz 2006), and a level set–based MATLAB
elastic structure. The corresponding FreeFEM++ code is code using a reaction-diffusion equation (Otomori et al.
2015). The design algorithm of the code provided in the paper
Responsible Editor: Gregoire Allaire is based on the studies for RDE-based topology optimization
Electronic supplementary material The online version of this article (Choi et al. 2011; Seong et al. 2018) and the work which
(https://doi.org/10.1007/s00158-020-02498-3) contains supplementary integrates the double-well potential (DWP) with RDE-based
material, which is available to authorized users. topology optimization (Takezawa et al. 2010).
The objective other than the educational purposes of this
* Jeonghoon Yoo paper is to propose a design procedure for representing high-
yoojh@yonsei.ac.kr
resolution boundaries of the optimal shape from the RDE-
Cheolwoong Kim based design method by reducing the gray area through the
kcw541@naver.com
adaptive mesh refinement (AMR) and the gradual decrease of
1 the diffusion coefficient. In the RDE-based design method, the
Graduate School of Mechanical Engineering, Yonsei University,
Seoul 03722, South Korea RDE is used for evolving the design variable, and the diffu-
2 sion coefficient, which is the main parameter of the design
Department of Mechanical Engineering and Science, Kyoto
University, Kyotodaigaku-katsura, Nishikyo-ku, Kyoto 615-8540, method, can control the complexity of the structure shape
Japan (Yamada et al. 2010). The RDE consists of two characteristic
3
Department of Mechanical engineering, Yonsei University, terms: The reaction term includes the sensitivity information
Seoul 03722, South Korea and expresses the local reaction between different material
440 C. Kim et al.

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 :

Therefore, compared with the governing equation and


boundary conditions, p = − u. Such problem is called as
self-adjoint.
The sensitivity of the objective function is obtained by
taking the derivative of
J ðϕÞ ¼ Lðϕ; u; pÞ ð24Þ
Fig. 1 Schematic diagram for compliance minimization problem for a
cantilever beam with respect to the design variable ϕ:
FreeFEM++ code for reaction-diffusion equation–based topology optimization: for high-resolution boundary... 443

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ϕ

In this study, we neglect the effect of the body force g. e ðϕ; q ; rk Þ


min L s:t: 0≤ ϕ ≤ 1 ð32Þ
k
ϕ
Then, the sensitivity of the objective function is
Once the above subproblem is solved, the Lagrange multi-
  plier q and the penalty parameter r are updated by (Bertsekas
dJ dC
¼− εðuÞ : εðuÞ: ð27Þ 2014)
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 :

w(ϕ) is a smooth Dirac delta function, and a is the


parameter to control the thickness of the gray area. The
larger the value of this parameter, the bigger the penalty
for the gray area, which in turn reduces the overall gray
area. The value was set to 10 in this study. Since w(0) =
w(1) = 0, w(ϕ) serves to enable the design variable up-
date only along the structural boundary. In the proposed
design procedure, the modified RDE is applied in loop 2 Fig. 2 The symmetric structural mesh composed of 14,400 triangular
of Fig. 3 after an approximate optimal shape is generated elements on 120 × 60 grids
FreeFEM++ code for reaction-diffusion equation–based topology optimization: for high-resolution boundary... 445

Fig. 3 Flow chart of the provided FreeFEM++ program

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.

Fig. 5 Configuration change


during the Loop 1 process

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

Fig. 6 Optimal configuration


changes (right) with refined
meshes (left) during the loop 2
process

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.

a Loop 1 Loop 2 3.5 Optimization loop (lines 60–108)


6.0E-03
3.5.1 Loop 1 using RDE (lines 60–84)
Co m p l i an ce ( N ·m )

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)

0.4 Loop 2 is similar to loop 1 except for a few lines. Before


entering the while loop, line 86 stores the mesh used in loop
0.2
1 into Sh. In line 91, the ‘adaptmesh’ command generates the
0
refined mesh from the oldphi based on the loop 1 mesh. nbvx
0 20 40 60 80 100 120 140 is the maximum number of nodes that can be added for the
AMR. Then, the weak forms of elasticity and DWP are solved
Iteration
on the refined mesh. As mentioned earlier, the reason for using
c Loop 1 Loop 2 the DWP is to prevent topological changes in the refined
meshing model. Finally, the diffusion coefficient κ is de-
100
creased for each iteration to reduce the gray area (line 105).
80
Gr ay ( %)

3.6 Implementation result


60

In the provided code (see Appendix), the design domain is


40
discretized with 14,400 triangular mesh. The force f of
20 10 kN/m2 is applied downwards and the diffusion coefficient
is set as κ = 5 × 10−4.
0 Figure 5 shows the shape variation of the design area in the
0 20 40 60 80 100 120 140 process of loop 1. At the iteration of 107, the resultant con-
Iteration verged shape still shows a broad gray area around the struc-
Fig. 7 Convergence histories. a The compliance. b The volume fraction. tural boundary.
c The gray area (value of Mnd) Figure 6 represents configuration changes correspond-
ing to refined meshes during the loop 2 process. The AMR
generates many nodes in the vicinity of the boundary of
(16) with respect to ϕ. Also, sens and augGrad correspond to the resultant shape where ϕ varies from 0 to 1 at each of
(28) and (37), respectively. In line 55, by g ' (0) = g ' (1) = 0, iterations. As displayed in Fig. 6, the optimal shape of
DWPAugGrad defined in (41) restricts topological change loop 2 maintains the topological shape derived from loop
when applying the AMR in loop 2. Lines 57 and 58 represent 1 reflecting the sensitivity only at the boundary by apply-
(11) and (39), respectively. Note that the on (2,u1 = 0,u2 = 0) ing the DWP. As a result, by using the AMR and the
command in line 57, based on the penalty method, imposes gradual reduction of the diffusion coefficient, high-
the Dirichlet boundary condition on the boundary having label resolution boundaries with less grayscale area can be
2 in Fig. 4. obtained.
FreeFEM++ code for reaction-diffusion equation–based topology optimization: for high-resolution boundary... 449

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);

4.1 Mesh independency


Listing 1 Non-structural mesh code
In order to confirm the mesh independence of the proposed
algorithm shown in Fig. 3, Table 2 presents the results of the As shown in Table 2, it is confirmed that optimal configura-
three different mesh sizes (n = 6, 9, and 12 in line 16) and non- tions are similar to each other regardless of the size and type of
structural mesh. Non-structural mesh uses triangular free mesh the mesh. In addition, the compliance and the gray area after
replacing lines 15–26 with the content in Listing 1. performing loop 2 are reduced compared with those after loop
450 C. Kim et al.

originally discretized model. For the comparison of the result


using a commercial package, COMSOL™ Multiphysics ver.
5.4 was employed. This package provides the SIMP method–
based topology optimization module including the MMA opti-
mizer and the Helmholtz filtering. Except for the use of a 16- mm
filtering radius and a quadrilateral mesh, all parameters were set
identical to the example of FreeFEM++ with 120 × 60 mesh
density. The AMR was not applied in this case. Due to the effect
of the filtering radius, the compliance value is slightly different
from the values in other cases. However, the derived optimal
configuration is similar to the other results.
Figure 8 shows that the quantitative values of the compli-
ance and the volume fraction are independent of mesh density.
Including the 107th iteration where loop 1 ends, the values
displayed are similar regardless of the model used.

4.2 Effect of the diffusion coefficient

A suitable quantitative measure for the complexity of the op-


timal shape can be given using the total variation of ϕ (Haber
et al. 1996).
TVðϕÞ ¼ ∫Ω j∇ϕj dΩ ð45Þ
Fig. 8 Comparison of the compliance and the volume fraction for
different mesh density and unstructured models at specific iterations If the gray area is reduced enough as in loop 2, the total
variation of the ϕ can be regarded as the perimeter of the
1. As shown in the refined meshes in loop 2, the higher the optimal shape.
density of the original mesh, the less zigzag shape along the Table 3 shows the effect of the diffusion coefficients for the
boundary because the AMR refines the meshes based on the values of 5 × 10−4, 1 × 10−4, and 5 × 10−5. As the diffusion

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

at the bottom center. To implement boundary conditions


for the bridge problem, lines 15–26 and line 58 are re-
placed with Listing 2 and Listing 3. The command
on(2,u1 = 0,u2 = 0) and on(4,u2 = 0) in Listing 3 means
left and right fixing conditions at the bottom of the
bridge.

// Shape & Mesh


int n = 2; // mesh density
real L = 2, H = 1; //Shape
real x0= 0, x1= L ;

// 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);

Listing 3 The weak form of the bridge problem


This can be solved by increasing the number of vertices
allowed for the mesh using the option nbvx as shown above,
On the other hand, the left side is fixed to the x
or by controlling the minimum length and anisotropy of the
direction in the half-MBB problem and the bottom right
triangular elements.
is constrained to the y direction. The force is applied
Similar to the results in Table 2, both the objective function
from the top left corner downward. To apply the bound-
and the quantity of the gray area in loop 2 are reduced com-
ary and load conditions, lines 15–26 and line 58 are
pared with those in loop 1.
changed with Listing 4 and Listing 5. In Listing 5,
the commands on(2,u1 = 0) and on(4,u2 = 0) represent
4.3 Results with other boundary conditions the left side and the bottom right boundary conditions,
respectively. To obtain appropriate optimal configura-
Two other boundary conditions for the design problems tions, we set κ = 1 × 10−3 in the half-MBB example.
of a bridge and a half-MBB are applied as displayed in Table 4 displays the design results for the bridge and
Fig. 9. In the bridge example, the bottom left corner is the half-MBB problem. As in the previous examples,
fixed to the x and y directions while the bottom right we obtained high-resolution boundaries of the optimal
corner is fixed only to the y-axis with the applied force configurations.
452 C. Kim et al.

// Shape & Mesh


int n = 4; // mesh density
real L = 3, H = 1; //Shape
real x0= 0 , x1= L ;
// right boundary of the mesh
border bd(t=-H/2,H/2) { x=L; y=t; label=1; };
//left boundary of the mesh
border bg(t=H/2,-H/2) { x=0; y=t; label=2; };
// upper boundary of the mesh
border bs1(t=L,L/160) { x=t; y=H/2; label=1; };
border bs2(t=L/160,0) { x=t; y=H/2; label=3; };
// lower boundary of the mesh
border bi1(t=0,L-L/160) { x=t; y=-H/2; label=1; };
border bi2(t=L-L/160,L) { x=t; y=-H/2; label=4; };
// label meanings: 1= Free, 2,4=Fixed, 3=Applied force,

mesh Th= buildmesh (bd(10*n)+


bg(10*n)+bs1(28*n)+bs2(1*n)+bi1(28*n)+bi2(1*n));
plot(Th, boundary = 0, WindowIndex = 0,wait=0);

Listing 4 Shape and mesh definition for the half-MBB problem

// 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);

Listing 5 The weak form of the half-MBB problem

Table 4 Other boundary conditions: a bridge and b half-MBB


Mesh density Bridge Non-structural
Iteration 100 132
Compliance 5.46891 e-05 3.49 e-5
Gray 16.70 % 18.68 %
# of element 7,232 triangles 9,472 triangles

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

5 Conclusion Appendix: FreeFEM++ Code


1 // Parameter define
This paper presents the FreeFEM++ code for RDE-
2 real E0 = 2e11;
based topology optimization to represent high-
3 real Emin = 0.001;
resolution boundaries using the AMR. As the optimizer
4 real nu = 0.33;
of the design method, the RDE and the DWP have been
5 real p = 3;
applied to each role and purpose. To implement the 6 real InitVol = 0.5;
finite element analysis and topology optimization using 7 real VolReq = 0.45;
FreeFEM++, detailed derivations of the weak forms for 8 real k = 5e-4;
structural problems and RDE formulations are provided. 9 real eta = 1;
Numerical examples are provided to confirm the robust- 10 real gamma = 1.025;
ness and capability of the proposed algorithm to obtain 11 real q = 0;
high-resolution boundaries. 12 real r = 0.2;
13 real dt = 0.1;
Funding information This research was supported by the Korea institute 14 real AMRnode = 40000;
of Energy Technology Evaluation and Planning (KETEP) grant funded 15 // Shape & Mesh
by the Ministry of Trade, Industry and Energy, Republic of Korea (No. 16 int n = 12;
20184030201940) and also supported by the National Research 17 real L = 2, H = 1;
Foundation of Korea (NRF) grant funded by the Korea government 18 real x0 = 0 , x1 = L ;
(NRF-2019R1A2B5B01069788).
19 real y0 = -H/2 , y1 = -H/10 , y2 = H/10 , y3 = H/2 ;
20 int[int] l1=[1,1,0,2] ;
Compliance with ethical standards 21 int[int] l2=[0,3,0,2] ;
22 int[int] l3=[0,1,1,2] ;
Conflict of interest The authors declare that they have no conflict of 23 mesh Th1=square(L*5*n,2*H*n,[x0+(x1-x0)*x,y0+(y1-
interest.
y0)*y],label=l1,flags=1);
24 mesh Th2=square(L*5*n,H*n,[x0+(x1-x0)*x,y1+(y2-
Replication of results The source code is given in the Appendix. The
y1)*y],label=l2,flags=1);
results shown in Figs. 5 and 6 are obtained by direct running of the code.
As explained in Section 4.1, results for mesh density 6 and 9 in Table 2 25 mesh Th3=square(L*5*n,2*H*n,[x0+(x1-x0)*x,y2+(y3-
can be obtained by changing the value of n in the code. Also, the result for y2)*y],label=l3,flags=1);
non-structural mesh in Table 2 is obtained by changing the original code 26 mesh Th = Th1+Th2+Th3;
(lines 15–26) using Listing 1. Results in Table 3 are obtained by changing 27 plot(Th, boundary=0, WindowIndex=0, wait=0);
the value of k in line 8 and the value of AMRnode in line 14 of the 28 // Macro
original code according to the direction in Section 4.2.
29 real sqrt2 = sqrt(2.);
Results for the bridge and the MBB beam in Table 4 are obtained by
30 macro u [u1,u2] //
using Listings 2 and 3 and Listings 4 and 5, respectively. Detail directions
are given in Section 4.3. 31 macro v [v1,v2] //
32 macro f [0,-10000] //
33 macro e(u) [dx(u[0]), dy(u[1]), (dy(u[0])+dx(u[1]))/sqrt2] //
34 macro div(u) (dx(u[0])+dy(u[1])) //
35 macro grad(phi) [dx(phi), dy(phi)] //
36 // Define the Finite element space
37 fespace Vh(Th,[P1,P1]);
38 Vh u, v;
39 fespace Vh1(Th,P2);
40 Vh1 phi, vphi, oldphi, phierror ;
41 // Initial parameter of Optimization process
42 real Voltot = int2d(Th)(1.);
43 real Vol = int2d(Th)(InitVol)/Voltot;
44 k = Voltot*k;
45 // Function
46 func E = Emin+(E0-Emin)*(oldphi)^p;
47 func lambda = E*nu*(1/((1+nu)*(1-2*nu)));
48 func mu = E*(1/(2*(1+nu)));
49 func DE = p*(E0-Emin)*(oldphi)^(p-1);
50 func Dlambda = DE*nu*(1/((1+nu)*(1-2*nu)));
51 func Dmu = DE*(1/(2*(1+nu)));
454 C. Kim et al.

52 // Sensitivity Analysis 96 Mnd = (int2d(Th)(4*oldphi*(1-oldphi)))/(int2d(Th)(1))*100;


53 func sens = -(Dlambda*div(u)*div(u)+2.*Dmu*(e(u)'*e(u))); 97 caption = "AMR Iteration "+iter+", Compliance "+objective+",
54 func augGrad = eta*sens+((Vol-VolReq)>=(-q/r))*(q +r*max(Vol- Volume "+Vol+ ", k "+k+", Change "+change+", Gray area
VolReq,-q/r))/Voltot; "+Mnd;
55 func DWPaugGrad = (10)*2*oldphi*(2*oldphi^2-
98 plot(Th, oldphi, WindowIndex=3, boundary=0, hsv=grey, fill=1,
3*oldphi+1)+(eta*sens+((Vol-VolReq)>=(-q/r))*(q+r*max(Vol-
value=0, wait=0, cmm=caption);
VolReq,-q/r))/Voltot)*(30*oldphi^2*(1-oldphi)^2);
99 DWP ;
56 // Elasticity system
100 phi = min(1,phi);
57 problem elasticity(u,v) = int2d(Th)(lambda*div(v)*div(u)+
101 phi = max(0,phi);
2.*mu*(e(v)'*e(u)))-int1d(Th,3)(f'*v)+on(2,u1=0,u2=0);
102 phierror = phi-oldphi;
58 problem RDE(phi,vphi) =
int2d(Th)(phi*vphi+dt*k*grad(phi)'*grad(vphi))+int2d(Th)(dt*augGrad* 103 change = phierror[].linfty;
vphi)-int2d(Th)(oldphi*vphi); 104 Vol = int2d(Th)(phi)/Voltot;
59 problem DWP(phi,vphi) = 105 k = k*0.9;
int2d(Th)(phi*vphi+dt*k*grad(phi)'*grad(vphi))+int2d(Th)(dt*DWPaug 106 q = q + r*max(Vol-VolReq,-q/r);
Grad*vphi)-int2d(Th)(oldphi*vphi); 107 r = gamma*r;
60 // Loop1 RDE // 108 oldphi = phi; }
61 real iter = 0;
62 oldphi = InitVol;
63 real objective; References
64 real change = 1;
65 real Mnd; Allaire G, Pantz O (2006) Structural optimization with FreeFEM++.
66 string caption;
Struct Multidiscip Optim 32:173–181
Bathe K-J (2006) Finite element procedures. Klaus-Jurgen Bathe
67 real[int] grey = [ 0, 0 , 1, 0, 0 , 0 ]; // < HSV (Hue, Saturation, Value)
Bendsøe MP, Sigmund O (2003) Topology optimization: theory, methods
>
and applications. Springer-Verlag, Berlin
68 while (change > 0.01 || iter ==1) Bertsekas DP (2014) Constrained optimization and Lagrange multiplier
69 { iter = iter+1; methods. Academic press, New York
70 elasticity ; Bourdin B, Chambolle A (2003) Design-dependent loads in topology
71 objective = int1d(Th,3)(f'*u); optimization. Esaim Contr Optim Ca 9:19–48
72 eta = Voltot/sqrt(int2d(Th)(sens^2)); Choi JS, Yamada T, Izui K, Nishiwaki S, Yoo J (2011) Topology optimi-
zation using a reaction–diffusion equation. Comput Method Appl M
73 Mnd = (int2d(Th)(4*oldphi*(1-oldphi)))/(int2d(Th)(1))*100;
200:2407–2420
74 caption="Iteration "+ iter +", Compliance "+ objective + ", Volume
Flemings MC (1974) Solidification processing. Metall Trans A 5:2121–
" + Vol + ", Change " + change +", Gray area" + Mnd ; 2134
75 plot(Th, oldphi, WindowIndex=1, boundary=0, hsv=grey, fill=1, Garcke H, Hecht C, Hinze M, Kahle C (2015) Numerical approximation
value=0, wait=0, cmm=caption); of phase field based shape and topology optimization for fluids.
76 RDE ; SIAM J Sci Comput 37:A1846–A1871
77 phi = min(1,phi); Gibbs J (1928) The collected work of JW Gibbs, Volumen I. Longmans,
Green and Co, New York
78 phi = max(0,phi);
Haber RB, Jog CS, Bendsøe MP (1996) A new approach to variable-
79 phierror = phi-oldphi;
topology shape design using a constraint on perimeter. Struct Optim
80 change = phierror[].linfty; 11:1–12
81 Vol = int2d(Th)(phi)/Voltot; Hecht F (2012) New development in FreeFEM++. J Numer Math 20:
82 q = q + r*max(Vol-VolReq,-q/r); 251–266
83 r = gamma*r; Hestenes MR (1969) Multiplier and gradient methods. J Optim Theory
84 oldphi = phi; } App 4:303–320
85 // Loop2 Adaptive mesh & DWP //
Jeong S, Seong HK, Kim CW, Yoo J (2019) Structural design considering
the uncertainty of load positions using the phase field design meth-
86 mesh Sh = Th;
od. Finite Elem Anal Des 161:1–15
87 change = 1; Karma A (1994) Phase-field model of eutectic growth. Phys Rev E 49:
88 iter = 0; 2245
89 while (Mnd>1.0) Kim CW, Seong HK, Yoo J (2019) Study on the clear boundary determi-
90 { iter = iter + 1; nation from results of the phase field design method. Int J Precis Eng
91 Th = adaptmesh(Sh, oldphi, nbvx=AMRnode, anisomax=0, Manuf 20:1553–1561
splitin2=0);
Kurz W, Fisher DJ (1989) Fundamentals of solidification. Trans Tech
Publications Ltd, Switzerland
92 plot(Th, WindowIndex =2, boundary=0, wait=0, cmm="Adaptive
Langer JS (1980) Instabilities and pattern formation in crystal growth.
mesh "+ iter); Rev Mod Phys 52:1
93 elasticity ; Lawry M, Maute K (2015) Level set topology optimization of problems
94 objective = int1d(Th,3)(f'*u); with sliding contact interfaces. Struct Multidiscip Optim 52:1107–
95 eta = Voltot/sqrt(int2d(Th)(sens^2)); 1119
FreeFEM++ code for reaction-diffusion equation–based topology optimization: for high-resolution boundary... 455

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

You might also like