Adjoint approach to optimization using automatic differentiation - - PowerPoint PPT Presentation

adjoint approach to optimization using automatic
SMART_READER_LITE
LIVE PREVIEW

Adjoint approach to optimization using automatic differentiation - - PowerPoint PPT Presentation

Adjoint approach to optimization using automatic differentiation (AD) Praveen. C praveen@math.tifrbng.res.in Tata Institute of Fundamental Research Center for Applicable Mathematics Bangalore - 560 065 http://math.tifrbng.res.in Indo-German


slide-1
SLIDE 1

Adjoint approach to optimization using automatic differentiation (AD)

  • Praveen. C

praveen@math.tifrbng.res.in

Tata Institute of Fundamental Research Center for Applicable Mathematics Bangalore - 560 065 http://math.tifrbng.res.in

Indo-German Workshop IIT Madras November 2008

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 1 / 62

slide-2
SLIDE 2

Outline

1

Mathematical formulation

2

Computing gradients

3

Quasi 1-D flow

4

Gradient smoothing

5

Quasi 1-D optimization: Pressure matching

6

Example codes

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 2 / 62

slide-3
SLIDE 3

Outline

1

Mathematical formulation

2

Computing gradients

3

Quasi 1-D flow

4

Gradient smoothing

5

Quasi 1-D optimization: Pressure matching

6

Example codes

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 3 / 62

slide-4
SLIDE 4

Introduction

Maturing of high fidelity analysis tools like Computational Fluid Dynamics (CFD) Finite Element Method (FEM) Increase in computational power Shift towards optimization and control Fluid dynamics

Design aircraft wing shape to reduce drag Ship hull shape optimization to reduce drag Minimize unsteady forces through boundary suction/blowing Suppress boundary layer separation Enhance mixing

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 4 / 62

slide-5
SLIDE 5

Introduction

Maturing of high fidelity analysis tools like Computational Fluid Dynamics (CFD) Finite Element Method (FEM) Increase in computational power Shift towards optimization and control Fluid dynamics

Design aircraft wing shape to reduce drag Ship hull shape optimization to reduce drag Minimize unsteady forces through boundary suction/blowing Suppress boundary layer separation Enhance mixing

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 4 / 62

slide-6
SLIDE 6

Objectives and controls

Objective function J(α) = J(α, u) mathematical representation of system performance Control variables α

Parametric controls α ∈ Rn Infinite dimensional controls α : X → Y Shape α ∈ set of admissible shapes

State variable u: solution of an ODE or PDE R(α, u) = 0

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 5 / 62

slide-7
SLIDE 7

Mathematical formulation

Constrained minimization problem min

α J(α, u)

subject to R(α, u) = 0 Find δα such that δJ < 0 δJ = ∂J ∂αδα + ∂J ∂u δu = ∂J ∂αδα + ∂J ∂u ∂u ∂αδα = ∂J ∂α + ∂J ∂u ∂u ∂α

  • δα =: Gδα

Steepest descent δα = −ǫG ⊤ δJ = −ǫGG ⊤ = −ǫG2 < 0

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 6 / 62

slide-8
SLIDE 8

Mathematical formulation

Constrained minimization problem min

α J(α, u)

subject to R(α, u) = 0 Find δα such that δJ < 0 δJ = ∂J ∂αδα + ∂J ∂u δu = ∂J ∂αδα + ∂J ∂u ∂u ∂αδα = ∂J ∂α + ∂J ∂u ∂u ∂α

  • δα =: Gδα

Steepest descent δα = −ǫG ⊤ δJ = −ǫGG ⊤ = −ǫG2 < 0

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 7 / 62

slide-9
SLIDE 9

Sensitivity approach

Linearized state equation ∂R ∂α δα + ∂R ∂u δu = 0

  • r

∂R ∂u ∂u ∂α = −∂R ∂α Solve sensitivity equation iteratively ∂ ∂t ∂u ∂α + ∂R ∂u ∂u ∂α = −∂R ∂α Gradient dJ dα = ∂J ∂α + ∂J ∂u ∂u ∂α

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 8 / 62

slide-10
SLIDE 10

Sensitivity approach: Computational cost

n design variables: α = (α1, . . . , αn) Solve primal problem R(α, u) = 0 to get u(α) For i = 1, . . . , n

Solve sensitivity equation wrt αi ∂R ∂u ∂u ∂αi = − ∂R ∂αi Compute derivative wrt αi dJ dαi = ∂J ∂αi + ∂J ∂u ∂u ∂αi

