# Interactive Airfoil Optimization Using Parsec Parametrization and Adjoint Method
## 4 Airfoil Optimization: Governing Equations and Implementation
### Resulting Shape Feasibility and Convergence of the Optimization  
The programming implementation of the procedure presented in Section 4.1. and Section 4.2. is rather simple but requires the addressing of a few tasks. The first task is to prevent the occurrence of distorted shapes during optimization. In the solution of this problem, the clear geometrical meaning of parsec parameters is very handy. With that meaning, it is possible to simply prescribe the conditions that assure the geometrical feasibility of those shapes. This is carried out by monitoring the values of the parameters (like \(r_{up}\), \(r_{l0}\), \(x_{up}\), \(x_{lo}\), and \(\beta_{te}\)); if they get outside the allowed range, the optimization is immediately stopped. The allowed range can be completely controlled by the user, enabling custom restrictions to be made. On top of that, the airfoil paneling is constructed in such a way that the panel nodes in the top and bottom halves of the airfoil share x coordinates. Because of that, it is easy to compare the y coordinates of the corresponding nodes and to make sure that the y coordinate of the upper-surface node is always greater than that of the lower-surface one. If any self-intersection of the airfoil's surface is detected in this way, the optimization is immediately stopped, providing another layer of protection besides the allowed parameter values.  
The next task is convergence monitoring. In the case of this optimization, monotone convergence is required. In the case of the worsening of the value of the cost function between subsequent iterations, a warning is displayed, but the optimization process is not terminated. This allows the procedure the possibility to regain monotone convergence once again.  
The final task is to define the convergence criteria. As the inviscid incompressible potential flow is assumed, the \(C_{y}\) may become unbounded, as there is no flow separation allowed other than that at the trailing edge. This means that reaching the true maximum of \(C_{y}\) in the incompressible inviscid scenario may be, and probably is, impossible. This renders the classical convergence criteria for reaching the extremum unusable and also means that geometrically feasible but nonsensical and obviously wrong shapes are possible if the optimization is allowed to continue for too many iterations (more than a few tens). To stop this from happening, other convergence criteria were implemented. The optimization has three stopping criteria in total. The first states that convergence is reached when a defined improvement, whether absolute or relative, has been made. The second one stops the iteration when a defined change in shape, measured as the root mean square difference from the original shape, has been made. The final one limits the maximum number of iterations allowed.  
The proposed criteria, however, cause the optimal result to be influenced by the threshold values chosen. The shape change criterion is the most objective of the three, as it can be interpreted as defining the region of design space for the algorithm to search in. It can also be tackled from the engineering viewpoint, as the baseline shape is usually chosen for a reason, and one may not want to change it much during the optimization. For more objective criteria to be defined, it would be possible to add a simple boundary layer solver based on the von Karman momentum integral equation and Pohlhausen's method to determine whether the flow separation was occurring on the airfoil. The stopping criterion could then be the occurrence of the separation, for example (or, as a variation of this criterion, the reaching of a certain distance from the trailing edge). This modification, however, would bring with it some computation costs, which in this context would be rather large.  
The script conducting the optimization proposed in this paper was written in MATLAB R2023b. The script operates according to the flowchart shown in Figure 5.  
Figure 5: Flowchart of the optimization script.