analysis of the adjoint euler equations as used for

42
Analysis of the Adjoint Euler Equations as used for Gradient-based Aerodynamic Shape Optimization Final Presentation Dylan Jude Graduate Research Assistant University of Maryland AMSC 663/664 May 4, 2017

Upload: others

Post on 23-Apr-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Analysis of the Adjoint Euler Equations as used for

Analysis of the Adjoint Euler Equations asused for Gradient-based Aerodynamic Shape

Optimization

Final Presentation

Dylan JudeGraduate Research Assistant

University of MarylandAMSC 663/664

May 4, 2017

Page 2: Analysis of the Adjoint Euler Equations as used for

Abstract

I Adjoint methods are often used in gradient-basedoptimization because they allow for a significant reductionof computational cost for problems with many designvariables.

I The project focuses on the use of adjoint methods fortwo-dimensional airfoil shape optimization usingComputational Fluid Dynamics to solve the steady Eulerequations.

Adjoints in CFD 2/36

Page 3: Analysis of the Adjoint Euler Equations as used for

Design Problem

We can change the shape of an airfoil by prescribing sinusoidal“bumps” along the surface of the airfoil:

Known as Hicks-Henne “bumps”, both the location and theheight of the bumps can be changed to alter the airfoil shape.[Hicks and Henne(1977)]

Adjoints in CFD 3/36

Page 4: Analysis of the Adjoint Euler Equations as used for

Design ProblemWe would want to alter an airfoil to obtain more favorableaerodynamic properties. A simple example would be toapproach a desired pressure distribution.

Mathematically, we wantto minimize the costfunction:

Ic(α) =

∮airfoil

1

2(P−Pd)2

where α is the set ofdesign variables andP = P (α)

[Nadarajah and Jameson(2002)]Adjoints in CFD 4/36

Page 5: Analysis of the Adjoint Euler Equations as used for

Design ProblemFor a single variable representing the location of one bump onthe surface of the airfoil

a parametric sweep of the cost function for a given desiredpressure distribution shows

Adjoints in CFD 5/36

Page 6: Analysis of the Adjoint Euler Equations as used for

Design Problem

I The goal of airfoil optimization is to obtain the design variable (airfoilgeometry) where the cost function is a minimum.

I As shown, it is possible to have local minima in the cost function.

This can be a challenge for gradient-based optimization methods.

◦ This will be discussed in a few slides

I Parametric sweeps of the design space (as shown above) are veryexpensive for multiple variables.

Adjoints in CFD 6/36

Page 7: Analysis of the Adjoint Euler Equations as used for

Computing the Cost Function

I Most design cases will have many variables.

I Computing the value of the cost function is an expensiveprocess because it requires solving the Euler Equations(using Computational Fluid Dynamics or CFD) to find thepressure.

I Knowing the gradient of the cost function is often requiredfor gradient-based optimization methods however findingthe gradient is non-trivial and expensive.

Adjoints in CFD 7/36

Page 8: Analysis of the Adjoint Euler Equations as used for

Computing the Cost Function

We want the gradient of the cost function with respect to thedesign variables. Using a brute-force approach:

∂Ic∂α1

=Ic(α1 + ∆α1)− Ic(α1)

∆α1

For 2 variables, 3 expensive CFD flow calculations arerequired to find

Ic(α1,2), Ic(α1 + ∆α1), Ic(α2 + ∆α2)

The adjoint method instead can find N variable sensitivitieswith the cost of a single CFD flow-computation and anadditional adjoint.

Adjoints in CFD 8/36

Page 9: Analysis of the Adjoint Euler Equations as used for

Discrete Euler Equations

The Euler equations in coordinate directions ξ:

∂q

∂t+∂fc,i∂ξi

= 0 , i = 1, 2 (1)

q = J−1

ρ

ρu1

ρu2

e

, fc = J−1

ρV1

ρu1V1 + ξ1,1p

ρu2V1 + ξ1,2p

(e+ p)V1

(2)

Vi = u1ξi,1 + u2ξi,2 (3)