One primal equation, n sensitivity equations Computational cost = n + 1

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 9 / 62

slide-11
SLIDE 11

Adjoint approach

We have δJ = ∂J ∂αδα + ∂J ∂u δu and ∂R ∂α δα + ∂R ∂u δu = 0 Introduce a new unknown v δJ = ∂J ∂αδα + ∂J ∂u δu + v⊤ ∂R ∂α δα + ∂R ∂u δu

  • =

∂J ∂α + v⊤ ∂R ∂α

  • δα +

∂J ∂u + v⊤ ∂R ∂u

  • δu

Adjoint equation ∂R ∂u ⊤ v = − ∂J ∂u ⊤ Iterative solution ∂v ∂t + ∂R ∂u ⊤ v = − ∂J ∂u ⊤

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 10 / 62

slide-12
SLIDE 12

Adjoint approach: Computational cost

n design variables: α = (α1, . . . , αn) Solve primal problem R(α, u) = 0 to get u(α) Solve adjoint problem ∂R ∂u ⊤ v = − ∂J ∂u ⊤ For i = 1, . . . , n

Compute derivative wrt αi dJ dαi = ∂J ∂αi + v ⊤ ∂R ∂αi

One primal equation, one adjoint equation Computational cost = 2, independent of n

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 11 / 62

slide-13
SLIDE 13

Continuous vs Discrete

Continuous approach:

Start with governing PDE R(α, u) = 0 Derive adjoint PDE and boundary conditions Discretize adjoint PDE and solve Must be re-derived whenever cost function changes Gradient is not consistent: discretization error

Discrete approach:

Start with discrete approximation R(α, u) = 0 Derive discrete adjoint equations Solve discrete adjoint equations True gradient of discrete solution Can be automated using AD

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 12 / 62

slide-14
SLIDE 14

Outline

1

Mathematical formulation

2

Computing gradients

3

Quasi 1-D flow

4

Gradient smoothing

5

Quasi 1-D optimization: Pressure matching

6

Example codes

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 13 / 62

slide-15
SLIDE 15

Techniques for computing gradients

Hand differentiation Finite difference method Complex variable method Automatic Differentiation (AD)

Computer code to compute some function Chain rule of differentiation Generates a code to compute derivatives ADIFOR, ADOLC, ODYSEE, TAMC, TAF, TAPENADE see http://www.autodiff.org

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 14 / 62

slide-16
SLIDE 16

Derivatives

Given a program P computing a function F F : Rm → Rn X → Y build a program that computes derivatives of F X : independent variables Y : dependent variables

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 15 / 62

slide-17
SLIDE 17

Derivatives

Jacobian matrix: J = ∂yj

∂xi

  • Directional or tangent derivative

˙ Y = J ˙ X Adjoint mode ¯ X = J⊤ ¯ Y Gradients (n = 1 output) J = ∂y ∂xi

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 16 / 62

slide-18
SLIDE 18

Forward differentiation

Program P is a sequence of instructions Fk To = X, given k’th line Tk = Fk(Tk−1) Function is a composition F = Fp ◦ Fp−1 ◦ . . . ◦ F1 Chain rule ˙ Y = F ′(X) ˙ X = F ′

p(Tp−1)F ′ p−1(Tp−2) . . . F ′ 1(To) ˙

X X, ˙ X → Y , ˙ Y cost( ˙ Y ) = 4 ∗ cost(Y )

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 17 / 62

slide-19
SLIDE 19

Differentiation: Example

A simple example f = (xy + sin x + 4)(3y2 + 6) Computer code, f = t10 t1 = x t2 = y t3 = t1t2 t4 = sin t1 t5 = t3 + t4 t6 = t5 + 4 t7 = t2

2

t8 = 3t7 t9 = t8 + 6 t10 = t6t9

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 18 / 62

slide-20
SLIDE 20

F77 code: costfunc.f

subroutine costfunc(x, y, f) t1 = x t2 = y t3 = t1*t2 t4 = sin(t1) t5 = t3 + t4 t6 = t5 + 4 t7 = t2**2 t8 = 3.0* t7 t9 = t8 + 6.0 t10 = t6*t9 f = t10 end

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 19 / 62

slide-21
SLIDE 21

Differentiation: Direct mode

