You are on page 1of 13

Structural and Multidisciplinary Optimization (2021) 63:1015–1027

https://doi.org/10.1007/s00158-020-02733-x

EDUCATIONAL PAPER

An 89-line code for geometrically nonlinear topology optimization


written in FreeFEM
Benliang Zhu1,2 · Xianmin Zhang1 · Hai Li1 · Junwen Liang1 · Rixin Wang1 · Hao Li2 · Shinji Nishiwaki2

Received: 19 June 2020 / Revised: 24 August 2020 / Accepted: 28 August 2020 / Published online: 24 Septembe r 2020
© Springer-Verlag GmbH Germany, part of Springer Nature 2020

Abstract
Topology optimization has emerged as a powerful tool for structural configuration design. To further promote the
development of topology optimization, many computer programs have been published for educational purposes over the past
decades. However, most of the computer programs are constructed based on a linear assumption. This paper presents an 89-
line code for nonlinear topology optimization written in FreeFEM based on the popular SIMP (solid isotropic material with
penalization) method. Excluding thirteen lines which are used for explanation, only 76 lines are needed for the initialization
of the design parameters, nonlinear finite element analysis, sensitivity calculation, and updated design variables. Different
design problems can be solved by modifying several lines in the proposed program. The complete program is given in the
Appendix and is intended for educational purposes only.

Keywords Topology optimization · Nonlinearity · SIMP · FreeFEM · Mean compliance

