## Work Packages ≻ Optimal Control in OpenFOAM ≻

Author: - 30 June 2018

A natural application in the framework of shape optimization is the aerodynamic design of an airfoil. An object defined by a domain $\Omega_s \in \mathbb{R}^d$ with boundary $\Gamma_s$ immersed in a fluid will experience a net force given by

$F_i = \int_{\Gamma_s \left( \theta \right )} -\sigma_{ij}\left(p, \bm{u}\right) \, n_j \ \mathrm{d} \Gamma,$

where $\sigma_{ij}\left(p, \bm{u}\right) = -p \delta_{ij} + 2\nu S_{ij}\left(\bm{u}\right)$ is the stress tensor, $p$ is the fluid pressure, $\nu$ is the kinematic viscosity, $S_{ij}\left(\mathbf{u}\right) = \frac{1}{2} \left( \partial_j u_i + \partial_i u_j \right)$ is the strain rate tensor, and $\mathbf{u} \in \mathbb{R}^d$ is the fluid velocity vector field.

The force exerted by the fluid on the airfoil parallel to the fluid velocity at infinity is referred to as the drag force, whereas the force in perpendicular direction is often named the lift.

$D = d^D_i \int_{\Gamma_s \left( \theta \right )} -\sigma_{ij}\left(p, \bm{u}\right) \, n_j \ \mathrm{d} \Gamma,$

$L = d^L_i \int_{\Gamma_s \left( \theta \right )} -\sigma_{ij}\left(p, \bm{u}\right) \, n_j \ \mathrm{d} \Gamma.$

We look for the optimal shape in order to minimize the drag, as this force produces energy losses, and at the same time maximize the lift for a fixed airfoil volume. This can be expressed by means of the functional

$\mathcal{J} \left( \theta \right) = w^D D - w^L L = d_i \int_{\Gamma_s \left( \theta \right)} -\sigma_{ij}\left(p, \mathbf{u}\right)n_j \mathrm{d} \Gamma,$

$d_i = w^D d^D_i - w^L d^L_i,$

where $w^D$ and $w^L$ are weighting factors for drag and lift forces, respectively, and with $\theta \in L^2\left( \Gamma_s \right)$. The state variables are subject to a set of constraints in the fluid domain $\Omega_f \left( \theta \right )$ with boundary $\Gamma_f = \Gamma_{in} \cup \Gamma_{out} \cup \Gamma_s\left( \theta \right ) \cup \Gamma_w$, namely the steady Navier-Stokes equations,

$\begin{cases} u_j \partial_j u_i - \partial_j \left[ \sigma_{ij}\left(p, \mathbf{u} \right) \right] = 0 & \text{in } \Omega_f \left( \theta \right ), \\ \partial_j u_j = 0 & \text{in } \Omega_f \left( \theta \right ), \\ u_i = u^\infty_i & \text{on } \Gamma_{in}, \\ u_i = 0 & \text{on } \Gamma_s \left( \theta \right ) \cup \Gamma_w, \\ \sigma_{ij} \left(p, \mathbf{u} \right) n_j = 0 & \text{on } \Gamma_{out}, \end{cases}$

and to the volume constraint

$\left| \Omega_{s} \right| = \Omega_0.$

$\begin{cases} v_j \partial_i u_j - \partial_j \left( u_j v_i \right) - \partial_j \left[ \sigma_{ij} \left(q, \mathbf{v} \right) \right] = 0 & \text{in } \Omega_f \left( \theta \right ), \\ \partial_j v_j = 0 & \text{in } \Omega_f \left( \theta \right ), \\ v_i = 0 & \text{on } \Gamma_{in} \cup \Gamma_w, \\ v_i = -d_i & \text{on } \Gamma_s \left( \theta \right ), \\ \sigma_{ij} \left(q, \mathbf{v} \right) n_j + v_i u_j n_j = 0 & \text{on } \Gamma_{out}. \end{cases}$

The directional derivative of the functional is given by

$\mathcal{D}_{\delta \theta} \mathcal{J} = \int_{\Gamma_s \left( \theta \right )} \left[ r - 2 \nu S_{ij} \left( \mathbf{v} \right) \, n_j \, n_k \, \partial_k u_i \right] \, \delta \theta \ \mathrm{d} \Gamma,$

