Differential equations for chemical kinetics

Similar documents
Strang Splitting Versus Implicit-Explicit Methods in Solving Chemistry Transport Models. A contribution to subproject GLOREAM. O. Knoth and R.

Chemical Reaction Engineering - Part 4 - Integration Richard K. Herz,

ODEs occur quite often in physics and astrophysics: Wave Equation in 1-D stellar structure equations hydrostatic equation in atmospheres orbits

MATH2071: LAB 2: Explicit ODE methods

ChE 400: Applied Chemical Engineering Calculations Tutorial 6: Numerical Solution of ODE Using Excel and Matlab

Ordinary differential equations solving methods

Mass-Spring Systems. Last Time?

An Introduction to Flow Visualization (1) Christoph Garth

over The idea is to construct an algorithm to solve the IVP ODE (9.1)

Goals for This Lecture:

Both the polynomial must meet and give same value at t=4 and should look like this

Homework Set 5 (Sections )

Discontinuous Galerkin Sparse Grid method for Maxwell s equations

Part I: Theoretical Background and Integration-Based Methods

CS205b/CME306. Lecture 9

Data Visualization. Fall 2017

over The idea is to construct an algorithm to solve the IVP ODE (8.1)

Ordinary Differential Equations

POLYMATH Example for the Numerical Solution of ODEs

Modeling with Uncertainty Interval Computations Using Fuzzy Sets

Package nlsrk. R topics documented: June 24, Version 1.1 Date Title Runge-Kutta Solver for Function nls()

Enabling model based decision making by sharing consistent equation oriented dynamic models. optimization environments. Ajay Lakshmanan Manager, R&D

4 Visualization and. Approximation

Isothermal Batch Reactor Modeling

2. What are the advantages of simulating a molecule or a reaction over doing the experiment in a lab?

Matlab Handout Nancy Chen Math 19 Fall 2004

Accelerating the Implicit Integration of Stiff Chemical Systems with Emerging Multi-core Technologies

Parallel implicit ordinary differential equation solver for cuda. Tomasz M. Kardaś

Mathematics for chemical engineers

Chapter 6 Visualization Techniques for Vector Fields

The vertical stratification is modeled by 4 layers in which we work with averaged concentrations in vertical direction:

Numerical Simulation of Dynamic Systems XXIV

MATLAB primer for CHE 225

Table 2 1. F90/95 Data Types and Pointer Attributes. Data Option. (Default Precision) Selected-Int-Kind

Both the polynomial must meet and give same value at t=4 and should look like this

Modeling Cloth Using Mass Spring Systems

RT3D User-Defined Reactions

v. 9.1 GMS 9.1 Tutorial RT3D User-Defined Reactions Prerequisite Tutorials Time Required Components

Example 1: DC/DC Converter

Global Solution of Mixed-Integer Dynamic Optimization Problems

Topic 2.3: Tangent Planes, Differentiability, and Linear Approximations. Textbook: Section 14.4

Numerical Integration

Physically based modelling Computer Graphics I February 27, 2003

Replacing Neural Networks with Black-Box ODE Solvers

KINETICS CALCS AND GRAPHS INSTRUCTIONS

Olivier Brüls. Department of Aerospace and Mechanical Engineering University of Liège

QP-Collide: A New Approach to Collision Treatment

Math 4242 Polynomial Time algorithms, IndependentSet problem

Debojyoti Ghosh. Adviser: Dr. James Baeder Alfred Gessow Rotorcraft Center Department of Aerospace Engineering

(Part - 1) P. Sam Johnson. April 14, Numerical Solution of. Ordinary Differential Equations. (Part - 1) Sam Johnson. NIT Karnataka.

J. Vira, M. Sofiev SILAM winter school, February 2013, FMI

Optimization problems with constraints - the method of Lagrange multipliers

Calculus II (Math 122) Final Exam, 11 December 2013

Report for Experiment 5

Bucknell University Using ODE45 MATLAB Help

Chemistry 30 Tips for Creating Graphs using Microsoft Excel

Topic 5.1: Line Elements and Scalar Line Integrals. Textbook: Section 16.2

1.7.1 Laplacian Smoothing

ECHE-322: Mass Transfer Spring Absorption Column Design Using HYSYS 3.2 Tutorial

Finite difference methods

Vector Field Visualization: Introduction

Particle Systems. g(x,t) x. Reading. Particle in a flow field. What are particle systems? CSE 457 Winter 2014