1 Introduction 1999; Zhu et al. 2014), level set methods (LSM) (Allaire
et al. 2005; Wang et al. 2003; Yamada et al. 2010; Zhu
The structural topology is the material layout. Topology et al. 2015), evolutional structural optimization (ESO)
optimization is a design method that can determine the methods (Huang and Xie 2009; Xie and Steven 1997),
best material layout within a given design domain that and moving morphable components (MMC) methods (Guo
can satisfy a set of constraints while maximizing a et al. 2016; Wang et al. 2019). For a comprehensive review
certain kind of performance. Since 1988, when Bendsøe of established topology optimization methods and their
and Kikuchi (Bendsøe and Kikuchi 1988) introduced applications, the readers may refer to (Rozvany 2009; van
the homogenization-based topology optimization method, Dijk et al. 2013; Sigmund and Maute 2013; Zhu et al. 2020).
various techniques have been developed for achieving the At the same time, computational programs concerning
design goal of finding the optimal structural topology, such structural topology optimization have been gradually
as density-based methods (Lazarov et al. 2016; Dilgen published in the literature. These programs, which are
et al. 2018; Rozvany et al. 1992; Bendsøe and Sigmund constructed for educational purposes, have paved the way
for the flourished development of topology optimization.
Meanwhile, these codes have been helpful for newcomers
Responsible Editor: Emilio Carlos Nelli Silva
to understand the underlying idea of structural topology
 Benliang Zhu optimization.
meblzhu@scut.edu.cn Although a detailed collection of such programs can
be found in the review paper (Zhu et al. 2020), some
Xianmin Zhang
zhangxm@scut.edu.cn of these programs are also introduced in Table 1 based
on several newly published codes that have been added
1
since 2019. In the table, SIMP stands for solid isotropic
Guangdong Key Lab. of Precision Equipment
and Manufacturing Technology, South China University
microstructure with penalization for intermediate densities,
of Technology, Guangzhou, 510640, China which is one of the most widely utilized approaches in
2 Department of Mechanical Engineering and Science,
density-based topology optimization methods. Readers who
Graduate School of Engineering, Kyoto University, are interested in this approach can refer to the 99-line
Kyoto, 606-8501, Japan code and its improved versions, such as the 88-line
1016 B. Zhu et al.

program (Andreassen et al. 2011). Computer programs program has been published that considers nonlinear
that focus on using this approach to three-dimensional topology optimization, which is called the 213-line.
topology optimization have also been published, such as However, the code is built based on the commercial software
169-line 3D and AC# 3D codes. In addition, a 115-line MATLAB and ANSYS. The data transfer between these
program for multimaterial topology optimization problems two platforms can cause several unexpected issues, such
using the SIMP method as been presented in (Tavakoli as that special attention is needed to obtain the sensitivity
and Mohseni 2014). To obtain a pure black-white solution, information (Chen et al. 2019). In addition, although most of
Liang and Cheng (Liang and Cheng 2020) presented a the published codes are built by using commercial software,
128-line code using sequential integer programming and such as MATLAB and ANSYS, several codes have been
a canonical relaxation algorithm. built by using open source software platforms such as
Several computer programs have been proposed based FEniCS or FreeFEM. For example, Kim et al. presented a
on the ESO methods. These codes can be used to solve 108-line code for obtaining topology optimized results
either two-dimensional (soft-kill and SERA) or three- with high-resolution boundary representation based on
dimensional (PYTHON 3D) structural topology optimization adaptive mesh refinement. FreeFEM (Hecht 2012) is an
problems. Furthermore, Talischi et al. presented a PolyTop open source program platform developed for numerically
code that can be employed for topology optimization solving partial differential equations. It can fulfill the finite
using unstructured polygonal finite element meshes in element analysis with only a few lines of codes without
arbitrary domains. Meanwhile, there have been several manually operating the stiffness assembly, etc. One may
available codes published by using the level set methods. refer to (Allaire and Pantz 2006) for a good example of the
For example, one can use dLSM, FEniCS, 108-line, or application of FreeFEM for structural shape optimization.
62-line to quickly become familiar with the classical level Therefore, in this paper, we present a FreeFEM-based
set methods, which normally obtain the optimal results by code for geometrical nonlinear topology optimization. It
solving the Hamilton-Jacobi equation. In addition, one can only contains 89 lines in which 13 lines are comments. The
use the 88-line code, which is programmed based on the remainder of the paper is organized as follows. In Section 2,
parameterization level set method (Luo et al. 2007). the theoretical background of topology optimization consid-
From Table 1, one can easily observe that most of ering geometrical nonlinearity is introduced. In Section 4,
the published codes are constructed by using the linear a detailed explanation of the presented code is presented.
assumption. In regard to nonlinear topology optimization, In Section 5, some examples are presented to show how to
one can hardly find convenient and compact published code. extend the presented code to design other problems. Finally,
To the best of the authors’ knowledge, only one computer conclusions are given in Section 6.

Table 1 Educational computer


programs for structural Name and authors Environment Method Assumption
topology optimization
99-line (Sigmund 2001) MATLAB SIMP Linear
SOFT-KILL (Huang and Xie 2010) MATLAB ESO Linear
dLSM (Challis 2010) MATLAB LSM Linear
PolyTop (Talischi et al. 2012) MATLAB SIMP Linear
169-line 3D (Liu and Tovar 2014) MATLAB SIMP Linear
115-line (Tavakoli and Mohseni 2014) MATLAB SIMP Linear
PYTHON 3D (Zuo and Xie 2015) PYTHON and ABAQUS ESO Linear
MMC188 (Zhang et al. 2016) MATLAB MMC Linear
SERA (Loyola et al. 2018) MATLAB ESO Linear
FEniCS (Laurain 2018) FEniCS LSM Linear
88-line (Wei et al. 2018) MATLAB LSM Linear
213-line (Chen et al. 2019) MATLAB and ANSYS SIMP Nonlinear
185-line (Laurain 2018) FEniCS LSM Linear
AC# 3D (Lagaros et al. 2019) SAP2000 SIMP Linear
128-line (Liang and Cheng 2020) MATLAB SIMP Linear
108-line (Kim et al. 2020) FREEFEM LSM Linear
62-line (Yaghmaei et al. 2020) MATLAB LSM Linear
An 89-line code for geometrically nonlinear topology optimization written in FreeFEM 1017

2 Structural topology optimization where 0 Ω and 0 Γn denote the body Ω and surface Γn in
considering the geometrical nonlinearity the initial configuration (Fig. 1). ui are components of u,
and δui is the virtual displacement field. Sij are Cartesian
2.1 Optimization problem components of the second Piola-Kirchhoff stress tensor. εij
are components of the Green-Lagrange strain tensor, which
One of the most commonly used optimization models for must be defined with respect to the initial coordinates of the
structural topology optimization involves minimizing the body 0 x by taking into account the nonlinear term εnl as:
mean compliance subject to the volume constraint, which    
can be expressed as (Gea and Luo 2001; Buhl et al. 2000; 1 ∂ui ∂uj 1 ∂uk ∂uk
εij = + 0 + (3)
Abdi et al. 2018): 2 ∂ 0 xj ∂ xi 2 ∂ 0 xi ∂ 0 xj
     
εl εnl
min : J = FT u
s. t. : V /V  ≤ λ (1) where εl represents the linear term of the strain tensor, and
r(u) = 0 the Einstein summation convention is adopted which means
that the summation over k is implied.
where u is the displacement field due to the external force Assuming a large displacement but reasonably small
vector F, which consists of the body forces fb and surface strain, the material behavior can still be written as:
tractions fs . The fraction of the maximum allowed volume
usage and the volume of the whole space is lower than λ. Sij = Dij kl εkl (4)
The only difference between the optimization model (1) and
a standard linear topology optimization problem is that the where Dij kl are the components of the elasticity tensor.
equilibrium condition r(u) = 0 must be found using an Equations (2)–(4) are basic equations for evaluating the
iterative scheme to obtain the displacement field u. structural responses when considering geometric nonlinear-
ity (Abdi et al. 2018; Gea and Luo 2001). These equations
2.2 The basic problem of a geometrical nonlinear cannot be solved directly. A common strategy to solve
analysis these equations is to linearize the equilibrium condition
to find an approximate solution and iteratively reduce the
Suppose that we are given a sufficiently regular elastic approximation.
body Ω ⊂ d (d = 2, 3). In the following, we only
consider d = 2 for simplicity. The extension to d = 3 2.3 Linearized equation and incremental approach
should be straightforward. The elastic body Ω is fixed at its
boundary Γd ⊂ ∂Ω and subjected to surface loads fis on In the incremental approach, the structural response at
Γn ⊂ ∂Ω and body forces fib (Fig. 1). We assume that the pseudotime t + Δt is sought based on the known result
applied loads are deformation independent so that they do at pseudotime t. We can decompose the displacements and
not change their intensity and direction during deformation. strains at t + Δt as:
Using the Lagrangian approach and the principle of t+Δt
ui = t ui + Δui (5)
virtual displacements, the equilibrium condition of the body
can be expressed as:
t+Δt
εij = t εij + Δεij (6)
  
t+Δt
Sij = t Sij + ΔSij (7)
Sij δεij d 0 Ω = fib δui d 0 Ω + fis δui d 0 s (2)
0Ω 0Ω 0Γ
n where Δ(·) represents the increment of (·).

Fig. 1 A surface load f s and a


body load f b cause the
deformation of the body 0 Ω to
become t Ω
1018 B. Zhu et al.

Using (5) and (3), we can obtain the incremental strain as where KT is the tangent stiffness matrix and r is the load
  imbalance between the external forces F and the internal
1 ∂Δui ∂Δuj ∂ t uk ∂Δuk ∂Δuk ∂ t uk
Δεij = + 0 + 0 + 0 forces t FI . It will become 0 when the increase of the
2 ∂ 0 xj ∂ xi ∂ xi ∂ 0 xj ∂ xi ∂ 0 xj
   displacement Δu is 0. K0 , Kd and Kσ can be expressed as:
ij 
 
1 ∂Δuk ∂Δuk K0 = BTL0 DBL0 d 0 Ω (13)
+ (8) 

2 ∂ 0 xi ∂ 0 xj
   Kd = BTL0 DBL1 + BTL1 DBL0 + BTL1 DBL1 d 0 Ω(14)
ηij 0Ω

in which ij and ηij represent the linear and nonlinear Kσ = BTNL t SBNL d 0 Ω (15)
increments of strain, respectively. 0Ω

Submitting (8) into (2) yields: where BL0 and BL1 are the linear strain-displacement
  transformation matrices. BNL is the nonlinear strain-
ΔSij δΔεij d 0 Ω + t
Sij δηij d 0 Ω displacement transformation matrix. t S is the second Piola-
0Ω 0Ω
  Kirchhoff stress matrix.
= fi δΔui d 0 Ω +
t+Δt b
fi δΔui d 0 s
t+Δt s
The internal force t FI is calculated by using:
0Ω 0Γ
 n 
− t
Sij δ ij d 0 Ω (9)
t
FI = (BL0 + BL1 )T t S d 0 Ω (16)
0Ω 0Ω

The stress at t + Δt can be further expressed as: where t S is the second Piola-Kirchhoff stress vector. More
information on how to construct the tangent stiffness matrix
∂ t Sij
t+Δt
Sij = t Sij + Δεkl = t Sij + Dij kl Δεkl (10) KT and evaluate the internal force t FI can be found in
∂ t εkl standard books on finite element theory (see, e.g., (Bathe
which indicates that the incremental stress can be expressed 2006)).
as ΔSij = Dij kl ( kl + ηkl ) ≈ Dij kl kl . Equation (9) can
be further linearized by replacing ΔSij with Dij kl kl and
δΔεij with δ ij + δηij and assuming the multiplication of 3 SIMP-based topology optimization
ΔSij and δηij is small (Gea and Luo 2001). Therefore, we
can obtain the following linearized incremental equation of 3.1 The node-based SIMP method
the equilibrium condition:
  In density-based methods, several different material inter-
Dij kl ij δ kl d 0 Ω + t
Sij δηij d 0 Ω polation and discretization approaches can be used to solve
0Ω 0Ω
  structural topology optimization problems. Among them,
= t+Δt b
fi δΔui d Ω +0 t+Δt s
fi δΔui d 0 s the SIMP method has been widely utilized due to its sim-
0Ω 0Γ
 n plicity. For the classic SIMP method, the design domain
− t
Sij δ ij d 0 Ω (11) is discretized using N finite elements. The uniform mate-
0Ω rial density of each element is a design variable (Fig. 2).
in which the right side represents the out-of-balance virtual In FreeFEM, the design variables are automatically defined
work. This equation should be solved iteratively until at the elements’ nodes and a linear interpolation scheme
the out-of-balance force vanishes. For more details about
the basic formulations concerning geometrically nonlinear
analysis, the readers can refer to (Holzapfel 2000; Gurtin
et al. 2010; De Borst et al. 2012; Bathe 2006).

2.4 Finite element formulation

Although for the FreeFEM implementation, (11) can be


directly coded, we also transform the continuous form of the
equation of motion into a finite element (FE) formulation
to make it easy to understand. The equilibrium equation is
obtained as (Gea and Luo 2001):
Fig. 2 The element-based (left) and node-based (right) design variable
t
KT Δu = (K0 + Kd + Kσ ) Δu = r (12) implementations
An 89-line code for geometrically nonlinear topology optimization written in FreeFEM 1019

is adopted to determine the density in an element (Fig. 2). Since r = 0, φ can be chosen freely. Therefore, to eliminate
∂u
This ensures the continuity C 0 of the design variables and ∂θm , we can let:
thereby can eliminate or alleviate the checkerboard instabil-
ities that are a concern with element-based design variables FT = φ T KT (23)
(Paulino and Le 2009; Rahmatalla and Swan 2004). Using
and obtain the sensitivity of the end-compliance with
the power law approach, we have
respect to θm as:
p
Dije kl = θe (Dij1 kl − Dij0 kl ) + Dij0 kl (17) ∂J ∂r
= φT (24)
where θe is the value of the design variable on element ∂θm ∂θm
e which is determined through a linear interpolation of where φ is obtained by solving (23), which is a linear
its nodal design variables θm , p is the penalty, and Dij1 kl system since the tangent matrix has been found during
and Dij0 kl are the constitutive tensors for solid and void the equilibrium iterations. To be consistent with the code
materials, respectively. Since only two-dimensional design provided in the Appendix, one can also perform a sensitivity
problems with isotropic materials are considered in this analysis directly from the weak form of the end-compliance.
study, (17) can be rewritten as: Examples can be found in (Gea and Luo 2001; Zhu et al.
2018).
p
E e = θe (E 1 − E 0 ) + E 0 (18)

where E 1 is the Young’s modulus of the solid material and


4 FreeFEM implementation
E 0 = 10−9 E 1 represents the Young’s modulus of the void
area. The design problem (1) can be rewritten as:
The FreeFEM code can be built with the aforementioned
min : J = FT u(θ ) formulations (see the Appendix) by solving a standard
  cantilever design problem. The design conditions are shown
s. t. : θm dΩ dΩ ≤ λ in Fig. 3. The left side of the design domain is fixed. A
D D
surface traction f is applied at the center of the right side.
r(u, θ ) = 0
The ratio between the width W and length L is 1:4. To run
0 ≤ θm ≤ 1 (19) the program, one can simply copy and paste all the lines into
and the structural response is obtained by solving (11) or a text file and save the file in .edp format. Double click the
(12). file to run the program. Figure 4 shows some intermediate
and optimized topologies of the cantilever obtained by the
3.2 Sensitivity analysis code given in the Appendix. It can be clearly seen that the
nonlinear topology becomes asymmetric with a sufficiently
The sensitivity of the end-compliance with respect to the large input force. Furthermore, the obtained topology is
design variable θm is: consistent with the results that have been published. A
detailed explanation of the FreeFEM code is presented in
∂J ∂u the following subsections.
= FT . (20)
∂θm ∂θm
Here, we can use the adjoint method to obtain the sensitivity 4.1 Lines 1–6: Macros
∂u
∂θm (Bruns and Tortorelli 2001; Buhl et al. 2000). Assume
that equilibrium has been achieved. Then, we can modify Several macros are defined to make the program more
the objective function to obtain: compact, although it is not necessary to use macros in the
program. For the defined macros, el and enl are the linear
J = FT u + φ T r (21) and nonlinear strains in (3). denl represents the variation
in the nonlinear increment of the strain in (8). e and de
where φ is a vector of Lagrangian multipliers. Then, we represent the strain and its variation, respectively.
have:
 
∂J T ∂u ∂r ∂u ∂r
=F +φ T
+
∂θm ∂θm ∂u ∂θm ∂θm
∂u ∂u ∂r
= FT − φ T KT + φT
∂θm ∂θm ∂θm
∂u ∂r
= FT − φ T KT + φT . (22)
∂θm ∂θm Fig. 3 The design domain of the cantilever problem
1020 B. Zhu et al.

Fig. 4 a–f The nonlinear


topology optimization process
of the cantilever

(a) Step 1 (b) Step 20

(c) Step 40 (d) Step 60

(e) Step 80 (f) Step 100 (final)

4.2 Lines 7–23: Parameter initialization defined in lines 26–31, and each boundary is labeled
according to its conditions, e.g., fixed, free, or loaded.
The parameters for the design of the cantilever are defined During the boundary parameterization, one must define the
from lines 7 to 23, where L and W are set to 4 m and 1 proper junction and orientation of the different boundary
m, respectively. The Young’s modulus of the solid material parts. After obtaining the boundaries, the design domain is
E1 is set to 3 GPa with the Poisson’s ratio nu equal to 0.4. meshed with triangles using line 33, and the resulting mesh
The Young’s modulus for the void material E0 is set to 1 × is denoted by th in the remaining codes.
10−9 E1 with the same Poisson’s ratio. Although the design
problem in Fig. 3 only uses a vertical load, we provide 4.4 Lines 34–48: Finite element space and variables
the possibility of defining loads in both directions, i.e., fx
and fy. The corresponding loads for solving the adjoint fespace Vh(th,.) (or fespace Vh1(th,.)) defines
equations are defined as fxa and fya. volfrac is the Vh (or Vh1) to be the space of continuous functions that
volume fraction constraint λ in (1). p is the penalty in (17). are affine functions in x and y on each triangle of th. In
Note that in this program, we let p gradually increases from this program, we use P1×P1 Lagrange finite elements to
1 to 3 to stabilize the optimization process (p determined in compute all the related displacement fields. Meanwhile, we
line 52). The optimization process will terminate if either use P1 elements to compute all the scalar function values,
the change (chg) in the design variables is small enough or such as θ . For more details about P1 and the other types
the maximum loop number Imax is reached. The mesh size of Lagrangian finite elements in FreeFEM, please refer
of the design domain is controlled by s, which is used in to https://doc.freefem.org/documentation/finite-element.
line 33. html#Lagrangian-finite-elements. Lines 40 and 41 give the
initial topology and the relationship between the design
4.3 Lines 24–33: Definition of the design problem variables and Young’s modulus based on (17), respectively.
Since only two-dimensional design problems are consid-
The design problem shown in Fig. 3 can be easily and ered, lines 42–48 define the Lamé moduli and the elasticity
explicitly built. Its boundary can be divided into six parts, tensor with:
⎡ ⎤
from b1 to b6, as shown in Fig. 5. All six parts are 2(1 − ν) 0 ν
1 ⎣ ⎦
D= 0 1−2ν
0 (25)
(1 + ν)(1 − 2ν) 2
ν 0 2(1 − ν)
where ν is the Poisson’s ratio. Note that since E is related
to the design variables, D is defined as a constant matrix
without consideration of E.

4.5 Lines 49–89: Optimization loop

Fig. 5 The coordinate system for defining the separated boundaries of The optimization loop starts with the temporary storage of
the cantilever design problem the current element densities. Then, lines 53–63 are used
An 89-line code for geometrically nonlinear topology optimization written in FreeFEM 1021

to solve the nonlinear finite element analysis stated in (11) has been used in image processing for smoothing purposes
with starting points of ui = 0 and Δui = 0. The residual (Shen et al. 2007). For this reason, α can be seen as a
res is defined as the difference in the L-infinity norms of pseudotime step. There are several other filtering techniques
Δui between the current Newton iteration and the first one. that are available in structural topology optimization that
The nonlinear finite element analysis iteration will stop if can also be directly adapted (Bendsøe and Sigmund 2003).
res is reduced by a thousand times. In the density-based The sensitivity smoothing is followed by a call to the
nonlinear topology optimization, large displacements on Optimality Criteria (OC) optimizer (lines 70–81) to update
low-density elements may cause the tangent stiffness matrix the design variables. This has been a standard form for the
to become indefinite, which results in the nonconvergence OC method, which can be seen in several published codes,
of the equilibrium iterations. A number of techniques have such as 99-line. After that, the mean compliance, volume
been proposed to resolve this problem (Lahuerta et al. 2013; fraction, and variable changes are calculated in lines 82–
Penzler et al. 2012; Buhl et al. 2000; Wang et al. 2014). 86. The commands plot and cout are used to print the
Lines 64–69 calculate the mean compliance sensitiv- structural topology and other results.
ity and its smoothed version of the nonlinear structures.
After obtaining the displacements, the process of obtain-
ing sensitivity is quite straightforward, as stated in (Gea 5 Some extensions
and Luo 2001). In density-based methods, sensitivity filter-
ing has been widely used to achieve mesh-independent or In this section, we further discuss the FreeFEM code given
checkerboard patten-free designs (Sigmund 2007; Bendsøe in the Appendix, which solves the cantilever optimization
and Sigmund 2003). Although the implementation of the problem (Fig. 3) with a load of 2.25 × 104 kN. Cases with
node density method can avoid numerical instabilities asso- different loads will be discussed first. A number of possible
ciated with the element density method, e.g., checkerboard extensions and changes in the program will be given in the
pattern, it is found that a new phenomenon that takes following sections.
the form of layering in the material layout design occurs.
Smoothing the sensitivities can eliminate this phenomenon 5.1 Cantilever problem with different loads
(Rahmatalla and Swan 2004). In this program, with the help
of FreeFEM’s powerful partial differential equation calcu- The cantilever design problem defined in Fig. 3 is further
lation ability, we use the following equation to smooth the solved for six different load magnitudes by only changing
sensitivity information (Choi et al. 2011): the corresponding code in line 14 in the program. Figure 6
  shows the resulting topologies, and Table 2 shows the end
(α∇Sn · ∇ (δSn ) + Sn · (δSn )) dΩ = S · (δSn ) dΩ compliances.
D D The optimized topologies obtained from a small load
(26)
are symmetric and similar to the results obtained using the
where Sn and S are the smoothed and original sensitivities, linear assumption (Abdi et al. 2018). As the load increases,
respectively. δSn is the variation of Sn . This equation is the topologies become asymmetric. The program could fail
actually the weak form of the heat conduction equation that to find a meaningful solution with a very large load, e.g.,

Fig. 6 a–f The cantilevers were


obtained by using the program
in the Appendix with different
load magnitudes

(a) 1 × 10 2 kN (b) 1 × 10 3 kN

(c) 1 × 10 4 kN (d) 2 × 10 4 kN

(e) 2 .5 × 10 4 kN (f) 3 × 10 4 kN
1022 B. Zhu et al.

Table 2 The end compliance of the cantilevers shown in Fig. 6

Case in Fig. 6 (a) (b) (c) (d) (e) (f)

Compliance (kJ) 0.002 0.255 25.541 102.571 161.179 276.517

Fig. 7 The topology optimized cantilever with a load of 3 × 104 kN.


3 × 104 kN. The obtained result shown in Fig. 6f has a The compliance is 238.573 kJ
degenerated topology. This phenomenon occurs because we
used the end-compliance as the objective function. One can where β controls the sharpness of the projection and ξ = 0.5
remedy this problem by using the complementary elastic is the threshold. β starts with 1 and is updated every twenty
work as the design objective function, as stated in (Wang iterations when β ≤ 40. For numerical implementation, we
et al. 2014; Buhl et al. 2000). filter the density at the first 100 iterations and then project
the density using (28). Therefore, we add the following two
5.2 A scheme to overcome the nonconvergence lines to initialize β and ξ .
problem

During the design process of obtaining Fig. 6f, several non-


linear finite element analysis iterations fail to converge to Then, we modify line 38 to be
the criteria of line 62 even though a clear configuration is
obtained. It has been pointed out that a large displacement
may cause the tangent stiffness matrix to become indef-
to define θ̄(thetan) and δ θ̄(thetav) in the finite element
initely defined and result in nonconvergence of the equi-
space. Finally, we utilize the following codes:
librium iterations. Such a problem occurs in low-density
areas (Buhl et al. 2000). Many methods have been pro-
posed to overcome this issue, and a rough collection of
those methods can be found in (Chen et al. 2019). Here,
we employ the idea proposed in (Wang et al. 2014), which
is to model the elastic energy density in the solid and void
regions by using large deformation theory and small defor-
mation theory, respectively. Meanwhile, a density filtering
and projection technique is employed.
Suppose that areas with densities lower than 0.01 are
modeled using small deformation theory. This is achieved between line 80 and line 81. By resolving the cantilever
by changing lines 3–4 to be: design problem with f = 3 × 104 kN and a maximum loop
of Imax = 200, we can obtain the result shown in Fig. 7.
In this case, during the optimization process, we did not
experience convergence problems.

5.3 Design with different boundary conditions

For density filtering, we use the same method as in (26), It is rather simple to use the program for the design of
which leads to: other problems. Changing the boundary conditions can be
  done by simply modifying a few lines of the program.
       An example can be shown in Fig. 8 in which a slender
ζ ∇ θ̄ · ∇ δ θ̄ + θ̄ · δ θ̄ dΩ = θ · δ θ̄ dΩ (27)
D D

where θ̄ and θ are the smoothed and original densities,


respectively. δ θ̄ is the variation of θ̄. ζ is a positive constant
that is set to 0.001. The density projection is achieved with
the help of a tanh function by using (Wang et al. 2014):

tanh(βξ ) + tanh(β(θ̄ − ξ ))
θ̃ = (28)
tanh(βξ ) + tanh(β(1 − ξ )) Fig. 8 The design domain of the slender bar problem
An 89-line code for geometrically nonlinear topology optimization written in FreeFEM 1023

Fig. 9 a, b The topology


optimized slender bars with a
load of 2 × 104 kN

(a) Linear(51.145 kJ) (b) Nonlinear (50.595 kJ)

bar design problem is considered. The volume fraction holes are located inside of the design domain. The size and
constraint is set to 20%. Suppose all the material parameters location of the holes are defined by:
are the same as the cantilever design problem in Section 4.  
To solve the slender bar problem, we first need to change L 2 2
x− + y 2 = 3W 10 (29)
line 17 to be 8
 
L 2 2
x+ + y 2 = 3W 10 (30)
8
and lines 25–31 to be:
Again, we assume the volume fraction constraint is set to
20%. Suppose all the material parameters are the same as
those in the cantilever design problem in Section 4. To solve
this problem, in addition to changing line 17 to meet the
volume fraction constraint, we need to replace lines 25–31
with:

and change line 33 to be

With these changes, we can obtain a nonlinear design by


using a load of 30 × 103 kN. Meanwhile, to make a clear
comparison, we also present the result obtained by using a
linear assumption with the same load. The obtained results
are shown in Fig. 9, which clearly shows the difference
when using nonlinear topology optimization to solve the
design problem.

5.4 Design with the void area

In some cases, some areas of the design domain may be


required to remain void, e.g., a hole. This can be easily
done in FreeFEM by appropriately defining the boundaries.
Consider the design problem shown in Fig. 10 where two Fig. 10 The design domain of the slender bar with two holes
1024 B. Zhu et al.

Fig. 11 a, b The topology


optimized slender bars with a
load of 2 × 104 kN

(a) 20kN (0.029 × 10 − 3 kJ) (b) 20 × 10 3 kN (26.855 kJ)

and replace line 33 with (201906010061), and the Fundamental Research Funds for the Central
Universities.

Compliance with ethical standards

Conflict of interest The authors declare that they have no conflicts of


interest.

Replication of results All the necessary data to reproduce the results


Finally, we also examine two different cases in which a reported here are provided in the Appendix. Readers can also contact
small load of 20 kN and a large load of 20 × 103 kN are us to obtain the codes by Email: meblzhu@scut.edu.cn.
used. The obtained results are shown in Fig. 11.

Appendix
6 Conclusions

This paper presents an 89-line code written in FreeFEM for


geometrically nonlinear structural topology optimization.
To simplify the code, the end compliance is selected
as the objective, although for some design cases, it
can result in a degenerated topology. Thirteen lines are
used for comments. Less than 80 lines are needed to
accomplish the parameter initialization, design problem
definition, nonlinear finite element analysis, smoothing
sensitivities, and design variable updating based on the
OC optimizer. Compared with our previously published
nonlinear topology optimization code 213-line, the
proposed code is easy to implement and understand.
Future work includes extending the proposed program by
implementing a nonlinear optimizer, e.g., MMA (method
of moving asymptotes (Svanberg 1987)), which allows for
more complex design problems to be solved where more
than one constraint is considered.

Acknowledgments The authors were inspired by some FreeFEM


codes provided by both Professor G. Allaire (http://www.cmap.
polytechnique.fr/∼allaire/GAUS.html) and the official FreeFEM web-
site. The authors would like to acknowledge this help.

Funding This research was supported by the National Natural


Science Foundation of China (Grant No. 51975216, 51820105007),
the scholarship provided by JSPS (The Japan Society for the
Promotion of Science), the Pearl River Nova Program of Guangzhou
An 89-line code for geometrically nonlinear topology optimization written in FreeFEM 1025

References

Abdi M, Ashcroft I, Wildman R (2018) Topology optimization


of geometrically nonlinear structures using an evolutionary
optimization method. Eng Optim 50(11):1850–1870
Allaire G, Pantz O (2006) Structural optimization with freefem++.
Struct Multidiscip Optim 32(3):173–181
Allaire G, De Gournay F, Jouve F, Toader A-M (2005) Structural
optimization using topological and shape sensitivity via a level set
method. Control and cybernetics 34(1):59
Andreassen E, Clausen A, Schevenels M, Lazarov BS, Sigmund O
(2011) Efficient topology optimization in matlab using 88 lines of
code. Struct Multidiscip Optim 43(1):1–16
Bathe K-J (2006) Finite element procedures. Klaus-Jurgen Bathe
Bendsøe MP, Kikuchi N (1988) Generating optimal topologies
in structural design using a homogenization method. Comput
Methods Appl Mech Eng 71(2):197–224
Bendsøe MP, Sigmund O (1999) Material interpolation schemes in
topology optimization. Arch Appl Mech 69(9-10):635–654
Bendsøe MP, Sigmund O (2003) Topology optimization: theory,
methods and applications. Springer
Bruns TE, Tortorelli DA (2001) Topology optimization of non-
linear elastic structures and compliant mechanisms. Computer
methods in applied mechanics and engineering 190(26-27):3443–
3459
Buhl T, Pedersen ClausBW, Sigmund O (2000) Stiffness design of
geometrically nonlinear structures using topology optimization.
Struct Multidiscip Optim 19(2):93–104
1026 B. Zhu et al.

Challis VJ (2010) A discrete level-set topology optimization code Rozvany GIN, Zhou M, Birker T (1992) Generalized shape
written in matlab. Struct Multidiscip Optim 41(3):453–464 Optimization without homogenization. Structural Optimization
Chen Q, Zhang X, Zhu B (2019) A 213-line topology optimization 4(3-4):250–252
code for geometrically nonlinear structures. Struct Multidiscip Rozvany GIN (2009) A critical review of established methods
Optim 59(5):1863–1879 of structural topology optimization. Struct Multidiscip Optim
Choi JS, Yamada T, Izui K, Nishiwaki S, Yoo J (2011) Topology opti- 37(3):217–237
mization using a reaction–diffusion equation. Comput Methods Shen J, Jin X, Zhou C, Wang CharlieCL (2007) Gradient based
Appl Mech Eng 200(29-32):2407–2420 image completion by solving the poisson equation. Computers &
De Borst R, Crisfield MA, Remmers JorisJC, Verhoosel CV (2012) Graphics 31(1):119–126
Nonlinear finite element analysis of solids and structures. John Sigmund O (2001) A 99 line topology optimization code written in
Wiley & Sons matlab. Struct Multidiscip Optim 21(2):120–127
Dilgen SB, Dilgen CB, Fuhrman DR, Sigmund O, Lazarov BS Sigmund O (2007) Morphology-based black and white filters for
(2018) Density based topology optimization of turbulent flow heat topology optimization. Struct Multidiscip Optim 33(4-5):401–424
transfer systems. Struct Multidiscip Optim 57(5):1905–1918 Sigmund O, Maute K (2013) Topology optimization approaches.
Gea HC, Luo J (2001) Topology optimization of structures with geo- Struct Multidiscip Optim 48(6):1031–1055
metrical nonlinearities. Computers & Structures 79(20-21):1977– Svanberg K (1987) The method of moving asymptotesa new method
1985 for structural optimization. Int J Numer Methods Eng 24(2):359–
Guo X, Zhang W, Zhang J, Yuan J (2016) Explicit structural topology 373
optimization based on moving morphable components (mmc) with Talischi C, Paulino GH, Pereira A, Menezes IvanFM (2012) Polytop:
curved skeletons. Comput Methods Appl Mech Eng 310:711–748 a matlab implementation of a general topology optimization
Gurtin ME, Fried E, Anand L (2010) The mechanics and thermody- framework using unstructured polygonal finite element meshes.
namics of continua. Cambridge University Press, Cambridge Struct Multidiscip Optim 45(3):329–357
Hecht F (2012) New development in freefem++. J Numer Math Tavakoli R, Mohseni SM (2014) Alternating active-phase algorithm
20(3-4):251–265. MR3043640 for multimaterial topology optimization problems: a 115-line
Holzapfel AG (2000) Nonlinear solid mechanics ii matlab implementation. Struct Multidiscip Optim 49(4):621–642
Huang X, Xie YM (2009) Bi-directional evolutionary topology van Dijk NP, Maute K, Langelaar M, Van Keulen F (2013) Level-
optimization of continuum structures with one or multiple set methods for structural topology optimization: a review. Struct
materials. Comput Mech 43(3):393 Multidiscip Optim 48(3):437–472
Huang X, Xie Y-M (2010) A further review of eso type methods for Wang MY, Wang X, Guo D (2003) A level set method for structural
topology optimization. Struct Multidiscip Optim 41(5):671–683 topology optimization. Computer methods in applied mechanics
Kim C, Jung M, Yamada T, et al. (2020) Freefem++ code for and engineering 192(1-2):227–246
reaction-diffusion equation–based topology optimization: for Wang F, Lazarov BS, Sigmund O, Jensen JS (2014) Interpolation
high-resolution boundary representation using adaptive mesh scheme for fictitious domain techniques and topology optimiza-
refinement. Struct Multidiscip Optim 62:439–455 tion of finite strain elastic problems. Comput Methods Appl Mech
Lagaros ND, Vasileiou N, Kazakis G (2019) Ac# code for solving Eng 276:453–472
3d topology optimization problems using sap2000. Optim Eng Wang R, Zhang X, Zhu B (2019) Imposing minimum length
20(1):1–35 scale in moving morphable component (mmc)-based topology
Lahuerta RD, Simões ET, Campello EduardoMB, Pimenta PM, optimization using an effective connection status (ecs) control
Silva EmilioCN (2013) Towards the stabilization of the low method. Comput Methods Appl Mech Eng 351:667–693
density elements in topology optimization with large deformation. Wei P, Li Z, Li X, Wang MY (2018) An 88-line matlab code for the
Comput Mech 52(4):779–797 parameterized level set method based topology optimization using
Laurain A (2018) A level set-based structural optimization code using radial basis functions. Struct Multidiscip Optim 58(2):831–849
fenics. Struct Multidiscip Optim 58(3):1311–1334 Xie YM, Steven GP (1997) Evolutionary structural optimization.
Lazarov BS, Wang F, Sigmund O (2016) Length scale and Springer, Berlin
manufacturability in density-based topology optimization. Arch Yaghmaei M, Ghoddosian A, Khatibi MM (2020) A filter-based level
Appl Mech 86(1-2):189–218 set topology optimization method using a 62-line matlab code.
Liang Y, Cheng G (2020) Further elaborations on topology Struct Multidisc Optim 62:1001–1018
optimization via sequential integer programming and canonical Yamada T, Izui K, Nishiwaki S, Takezawa A (2010) A topology
relaxation algorithm and 128-line matlab code. Struct Multidiscip optimization method based on the level set method incorporating
Optim 61(1):411–431 a fictitious interface energy. Comput Methods Appl Mech Eng
Liu K, Tovar A (2014) An efficient 3d topology optimization code 199(45-48):2876–2891
written in matlab. Struct Multidiscip Optim 50(6):1175–1196 Zhang W, Yuan J, Zhang J, Guo X (2016) A new topology optimization
Loyola RA, Querin OM, Jiménez AG, et al. (2018) A sequential approach based on moving morphable components (mmc) and the
element rejection and admission (SERA) topology optimization ersatz material model. Struct Multidiscip Optim 53(6):1243–1260
code written in matlab. Struct Multidiscip Optim 58(3):1297–1310 Zhu B, Zhang X, Fatikow S (2014) Design of single-axis flexure
Luo Z, Tong L, Wang MY, Wang S (2007) Shape and topology hinges using continuum topology optimization method. Sci China
optimization of compliant mechanisms using a parameterization Technol Sci 57(3):560–567
level set method. J Comput Phys 227(1):680–705 Zhu B, Zhang X, Fatikow S (2015) Structural topology and shape
Paulino GH, Le CH (2009) A modified q4/q4 element for topology optimization using a level set method with distance-suppression
optimization. Struct Multidiscip Optim 37(3):255–264 scheme. Comput Methods Appl Mech Eng 283:1214–1239
Penzler P, Rumpf M, Wirth B (2012) A phase-field model for Zhu B, Chen Q, Wang R, Zhang X (2018) Structural topology
compliance shape optimization in nonlinear elasticity. ESAIM: optimization using a moving morphable component-based method
Control, Optimisation and Calculus of Variations 18(1):229–258 considering geometrical nonlinearity. J Mech Des 140(8):081403
Rahmatalla SF, Swan CC (2004) A q4/q4 continuum structural Zhu B, Zhang X, Zhang H, Liang J, Zang H, Li H, Wang R (2020)
topology optimization implementation. Struct Multidiscip Optim Design of compliant mechanisms using continuum topology
27(1-2):130–135 optimization: a review. Mech Mach Theory 143:103622
An 89-line code for geometrically nonlinear topology optimization written in FreeFEM 1027

Zuo ZH, Xie YM (2015) A simple and compact python code for Publisher’s note Springer Nature remains neutral with regard to
complex 3d topology optimization. Adv Eng Softw 85:1–11 jurisdictional claims in published maps and institutional affiliations.

You might also like