# Multi-Fidelity Gradient-Based Strategy for Robust Optimization in Computational Fluid Dynamics
## Appendix A Calculation of the Gradient from CFD Codes
### Continuous Adjoint  
For the continuous adjoint, the adjoint equations with respect to \(J\) are derived from the continuous form of the governing equations \(R\); afterwards, they are discretized and solved.  
Considering the quasi-1D nozzle geometry described in Section 2.1 and the definition of \(J\) provided in Equation (3), one can write the differential form of \(J\) as in Equation (18).  
\[\frac{\partial J}{\partial\alpha}=\int_{0}^{L}(P-P_{des})\frac{\delta P}{ \delta\alpha}dx \tag{18}\]As the differential form of the governing equation \(R\) Equation (A2) is equal to zero, it is possible to multiply it by a vector \(\theta^{T}\), then integrate it over the domain, and finally, subtract it from the variation of the cost function \(dJ\), obtaining the relation in Equation (A9).  
\[J=J-\int_{0}^{L}\theta^{T}\frac{dR}{dx}dx\] (A9)  
where \(\theta^{T}\) is an arbitrary line vector with dimension \(N_{\omega}\) containing the continuous adjoint variables.  
As the objective is to obtain the gradient \(\frac{dJ}{da}\), Equation (A9) can be differentiated, and with the assumption that \(\theta^{T}\) is also differentiable, it is possible to integrate the integrals containing \(\theta^{T}\) by parts, obtaining the formulation as in Equation (A10).  
\[\begin{split}\frac{dJ}{da}=\int_{0}^{L}(P-P_{des})\frac{\delta P} {\delta\alpha}dx-\int_{0}^{L}\frac{d\theta^{T}}{dx}S\frac{df}{da}dx-\int_{0}^ {L}\frac{d\theta^{T}}{dx}f\frac{dS}{da}dx+\int_{0}^{L}\theta^{T}\frac{ds}{dx} \frac{dK}{da}dx-\\ \int_{0}^{L}\frac{d\theta^{T}}{dx}K\frac{dS}{da}dx+\left[\theta^ {T}S\frac{df}{da}\right]_{0}^{L}+\left[\theta^{T}f\frac{dS}{da}\right]_{0}^{L }+\left[\theta^{T}K\frac{dS}{da}\right]_{0}^{L}\end{split}\] (A10)  
where \(K\), \(S\), and \(f\) were already defined in Equation (4). At this point, since \(\theta^{T}\) is an arbitrary differentiable function, it can be chosen in order to remove the dependence of \(dJ\) from the variation of the state vector \(d\omega\), obtaining the differential adjoint problem defined in Equation (A11).  
\[\int_{0}^{L}(P-P_{des})\frac{\delta P}{\delta\alpha}dx-\int_{0}^{L}\frac{d \theta^{T}}{dx}S\frac{df}{da}dx+\int_{0}^{L}\theta^{T}\frac{ds}{dx}\frac{dK}{ da}dx+\left[\theta^{T}S\frac{df}{da}\right]_{0}^{L}=0\] (A11)  
As all thermodynamic conditions are fixed at the nozzle inlet, so the boundary conditions \(\left[\frac{df}{da}\right]_{0}\) are equal to zero; consequently, solving \(\theta^{T}\) becomesthe differential problem defined by the linear system in Equation (A12) with the boundary conditions provided in Equation (A13).  
\[\int_{0}^{L}(P-P_{des})\frac{\delta P}{\delta\alpha}dx-\int_{0}^{L}\frac{d \theta^{T}}{dx}S\frac{df}{da}dx+\int_{0}^{L}\theta^{T}\frac{ds}{dx}\frac{dK}{ da}dx=0\] (A12)  
\[\left[\theta^{T}S\frac{df}{da}\right]_{x=L}=0\] (A13)  
Once \(\theta^{T}\) has been determined, the variation of the cost function \(dJ\) with respect to the design parameters \(\alpha\) can be easily calculated by considering just the variation of \(dS\), as stated in Equation (A14).  
\[\frac{dJ}{d\alpha}=-\int_{0}^{L}\frac{d\theta^{T}}{dx}f\frac{dS}{da}dx-\int_{0 }^{L}\frac{d\theta^{T}}{dx}K\frac{dS}{da}dx+\left[\theta^{T}f\frac{dS}{da} \right]_{0}^{L}+\left[\theta^{T}K\frac{dS}{da}\right]_{0}^{L}\] (A14)  
In the present work, the system of linear equations defined in Equation (A12) is discretized by a cell-centered finite volume formulation, using [PERSON]'s first-order scheme for space integration, while the boundary conditions in Equation (A13) with a second-order backward finite differences scheme; this set of equation was solved with Gaussian elimination with partial pivoting.