Note: Conventional usage of ρ, ui, e, p for density, velocity, energy, and pressure

Adjoints in CFD 9/36

Page 10: Analysis of the Adjoint Euler Equations as used for

Discrete Euler Residual

Let f denote flux in j-coordinate direction and g denote flux ink-coordinate direction.

∂q

∂t+∂f

∂ξ1+∂g

∂ξ2= 0

Let the Residual of the steady Euler Equation be defined as:

Rn =qn+1 − qn

∆t= 0 (4)

The Residual expanded in both dimensions j, k at time n is

Rnj,k = −(fj+1/2,k − fj−1/2,k

)−(gj,k+1/2 − gj,k−1/2

)= 0 (5)

Adjoints in CFD 10/36

Page 11: Analysis of the Adjoint Euler Equations as used for

Approach: Adjoint Equation

For our flow solution q and airfoil geometry X = X(α1, ..., αn)our cost function is

Ic = Ic(q,X)

and a perturbation of the cost function is represented as:

δI =∂IT

∂qδq +

∂IT

∂XδX

A perturbation of the flow residual R is represented as:

δ

[∂~q

∂t+∂ ~fc,i∂ξi

]= δR =

[∂R

∂q

]δq +

[∂R

∂X

]δX = 0

Adjoints in CFD 11/36

Page 12: Analysis of the Adjoint Euler Equations as used for

Using the method of Lagrange multipliers:

δI =∂IT

∂qδq +

∂IT

∂XδX − ψT

{[∂R

∂q

]δq +

[∂R

∂X

]δX

}

If the adjoint equation is satisfied:[∂R

∂q

]Tψ =

∂I

∂q→ ψT

[∂R

∂q

]=∂IT

∂q

then

δI =

{∂IT

∂X− ψT

[∂R

∂X

]}δX

Adjoints in CFD 12/36

Page 13: Analysis of the Adjoint Euler Equations as used for

In this final equation:

δI =

{∂IT

∂X− ψT

[∂R

∂X

]}δX

the cost function is independent of the flow solution. Thismeans we can calculate all sensitivities

∂Ic∂α1

,∂Ic∂α2

from “simply” solving the adjoint equation ( same cost as Eulerequations ) [

∂R

∂q

]Tψ =

∂I

∂q

Adjoints in CFD 13/36

Page 14: Analysis of the Adjoint Euler Equations as used for

Adjoint and Euler Problem

I The 2-D problems covered in this project are relativelysimple in terms of memory requirements andcomputational cost.

I The selected 2D grid dimensions are:

◦ 181 (around airfoil) × 60 (normal to airfoil) for a total of10860 points, 43440 degrees of freedom.

◦ Euler solver with implicit routine converges 8-orders in 1000iterations in ∼ 10 seconds (Intel i7 : 3.2 GHz).

I This problem size is intended to be small. More common2D problems will have O(1× 105) degrees of freedom.

Adjoints in CFD 14/36

Page 15: Analysis of the Adjoint Euler Equations as used for

Summary of Methodology

I An Euler code, mesh generator, and adjoint code have beenwritten in C++ and wrapped in a Python framework forcommunication.

I The Euler code has been Auto-Differentiated usingTAPENADE [Hascoet and Pascual(2004)]

I The discrete adjoint has been derived for the Eulerequations.

I The discrete adjoint equations have been hand-coded andvalidated against auto-differentiated and brute-forcegradients.

I Gradients from the adjoint solutions have been applied tomulti-variable airfoil optimization.

Adjoints in CFD 15/36

Page 16: Analysis of the Adjoint Euler Equations as used for

Summary of Methodology

I An Euler code, mesh generator, and adjoint code have beenwritten in C++ and wrapped in a Python framework forcommunication.

I The Euler code has been Auto-Differentiated usingTAPENADE [Hascoet and Pascual(2004)]

I The discrete adjoint has been derived for the Eulerequations.

I The discrete adjoint equations have been hand-coded andvalidated against auto-differentiated and brute-forcegradients.