Apply chain rule of differentiation t1 = x ˙ t1 = ˙ x t2 = y ˙ t2 = ˙ y t3 = t1t2 ˙ t3 = ˙ t1t2 + t1˙ t2 t4 = sin(t1) ˙ t4 = cos(t1)˙ t1 t5 = t3 + t4 ˙ t5 = ˙ t3 + ˙ t4 t6 = t5 + 4 ˙ t6 = ˙ t5 t7 = t2

2

˙ t7 = 2t2˙ t2 t8 = 3t7 ˙ t8 = 3˙ t7 t9 = t8 + 6 ˙ t9 = ˙ t8 t10 = t6t9 ˙ t10 = ˙ t6t9 + t6˙ t9 ˙ x = 1, ˙ y = 0, ˙ t10 = ∂f

∂x

and ˙ x = 0, ˙ y = 1, ˙ t10 = ∂f

∂y

tapenade -d -vars "x y" -outvars f costfunc.f

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 20 / 62

slide-22
SLIDE 22

Automatic Differentiation: Direct mode

SUBROUTINE COSTFUNC_D(x, xd, y, yd, f, fd) t1d = xd t1 = x t2d = yd t2 = y t3d = t1d*t2 + t1*t2d t3 = t1*t2 t4d = t1d*COS(t1) t4 = SIN(t1) t5d = t3d + t4d t5 = t3 + t4 t6d = t5d t6 = t5 + 4 t7d = 2*t2*t2d t7 = t2**2 t8d = 3.0*t7d t8 = 3.0*t7 t9d = t8d t9 = t8 + 6.0 t10d = t6d*t9 + t6*t9d t10 = t6*t9 fd = t10d f = t10 END

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 21 / 62

slide-23
SLIDE 23

Backward differentiation

Program P is a sequence of instructions Fk To = X, given k’th line Tk = Fk(Tk−1) Function is a composition F = Fp ◦ Fp−1 ◦ . . . ◦ F1 Chain rule ¯ X = [F ′(X)]⊤ ¯ Y = [F ′

1(To)]⊤[F ′ 2(T1)]⊤ . . . [F ′ p(Tp−1)]⊤ ¯

Y X, ¯ Y → ¯ X cost(¯ X) = 4 ∗ cost(Y )

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 22 / 62

slide-24
SLIDE 24

Differentiation: Reverse mode

Apply chain rule of differentiation in reverse t1 = x ¯ t10 = 1 t2 = y ¯ t9 = ¯ t10t10,9 = t6 t3 = t1t2 ¯ t8 = ¯ t9t9,8 = t6 t4 = sin(t1) ¯ t7 = ¯ t8t8,7 = 3t6 t5 = t3 + t4 ¯ t6 = ¯ t10t10,6 = t9 t6 = t5 + 4 ¯ t5 = ¯ t6t6,5 = t9 t7 = t2

2

¯ t4 = ¯ t5t5,4 = t9 t8 = 3t7 ¯ t3 = ¯ t5t5,3 = t9 t9 = t8 + 6 ¯ t2 = ¯ t7t7,2 + ¯ t3t3,2 = 6t2t6 + t1t9 t10 = t6t9 ¯ t1 = ¯ t4t4,1 + ¯ t3t3,1 = t9 cos(t1) + t9t2 ¯ t1 = ∂f

∂x , ¯

t2 = ∂f

∂y

tapenade -b -vars "x y" -outvars f costfunc.f

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 23 / 62

slide-25
SLIDE 25

Automatic Differentiation: Reverse mode

SUBROUTINE COSTFUNC_B(x, xb, y, yb, f, fb) t1 = x t2 = y t3 = t1*t2 t4 = SIN(t1) t5 = t3 + t4 t6 = t5 + 4 t7 = t2**2 t8 = 3.0*t7 t9 = t8 + 6.0 t10b = fb t6b = t9*t10b t9b = t6*t10b t8b = t9b t7b = 3.0*t8b t5b = t6b t3b = t5b t2b = t1*t3b + 2*t2*t7b t4b = t5b t1b = t2*t3b + COS(t1)*t4b yb = t2b xb = t1b fb = 0.0 END

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 24 / 62

slide-26
SLIDE 26

Direct versus reverse AD

F : Rm → Rn Direct mode cost(J) = m ∗ 4 ∗ cost(P) Reverse mode cost(J) = n ∗ 4 ∗ cost(P) Scalar output F ∈ R, n = 1

