# Topology Optimization Considering Porosity Defects in Metal Additive Manufacturing
## 5 Optimization Procedure  
In this paper, the Lagrangian method is used to solve the level set topology optimization problem (40), which transforms the optimization problem into the Lagrangian unconstrained minimization problem. The topology optimization problem is transformed into:  
\[\begin{array}{ll}L(\Omega,\ell,\Gamma)=J(\Omega)-\ell_{1}C_{p}(\Omega)-\ell _{2}(Vol(\Omega)-V_{max})\\ &+\frac{\Gamma_{1}}{2}\left(C_{p}(\Omega)\right)^{2}+\frac{\Gamma_{2}}{2} \left(Vol(\Omega)-V_{max}\right)^{2}\end{array} \tag{52}\]  
where \(\ell=(\ell_{1},\ell_{2})\) and \(\Gamma\) = (\(\Gamma_{1}\), \(\Gamma_{2}\)) are the Lagrangian multipliers and the penalty factors of the constraint function, respectively.  
The shape sensitivity of the augmented Lagrangian function can be derived as:  
\[\begin{array}{ll}L^{\prime}(\Omega,\ell,\Gamma)(\theta)=&J^{\prime}(\Omega) (\theta)-\ell_{1}C_{p}^{\prime}(\Omega)(\theta)-\ell_{2}\int_{\Omega}\theta \cdot nds+\Gamma_{1}C_{p}(\Omega)C_{p}^{\prime}(\Omega)(\theta)\\ &+\Gamma_{2}(Vol(\Omega)-V_{max})\int_{\Omega}\theta\cdot nds\end{array} \tag{53}\]  
Substituting \(J^{\prime}(\Omega)(\theta)\) and \(C_{p}^{\prime}(\Omega)(\theta)\), the normal evolution velocity \(V_{n}\) of the Hamilton-Jacobi equation can be obtained.  
When performing a one-step solution, it is easy to make the optimization considering the effects of porosity converge to the local optimal solution. Addressing the issue, the topology optimization is solved in two steps in this paper. For one thing, the hole nucleation method combining BESO and topological sensitivity can be used to reduce the influence of initial hole distribution on the optimization results. For another, the optimization results obtained in the previous step can be directly used in the second step, which improves the convergence efficiency of the optimization. Therefore, the level set topology optimization algorithm considering porosity constraints is summarized as follows:  
1. Perform preliminary structural optimization according to the level set topology optimization combining BESO and topological sensitivity and obtain optimal results without considering porosity constraints;
2. Import optimization results without considering porosity constraints for subsequent optimization;
3. Initialize the level set function \(\Phi_{2}\) according to the preliminary optimization results;
4. According to the given load conditions, solving the elastic balance equation \(a(u,v,\Phi)\) = \(L(v,\Phi)\), the displacement field vector \(u_{\Omega}\) and the topological sensitivity \(D_{T}\)\(J(\Omega)\) are obtained;
5. Solve the adjoint vector \(p_{\Omega}\) using (49);
6. Calculate the shape sensitivity using (48);
7. Solve the level set velocity field vector \(Vn\), and extend the velocity to the entire design domain \(\Omega\);
8. Using the existing level set function and the obtained velocity \(Vn\), solve the Hamilton-Jacobi equation \(\frac{\partial\Phi}{\partial t}-V_{n}\|\
abla\Phi\|=0\) by finite difference to obtain a new level set function;
9. Reinitialize the signed distance function for the new level set function;
10. Check whether the level set function satisfies the convergence criterion. If not, repeat steps 4 to 10 until convergence. The convergence criterion is:  
\[\left|J^{n}-J^{n-k}\right|\leq 0.01J^{n}\ \&\&\ \left|C_{p}^{n}-C_{p}^{n-k} \right|\leq 0.01C^{n}\ \&\ \&\ \left|V^{n}-V_{max}\right|\leq 0.01 \tag{54}\]where \(1\leq k\leq 5\).  
The optimization process of level set topology optimization considering porosity constraints is shown in Figure 2.