I Gradients from the adjoint solutions have been applied tomulti-variable airfoil optimization.

Adjoints in CFD 15/36

Page 17: Analysis of the Adjoint Euler Equations as used for

Summary of Methodology

I An Euler code, mesh generator, and adjoint code have beenwritten in C++ and wrapped in a Python framework forcommunication.

I The Euler code has been Auto-Differentiated usingTAPENADE [Hascoet and Pascual(2004)]

I The discrete adjoint has been derived for the Eulerequations.

I The discrete adjoint equations have been hand-coded andvalidated against auto-differentiated and brute-forcegradients.

I Gradients from the adjoint solutions have been applied tomulti-variable airfoil optimization.

Adjoints in CFD 15/36

Page 18: Analysis of the Adjoint Euler Equations as used for

Summary of Methodology

I An Euler code, mesh generator, and adjoint code have beenwritten in C++ and wrapped in a Python framework forcommunication.

I The Euler code has been Auto-Differentiated usingTAPENADE [Hascoet and Pascual(2004)]

I The discrete adjoint has been derived for the Eulerequations.

I The discrete adjoint equations have been hand-coded andvalidated against auto-differentiated and brute-forcegradients.

I Gradients from the adjoint solutions have been applied tomulti-variable airfoil optimization.

Adjoints in CFD 15/36

Page 19: Analysis of the Adjoint Euler Equations as used for

Summary of Methodology

I An Euler code, mesh generator, and adjoint code have beenwritten in C++ and wrapped in a Python framework forcommunication.

I The Euler code has been Auto-Differentiated usingTAPENADE [Hascoet and Pascual(2004)]

I The discrete adjoint has been derived for the Eulerequations.

I The discrete adjoint equations have been hand-coded andvalidated against auto-differentiated and brute-forcegradients.

I Gradients from the adjoint solutions have been applied tomulti-variable airfoil optimization.

Adjoints in CFD 15/36

Page 20: Analysis of the Adjoint Euler Equations as used for

Comparing Hand-Coded vs. Auto-Diff Adjoint

I Use of TAPENADE very convenient for auto-differentiationhowever

◦ Unable to auto-differentiate certain, more complicatedsection of code (ie. Implicit routines of the Euler solver)

◦ Creates complex code more difficult to read, optimize, andparallelize with OpenMP

I Hand-coded Adjoint was challenging to implement butgives full control over memory usage and code optimization

Auto-Diff By-hand By-hand + OpenMP

Time (s) 126.3 120.5 15.1

Speedup 1.0 1.05 8.36

Timing Results for 10000 Adjoint iterations (8-core CPU)

Adjoints in CFD 16/36

Page 21: Analysis of the Adjoint Euler Equations as used for

Optimization Algorithm

I The final step for airfoil optimization is to use thegradients from the adjoint solution in a gradient-basedoptimization algorithm

◦ Entire courses are taught on optimization algorithms◦ Many algorithms are readily available in pre-packaged

libraries

I The Scientific Python “SciPy” optimization library hasbeen specifically for use with:

◦ Conjugate Gradient (CG) method, variant of theFletcher-Reeves method [Nocedal and Wright(2006)]

◦ Sequential Least SQuares Programming (SLSQP)[Kraft(1988)]

Adjoints in CFD 17/36

Page 22: Analysis of the Adjoint Euler Equations as used for

1-Variable ResultsRecall the 1-variable case of moving a single bump along thesurface of an airfoil

Adjoints in CFD 18/36

Page 23: Analysis of the Adjoint Euler Equations as used for

1-Variable ResultsRecall the 1-variable case of moving a single bump along thesurface of an airfoil

Adjoints in CFD 18/36

Page 24: Analysis of the Adjoint Euler Equations as used for

1-Variable Results

Brute-Force Auto-Diff Adjoint By-Hand Adjoint

Gradients -0.0054687 -0.0054693 -0.0055054

Note: difference in by-hand adjoint from approximation of dissipation flux

Adjoints in CFD 19/36

Page 25: Analysis of the Adjoint Euler Equations as used for

Optimization Method: SLSQP