16.1 Runge-Kutta Method

2.7 Cloth Animation. Jacobs University Visualization and Computer Graphics Lab : Advanced Graphics - Chapter 2 123

Using efficient numerical methods in large-scale air pollution modelling

Soil Trace Element Model (Single Layer) Documentation

Euler s Method for Approximating Solution Curves

Math 133A, September 10: Numerical Methods (Euler & Runge-Kutta) Section 1: Numerical Methods

8/30/2016. In Binary, We Have A Binary Point. ECE 120: Introduction to Computing. Fixed-Point Representations Support Fractions

Upgraded Swimmer for Computationally Efficient Particle Tracking for Jefferson Lab s CLAS12 Spectrometer

Recent developments in simulation, optimization and control of flexible multibody systems

Homework Set #2-3, Math 475B

Methane Combustion Modelling Tutorial using ANSYS CFX

Post Processing, Visualization, and Sample Output

3x - 5 = 22 4x - 12 = 2x - 9

Lab #5 Ocean Acoustic Environment

Project assignment: Particle-based simulation of transport by ocean currents

1.2 Numerical Solutions of Flow Problems

CPIB SUMMER SCHOOL 2011: INTRODUCTION TO BIOLOGICAL MODELLING

Excel for Chemists. Second Edition

Coupling of STAR-CCM+ to Other Theoretical or Numerical Solutions. Milovan Perić

Basic matrix math in R

Approximate Solutions to Differential Equations Slope Fields (graphical) and Euler s Method (numeric) by Dave Slomer

Regression Solver. User Manual. Process Design and Gas Processing Laboratory Illinois Institute of Technology Chicago, IL,

Parallel Summation of Inter-Particle Forces in SPH

2.1 System Dynamics Tool: STELLA Version 10 Tutorial 1. Introduction to Computational Science: Modeling and Simulation for the Sciences, 2nd Edition

Chemical Equilibrium CHAPTER 15. Chemistry: The Molecular Nature of Matter, 6 th edition By Jesperson, Brady, & Hyslop

Atmospheric Modeling (5 ECTS)

37 Self-Assessment. 38 Two-stage Runge-Kutta Methods. Chapter 10 Runge Kutta Methods

Mathematical Methods and Modeling Laboratory class. Numerical Integration of Ordinary Differential Equations

Exercises for a Numerical Methods Course

Math Lab 6: Powerful Fun with Power Series Representations of Functions Due noon Thu. Jan. 11 in class *note new due time, location for winter quarter

VCell Tutorial. FRAP with binding

Math 225 Scientific Computing II Outline of Lectures

You will need to use a calculator for this worksheet A (1, 1)

Simulation in Computer Graphics. Particles. Matthias Teschner. Computer Science Department University of Freiburg

Journal of Computational Physics

Chapter 1 Section 1 Lesson: Solving Linear Equations

Manual for explicit parallel peer code EPPEER

Real-Time Simulation of Simscape Models

Transcription:

Differential equations for chemical kinetics Atmospheric Modelling course Sampo Smolander sampo.smolander@helsinki.fi 15.11.2010 Sampo Smolander Chemical kinetics 15.11.2010 1 / 24

Chemical equation reactants products : rate coefficient SO 3 + H 2 O H 2 SO 4 : 5.0 15 [H 2 SO 4 ] [SO 3 ] [H 2 O] = k 1 [SO 3 ][H 2 O] = k 1 [SO 3 ][H 2 O] = k 1 [SO 3 ][H 2 O] k 1 = 5.0 15 mol/s Sampo Smolander Chemical kinetics 15.11.2010 2 / 24

CH 4 + 2 O 2 CO 2 + 2 H 2 O : k 2 [CH 4 ] [O 2 ] [CO 2 ] [H 2 O] = k 2 [CH 4 ][O 2 ] 2 = 2 k 2 [CH 4 ][O 2 ] 2 = k 2 [CH 4 ][O 2 ] 2 = 2 k 2 [CH 4 ][O 2 ] 2 Sampo Smolander Chemical kinetics 15.11.2010 3 / 24

CH 4 + 2 O 2 CO 2 + 2 H 2 O : k 2 There is ca. 21% = 210 000 ppm oxygen and 1.8 ppm methane in atmosphere, so we don t really need to monitor the tiny change in the amount of oxygen CH 4 CO 2 + 2 H 2 O : k 2 [O 2 ] 2 or actually not water either CH 4 CO 2 : k 2 [O 2 ] 2 but the reaction rate still depends on the oxygen concentration (Writing like this ignores the conservation of atoms, but we don t care) Sampo Smolander Chemical kinetics 15.11.2010 4 / 24

