Download presentation
Presentation is loading. Please wait.
1
Ordinary Differential Equations (ODEs)
Daniel Baur ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften ETH Hönggerberg / HCI F128 – Zürich Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
2
Definition of an Implicit Algorithm
In an implicit algorithm, the function value at the next step appears on the right hand side of the step equation: A simple example is the Backward Euler method: Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
3
Example Consider a batch reactor where these reactions take place
In our example k1 = 1 and k2 = 10 Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
4
Analytical Solution The system describing first order reactions in a batch reactor (assuming V = const. and T = const.) has the following general form where A is a (N x N) matrix of constant coefficients The analytical solution to these systems reads where B is matrix of constant coefficients and λ is the vector of the eigenvalues of A B can be found by imposing that the solution satisfies the initial differential equaiton and the initial values of y Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
5
Analytical Solution of the Batch Reactor
The Jacobian matrix reads Its eigenvalues are Imposing A0 = 1 and B0 = 0, the solution reads Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
6
Forward Euler Method In the linear case, we can look at the Forward Euler method in a different way, by noticing that With the definition of the Forward Euler algorithm y will only converge towards a value if the spectral radius of the matrix (I + hJ) is smaller than 1, i.e. Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
7
Solution with Forward Euler
Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
8
Backward Euler Method As mentioned before, the simplest implicit method is the Backward Euler method If we substitute our problem We obtain In case of linear ODEs, this is a linear system of the form Ax = b that has to be solved at every iteration step Note that in general this can be a non-linear system Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
9
Stability of the Backward Euler Method
If we solve for the next step, we get Again the spectral radius of the iteration matrix determines convergence: As we can see, the Backward Euler method is stable for every system that it is well conditioned, i.e. if Re(λmax) < 0 Algorithms with this property are called A-stable algorithms There can be no stability limitation on the step size, which also makes the Backward Euler better for stiff systems than the Forward Euler Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
10
Implicit Trapezoidal Rule
The implicit trapezoidal algorithm reads as follows Substituting our problem, we get This is again an A-stable algorithm h = 0.1 h = 0.2 Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
11
A-Stability of other Algorithms
Explicit Runge-Kutta methods, as well as explicit multi-step methods can never be A-stable Note that the Forward Euler method can be seen as both an explicit multi-step method or RK method of order 1 Implicit multi-step methods can only be A-stable if they are of order 2 or lower (second Dahlquist barrier) However, implicit RK methods of higher order can be A-stable Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
12
Multi-Step Algorithms
Multi-step methods use not only the current function value yn to compute the next value yn+1, but also function values at previous times (yn-1, ...) In implicit solvers, they can be used in predictor / corrector pairs to avoid solving large systems of equations One example are the Adams-Bashforth-Moulton methods The corrector step can be looped until it converges, i.e. use the yn+1 from the corrector as the prediction and evaluate the corrector again, until its change is sufficiently small Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
13
Convergence of the Corrector Step
Let us reformulate the AM corrector step to incorporate the convergence iteration This iteration will only converge if the spectral radius of the iteration matrix is smaller than 1, i.e. This restricts the maximum step size almost as badly as stability issues restrict the Forward Euler method Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
14
Example of the AB/AM Algorithm
Startup was done with the Implicit Trapezoid rule; h = 0.2 The convergence loop more than triples the overall time needed, but it increases stability Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
15
Implicit Algorithms and Stiff Problems
Since implicit algorithms are generally more stable than explicit algorithms (some are even A-stable!), they fare much better with stiff problems, where the step size is often restricted by stability issues For non-A-stable implicit algorithms, the main goal is usually to get the largest possible stability region, since this is the main advantage of implicit algorithms However, this stability comes at the price of larger computational demand per step, which is needed to solve the arising algebraic equation systems There are however highly specialized algorithms to solve systems arising from implicit solvers, which can take into account special features of the problem like sparseness or bandedness Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
16
Sparse and Banded Matrices
It is computationally very advatageous if sparse or in the best case even banded matrices can be used: Sparse: Storing and operating on only 510 non-zero elements (times two for their position) instead of 10’000 Banded: All non-zero elements are grouped in a band around the diagonal, which further simplifies computations Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
17
Variable Step Size and Order Algorithms
Since the step size h is of such importance for stability and accuracy, sophisticated algorithms adjust it during runtime This requires error estimation, which is usually done by comparing the result to what the same algorithm produces with a higher order Some algorithms even adjust their order p dynamically Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
18
Assignment 1 Implement the Implicit Trapezoid method (see slide 10) for the batch reactor given on slide 3. Simply use left division «\» to solve the arising linear systems. What is the maximum step size h that still insures stability? What step size h is needed to get a maximum error of 0.1% at all time points, compared to the analytical solution? Plot the solutions. Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
19
Exercise 2 The following reaction scheme is known as the Oregonator A and B are held constant P and Q are constantly withdrawn, therefore ≈ 0 Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
20
Exercise 2 (Continued) This leads to the following system of ODEs
Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
21
Assignment 2 Solve the system using a suitable built-in Matlab solver (which one? Note the dynamics!), using the following parameters: A = B = 0.5 = const.; k1 = 1.34; k2 = 1e9; k3 = 8e3; k4 = 4e7; k5 = 1; X0 = Y0 = Z0 = 0.2; tspan = [0, 300]; Plot the solution. What is special, given the fact that this is a model for a chemical reaction? Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.