Direct mode gives ∇F · ˙ X for given vector ˙ X Reverse mode gives ∇F, hence preferred

Vector output F ∈ Rn

Direct mode gives ∇F · ˙ X for given vector ˙ X use for sensitivity equation approach Reverse mode gives (∇F)⊤ · ¯ Y use for adjoint approach

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 25 / 62

slide-27
SLIDE 27

Issues in reverse AD

Intermediate variables required in reverse order Some variables may be over-written Variables may be stored in a stack (PUSH/POP) Iterative solvers

Only final solution required AD differentiates the iterative loop Intermediate solutions stored in stack Huge memory requirements Not practical for large problems

Piecemeal differentiation approach (Courty et al., Giles et al.):

Modular flow solver Adjoint solver written manually AD for differentiating the modules

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 26 / 62

slide-28
SLIDE 28

Black-box AD

cost depends on alpha call ComputeCost(alpha, cost) Subroutine for cost function subroutine ComputeCost(alpha, cost) call SolveState(alpha, u) call CostFun(alpha, u, cost) end Reverse differentiation using AD tapenade -backward \

  • head ComputeCost \
  • vars alpha \
  • outvars cost \

ComputeCost.f SolveState.f CostFun.f

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 27 / 62

slide-29
SLIDE 29

Black-box AD

Diffentiated subroutines: ComputeCost b.f, SolveState b.f, CostFun b.f subroutine ComputeCost_b(alpha,alphab,cost,costb) call SolveState(alpha, u) call CostFun_b(alpha, alphab, u, ub, cost, costb) call SolveState_b(alpha, alphab, u, ub) end Compute gradient using costb = 1.0 call ComputeCost_b(alpha, alphab, cost, costb) Gradient given by alphab alphab = ∂(cost) ∂(alpha)

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 28 / 62

slide-30
SLIDE 30

AD for iterative problems

Solve state equation R(α, u) = 0 as steady state of du dt + R(α, u) = 0, u(0) = uo State solver subroutine SolveState(alpha, u) u = 0.0 do while( abs(res) > TOL) call Residue(alpha, u, res) u = u - dt * res end do end subroutine

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 29 / 62

slide-31
SLIDE 31

AD for iterative problems

Adjoint solver, hand written subroutine SolveState_b (alpha ,alphab ,u,ub) resb = 0.0 do while( abs(ub+ub1) .gt. 1.0e-5) ub1 = 0.0 call Residue_bu(alpha ,u,ub1 ,res ,resb) resb = resb - (ub + ub1) end do call Residue_ba(alpha ,alphab ,u,res ,resb) end subroutine resb = Adjoint variable ub = ∂J ∂u , ub1 = ∂R ∂u ⊤ v

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 30 / 62

slide-32
SLIDE 32

Adjoint iterative scheme

Forward iterations linearly stable un+1 = un − ∆t R(α, un), ∆t < S(σ(R′)) Adjoint iteration vn+1 = vn − ∆t

  • [R′(α, u∞)]⊤vn + ∂J

∂u

  • [R′]⊤ has same eigenvalues as R′ =

⇒ adjoint iterations stable under same condition on ∆t Preconditioner for adjoint = (preconditioner for primal problem)⊤

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 31 / 62

slide-33
SLIDE 33

Outline

1

Mathematical formulation

2

Computing gradients

3

Quasi 1-D flow

4

Gradient smoothing

5

Quasi 1-D optimization: Pressure matching

6

Example codes

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 32 / 62

slide-34
SLIDE 34

1-D flow equations

1-D conservation law ∂U ∂t + ∂F ∂x = 0, U ∈ R3, F(U) ∈ R3 Finite volume scheme Un+1

i

− Un

i

∆t + F n

i+1/2 − F n i−1/2

∆x = 0 Update equation Un+1

i

= Un

i − ∆t

∆x Rn

i ,

Rn

i = F n i+1/2 − F n i−1/2

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 33 / 62

slide-35
SLIDE 35

Discrete 1-D adjoint equations

Finite volume residual for i’th cell, steady state Ri := Fi+1/2 − Fi−1/2 = 0 Numerical flux function F = F(X, Y ), Fi+1/2 = F(Ui, Ui+1) Perturbation equation δRi =

∂ ∂X Fi+1/2δUi + ∂ ∂Y Fi+1/2δUi+1

− ∂

∂X Fi−1/2δUi−1 − ∂ ∂Y Fi−1/2δUi + ∂Ri ∂α δα

