# Robust Algorithm Software for NACA 4-Digit Airfoil Shape Optimization Using the Adjoint Method
## 3 Methodology
### Optimization Algorithm  
Based on the discussion of the adjoint equation formation for a fluid problem, the optimization algorithm can be conceptualized in the following manner:  
* Step 1: The initial step involves defining the initial parameters for the algorithm, which initiates the primary optimization loop.
* Step 2: The flow field equations are solved to obtain a reliable solution. AUSM\({}^{+}\)[27] was employed to compute the flow field variables that will be utilized in subsequent steps.
* Step 3: The adjoint equation is formulated and solved by the algorithm. The algorithm reconstructs the adjoint equation using the flow field variables.
* Step 4: The boundary geometry is deformed in the direction of the maximum steepest descent, adhering to the NACA standard. After observing the trend of movement of the boundary geometry, the shape of the airfoil is altered to approach the optimal condition.
* The field mesh is reproduced, and the algorithm returns to Step 1 to attain the minimum-cost function. In each iteration, the shape undergoes modifications, and a new mesh is produced at the field boundary.  
The loop of the algorithm aimed at achieving the optimized shape is depicted in Figure 1. To identify the path of deformation, the relation given by Equation (12) can be employed to enhance the form, as  
\[\delta\mathcal{F}=-\lambda\mathcal{G}, \tag{26}\]  
where \(\lambda\) is the step size. The following equation provides the search direction toward the optimal value using the steepest descent method  
\[\mathcal{S}=-\mathcal{G} \tag{27}\]  
Determining the step size is also necessary to move in this direction  
\[\lambda=\frac{e^{b\ln 10}}{e^{a\ln 10}}=e^{(b-a)\ln 10}, \tag{28}\]  
where \(a\) and \(b\) are the results of  
\[a=\left\{\begin{array}{ll}2&\text{if}\quad\mathcal{S}=0\\ \log|\mathcal{S}|&\text{if}\quad\mathcal{S}\
eq 0\end{array},\quad b=\left\{ \begin{array}{ll}-2&\text{if}\quad\mathcal{F}=0\\ \log|\mathcal{F}|&\text{if}\quad\mathcal{F}\
eq 0\end{array}\right.. \tag{29}\]  
To maximize the ratio of the lift-to-drag coefficient, one can combine the objective functions of maximizing the lift coefficient and minimizing the drag coefficient. For this purpose, the coefficients of the general objective function must be calculated as  
\[I=\begin{cases}\left(1-\frac{C_{l}}{C_{\text{max}}}\right)^{2}&\text{if}\quad C _{d}\leq Cd_{\text{min}}\\ \frac{1}{2}\left(1-\frac{C_{l}}{C_{\text{max}}}\right)^{2}+\frac{1}{2}\left( 1-\frac{C_{d}}{Cd_{\text{min}}}\right)^{2}&\text{if}\quad C_{d}>Cd_{\text{ min}}\end{cases}, \tag{30}\]  
where \(Cd_{\text{min}}\) is the target value of the drag coefficient and \(Cd_{\text{max}}\) is the target value of the lift coefficient. As a result, the objective function changes, as  
\[\delta I=\begin{cases}-2\left(1-\frac{C_{l}}{C_{\text{max}}}\right)\frac{ \delta C_{l}}{C_{\text{max}}}&\text{if}\quad C_{d}\leq Cd_{min}\\ -\left(1-\frac{C_{l}}{C_{\text{max}}}\right)\frac{\delta C_{l}}{C_{\text{max}} }-\left(1-\frac{C_{d}}{Cd_{min}}\right)\frac{\delta C_{d}}{Cd_{min}}&\text{ if}\quad C_{d}>Cd_{min}.\end{cases} \tag{31}\]In the optimization process, limitations are set by taking into account the varying abilities of morphing airfoils compared to other airfoils. The range of changes allowed in the determining components of the flap geometry during the optimization path are presented in Table 1.  
Figure 1: The algorithmic flowchart for the shape optimization procedure involves solving the flow field equations, formulating and solving the adjoint equations, computing the converged adjoint variables, and determining the optimization direction based on the adjoint solver variables.