and the cost function descreases by choosing the normal displacement to the controlled boundary as

$\delta \theta ^{\left(n\right)} = - \left[ r^{\left(n\right)} - 2 \nu S_{ij} \left( \mathbf{v}^{\left(n\right)} \right) \, n_j^{\left(n\right)} \ n_k^{\left(n\right)} \, \partial_k u_i^{\left(n\right)} \right].$

Hence,

$\theta ^{\left(n+1\right)} = \theta ^{\left(n\right)} + \epsilon \delta \theta ^{\left(n\right)},$

for a sufficiently small value of $\epsilon$.

The remaining Lagrange multiplier associated to the volume constraint is computed in order to ensure the volume conservation,

$r^{\left(n\right)} = \frac{1}{\left| \Gamma_s \left( \theta \right ) \right|} \int_{\Gamma_s \left( \theta \right )} 2 \nu S_{ij} \left( \mathbf{v}^{\left(n\right)} \right) n_j^{\left(n\right)} n_k^{\left(n\right)} \partial_k u_i^{\left(n\right)} \ \mathrm{d} \Gamma.$

In summary, the shape optimization iteration is as follows:

• Solve the primal problem.
• Solve the adjoint problem with the previously computed state variables.
• Compute the Lagrange multiplier for the volume constraint.
• Compute the displacement field.
• Update the displacement field of the previous iteration.
• Perform the mesh motion.

## Getting Started

The solver must be compiled in the terminal. It is advisable to first clean previous compilations with

wclean


and then use

wmake


### Prerequisites

OpenFOAM C++ library must be installed in order to compile the code.

The OpenFOAM distribution provided by the OpenFOAM Foundation was used.

## Running a Case

The above shape optimization process has been implemented in the open-source C++ library OpenFOAM. The already existing solver adjointShapeOptimizationFoam is a topological optimization routine that relies on a porosity variable and on the calculation of volume sensitivities to determine which regions of the domain must be blocked to the fluid passage in order to minimize a known functional. We have coded a new solver shapeOptimizationFoam that takes some ideas from the aforementioned one, but which performs a shape optimization iteration instead by computing shape sensitivities.

The solver has been tested in the minimization of the the cost function

$\mathcal{J} \left( \theta \right) = \left( w^D d^D_i - w^L d^L_i \right) \int_{\Gamma_s \left( \theta \right)} -\sigma_{ij}\left(p, \mathbf{u}\right)n_j \ \mathrm{d} \Gamma,$

subject to

$\begin{cases} u_j \partial_j u_i - \partial_j \left[ \sigma_{ij}\left(p, \mathbf{u} \right) \right] = 0 & \text{in } \Omega_f \left( \theta \right) \right ), \\ \partial_j u_j = 0 & \text{in } \Omega_f \left( \theta \right) \right ), \\ u_i = u^\infty_i & \text{on } \Gamma_{\infty}, \\ u_i = 0 & \text{on } \Gamma_s \left( \theta \right) \right ). \\ \end{cases}$

$\begin{cases} v_j \partial_i u_j - \partial_j \left( u_j v_i \right) - \partial_j \left[ \sigma_{ij} \left(q, \mathbf{v} \right) \right] = 0 & \text{in } \Omega_f \left( \theta \right ), \\ \partial_j v_j = 0 & \text{in } \Omega_f \left( \theta \right ), \\ v_i = 0 & \text{on } \Gamma_{\infty}, \\ v_i = -d_i & \text{on } \Gamma_s \left( \theta \right ). \\ \end{cases}$

In order to run the solver move to the case folder shapeOptimizationFoamCase and type in the command line

./Allprepare

shapeOptimizationFoam


The solver has been run for three different Reynolds numbers and the cost functional value has been normalized with

$\frac{1}{2} \rho U_{\infty}^2 D e$

where $D$ and $e$ are the cylinder diameter and thickness, respectively.

### Warning

It might be needed to use

sed -i -e 's/\r\$//' filename


and

chmod +x filename


in order to be able to execute

