Strategies for computing second-order derivatives in CFD design problems Massimiliano Martinelli Alain Dervieux Laurent Hascoët INRIA Sophia-Antipolis Project TROPICS WEHSFF, Moscou, november 20, 2007 M. Martinelli Strategies for computing second-order derivatives in CFD design problems
Nonlinear constrained functional The problem Given a computer program computing a functional j ( c ) = J ( c , W ( c )) we want, applying a source-to-source programme differentiation software , viz. TAPENADE, to get a computer program computing the second derivatives d 2 j dc 2 = ( H ii ) W ( c ) is solution of the state equation Ψ ( c , W ) = 0 ∂ Ψ ∂ c + ∂ Ψ dW = ⇒ dc = 0 ∂ W W obtained by explicit or implicit pseudo-time advancing techniques c ∈ R n and W ∈ R N with n ≪ N Remark We assume that the solution W ( c ) is not time-dependent (steady-state solution) M. Martinelli Strategies for computing second-order derivatives in CFD design problems
Why we need Hessian? Perturbative methods for uncertainty propagation (Taylor expansion-based) Method of Moments µ j ≃ j ( µ c )+ 1 2 ∑ H ii σ 2 i i i + 1 j ≃ ∑ 2 ∑ σ 2 G 2 i σ 2 H 2 ik σ 2 i σ 2 k i i , k “Inexpensive Monte Carlo” methods of M.Giles. Robust optimization Gradient-based methods for j robust ( c ) = j ( c )+ ε || dj dc || 2 ∑ i H ii σ 2 Gradient-free methods for j robust ( c ) = j ( c )+ 1 i Gradient-free methods for j robust ( c ) = j ( c )+ k σ 2 j Adjoint-corrected functionals Gradient-based methods for j corr ( c ) = j ( c ) − Ψ ex ( c , W ) , Π 0 � � M. Martinelli Strategies for computing second-order derivatives in CFD design problems
Flow solver: basic algorithm Initialize c , W 0 i = i + 1 Compute Ψ i = Ψ ( c , W i ) functional(j,c) Compute δ W i = F ( Ψ i ) (implicit or explicit) Update W i + 1 = W i + δ W i False Test || δ W i || < ε True Compute j = J ( c , W ∞ ) M. Martinelli Strategies for computing second-order derivatives in CFD design problems
Differentiability/Differentiation modes For a given ε > 0 Functional j is only piecewise differentiable. Values of state W depend on initial conditions of solution algorithm, in a similar manner to unsteady system. Assuming ε = 0 Functional j is differentiable. Values of state W do not depend on initial conditions of solution algorithm (if convergent). Direct/Tangent mode Differentiated code computes j ′ ( c ) . δ c Computational cost factor: α T ≈ 4 Does not store intermediate variables Backward/Reverse mode Differentiated code computes ( j ′ ( x )) ∗ . δ j Computational cost factor: α R ≈ 5 Stores intermediate variables M. Martinelli Strategies for computing second-order derivatives in CFD design problems
Flow solver: basic algorithm Initialize c , W 0 i = i + 1 Compute Ψ i = Ψ ( c , W i ) functional(j,c) Compute δ W i = F ( Ψ i ) (implicit or explicit) Update W i + 1 = W i + δ W i False Test || δ W i || < ε True Compute j = J ( c , W ∞ ) M. Martinelli Strategies for computing second-order derivatives in CFD design problems
Flow solver: basic algorithm Initialize c , W 0 state(psi,c,w) i = i + 1 Compute Ψ i = Ψ ( c , W i ) Compute δ W i = F ( Ψ i ) (implicit or explicit) Update W i + 1 = W i + δ W i False Test || δ W i || < ε True func(j,c,w) Compute j = J ( c , W ∞ ) M. Martinelli Strategies for computing second-order derivatives in CFD design problems
Non-differentiated matrix-free iterative solver We use iterative methods to solve Ax = b Loop of matrix-by-vector multiplications Re-engineering of preconditioner To compute matrix-by-vector multiplication: � ∂ Ψ � ∗ if A = we use backward mode: state_dw_b ∂ W x psib , c c , W state_dw_b( psi w , wb ) � ∂ Ψ , Ψ � ∗ x ∂ W � ∂ Ψ � we use direct mode: state_dw_d if A = ∂ W x , c c , W state_dw_d( psi , psid w , wd ) � ∂ Ψ Ψ � x ∂ W M. Martinelli Strategies for computing second-order derivatives in CFD design problems
First Derivatives: basic Tangent algorithm Solve Ψ ( c , W ) = 0 Solve ∂ Ψ ∂ W θ = − ∂ Ψ solve_matrixfree_tan c ∂ c ˙ Compute ∂ J ∂ W θ M. Martinelli Strategies for computing second-order derivatives in CFD design problems
First-order derivative: Tangent Mode ↓ ↓ state( psi , c , w ) c W ˙ , c cd , W ˙ state_d( psi , psid c , w , wd ) Ψ Ψ ˙ Input variables: c = c , w = W , cd = ˙ c , wd = ˙ W � ∂ Ψ � ∂ Ψ � � Output variables: psi = Ψ , psid = ˙ Ψ = c + W ˙ ˙ ∂ c ∂ W M. Martinelli Strategies for computing second-order derivatives in CFD design problems
First-order derivative: Tangent Mode ↓ ↓ func( j , c , w ) c W ˙ , c cd , W ˙ func_d( j , jd c , w , wd ) J J ˙ Input variables: c = c , w = W , cd = ˙ c , wd = ˙ W � ∂ J � ∂ J � � Output variables: j = J , jd = ˙ J = c + W ˙ ˙ ∂ c ∂ W M. Martinelli Strategies for computing second-order derivatives in CFD design problems
First Derivative: Reverse algorithm Solve Ψ ( c , W ) = 0 � ∂ Ψ � ∂ J � ∗ � ∗ Π = solve_matrixfree_tan Solve ∂ W ∂ W � dj � ∗ � ∂ J � ∗ � ∂ Ψ � ∗ Π 0 = − ∂ c ∂ c dc M. Martinelli Strategies for computing second-order derivatives in CFD design problems
First-order derivative: Reverse Mode ↓ ↓ func( j c , w ) , ↓ J ¯ jb , c c , W func_b( j c , cb w , wb ) , J ¯ W ¯ Input variables: c = c , w = W , jb = ¯ J Output variables: j = J , � ∂ J � ∗ cb = ¯ c = J ¯ ∂ c � ∂ J � ∗ wb = ¯ W = J ¯ ∂ W M. Martinelli Strategies for computing second-order derivatives in CFD design problems
First-order derivative: Reverse Mode ↓ ↓ state( psi c , w ) , ↓ Ψ ¯ psib , c c , W state_b( psi c , cb w , wb ) , Ψ W ¯ ¯ Input variables: c = c , w = W , psib = ¯ Ψ Output variables: psi = Ψ , � ∂ Ψ � ∗ cb = ¯ Ψ c = ¯ ∂ c � ∂ Ψ � ∗ wb = ¯ W = Ψ ¯ ∂ W M. Martinelli Strategies for computing second-order derivatives in CFD design problems
Second derivative: Tangent-on-Tangent approach d 2 j = − Π ∗ 0 D 2 i , k Ψ + D 2 i , k J dc i dc k with Π 0 solution of the adjoint system � ∂ Ψ � ∂ J � ∗ � ∗ Π = ∂ W ∂ W and � ∂ J i , k J = ∂ � ∂ J e k + ∂ � ∂ J θ k + ∂ � ∂ J θ i + ∂ � � � � ∂ W θ i θ k D 2 ∂ ce i ∂ ce i ∂ ce k ∂ c ∂ W ∂ W ∂ W � ∂ Ψ i , k Ψ = ∂ � ∂ Ψ e k + ∂ � ∂ Ψ θ k + ∂ � ∂ Ψ θ i + ∂ � � � � ∂ W θ i θ k D 2 ∂ c e i ∂ c e i ∂ c e k ∂ c ∂ W ∂ W ∂ W where θ k = dW is the solution of the system dc k ∂ Ψ dW = − ∂ Ψ ∂ c e k ∂ W dc k M. Martinelli Strategies for computing second-order derivatives in CFD design problems
Second Derivatives: basic ToT algorithm Solve Ψ ( c , W ) = 0 � ∂ Ψ � ∂ J � ∗ � ∗ Π = solve_matrixfree_adj Solve ∂ W ∂ W i = 1 ,..., n Initialize e i Solve ∂ Ψ ∂ W θ i = − ∂ Ψ ∂ c e i solve_matrixfree_tan i = 1 ,..., n k = i ,..., n i , k Ψ func_d_d Compute D 2 i , k J Compute D 2 state_d_d d 2 j i , k J − Π ∗ D 2 i , k Ψ = D 2 Compute dc i dc k M. Martinelli Strategies for computing second-order derivatives in CFD design problems
Second derivative: Tangent-on-Tangent Mode ↓ ↓ state_d( psi , psid c , cd , w , wd ) , ↓ θ k θ i e k e i , c cd , W state_d_d( psi , psid , psidd c , cd0 , w , wd0 , wd ) Ψ Ψ ˙ ˙ Ψ ˙ Input variables: c = c , cd = e i , w = W , wd = θ i , cd0 = e k , wd0 = θ k � ∂ Ψ � ∂ Ψ � � Output variables: psi = Ψ , psid = ˙ Ψ = θ i e i + ∂ c ∂ W � ∂ Ψ psidd = ∂ � ∂ Ψ e k + ∂ � ∂ Ψ θ k + ∂ � ∂ Ψ θ i + ∂ � � � � ∂ W θ i θ k ∂ c e i ∂ c e i ∂ c e k ∂ c ∂ W ∂ W ∂ W = D 2 i , k Ψ M. Martinelli Strategies for computing second-order derivatives in CFD design problems
Second derivative: Tangent-on-Tangent Mode ↓ ↓ func_d( j , jd c , cd , w , wd ) , ↓ θ k θ i e k e i , c cd , W func_d_d( j , jd , jdd c , cd0 , w , wd0 , wd ) J J ˙ ˙ ˙ J Input variables: c = c , cd = e i , w = W , wd = θ i , cd0 = e k , wd0 = θ k � ∂ J � ∂ J � � Output variables: j = J , jd = ˙ θ i J = e i + ∂ c ∂ W � ∂ J jdd = ∂ � ∂ J e k + ∂ � ∂ J θ k + ∂ � ∂ J θ i + ∂ � � � � ∂ W θ i θ k ∂ ce i ∂ ce i ∂ ce k ∂ c ∂ W ∂ W ∂ W = D 2 i , k J M. Martinelli Strategies for computing second-order derivatives in CFD design problems
Recommend
More recommend