I The Sequential Least SQuares Programming (SLSQP)method for gradient-based optimization is effectivelyNewton’s method for unconstrained problems.

I 4-iterations: 5 Adjoint calls, 5 Euler calls, 209.7 seconds

Adjoints in CFD 20/36

Page 26: Analysis of the Adjoint Euler Equations as used for

Optimization Method: Conjugate Gradient

I The Conjugate Gradient (CG) method of non-linear

I Possibly multiple function calls and adjoint calls periteration.

I 4-iterations: 14 Adjoint calls, 14 Euler calls, 469.7 seconds

Adjoints in CFD 21/36

Page 27: Analysis of the Adjoint Euler Equations as used for

Optimization Methods: Comments

I Both CG and SLSQP only found local minima of thesingle-variable cost function.

I CG converged faster to the solution with 4 “iterations”however each iteration required more function and adjointcalls.

I Because SLSQP required less function and adjoint calls,the 4 iterations ran in less wall-clock time.

Adjoints in CFD 22/36

Page 28: Analysis of the Adjoint Euler Equations as used for

Optimization: Local Minima

I By changing the location of the initial guess, a differentlocal minima is reached

Adjoints in CFD 23/36

Page 29: Analysis of the Adjoint Euler Equations as used for

6-Variable Results

I 3 bumps on the lower surface, 3 on the upper surface

I Location of the bumps fixed at 25%, 50%, and 75% alongthe airfoil

I Only bump amplitudes are changed → 6 total designvariables

Initial Gradients:

∂I/∂α1 ∂I/∂α2 ∂I/∂α3 ∂I/∂α4 ∂I/∂α5 ∂I/∂α6

Brute-Force -0.8495 -0.4387 -0.1935 -3.588 -0.8853 -0.1000

AD Adjoint -0.8495 -0.4389 -0.1937 -3.588 -0.8855 -0.1003

Adjoint -0.8549 -0.4365 -0.1851 -3.635 -0.8902 -0.0946

Note: Discrepancy between AD adjoint and by-hand adjoint from approximationof dissipation terms

Adjoints in CFD 24/36

Page 30: Analysis of the Adjoint Euler Equations as used for

SLSQP 6-variable Results

Adjoints in CFD 25/36

Page 31: Analysis of the Adjoint Euler Equations as used for

SLSQP 6-variable Results

Adjoints in CFD 26/36

Page 32: Analysis of the Adjoint Euler Equations as used for

Multi-variable Results: Comments

I Pressure matched relatively well except at trailing edge

I By adding additional bumps near the trailing edge thisshould help the solution

Adjoints in CFD 27/36

Page 33: Analysis of the Adjoint Euler Equations as used for

8-Variable Results

One more bump added on both the upper and lower surface at95% along airfoil helps to reduce the error at the trailing edge.The solution after 7 SLSQP iterations is shown below.

Adjoints in CFD 28/36

Page 34: Analysis of the Adjoint Euler Equations as used for

8-Variable Results

One more bump added on both the upper and lower surface at95% along airfoil helps to reduce the error at the trailing edge.The solution after 7 SLSQP iterations is shown below.

Adjoints in CFD 28/36

Page 35: Analysis of the Adjoint Euler Equations as used for

Summary / Discussion

I Use of adjoint methods significantly reduces the cost ofcomputing gradients of a cost function where the Eulerequations must be solved.

I Use of both the auto-differentiated and by-hand Adjointcodes provide accurate gradients of a cost function withrespect to a set of variables.

I These gradients can be used with gradient-basedoptimization methods to approach local minima of the costfunction

◦ Converging to a local minima is sufficient for aerodynamicshape optimization problems since commonly engineers areinterested in incremental changes from an initial, trustedguess.

Adjoints in CFD 29/36

Page 36: Analysis of the Adjoint Euler Equations as used for

Milestones

Functioning airfoil perturbation function in combination withmesh generation and 2D Euler Solver.

Late Oct

Functioning brute-force method for sensitivity of Pressure costfunction to airfoil perturbation variables.