We can have: Variable reactants we monitor the change Constant reactants we need to know the concentration, to calculate reaction rates, but we can assume constant concentration Variable products we monitor the change Uninteresting products we re not interested at all Sampo Smolander Chemical kinetics 15.11.2010 5 / 24

Brusselator (theoretical example) Constant: A, B Variable: X, Y Uninteresting: C, D A X : k 1 2 X + Y 3 X : k 2 B + X Y + C : k 3 X D : k 4 http://en.wikipedia.org/wiki/brusselator http://www.idea.wsu.edu/oscilchem/#brusselator%20model Sampo Smolander Chemical kinetics 15.11.2010 6 / 24

A X 2 X + Y 3 X B + X Y + C X D [X] [X] = k 1 [A] = k 2 [X] 2 [Y] = k 2 [X] 2 [Y] [Y] [X] = k 3 [X][B] [Y] = k 3 [X][B] [X] = k 4 [X] We don t need to write equations for A, B because they stay constant And C, D we are not interested in Sampo Smolander Chemical kinetics 15.11.2010 7 / 24

Combine these [X] = k 1 [A], [X] = k 2 [X] 2 [Y], [X] = k 3 [X][B], [X] = k 4 [X] into [X] = k 1[A] + k 2 [X] 2 [Y] k 3 [X][B] k 4 [X] Do same for [Y], get... Sampo Smolander Chemical kinetics 15.11.2010 8 / 24

[X] [Y] = k 1 [A] + k 2 [X] 2 [Y] k 3 [X][B] k 4 [X] = k 2 [X] 2 [Y] + k 3 [X][B] Or with more chemicals and reactions, you ll just get a larger system of coupled differential equations. But the principle is easy? Next: numerics Sampo Smolander Chemical kinetics 15.11.2010 9 / 24

[X] [Y] = k 1 [A] + k 2 [X] 2 [Y] k 3 [X][B] k 4 [X] = k 2 [X] 2 [Y] + k 3 [X][B]! c(1)=x, c(2)=y ; cc(1)=a, cc(2)=b SUBROUTINE deriv (dc, c, cc, k) REAL(dp), INTENT( in ) : : c (dim_c ), cc (dim_cc ), k(dim_k) REAL(dp), INTENT( out ) : : dc(dim_c) dc(1) = k(1)* cc (1) + k(2)*c(1)*c(1)*c(2) & k(3)* cc (2)*c(1) k(4)*c(1) dc(2) = k(3)* cc (2)*c(1) k(2)*c(1)*c(1)*c(2) END SUBROUTINE deriv Sampo Smolander Chemical kinetics 15.11.2010 10 / 24

PROGRAM brusselator! http : / / en. wikipedia. org / wiki / Brusselator IMPLICIT NONE INTEGER, PARAMETER : : dp = SELECTED_REAL_KIND(15)! so that things w i l l be in double precision! http : / / en. wikipedia. org / wiki / Double_precision_floating point_format INTEGER, PARAMETER : : dim_c = 2, dim_cc = 2, dim_k = 4 REAL(dp) : : dt, t, t2, k(dim_k ), c (dim_c ), dc(dim_c ), cc (dim_cc) dt = 0.2! time step k = ( / 1.0, 1.0, 1.0, 1.0 / )! rate coeffs! i n i t i a l conditions cc (1) = 1.0 ; cc (2) = 2.5 ; c(1) = 1.0 ; c(2) = 0.0 t = 0.0 ; t2 = 10*60.0 WRITE(*,*) c DO WHILE ( t < t2 ) CALL deriv (dc, c, cc, k) c = c + dc*dt WRITE(*,*) c t = t+dt END DO CONTAINS SUBROUTINE deriv (dc, c, cc, k) REAL(dp), INTENT( in ) : : c (dim_c ), cc (dim_cc ),k(dim_k) REAL(dp), INTENT( out ) : : dc(dim_c) dc(1) = k(1)*cc (1) + k(2)*c(1)*c(1)*c(2) k(3)*cc(2)*c(1) k(4)*c(1) dc(2) = k(3)*cc(2)*c(1) k(2)*c(1)*c(1)*c(2) END SUBROUTINE deriv END PROGRAM brusselator Sampo Smolander Chemical kinetics 15.11.2010 11 / 24

