An Object-oriented Framework for Rapid Discrete Adjoint...

38
An Object-oriented Framework for Rapid Discrete Adjoint Development Using OpenFOAM Ping He, Charles A. Mader, Joaquim R.R.A. Martins, Kevin J. Maki AIAA SciTech, San Diego, January 9, 2019 Aerodynamics Heat transfer Structures

Transcript of An Object-oriented Framework for Rapid Discrete Adjoint...

Page 1: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

An Object-oriented Framework for Rapid Discrete Adjoint Development Using OpenFOAM

Ping He, Charles A. Mader, Joaquim R.R.A. Martins, Kevin J. Maki

AIAA SciTech, San Diego, January 9, 2019

Aerodynamics Heat transferStructures

Page 2: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

2

We focus on design optimization with high-fidelity

MDO for an electric aircraft using OpenMDAO. (Gray et al. SAMO 2018).

MDO for the uCRM model using ADflow. (Kenway et al. AIAA-2014-3274)

Ø Low-fidelity MDO (conceptual design phase)

Ø High-fidelity MDO (detailed design phase)

Page 3: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

3

Gradient-based optimization is preferable for handling large-scale design problems with high-fidelity

Aerostructural optimization using 972 design variables.(Kenway and Martins, AIAA-2015-2790)

Page 4: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

4

Adjoint derivative computation is a crucial component in the high-fidelity gradient-based optimization framework

An example of gradient-based optimization framework

Page 5: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

5

What is an efficient adjoint solver?

Speed & Scalability

Memory

Accuracy

Development Effort

Page 6: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

6

High development effort slows down MDO studies

Speed & Scalability

Memory

Accuracy

Development Effort

To develop an adjoint solver, we need to:

Ø Understand primal code implementations (10K+ lines)

Ø Implement adjoint derivative computation (10K+ lines)

Ø Debug and test

Page 7: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

7

Goal: Adjoint framework that needs minimal user input while compatible with any mesh, discipline, and code

Mesh Discipline Code

Structured &Unstructured

Aerodynamics,hydrodynamics, heattransfer,structures,multiphaseflow,combustion,radiation,andtheircoupling

CFD & CSDcodesinFortran,C,C++,Python, Matlab

Page 8: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

8

Intermediate Step: An adjoint Framework fora Multiphysics CFD Package: OpenFOAM

Mesh Discipline Code

Structured &Unstructured

Aerodynamics,hydrodynamics, heattransfer,structures,radiation

OpenFOAM

Develop an adjoint solver with adding or modifying only O(100) lines of source code

Page 9: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

9

Outline

Ø Introduction

Ø Adjoint framework

Ø Example of rapid adjoint development

Ø Demonstration1) Aerodynamic optimization for a low-speed UAV wing with

full and transitional turbulence2) Aerodynamic optimization for the CRM wing under

subsonic conditions3) Aerothermal optimization for a ribbed U bend channel4) Structural optimization for an engine fan

Page 10: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

10

Central recipe: We divide adjoint implementations into solver-agnostic and solver-specific parts

AdjointImplementation

Solver-agnostic implementation

Solver-specific implementation

Page 11: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

11

How to divide solver-agnostic and solver-specific?

𝑅 𝑤, 𝑥 = 0

𝑓 = 𝑓 𝑤, 𝑥

d𝑓d𝑥

=𝜕𝑓𝜕𝑥

+𝜕𝑓𝜕𝑤

d𝑤d𝑥

d𝑅d𝑥

=𝜕𝑅𝜕𝑥

+𝜕𝑅𝜕𝑤

d𝑤d𝑥

= 0

d𝑓d𝑥

=𝜕𝑓𝜕𝑥

−𝜕𝑓𝜕𝑤

𝜕𝑅𝜕𝑤

,-

./

𝜕𝑅𝜕𝑥

𝜕𝑅𝜕𝑤

0

𝜓 =𝜕𝑓𝜕𝑤

0

d𝑓d𝑥

=𝜕𝑓𝜕𝑥

− 𝜓0𝜕𝑅𝜕𝑥

Solver-specific part:Ø Elements in 𝑅 and 𝑤Ø Sparsity pattern for 𝜕𝑅/𝜕𝑤Ø Specific form for 𝑅(𝑤, 𝑥)

Solver-agnostic part:Ø Compute partial derivativesØ Solve the adjoint equations

Page 12: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

12

Solver-agnostic implementation:

ØCompute partial derivatives

ØSolve the adjoint equations

Page 13: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

13

We compute partial derivatives using finite-differencing, accelerated by a heuristic graph coloring scheme

With coloring, we reduce the number of function evaluations to O(1000), independent of the mesh size and CPU cores.

Example of Jacobian sparsity Example of graph coloring

Page 14: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

14

We solve the adjoint equations using the GMRES method with a nested preconditioning strategy

𝜕𝑅𝜕𝑤

0𝜓 =