Early Nov

Auto-differentiation of Euler CFD solver. Late Nov

Validate auto-diff and brute-force method for simple reverse-design perturbations.

Mid Dec

Hand-coded explicit discrete adjoint solver. Mid FebMarch 6

Implicit routine OpenMP Acceleration for discrete adjointsolver.

MarchEarly April

Validate discrete adjoint solver against auto-diff and brute-force methods.

MarchMid April

Test discrete adjoint solver with full reverse-design cases. Mid AprilEarly May

Adjoints in CFD 30/36

Page 37: Analysis of the Adjoint Euler Equations as used for

Deliverables

I Bitbucket GIT Repository of

◦ Euler, Grid-Generation, and Airfoil perturbation code inPython Framework

◦ Auto-differentiated Adjoint Code◦ Hand-differentiated Adjoint Code

I Equations of hand-derived Adjoint relations for flux anddissipation terms.

I Sample run files for Euler-only, Adjoint-only, and fulldesign case.

Adjoints in CFD 31/36

Page 38: Analysis of the Adjoint Euler Equations as used for

References I

[Hicks and Henne(1977)] R. Hicks and P. Henne.Wing design by numerical optimization.Aircraft Design and Technology Meeting. American Institute of Aeronauticsand Astronautics, Aug 1977.doi: 10.2514/6.1977-1247.URL http://dx.doi.org/10.2514/6.1977-1247.

[Nadarajah and Jameson(2002)] Siva Nadarajah and Antony Jameson.Optimal Control of Unsteady Flows Using a Time Accurate Method.Multidisciplinary Analysis Optimization Conferences, (June):—-, 2002.doi: 10.2514/6.2002-5436.URL http://dx.doi.org/10.2514/6.2002-5436.

[Hascoet and Pascual(2004)] Laurent Hascoet and Valerie Pascual.TAPENADE 2.1 user’s guide.2004.URL http://www.inria.fr/rrrt/rt-0300.html.

[Nocedal and Wright(2006)] Jorge Nocedal and Stephen J. Wright.Numerical optimization.Springer series in operations research and financial engineering. Springer, NewYork, 2006.

Adjoints in CFD 32/36

Page 39: Analysis of the Adjoint Euler Equations as used for

References II

[Kraft(1988)] Dieter Kraft.A software package for sequential quadratic programming.Technical Report DFVLR-FB 88-28. Institut fur Dynamik der Flugsysteme,Oberpfaffenhofen, July 1988.

[Nadarajah(2003)] S. Nadarajah.The Discrete Adjoint Approach to Aerodynamic Shape Optimization.Stanford University PhD Dissertation, 2003.

Adjoints in CFD 33/36

Page 40: Analysis of the Adjoint Euler Equations as used for

Appendex

Additional Slides

Adjoints in CFD 34/36

Page 41: Analysis of the Adjoint Euler Equations as used for

Comments: Dissipation

I The main reason for the mismatch between theauto-differentiation result and by-hand result is thedissipation in the flux routine

I If I remove the dissipation from the auto-differentiatedcode, I get exactly the same sensitivity

Looking at just the j-direction:

Rj = −(fj+ 1

2+ fj− 1

2

)−(hj+ 1

2+ hj− 1

2

)Where the scalar dissipation term hj+ 1

2is:

hj+ 12

= εσ (qj+1 − qj)

Adjoints in CFD 35/36

Page 42: Analysis of the Adjoint Euler Equations as used for

Dissipation Approximations

hj+ 12

= εσ (qj+1 − qj)

ε is a constant, approximately 0.25 [Nadarajah(2003)]. σ is thespectral radius scaled by the face area:

σ = ||V ||+ c||Sj+ 12||

and c is the speed of sound. Both V and c are functions of theflow q however according to Nadarajah [Nadarajah(2003)], σdoes not vary significantly and can be considered constant inderiving the adjoint dissipation terms. While this may be thecase for the variation of the residual with respect to q, myresults show this is not the case for the variation of the residualwith respect to X.

Adjoints in CFD 36/36