Introduction to Model Order Reduction Luca Daniel Massachusetts Institute of Technology luca@mit.edu http://onigo.mit.edu/~dluca/2006PisaMOR www.rle.mit.edu/cpg 1 Course Outline Numerical Simulation Quick intro to PDE Solvers Quick intro to ODE Solvers Model Order reduction Linear systems Common engineering practice Optimal techniques in terms of model accuracy Efficient techniques in terms of time and memory Non-Linear Systems Parameterized Model Order Reduction Linear Systems Non-Linear Systems 2 Outline – ODE solvers: Numerical Simulation of System Models • Steady State Analysis – I.3.a Linear Models • Gaussian Elimination or LU decomposition – I.3.b NonLinear Models • Multidimentional Newton Method • I.3.c Dynamical Analysis – Linear Models • ODE integrators + GE or Krylov – NonLinear Models • ODE integrators + Newton 3 Introduction to Model Order Reduction I.3.a Steady State Analysis Solving Linear Systems Luca Daniel Thanks to Jacob White, Deepak Ramaswamy, Michal Rewienski, and Karen Veroy I.3.a Outline • Linear Systems of Equations • Gaussian Elimination Cost: – Bandlimited GE – Sparse GE • Krylov Method cost: – Comparison GE-Krylov 5 Steady State Analysis dx A x(t ) B u (t ) dt y (t ) C x(t ) D u (t ) • At steady-state u (t ) u constant, dx 0 dt • The analysis boils down to solving a linear system of equations b A x B u y C xDu 6 Systems of Linear Equations A1 A2 x1 b1 x2 b 2 AN xN bN x1 A1 x2 A2 xN AN b Find a set of weights, x, so that the weighted sum of the columns of the matrix M is equal to the right hand side b 7 Key Questions Systems of Linear Equations • Given Ax = b – Is there a solution? – Is the solution Unique? • Is there a Solution? There exists weights, x1, x1 A1 x2 A2 xN , such that xN AN b A solution exists when b is in the span of the columns of M 8 Systems of Linear Equations Key Questions Continued • Is the Solution Unique? Suppose there exists weights, y1, y1 A1 y2 A2 yN , not all zero yN AN 0 Then if Ax b, therefore A x y b A solution is unique only if the columns of A are linearly independent. 9 Systems of Linear Equations Key Questions Square Matrices • Given Ax = b, where A is square – If a solution exists for any b, then the solution for a specific b is unique. For a solution to exist for any b, the columns of A must span all N-length vectors. Since there are only N columns of the matrix A to span this space, these vectors must be linearly independent. A square matrix with linearly independent columns is said to be nonsingular. 10 I.3.a Outline • Linear System of Equations • Gaussian Elimination Cost: – Bandlimited GE – Sparse GE • Krylov Method cost: – Comparison GE-Krylov 11 Dense GE or LU decomposition A11 A 0 21 A 031 041 A Picture A12 A13 A14 A2222 A A2323 A2424 A032 A33 A 34 33 34 A A A0 A 0 44 43 42 44 43 42 44 12 Dense GE Algorithm For i = 1 to n-1 { For j = i+1 to n { “For each Row” “For each Row below pivot” A ji ~ A ji Aii Form n-1 reciprocals (pivots) n 1 n2 Form (n i) multipliers 2 i 1 For k = i+1 to n { “For each element beyond Pivot” ~ ~ A jk A jk A ji Aik } } } n 1 2 3 Perform (n i) 3 n i 1 2 Multiply-adds 13 Complexity of dense GE for solving 3-D FEM or FD metrices 1-D 2-D 3-D matrix size n=m n=m2 n=m3 Domain size = m 1 D O ( n3 ) O ( m3 ) 100 pt grid O(106 ) ops 2D O (n3 ) O (m6 ) 100 100 grid O(1012 ) ops 3 D O (n3 ) O (m9 ) 100 100 100 grid O(1018 ) ops 317years 10msec 2h 46m E.g. on a 1 GFlops computer using m=100 and constant c=10 For 2- D and 3-D problems Need a Faster Solver ! 14 Triangularizing Banded GE Algorithm b 0 For i = 1 to n-1 { For j = i+1 to ni+b-1 { { For k = i+1 to ni+b-1 { { Ajk Ajk NONZEROS 0 Aji Aii Aik } } } n 1 Perform 2 2 (min( b 1, n i )) O b n i 1 Multiply-adds 15 Complexity of Banded GE 1-D 2-D 3-D matrix size n=m n=m2 n=m3 band b=1 b=m b=m2 Domain size = m 1 D O (b 2 n) O (m) 100 pt grid O(100) ops 2D O (b 2 n) O (m4 ) 100 100 grid O(108 ) ops 3 D O (b 2 n) O (m7 ) 100 100 100 grid O(1014 ) ops 11d 13h 1us 1sec E.g. on a 1 GFlops computer using m=100 and constant c=10 For 3 - D problems Still Need a Faster Solver ! 16 Fill-In Sparse Matrices Pattern of a Filled-in Matrix Very Sparse Very Sparse Dense d 2-D: d=m 3-D: d=m2 17 Complexity of sparse GE 1-D 2-D 3-D matrix size n=m n=m2 n=m3 dense block d=1 d=m d=m2 1-D O(n) + O(d3) = O(m) 2-D 3-D Domain size = m ← 100 pt grid O(100) ops 1us O(n) + O(d3) = O(m3) ← 100x100 pt grid O(106) ops 10ms O(n) + O(d3) = O(m6) ← 100x100x100 pt grid O(1012) ops 2h 46m E.g. on a 1 GFlops computer using m=100 and constant c=10 For 3 - D problems Can we do any better with Krylov subspace iterative methods 18 I.3.a Outline • Finite Difference Matrices in 1-D, 2-D and 3-D • Gaussian Elimination Cost: – Bandlimited GE – Sparse GE • Krylov Subspace Iterative cost: – Comparison GE-Krylov 19 Background Krylov subspace iterative methods Problem: solve Ax = b (where A is large and dense) guess x0 REPEAT – how good was my guess? Calculate residue ri = b-Axi – find next guess xi+1 from the space x0+span{r0,Ar0,A2r0,…,Air0} which minimizes the next residue UNTIL ||residue|| < desired accuracy Advantages over gaussian elimination: 1) get a great control on accuracy (can stop and save computation when desired accuracy is achieved) 2) only need a matrix vector product Ax per iteration: O(N2) 20 The World According to Krylov Work for Banded Gaussian Elimination, Relaxation and GCR Dimension Banded GE Sparse GE 1 O m 2 O m 3 O m 4 7 GCR GCR+precond O m O m O m O m O m O m 2 O(km) 3 3 2 6 4 O(km ) 3 O(km ) GCR + good preconditioner ( i.e. k = 5-10 ) is always the best choice for 2D and 3D problems! 21 Steady State Analysis The World According to Krylov Dimension Banded GE Sparse GE 1 2 3 GCR GCR+precond O10us m O10ms m O(0.1ms km) 4 O m years 317000 O10sec m O10sec m 2 7 6 O m 317 years 4 O2h m 46m O m 10us 2h O 46m m 3 2 3 O0.1sec (km ) 3 20s ) O1m (km E.g. on a 1 GFlops computer using m=1000 , k=10 and constant c=10 GCR + good preconditioner ( i.e. k = 5-10 ) is always the best choice for 2D and 3D problems! 22 I.3.a Summary. Steady State AnalysisLinear Models • Linear Systems of Equations • Gaussian Elimination Cost: – Bandlimited GE – Sparse GE • Krylov Method cost: – Comparison GE-Krylov 23 Outline Numerical Simulation of System Models • Steady State Analysis – I.3.a Linear Models • Gaussian Elimination or LU decomposition – I.3.b NonLinear Models • Multidimentional Newton Method • I.3.c Dynamical Analysis – Linear Models • ODE integrators + GE or Krylov – NonLinear Models • ODE integrators + Newton 24 Introduction to Model Order Reduction I.3.b Steady State Analysis Solving Non-Linear Systems Luca Daniel Thanks to Jacob White, Deepak Ramaswamy, Jaime Peraire, Michal Rewienski, and Karen Veroy Steady State Analysis ( x0 , y0 ) NonLinear Problems Strut Example ( x1 , y1 ) Given: x0, y0, x1, y1, fl ( x2 , y2 ) f l Load force Find: x2, y2 f Need to Solve: f x 0 y 0 26 Steady State Analysis Strut Example f ( x0 , y0 ) ( x1 , y1 ) * * fA fB ( x2 , y2 ) f l Load force * r * r * f * L0 r r r r r ( x, y ) * r ( x* , y * ) * A, x f * B, x fl , x 0 f A*, y f B*, y f l , y 0 f A*, x f * A, y y 2 y0 A LA, 0 LA LA LA f B*, x f * B, y x2 x0 A LA, 0 LA LA x2 x0 2 y2 y0 2 x2 x1 B LB , 0 LB LB y 2 y1 B LB , 0 LB LB LB x2 x1 2 y2 y1 2 27 Steady State Analysis Strut Example Why Nonlinear? Pull Hard on the Struts The strut forces change in both magnitude and direction Load force f l (0,10) f A*, y f B*, y f l , y 0 y 2 y0 y2 y1 A L0 LA B L0 LB f l , y 0 LA LB 28 Steady State Analysis F l x y 2 Example Problem Strut and Joint FL 2 (l lo ) F Ac E (l lo ) lo x x f x F E (l lo ) l l y y f y F E (l lo ) l l F x f x FLx 0 f y FLy 0 OR x E (l0 lo ) FLx 0 l y E (l0 lo ) FLy 0 l 29 Steady State Analysis v1 10v NonLinear Problems Circuit Example v2 10 Need to Solve + Id Ir 0 - I vsrc I r 0 +- V d Branch Equations 1 I r Vr 0 10 Vd I d I s (e Vt Non-Linear System of Equations f ( x) 0 1) 0 30 Steady State Analysis v1 i2 i1 Example Problem Nonlinear Resistors v2 i3 Nodal Analysis At Node 1: i1 i2 0 g v1 g v1 v2 0 At Node 2: i3 i2 0 Nonlinear Resistors i g v gg(v v23) g v1 v2 0 Two coupled nonlinear equations in two unknowns 31 1:33 Steady State Analysis dx F ( x(t ) , u (t ) ) dt y (t ) G ( x(t ) , u (t ) ) • At steady-state u (t ) u constant, dx 0 dt • The analysis boils down to solving a non-linear system of equations F ( x, u ) 0 y G ( x, u ) 32 Newton Idea 1-D Reminder Problem: Find x such that f x 0 * * Approximate f(x) with its Taylor series about xk: a straight line ˆf ( x ) f ( x k ) f ( x k ) ( x x k ) x Find the solution of the approximation: xk+1 1 f k k 1 k f k k k 1 k f ( x ) ( x ) ( x x ) 0 x x ( x ) f ( x k ) x x 33 1-D Reminder Newton Algorithm Algorithm Picture 34 1:20 Newton Algorithm 1-D Reminder x = Initial Guess, k 0 0 Repeat { 1 f k x x ( x ) f ( x k ) x k k 1 k 1 k } Until ? x k 1 x threshold ? k f x k 1 threshold ? 35 Newton’s Method Convergence Example Convergence Depends on a Good Initial Guess f(x) 1 x 1 x x 2 x 0 x 0 X 36 1:27 Multidimensional Newton Method Jacobian Matrix J F x x F x x F x F1 x x1 J F x x FN x x 1 F1 x xN x1 FN x xN xN 37 1:35 Multidimensional Newton Method General Setting Problem: Find x such that F x 0 * x R * N * and F : R R N N Approximate F(x) with its Taylor series about xk: k k k ˆ F ( x) F ( x ) J F ( x ) ( x x ) Jacobian Find the solution of the approximation: xk+1 F(x ) JF (x ) (x k k x k 1 k 1 x )0 k x JF (x ) k k 1 k F(x ) 38 Multidimensional Newton Method Newton Algorithm x = Initial Guess, k 0 0 Repeat { x x x F x for x Compute F x k , J F x k Solve J F k k 1 k k k 1 k k 1 } Until x k 1 x k , f x k 1 small enough 39 1:39 Multidimensional Newton Method Nodal Analysis Strut and Joint x R and F : R R * 2 2 F x E (l0 lo ) FLx 0 l y E (l0 lo ) FLy 0 l 2 FL ? ? JF x ? ? 40 Multidimensional Newton Method i1 Nonlinear Resistor x R and F : R R * v1 Nodal Analysis i2 B v2 i3 2 2 2 At Node 1: i1 i2 0 F1 v g v1 g v1 v2 0 A B At Node 2: i3 i2 0 F2 v gC(v v32) g v1 v2 0 B ? ? JF x ? ? 41 1:43 Computing the Jacobian and the Function Multidimensional Newton Method Consider the contribution of one nonlinear resistor Connected between nodes n1 and n2 i b + vb - n1 i g v b n2 b Summing currents at Node n1: Fn1 v g vn1 vn2 Summing currents at Node n 2 : Fn2 v g vn1 vn2 Differenting at Node n1: Fn1 v vn1 g vn1 vn2 vn1 g v Fn1 v vn2 g vn1 vn2 vn2 g v 42 Computing the Jacobian and the Function Multidimensional Newton Method i Stamping a Resistor n1 n2 v g vn1 vn2 + - n1 n2 n1 g vn1 vn2 vb g vn1 vn2 v g vn1 vn2 v v JF v n2 g vn1 vn2 g v v n1 n2 F (v ) n1 n 2 43 1:47 More Complete Multidimensional Newton Algorithm Newton Method 0 x = Initial Guess, k 0 Repeat { k k Compute F x , J x F Zero J F and F for each element Compute element currents and derivatives Sum currents to F , sum derivatives to J F Solve J F x k x k 1 x k F x k for x k 1 k k 1 } Until x k 1 x k , f x k 1 small enough 44 Multidimensional Newton’s Method Example: Heat Flow in immersed bar T 0 T 0 T1 TN ih kT 3 What is the Jacobian? 45 1:53 Outline Numerical Simulation of System Models • Steady State Analysis – I.3.a Linear Models • Gaussian Elimination or LU decomposition – I.3.b NonLinear Models • Multidimentional Newton Method • I.3.c Dynamical Analysis – Linear Models • ODE integrators + GE or Krylov – NonLinear Models • ODE integrators + Newton 46 Introduction to Model Order Reduction I.3.c - Dynamical Analysis of Systems ODE numerical integrators Luca Daniel Thanks to Jacob White, Deepak Ramaswamy, Jaime Peraire, Michal Rewienski, and Karen Veroy 47 Dynamical Analysis of Systems dx A x(t ) B u (t ) dt y (t ) C x(t ) D u (t ) dx F ( x(t ) , u (t ) ) dt y (t ) G ( x(t ) , u (t ) ) • Given a generic input u(t) calculate x(t) and y(t) • The analysis boils down to integrating numerically a system of linear or non-linear ordinary differential equations 48 Basic Concepts Finite Difference Methods t t First - Discretize Time 0 t1 t2 Second - Represent x(t) using values at ti 3 x̂ 2 4 x̂ 1 x̂ x̂ tL 0 t1 t2 t3 dx Third - approximat e dt using the discrete ? d xˆ l 1 xˆ l Example : x(tl ) dt tl 1 ? d x(tl 1 ) dt t t L 1 tL T x(tl ) Approx. Exact xˆ l solution solution xˆ l 49 1:55 Finite Difference Methods x d slope x(tl ) dt slope tl tl 1 x(tl 1 ) x(tl ) t Basic Concepts Forward Euler Approximation x(tl 1 ) x(tl ) d x(tl ) A x(tl ) dt t or x(tl 1 ) x(tl ) t A x(tl ) t x(tl 1 ) x(tl ) t A x(tl ) 50 Finite Difference Methods Basic Concepts Forward Euler Algorithm x(t1 ) xˆ1 x(0) tAx 0 x x(t2 ) xˆ 2 xˆ1 tAxˆ1 tAxˆ1 x(t L ) xˆ L xˆ L 1 tAxˆ L 1 tAx(0) t1 t2 t3 t 51 1:59 Basic Concepts Finite Difference Methods x d slope x(tl 1 ) dt slope tl tl 1 x(tl 1 ) x(tl ) t Backward Euler Approximation x(tl 1 ) x(tl ) d x(tl 1 ) A x(tl 1 ) dt t or x(tl 1 ) x(tl ) t A x(tl 1 ) t x(tl 1 ) x(tl ) t A x(tl 1 ) 52 2:01 Finite Difference Methods Basic Concepts Backward Euler Algorithm Solve with GE or iterative methods x(t1 ) xˆ1 x(0) tAxˆ1 [ I tA] xˆ1 x(0) x(t2 ) xˆ 2 [ I tA] 1 xˆ1 x(tL ) xˆ L [ I tA] 1 xˆ L 1 x tAxˆ 2 tAxˆ1 t1 t2 t 53 2:03 Finite Difference Methods 1 d d ( x(tl 1 ) x(tl )) 2 dt dt 1 ( Ax(tl 1 ) Ax(tl )) 2 x(tl 1 ) x(tl ) t 1 x(tl 1 ) x(tl ) tA( x(tl 1 ) x(tl )) 2 Basic Concepts Trapezoidal Rule slope x d x(tl ) dt slope slope d x(tl 1 ) dt x (tl 1 ) x (tl ) t t 1 1 ( x(tl 1 ) tAx(tl )) ( x(tl ) tAx(tl 1 )) 2 2 54 2:05 Finite Difference Methods Basic Concepts Trapezoidal Rule Algorithm Solve with GE or iterative methods t x (t1 ) xˆ x (0) Ax(0) Axˆ1 2 t 1 t I A xˆ I A x (0) 2 2 1 t x (t2 ) xˆ 2 I 2 x (tL ) xˆ L I t 2 1 t A I 2 1 t A I 2 A xˆ1 x t1 t2 t A xˆ L1 55 Finite Difference Methods Basic Concepts Summary Trap Rule, Forward-Euler, Backward-Euler Are all one-step methods ˆx l is computed using only xˆ l 1, not xˆ l 2 , xˆ l 3 , etc. Forward-Euler is simplest No equation solution explicit method. Backward-Euler is more expensive Equation solution each step implicit method Trapezoidal Rule might be more accurate Equation solution each step implicit method 56 2:13 Outline • Initial Value problem examples Signal propagation (circuits with capacitors). Space frame dynamics (struts and masses). Chemical reaction dynamics. • Eigenvalue analysis for dynamical systems • Investigate the simple finite-difference methods Forward-Euler, Backward-Euler, Trap Rule. Examine properties experimentally. 57 2:15 Application Problems Chemical Reaction Dynamics Crucible Reagent Strange green stuff • How fast is product produced? • Does it explode? 58 Application Problems Chemical Reaction Example A 2x2 Example Amount of reactant R, the temperature T dT T R dt dR R 4T dt More reactant causes temperature to rise, higher temperatures increases heat dissipation causing temperature to fall Higher temperatures raises reaction rates, increased reactant interferes with reaction and slows rate. 59 Finite Difference Methods Numerical Experiments Unstable Reaction 4 t 0.1 3.5 3 Exact Solution Backward-Euler 2.5 2 Trap rule 1.5 Forward-Euler 1 0.5 0 0.5 1 1.5 2 FE and BE results have larger errors than Trap Rule, and the errors grow with time. 60 2:15 Numerical Experiments Finite Difference Methods Unstable Reaction-Error Plots 0 0.4 6 -0.05 0.35 5 Backward Euler 0.3 -0.1 x 10 Trap Rule 4 0.25 3 0.2 2 0.15 1 0.1 0 0.05 -1 -3 -0.15 Forward Euler -0.2 -0.25 -0.3 -0.35 0 1 2 0 0 1 2 -2 0 1 2 All methods have errors which grow exponentially 61 2:17 Numerical Experiments Finite Difference Methods 10 M a x E r r o r 10 10 10 10 10 Unstable Reaction-Convergence 2 Backward-Euler 0 -2 -4 Trap rule Forward-Euler -6 -8 10 -3 10 -2 Timestep 10 -1 10 0 For FE and BE, Error t For Trap, Error t 2 62 2:19 Finite Difference Methods Basic Concepts Numerical Integration View tl 1 d x(t ) A x (t ) x (tl 1 ) x (tl ) Ax( )d tl dt tl 1 t Trap Ax ( t ) Ax ( t ) Ax ( ) d l l tl 2 tAx(tl 1 ) BE tAx(tl ) tl tl 1 FE 63 2:09 Application Problems y y0 u Struts, Joints and point mass example A 2x2 Example Constitutive Equations fs fm y y0 EAc f s E Ac u y0 y0 Conservation Law fs fm 0 d 2u fm M 2 dt Define v as velocity (du/dt) to yield a 2x2 System M 0 dv EAc 0 dt 0 v y0 u 1 du 0 dt 1 64 1:39 Finite Difference Methods 4 2 Numerical Experiments Oscillating Strut and Mass t 0.1 Forward-Euler 0 -2 -4 -6 Trap rule 0 5 10 Backward-Euler 15 20 25 30 FE result grow, BE result decay and the Trap rule preserves oscillations 65 Finite Difference Methods Numerical Experiments Two timescale RC Circuit small t Backward-Euler Computed Solution large t With Backward-Euler it is easy to use small timesteps for the fast dynamics and then switch to large timesteps for the slow decay 66 Finite Difference Methods Numerical Experiments Two timescale RC Circuit Forward-Euler Computed Solution The Forward-Euler is accurate for small timesteps, but goes unstable when the timestep is enlarged 67 NonLinear Systems ODE integrators Multistep Methods Nonlinear Differential Equation: k-Step Multistep Approach: l 2 xˆ l k xˆ ˆ l 1 l x xˆ d x(t ) f ( x(t ), u (t )) dt l j l j ˆ ˆ x t f x , u tl j j j k k j 0 j 0 Multistep coefficients Solution at discrete points tl k tl 3 tl 2 tl 1 tl Time discretization 68 Basic Equations Multistep Methods Common Algorithms Multistep Equation: Forward-Euler Approximation: FE Discrete Equation: Multistep Coefficients: BE Discrete Equation: Multistep Coefficients: l j l j ˆ ˆ x t f x , u tl j j j k k j 0 j 0 x tl x tl 1 t f x tl 1 , u tl 1 xˆ l xˆ l 1 t f xˆ l 1 , u tl 1 k 1, 0 1, 1 1, 0 0, 1 1 xˆ l xˆ l 1 t f xˆ l , u tl k 1, 0 1, 1 1, 0 1, 1 0 t f xˆ l , u tl f xˆ l 1 , u tl 1 Trap Discrete Equation: 2 1 1 Multistep Coefficients: k 1, 0 1, 1 1, 0 , 1 2 2 xˆ l xˆ l 1 69 Outline Numerical Simulation of System Models • Steady State Analysis – I.3.a Linear Models • Gaussian Elimination or LU decomposition – I.3.b NonLinear Models • Multidimentional Newton Method • I.3.c Dynamical Analysis – Linear Models • ODE integrators + GE or Krylov – NonLinear Models • ODE integrators + Newton 70