𝜕𝑓𝜕𝑤

0

Page 15: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

15

Solver-specific part:

ØElements in 𝑅 and 𝑤

ØSparsity pattern for 𝜕𝑅/𝜕𝑤

ØSpecific form for 𝑅(𝑤, 𝑥)

Page 16: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

16

We provide an object-oriented interface to specify residual functions and sparsity information

StateRegistry

regState(solver1)

regState(solver2)

..........

PhysicalModel

TurbulenceModel1

TurbulenceModel2

RadiationModel1

RadiationMode2

..........

Connectivity

conInfo(solver1)

conInfo(solver2)

..........

Derivative

calcRes(solver1)

calcRes(solver2)

..........

Register states Sparsity pattern Specify 𝑅(𝑤, 𝑥)

Page 17: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

17

It is straightforward to register states and set connectivity

Incompressible NS equations:𝛻 ⋅ 𝑈 = 0

𝛻𝑈𝑈 +1𝜌𝛻𝑝 − 𝜈Δ𝑈 = 0

Codestoregisterstates:

Codestosetconnectivity:

Example of level-2 stencil

Page 18: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

18

We can reuse existing high-level OpenFOAM codes to construct residual functions

Codestocomputeresiduals:

Page 19: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

19

We have implemented five adjoint solvers with four turbulence models and one radiation model

Solvers Governing EquationssimpleFoam Incompressible NS equations

buoyantBoussinesqSimpleFoam Incompressible NS equations with heat transfer, buoyancy, and radiation

rhoSimpleFoam Compressible NS equations

buoyantSimpleFoam Compressible NS equations with heat transfer, buoyancy, and radiation

SolidDisplacementFoam Structural displacement equation

Turbulence Models DescriptionSpalartAllmaras Spalart Allmaras one equation model

kEpsilon 𝑘 − 𝜀 two equation model

kOmegaSST 𝑘 − 𝜔 SST two equation model

kOmegaSSTLM Langtry-Menter four equation transitional model based on kOmegaSST

Radiation Model DescriptionP1 Diffusion equation for incident radiation

Page 20: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

20

Adjoint/flow runtime ratio less than 2, scaling well up to O(10) million cells and O(1000) CPU cores

Scalability using 10 million cells

Page 21: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

21

Adjoint derivatives match the reference values and the averaged error is less than 0.1%

Solvers PhysicalModel Reference Adjoint ErrorsimpleFoam SpalartAllmaras -7.4041616e-4 -7.4052219e-4 0.013%

kEpsilon -7.5604973e-4 -7.5629115e-4 0.032%

kOmegaSST -7.2540944e-4 -7.2553310e-4 0.017%

kOmegaSSTLM -7.5552809e-4 -7.5561422e-4 0.010%

buoyantBoussinesqSimpleFoam

SpalartAllmaras -7.1222547e-4 -7.1232432e-4 0.014%

rhoSimpleFoam SpalartAllmaras -9.2285449e-4 -9.2236336e-4 0.053%

buoyantSimpleFoam SpalartAllmaras -8.7694514e-4 -8.7612072e-4 0.094%

buoyantBoussinesqSimpleFoam

P1 radiation -8.0862271e-2 -8.0171881e-2 0.853%

soildDisplacementFoam N/A 1.2844550e5 1.2857850e5 0.101%

Page 22: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

22

Demonstration

1) Aerodynamic optimization for a low-speed UAV wing with full and transitional turbulence

2) Aerodynamic optimization for the CRM wing under subsonic conditions

3) Aerothermal optimization for a ribbed U bend channel

4) Structural optimization for an engine fan

Page 23: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

23

1) Aerodynamic optimization for a low-speed UAV wing

Solver: simpleFoamGoverning equations: incompressible NS equations𝛻 ⋅ 𝑈 = 0

𝛻 ⋅ 𝑈𝑈 +1𝜌𝛻𝑝 − 𝛻 ⋅ 𝜏 = 0

Objectivefunctions:𝐶CDesignvariables#:127

(shape+twist+angle ofattack)

Constraints#:414

(lift+volume+thickness+LETE)

Mesh and FFD

Page 24: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

24

Drag reduces by 5.6%

Page 25: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

25

We achieve the desired elliptical lift distribution

Page 26: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

26

Aerodynamic optimization for the low-speed UAV wing with turbulence transition

𝜕(𝑢E𝑘)𝜕𝑥E

− 𝑃G + 𝐷G −𝜕𝜕𝑥E

𝜈 + 𝜎G𝜈J𝜕𝑘𝜕𝑥E

= 0

𝜕(𝑢E𝜔)𝜕𝑥E

− 𝑃K + 𝐷K −𝜕𝜕𝑥E

𝜈 + 𝜎K𝜈J𝜕𝜔𝜕𝑥E

− 2 1 − 𝐹-𝜎KN𝜔

𝜕𝑘𝜕𝑥E

𝜕𝜔𝜕𝑥E