./filename


## References

• Antony Jameson. Aerodynamic design via control theory. Journal of scientific computing, 3(3):233–260, 1988.
• Antony Jameson and Luigi Martinelli. Aerodynamic shape optimization techniques based on control theory. In Computational Mathematics Driven by Industrial Problems, pages 151–221. Springer, 2000.
• Antony Jameson and James Reuther. Control theory based airfoil design using the euler equations. In 5th Symposium on Multidisciplinary Analysis and Optimization, page 4272, 1994.
• Bijan Mohammadi and Olivier Pironneau. Mesh adaption and automatic differentiation in a cad-free framework for optimal shape design. International Journal for Numerical Methods in Fluids, 30(2):127–136, 1999.
• Bijan Mohammadi and Olivier Pironneau. Applied shape optimization for fluids. Oxford University Press, 2010.
• C. Othmer. A continuous adjoint formulation for the computation of topological and surface sensitivities of ducted flows. International Journal for Numerical Methods in Fluids, 58(8):861–877, 2008.
• C. Othmer, E. Papoutsis-Kiachagias, and K. Haliskos. CFD optimization via sensitivity-based shape morphing. In Proceedings of the 4th ANSA & μETA Internat. Conf., Thessaloniki, Greece, BETA CAE Systems SA, 2011.
• Carsten Othmer. Adjoint methods for car aerodynamics. Journal of Mathematics in Industry, 4(1):6, 2014.
• Carsten Othmer, Eugene de Villiers, and Henry Weller. Implementation of a continuous adjoint for topology optimization of ducted flows. In 18th AIAA Computational Fluid Dynamics Conference, page 3947, 2007.
• Carsten Othmer and Thorsten Grahs. Approaches to fluid dynamic optimization in the car development process. In International Conference on Evolutionary and Deterministic Methods for Design, Optimization and Control With Applications to Industrial and Societal Problems, 2005.
• Carsten Othmer, Thomas Kaminski, and Ralf Giering. Computation of topological sensitivities in fluid dynamics: cost function versatility. In ECCOMAS CFD 2006: Proceedings of the European Conference on Computational Fluid Dynamics, Egmond aan Zee, The Netherlands, September 5-8, 2006. Citeseer, 2006.
• Olivier Pironneau. Optimal shape design for elliptic systems. Springer Science & Business Media, 2012.
• James Reuther and Antony Jameson. Aerodynamic shape optimization of wing and wing-body configurations using control theory. In 33rd Aerospace Sciences Meeting and Exhibit, page 123, 1995.
• James Reuther, Antony Jameson, James Farmer, Luigi Martinelli, and David Saunders. Aerodynamic shape optimization of complex aircraft configurations via an adjoint formulation. In 34th Aerospace Sciences Meeting and Exhibit, page 94, 1996.
• James J Reuther, Antony Jameson, Juan J Alonso, Mark J Rimlinger, and David Saunders. Constrained multipoint aerodynamic shape optimization using an adjoint formulation and parallel computers, part 1. Journal of aircraft, 36(1):51–60, 1999.
• J. Simon. Diferenciación de problemas de contorno respecto del dominio. Technical report, Universidad de Sevilla, Facultad de Matemáticas, Departamento de Análisis Matemático, 1989.
• Orlando Soto and Rainald Löhner. On the computation of flow sensitivities from boundary integrals. AIAA paper, 112:2004, 2004.
• Orlando Soto, Rainald Löhner, and Chi Yang. An adjoint-based design methodology for CFD problems. International Journal of Numerical Methods for Heat & Fluid Flow, 14(6):734–759, 2004.
• Schumacher Thomas, Othmer Carsten, et al. Adjoint optimization for vehicle external aerodynamics. International Journal of Automotive Engineering, 7(1):1–7, 2016.
• Henk Kaarle Versteeg and Weeratunge Malalasekera. An introduction to computational fluid dynamics: the finite volume method. Pearson Education, 2007.
• F. Feppon, G. Allaire, F. Bordeu, J. Cortial, and C. Dapogny. Shape optimization of a coupled thermal fluid-structure problem in a level set mesh evolution framework, 2018.