Run the program./a.out > xy.dat 3.5 3.0 2.5 2.0 1.5 1.0 0.5 Well, maybe the dt = 0.2 time step is a little large, try 0.1 Sampo Smolander Chemical kinetics 15.11.2010 12 / 24

Gives a bit smoother curves 3.5 3.0 2.5 2.0 1.5 1.0 0.5 (Not that this is very important in this course) Sampo Smolander Chemical kinetics 15.11.2010 13 / 24

A system of differential equations can be expressed as one vector-valued equation C = f(c, t) C = (c 1, c 2,...) are the chemical concentrations and f gives the derivatives c 1, c 2,... f may or may not depentd on t Sampo Smolander Chemical kinetics 15.11.2010 14 / 24

Equation like C = f(c, t) defines a vector field in every point in space Then we start from an initial point and try to follow a trajectory Sampo Smolander Chemical kinetics 15.11.2010 15 / 24

In the previous code, we are at some state C(t), then we evaluate the derivative at this state, and take a step to that direction This is called the Euler method http://en.wikipedia.org/wiki/euler_method It is the simplest, but also most imprecise method for solving differential equations numerically It is good enough for this course, but I just want to mention one another method Sampo Smolander Chemical kinetics 15.11.2010 16 / 24

Maybe the derivative changes during the step? With stepsize dt = h we step from C(t) to C(t + h) just following the direction C(t) but at C(t + h) we should already be going to direction C(t+h) Next: Runge-Kutta method Sampo Smolander Chemical kinetics 15.11.2010 17 / 24

C(t) = f(c(t), t) At the initial point C t the direction is k 1 = f(c t, t) take a half-step h/2 to that direction, and see what s the new direction there k 2 = f(c t + k 1 h/2, t + h/2) go back to initial point, and take a half-step to direction k 2 and see the new direction there k 3 = f(c t + k 2 h/2, t + h/2) go back, take a full step to direction k 3 k 4 = f(c t + k 3 h, t + h) Sampo Smolander Chemical kinetics 15.11.2010 18 / 24

7 6 5 4 3 2 Sampo Smolander Chemical kinetics 15.11.2010 19 / 24

Now, C t + k 3 h would already be a good step, but we re not done yet. We have 4 different candidates for the right direction to go Take a weighted average k 1, k 2, k 3, k 4 k = 1/6 (k 1 + 2k 2 + 2k 3 + k 4 ) and go there C t+1h = C t + k h This is the Runge-Kutta method http://en.wikipedia.org/wiki/runge-kutta_methods Sampo Smolander Chemical kinetics 15.11.2010 20 / 24

Not much more difficult to code... REAL(dp) : : k1(dim_c ),k2(dim_c ), & k3(dim_c ),k4(dim_c)... DO WHILE ( t < t2 ) CALL deriv (k1, c, cc, k) CALL deriv (k2, c+dt /2*k1, cc, k) CALL deriv (k3, c+dt /2*k2, cc, k) CALL deriv (k4, c+dt *k3, cc, k) dc=(k1 + 2*k2 + 2*k3 + k4)/6 c = c + dc*dt WRITE( *, * ) c t = t+dt END DO Sampo Smolander Chemical kinetics 15.11.2010 21 / 24

3.5 3.0 2.5 2.0 1.5 1.0 0.5 Blue: Euler, dt=0.1 Black: Runge-Kutta dt=0.4 (So that they should have about the same computational cost) Blue looks smoother, because time step is smaller, but which is more accurate? Sampo Smolander Chemical kinetics 15.11.2010 22 / 24

3.5 3.0 2.5 2.0 1.5 1.0 0.5 Blue: Euler, dt=0.02 Black: Runge-Kutta dt=0.4 (same as previously) So taking a very small time step in Euler method, it actually converges to the Runge-Kutta solution with 20 larger step size Sampo Smolander Chemical kinetics 15.11.2010 23 / 24

Now you should be able to: read chemical equations write the corresponding system of differential equations code numerical solution to the DE s Runge-Kutta is by no means very advanced algorithm either. In real work, we use algorithms with adaptive step size, and we use existing libraries and don t code the solvers ourselves More information: numerical analysis / numerical methods / differential equations textbooks. Google: ODE solvers, Stiff equations Sampo Smolander Chemical kinetics 15.11.2010 24 / 24