= 0

𝜕(𝑢E𝛾)𝜕𝑥E

− 𝑃P + 𝐷P −𝜕𝜕𝑥E

𝜈 +𝜈J𝜎Q

𝜕𝛾𝜕𝑥E

= 0

𝜕(𝑢E𝑅𝑒SJ)𝜕𝑥E

− 𝑃SJ −𝜕𝜕𝑥E

𝜎SJ 𝜈 + 𝜈J𝜕𝑅𝑒SJ𝜕𝑥E

= 0

Governing equations: Incompressible NS equationsTurbulence model: kOmegaSSTLM

Turbulent kinetic energy contour shows clear turbulence transition on both upper and lower surfaces of the wing

Transition locations

Page 27: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

27

Drag reduces by 6.0%; we obtain the desired elliptical lift distribution and a slightly larger laminar region

Page 28: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

28

2) Aerodynamic optimization for the CRM wing

Solver: rhoSimpleFoamGoverning equations: compressible NS equations:𝛻 ⋅ 𝜌𝑈 = 0𝛻 ⋅ 𝜌𝑈𝑈 + 𝛻𝑝 − 𝛻 ⋅ 𝜏 = 0𝛻 ⋅ 𝜌𝐸𝑈 + 𝛻 ⋅ 𝑝𝑈 − 𝛻 ⋅ (𝜏 ⋅ 𝑈) + 𝛻 ⋅ 𝑞 = 0

Objectivefunctions:𝐶CDesignvariables#:201

(shape+twist+angle ofattack)

Constraints#:770

(lift+volume+thickness+LETE)

Mesh and FFD for the CRM wing

Page 29: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

29

Drag reduces by 5.0%

Page 30: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

30

We achieve the desired elliptical lift distribution

Page 31: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

31

3) Aerothermal optimization for a ribbed U bend channel

Solver: buoyantBoussinesqSimpleFoamGoverning equations: incompressible NS equations with buoyancy, heat transfer, and radiation𝛻 ⋅ 𝑈 = 0

𝛻 ⋅ 𝑈𝑈 +1𝜌𝛻𝑝 − 𝛻 ⋅ 𝜏 + 𝜌𝑔 = 0

𝛻 ⋅ 𝑈𝑇 + 𝛼 + 𝛼J ΔT −aG − E − 4e𝜎𝑇_

𝜌𝐶`= 0

𝛾Δ𝐺 − 𝑎𝐺 + 4e𝜎𝑇_ − 𝐸 = 0

U bend without ribs.We have 114 design variables

U bend with ribs.We have 145 design variables.

Page 32: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

32

Simultaneously considering aerodynamics and heat transfer results in balanced designs

Weighted objective function: 𝑓 = 𝑤𝐶cd − (1 − 𝑤)𝑁𝑢f

Normalized Nusselt number: 𝑁𝑢f = gCh0i,0j Gklm

Normalized pressure loss: 𝐶cd =`mno,`mpqr

s.uvwmx

U bend without ribs U bend with ribs

Page 33: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

33

We achieve simultaneous improvement inaerodynamics (11.7%) and heat transfer (13.0%)

Velocity at the symmetry plane Local Nusselt number

Page 34: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

34

We achieve simultaneous improvement inaerodynamics (9.7%) and heat transfer (6.9%)

Page 35: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

35

4) Structural optimization for an engine fan

Solver: solidDisplacementFoamGoverning equations:

𝜕N(𝜌𝑢)𝜕𝑡N

− 𝛻 ⋅ 𝜇𝛻𝑢 + 𝜇 𝛻𝑢 0 + 𝜆𝑡𝑟 𝛻𝑢 𝐼 − 𝜔×(𝜔×𝑟) = 0

Objectivefunctions:max-von-Mises

Designvariables#:60(shape)

Load:centrifugalforce

FFD for Rotor67

Page 36: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

36

Max von Mises stress reduces by 13.5%

Page 37: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

37

Summary

Ø The object-oriented framework allows us to develop an adjoint solver with adding or modifying only O(100) lines of source code.

Ø The developed adjoint solvers scale up to O(10) million cells and O(1000) CPU cores and the averaged derivative errors are less than 0.1%.

Ø The developed adjoint solvers enable us to perform optimization for a wide range of disciplines (aerodynamics, heat transfer, and structures) and conditions (incompressible, compressible, full and transitional turbulence).

Ø This framework has the potential of becoming a useful MDO tool for general engineering problems (aircraft, engines, cars, wind turbines, and ships).

Page 38: An Object-oriented Framework for Rapid Discrete Adjoint ...drpinghe.com/wp-content/uploads/2019/03/AIAA_SciTech_2019_Presentation.pdf · Ø The object-oriented framework allows us

38

Thank You!

Aerodynamics Heat transferStructures

We acknowledge computational resources obtained from XSEDE, which is supported by National Science Foundation Grant number ACI-1548562.