= 0 Introduce adjoint variable Vi for i’th cell δJ = ∂J ∂αδα +

  • i

∂J ∂Ui δUi +

  • i

V ⊤

i δRi

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 34 / 62

slide-36
SLIDE 36

Discrete adjoint equations

Collecting terms containing δUi δJ =

  • i

∂J ∂Ui + V ⊤

i−1

∂ ∂Y Fi−1/2 + V ⊤

i

∂ ∂X Fi+1/2 − ∂ ∂Y Fi−1/2

V ⊤

i+1

∂ ∂X Fi+1/2

  • δUi + [. . .]δα

Adjoint equation for i’th cell ∂J ∂Ui ⊤ + ∂ ∂Y Fi−1/2 ⊤ Vi−1 + ∂ ∂X Fi+1/2 − ∂ ∂Y Fi−1/2 ⊤ Vi − ∂ ∂X Fi+1/2 ⊤ Vi+1 = 0

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 35 / 62

slide-37
SLIDE 37

Example flow solver

While u is not converged res = 0.0 fluxinflow(u(1), res(1)) do i=1,N-1 fluxinterior(u(i), u(i+1), res(i), res(i+1)) enddo fluxoutflow(u(N), res(N)) do i=1,N u(i) = u(i) – (dt/dx)*res(i) enddo endwhile cost=0.0 do i=1,N costfunc(u(i), cost) enddo

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 36 / 62

slide-38
SLIDE 38

Example adjoint solver

costb=1.0 do i=1,N costfunc_b(u(i), ub1(i), cost, costb) enddo v=0.0 While v is not converged ub2 = 0.0 fluxinflow_b(u(1), ub2(1), res(1), v(1)) do i=1,N-1 fluxinterior_b(u(i), ub2(i), u(i+1), ub2(i+1), res(i), v(i), res(i+1), v(i+1)) enddo fluxoutflow_b(u(N), ub2(N), res(N), v(N)) do i=1,N v(i) = v(i) – (dt/dx)*(ub1(i) + ub2(i)) enddo endwhile

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 37 / 62

slide-39
SLIDE 39

Quasi 1-D flow

Inflow Outflow h(x) x

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 38 / 62

slide-40
SLIDE 40

Quasi 1-D flow

Quasi 1-D flow in a duct ∂ ∂t (hU) + ∂ ∂x (hf ) = dh dx P, x ∈ (a, b) t > 0 U =   ρ ρu E   , f =   ρu p + ρu2 (E + p)u   , P =   p   h(x) = cross-section height of duct Inverse design: find shape h to get pressure distribution p∗ Optimization problem: find the shape h which minimizes J = b

a

(p − p∗)2dx

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 39 / 62

slide-41
SLIDE 41

Quasi 1-D flow

1 i i − 1 / 2 i + 1 / 2 N Inflow face Outflow face

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 40 / 62

slide-42
SLIDE 42

Quasi 1-D flow

Finite volume scheme hi dUi dt + hi+1/2Fi+1/2 − hi−1/2Fi−1/2 ∆x = (hi+1/2 − hi−1/2) ∆x Pi Discrete cost function J =

N

  • i=1

(pi − p∗

i )2

Control variables h1/2, h1+1/2, . . . , hi+1/2, . . . , hN+1/2 N = 100

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 41 / 62

slide-43
SLIDE 43

Duct shape

2 4 6 8 10 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 x h Duct shape Target shape Current shape

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 42 / 62

slide-44
SLIDE 44

Target pressure distribution p∗

2 4 6 8 10 0.5 1 1.5 2 2.5 x Pressure Target pressure AUSMDV KFVS LF

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 43 / 62

slide-45
SLIDE 45

Current pressure distribution

2 4 6 8 10 0.5 1 1.5 2 2.5 x Pressure Starting pressure AUSMDV KFVS LF

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 44 / 62

slide-46
SLIDE 46

Adjoint density

2 4 6 8 10 −35 −30 −25 −20 −15 −10 −5 5 x Adjoint density AUSMDV KFVS LF

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 45 / 62

slide-47
SLIDE 47

Convergence history: Explicit Euler

1000 2000 3000 4000 5000 6000 7000 −10 −9 −8 −7 −6 −5 −4 −3 −2 −1 No of iterations Residue Convergence history with AUSMDV flux Flow Adjoint

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 46 / 62

slide-48
SLIDE 48

