12/22/2020
Ali M. Sahlodin
Department of Chemical Engineering
AmirKabir University of Technology
1397 S.H
Stability of ODEs
Stability of ODE solvers
Forward (explicit) Euler
Backward (implicit) Euler
Copyright © Ali M. Sahlodin, Dept. of Chemical Engineering, AmirKabir Univ. of Tech.
2
1
12/22/2020
Implicit Euler for DAEs
Multi-step methods for DAEs
Backward differentiation formula (BDF)
Order and stability
Predictor-corrector method
Order selection
Fixed- vs. variable-step BDF
Copyright © Ali M. Sahlodin, Dept. of Chemical Engineering, AmirKabir Univ. of Tech.
3
From Mathworks website
Copyright © Ali M. Sahlodin, Dept. of Chemical Engineering, AmirKabir Univ. of Tech.
4
2
12/22/2020
Manual car-BDF solver analogy!
Better stability: lower gear/BDF order
Faster driving/integration: Higher gear/BDF order (still accurate with larger
steps)
Both start from the 1st gear/order (why?)
Copyright © Ali M. Sahlodin, Dept. of Chemical Engineering, AmirKabir Univ. of Tech.
5
Importance of a good initial guess
Cycling solution Solution divergence
Courtesy of Benoit Chachuat
Copyright © Ali M. Sahlodin, Dept. of Chemical Engineering, AmirKabir Univ. of Tech.
6
3
12/22/2020
Solver failure
Copyright © Ali M. Sahlodin, Dept. of Chemical Engineering, AmirKabir Univ. of Tech.
7
Copyright © Ali M. Sahlodin, Dept. of Chemical Engineering, AmirKabir Univ. of Tech.
8
4
12/22/2020
Equations K. E. Brenan, S. L. Campbell, and L. R. Petzold 1995
Numerical Solution of Initial-Value Problems in Differential-Algebraic
Corrector equation
Modified Newton’s method
Iteration matrix
Iteration matrix evaluated at predicted y and y’
Copyright © Ali M. Sahlodin, Dept. of Chemical Engineering, AmirKabir Univ. of Tech.
9
Iteration matrix: dominant cost of integration
Partial differentiation
Matrix inversion
Simplify matrix inversion: LU factorization
How to reduce computational cost?
Do not update G at every step!
May converge in more iterations
But, each iteration is less expensive
Copyright © Ali M. Sahlodin, Dept. of Chemical Engineering, AmirKabir Univ. of Tech.
10
5
12/22/2020
Symbolic differentiation
Exact derivatives
Difficult/impossible to obtain
Finite differences
Approximate derivatives
Easy to implement
Automatic differentiation
Exact derivatives
Easy to implement and use
Copyright © Ali M. Sahlodin, Dept. of Chemical Engineering, AmirKabir Univ. of Tech.
11
Break down the function into its constituting
elements
https://en.wikipedia.org/wiki/Automatic_
differentiation
Copyright © Ali M. Sahlodin, Dept. of Chemical Engineering, AmirKabir Univ. of Tech.
12
6
12/22/2020
Calculate both the function and its derivative at the same time
https://en.wikipedia.org/wiki/Automatic_
differentiation
Copyright © Ali M. Sahlodin, Dept. of Chemical Engineering, AmirKabir Univ. of Tech.
13
Operator overloading: define new data type that
carries both variable and its derivative
Evaluate derivatives along with function evaluations
less efficient
Easy to implement (C++, object-oriented and template)
Source code transformation: generate derivative
code from original program
More efficient
More difficult to implement
Copyright © Ali M. Sahlodin, Dept. of Chemical Engineering, AmirKabir Univ. of Tech.
14
7
12/22/2020
http://www.autodiff.org/
Copyright © Ali M. Sahlodin, Dept. of Chemical Engineering, AmirKabir Univ. of Tech.
15
Set your solver to use user-supplied
derivatives (instead of finite difference)
Have the automatic differentiation package
take the function derivatives
Supply the derivatives to the solver
Advanced simulation packages have built-in automatic differentiation
capabilities
User provides the original model only!
Copyright © Ali M. Sahlodin, Dept. of Chemical Engineering, AmirKabir Univ. of Tech.
16
8
12/22/2020
y y, diag (107 , 107 ,..., 107 ), n 5000
Without user-supplied Jacobian With user-supplied Jacobian
94 successful steps
0 failed attempts 94 successful steps
5190 function evaluations 0 failed attempts
1 partial derivatives 190 function evaluations
18 LU decompositions 1 partial derivatives
188 solutions of linear systems 18 LU decompositions
CPU time = 369.3594 188 solutions of linear systems
Elapsed time is 100.947378 CPU time = 81.8750
seconds. Elapsed time is 28.116323 seconds.
•Finite differencing requires a Large number of function evaluations
•User-supplied Jacobian saves a lot of time for large systems! (how?)
Copyright © Ali M. Sahlodin, Dept. of Chemical Engineering, AmirKabir Univ. of Tech.
17
Copyright © Ali M. Sahlodin, Dept. of Chemical Engineering, AmirKabir Univ. of Tech.
18
9
12/22/2020
From “Nonlinear and Dynamic Optimization”, Benoit Chachuat
Octave (daspk, dassl, ode15s, ode15i)
Modelica (OpenModelica)
MATLAB (ODE15i, ODE15s)
Copyright © Ali M. Sahlodin, Dept. of Chemical Engineering, AmirKabir Univ. of Tech.
19
10