Shape gradient

2 4 6 8 10 5 10 15 20 25 30 35 x Gradient Gradient AUSMDV KFVS LF

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 47 / 62

slide-49
SLIDE 49

Shape gradient

2 2.5 3 3.5 4 4.5 5 5.5 6 −5 5 10 15 20 25 30 35 40 x Gradient Gradient AUSMDV KFVS LF

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 48 / 62

slide-50
SLIDE 50

Validation of Shape gradient

2 4 6 8 10 5 10 15 20 25 30 35 x Gradient Gradient with AUSMDV flux A B C

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 49 / 62

slide-51
SLIDE 51

Validation of shape gradient

∂J ∂h ≈ J(h + ∆h) − J(h − ∆h) 2∆h ∆h A B C 0.01 0.4191069499 35.18452823 2.545316345 0.001 0.4231223499 36.10982621 2.556461900 0.0001 0.4231624999 36.11933154 2.556573499 0.00001 0.4231599998 36.11942125 2.556575000 0.000001 0.4231999994 36.11942305 2.556550001 0.0000001 0.4229999817 36.11942329 2.556499971 AD 0.4231628330 36.11941951 2.556574450

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 50 / 62

slide-52
SLIDE 52

Outline

1

Mathematical formulation

2

Computing gradients

3

Quasi 1-D flow

4

Gradient smoothing

5

Quasi 1-D optimization: Pressure matching

6

Example codes

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 51 / 62

slide-53
SLIDE 53

Gradient smoothing

Non-smooth gradients G especially in the presence of shocks Smooth using an elliptic equation

  • 1 − ǫ d2

dx2

  • ¯

G = G ǫi = {|Gi+1 − Gi| + |Gi − Gi−1|}Li Li = |Gi+1 − 2Gi + Gi−1| max(|Gi+1 − Gi| + |Gi − Gi−1|, TOL) Finite difference with Jacobi iterations

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 52 / 62

slide-54
SLIDE 54

Gradient smoothing

2 4 6 8 10 5 10 15 20 25 30 35 x Gradient Gradient using AUSMDV flux Original gradient Smoothed gradient

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 53 / 62

slide-55
SLIDE 55

Outline

1

Mathematical formulation

2

Computing gradients

3

Quasi 1-D flow

4

Gradient smoothing

5

Quasi 1-D optimization: Pressure matching

6

Example codes

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 54 / 62

slide-56
SLIDE 56

Quasi 1-D optimization: Shape

1 2 3 4 5 6 7 8 9 10 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 x h Target Initial

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 55 / 62

slide-57
SLIDE 57

Quasi 1-D optimization: Final shape

1 2 3 4 5 6 7 8 9 10 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 x h Target Initial Final

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 56 / 62

slide-58
SLIDE 58

Quasi 1-D optimization: Pressure

1 2 3 4 5 6 7 8 9 10 0.5 1 1.5 2 2.5 x Pressure Target Initial Final

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 57 / 62

slide-59
SLIDE 59

Quasi 1-D optimization: Convergence

5 10 15 20 25 30 35 40 45 50 10

−6

10

−5

10

−4

10

−3

10

−2

10

−1

10

  • No. of iterations

Cost/Gradient Cost Gradient

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 58 / 62

slide-60
SLIDE 60

Quasi 1-D optimization: Adjoint density

2 4 6 8 10 −25 −20 −15 −10 −5 x Adjoint density Initial Final

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 59 / 62

slide-61
SLIDE 61

Outline

1

Mathematical formulation

2

Computing gradients

3

Quasi 1-D flow

4

Gradient smoothing

5

Quasi 1-D optimization: Pressure matching

6

Example codes

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 60 / 62

slide-62
SLIDE 62

AD Tool: Tapenade

Source transformation tool Forward and backward mode F77, F90, F95, C (beta as of Nov 2008) Free http://www-sop.inria.fr/tropics

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 61 / 62

slide-63
SLIDE 63

Example codes

1-D example: nozzle flow (TAPENADE) http://cfdlab.googlecode.com 1-D example: nozzle flow (ADOLC) http://cfdlab.googlecode.com 2-D example: unstructured grid Euler solver (TAPENADE) http://euler2d.sourceforge.net 2/3-D example: structured grid Euler solver (TAPENADE) http://nuwtun.berlios.de

  • Praveen. C (TIFR-CAM)

Adjoints and optimization IITM, Nov 2008 62 / 62