KPP – a Software Environment for the Simulation of Chemical Kinetics

KPP – a Software Environment for the Simulation of Chemical Kinetics

KPP – A Software Environment for the Simulation of Chemical Kinetics Adrian Sandu Computer Science Department Virginia Tech NIST, May 25, 2004 Acknowledgements Dr. Valeriu Damian Dr. Florian Potra Dr. Gregory Carmichael Dr. Dacian Daescu Dr. Tianfeng Chai Dr. Mirela Damian Part of this work is supported by NSF ITR AP&IM-0205198 May 25, 2004 Related Work CHEMKIN (http://www.reactiondesign.com/lobby/open) Translates symbolic chemical system in a data file that is then used by internal libraries for simulation. Gas-phase kinetics, surface kinetics, reversible equations, transport, mixing, deposition for different types of reactors, direct sensitivity analysis (Senkin). Database of reaction data, graphical postprocessor for results. KINALC (http://www.chem.leeds.ac.uk/Combustion/kinalc.htm) Postprocessor to CHEMKIN for sensitivity and uncertainty analysis, parameter estimation, and mechanism reduction; etc. KINTECUS (http://www.kintecus.com) Compiler/ chemical modeling software. Can run heterogeneous and equilibrium chemistry, generates analytical Jacobians, fit/optimize rate constants, initial concentrations, etc. from data; sensitivity analysis; Excel interface. Can use Chemkin models and databases. CANTERA (http://rayleigh.cds.caltech.edu/~goodwin/cantera) Object-oriented package for chemically-reacting flows. C++ kernel, STL, standard numerical libraries, Interfaces for MATLAB, Python, C++, and Fortran. Capabilities: homogeneous and heterogeneous kinetics, equilibria, reactor modeling, multicomponent transport. LARKIN/LIMKIN (http://www.zib.de/nowak/codes/limkin_1.0/full) Simulation of LARge systems of chemical reaktion KINetics and parameter identification. Parser generates Fortran code for function and Jacobian, or internal data arrays. DYNAFIT (http://www.biokin.com/dynafit) Performs nonlinear least-squares regression of chemical kinetic, enzyme kinetic, or ligand- receptor binding data using experimental data. Parses symbolic equations. May 25, 2004 KPP in a Nutshell The Kinetic PreProcessor Purpose: automatically implement building blocks for large-scale simulations Parses chemical mechanisms Generates Fortran and C code for simulation, and direct and adjoint sensitivity analysis Function, Jacobian, Hessian, Stoichiometric matrix, derivatives of function&Jacobian w.r.t. rate coefficients Treatment of sparsity Comprehensive library of numerical integrators Used in several countries by academia/research/industry Free! http://www.cs.vt.edu/~asandu/Software/KPP May 25, 2004 KPP Architecture kinetic description files Fortran C Fortran C atoms Integrator file Utility file species equations C C options Fortran Fortran inline code Driver file I/O file Scanner / Parser Error checking KPP Compute best sparsity structure Reorder species for Substitution best sparsity pre-processor Compute expression trees for assignments Fortran C Code generation Fortran C prod/destr function integrator function utility functions jacobian code sparsity structure driver function(main) I/O functions May 25, 2004 KPP Example #INCLUDE atoms SUBROUTINE FunVar ( V, R, F, RCT, A_VAR ) INCLUDE 'small.h' REAL*8 V(NVAR), R(NRAD), F(NFIX) #DEFVAR REAL*8 RCT(NREACT), A_VAR(NVAR) O = O; O1D = O; O3 = O + O + O; C A - rate for each equation NO = N + O; NO2 = N + O + O; REAL*8 A(NREACT) C Computation of equation rates #DEFFIX A(1) = RCT(1)*F(2) A(2) = RCT(2)*V(2)*F(2) O2 = O + O; M = ignore; A(3) = RCT(3)*V(3) A(4) = RCT(4)*V(2)*V(3) #EQUATIONS { Small Stratospheric } A(5) = RCT(5)*V(3) O2 + hv = 2O : 2.6E-10*SUN**3; A(6) = RCT(6)*V(1)*F(1) A(7) = RCT(7)*V(1)*V(3) O + O2 = O3 : 8.0E-17; A(8) = RCT(8)*V(3)*V(4) O3 + hv = O + O2 : 6.1E-04*SUN; A(9) = RCT(9)*V(2)*V(5) O + O3 = 2O2 : 1.5E-15; A(10) = RCT(10)*V(5) O3 + hv = O1D + O2 : 1.0E-03*SUN**2; C Aggregate function A_VAR(1) = A(5)-A(6)-A(7) O1D + M = O + M : 7.1E-11; A_VAR(2) = 2*A(1)-A(2)+A(3)-A(4)+A(6)- O1D + O3 = 2O2 : 1.2E-10; &A(9)+A(10) NO + O3 = NO2 + O2 : 6.0E-15; A_VAR(3) = A(2)-A(3)-A(4)-A(5)-A(7)-A(8) NO2 + O = NO + O2 : 1.0E-11; A_VAR(4) = -A(8)+A(9)+A(10) A_VAR(5) = A(8)-A(9)-A(10) NO2 + hv = NO + O : 1.2E-02*SUN; RETURN END May 25, 2004 Sparse Jacobians E.g. SAPRC-99 74+5 spc./211 react. IDEAS: NZ=839, NZLU=920 • Chem. interactions: sparsity pattern (off-line) • Min. fill-in reordering 1 • Expand sparsity structure 10 • Row compressed form • Doolitle LU factorization 20 • Loop-free substitution 30 40 #JACOBIAN [ ON | OFF | SPARSE ] 50 JacVar(…), JacVar_SP(…), JacVar_SP_Vec(…), JacVarTR_SP_Vec(…) 60 KppDecomp(…) 70 74 KppSolve(…), KppSolveTR(…) 1 10 20 30 40 50 60 70 74 May 25, 2004 Computational Efficiency (1/Lapack) Dec Sol Dec+7Sol Linear Algebra Harwell 0.61 0.21 0.35 KPP 0.23 0.06 0.12 5 4.5 S−rodas Lsodes rodas 4 3.5 Stiff Integrators 3 2.5 S−sdirk4 vode sdirk4 2 Number of Accurate Digits 1.5 S−vode chemeq qssa 1 0.5 8 9 10 20 30 50 80 CPU time [seconds] May 25, 2004 Sparse Hessians E.g. SAPRC99. NZ = 848x2 (0.2%) 2 ∂ fi Hi, j,k = ∂y j∂yk •3-tensor • sparse coordinate format • account for symmetry #HESSIAN [ ON | OFF ] HessVar(…) HessVar_Vec(…) HessVarTR_Vec(…) May 25, 2004 Stoichiometric Form #STOICMAT [ ON | OFF ] STOICM (column compressed) dFunVar_dRcoeff(…) ReactantProd(…) dJacVar_dRcoeff(…) JacVarReactantProd(…) SAPRC−99. Stoichiometric Matrix. NZ = 1024 ( 6 % ) 1 20 40 Species 60 79 1 20 40 60 80 100 120 140 160 180 200 211 Reaction May 25, 2004 Requirements for Numerics Numerical stability (stiff chemistry) -6 -2 Accuracy: medium-low (relerr~10 -10 ) Low Computational Time Mass Balance Positivity May 25, 2004 Stiff Integration Methods k k [n] n−i [n] n−i BDF ∑αi y = hn ∑ βi f ()y i=0 i=0 s n+1 n y = y + ∑bj f ()Yj , Implicit j=1 Runge-Kutta s n Yi = y + ∑ ai, j f ()Yj j=1 May 25, 2004 Rosenbrock Methods 4 s 3.5 n +1 n y = y + ∑ m j k j j =1 3 Ros3 i −1 n 2.5 Yi = y + ∑ a i , j k j j =1 i −1 2 SDA 1 n 1 ()hγ I − J ⋅ k i = f ()Yi + ∑ h ci , j k j Rodas3 j =1 1.5 No Newton Iterations 1 VODE TWOSTEP RODAS Suitable for Stiff Systems 0.5 Mass Conservative SEULEX 0 Efficient: Low/Med Accuracy 0.6 0.8 9 1 2 3 4 5 6 7 8 10 CPU time [seconds] May 25, 2004 Direct Decoupled Sensitivity ⎧ y′ = f (t, y, p) S = ∂y ∂p Problem ⎨ l l S′ = J ()t, y, p ⋅ S + f p ()t, y, p 1≤ ≤ m ⎩ l l l l I − hγJ = PT LU ⇒ T ⎡ P L 0 L 0 ⎤ ⎢ −1 T ⎥ ⎡U L 0 ⎤ − hγ ()JS + J U P L 0 ⎢ []1 y p1 L ⎥ ⎢ ⎥ I − hγℑ = ⋅ ⎢ M O M ⎥ ⎢ M 0 O M ⎥ ⎢ −1 T ⎥ ⎣⎢ 0 L U ⎦⎥ − hγ ()JS + J U 0 P L ⎣⎢ []m y pm L ⎦⎥ May 25, 2004 DDM with KPP k −1 y n+1 = ∑ y n−i + hβ f n+1 i=0 k−1 BDF n+1 n+1 n−i n+1 []I − hβ J ⋅ S = S + hβ f p , 1≤ ≤ m l ∑ l l l (Dunker, ’84) i=0 s s i−1 y n+1 = y n + m k 0 , S n+1 = S n + m k l , Y i = y n + a k 0 ∑ i i l l ∑∑i i ij j i=1 i=1 j=1 i−1 1 n 0 i i 1 0 n []hγ I − J ⋅ki = f ()T ,Y , p + ∑ h cij k j + hγ i ft j=1 Rosenbrock ⎛ i−1 ⎞ (Sandu et. al. ‘02) 1 n l i i ⎜ n l ⎟ i i []hγ I − J ⋅ki = J ()T ,Y , p ⋅ S + aij k j + f p ()T ,Y , p ⎜ l ∑ ⎟ l ⎝ j=1 ⎠ i−1 1 l n 0 n n 0 n n n + cij k j + J p ⋅ki + ()H × S ⋅ki + hγ i Jt S + hγ i f p ,t ∑ h l l l l j=1 May 25, 2004 Adjoint Sensitivity Analysis Problem: Stiff ODE, scalar functional. 0 f f y' f t, y , t t t , y(t) 0 y(t ) = () ≤ ≤ ψ ( ) ⇒ ∇ y ψ ( ) Continuous: Take adjoint of problem, then discretize. T f 0 f f 0 λ'= −J ()t, y ⋅λ, t ≥ t ≥ t , λ(t )= (∇ yψ )(y(t )) ⇒ ∇ y0ψ = λ(t ) Discrete: Discretize the problem, then take adjoint: k+1 k k y = F ()y , k = 0,1,L, N −1 k k T k N N N 0 λ = ()()∇ y F y , λ = ()∇ yψ ()y ⇒ ∇ y0ψ ()y = λ Note: In both approaches the forward solution needs to be precomputed and stored. May 25, 2004 Linear Multistep Methods k k [n] n−i [n] n−i Method ∑αi y = hn ∑ βi f ()y i=0 i=0 k k [m] m+i [m] T m+i m+i Continuous Adjoint ∑αi λ = hm ∑ βi J ()y ⋅λ i=0 i=0 k k Discrete Adjoint [m+i] m+i T m [m+i] m+i ∑αi λ = J ()y ⋅∑ hm+i βi λ i=0 i=0 Consistency: ~one-leg method, in general not consistent with continuous adj. eqn. Implementation: with KPP May 25, 2004 Runge Kutta Methods s s n+1 n i i n j Method y = y + h∑bi f ()Y , Y = y + h∑ ai, j f (Y ) i=1 i=1 Continuous Adjoint s s n n+1 T n+1 i i n+1 T n+1 j λ = λ + h∑bi J ()y(t − cih) ⋅Λ , Λ = λ + h∑ ai, j J ()y(t − cih) ⋅Λ i=1 j=1 Discrete Adjoint s ⎡ s ⎤ λn = λn+1 + θ i , θ i = hJ T Y i ⋅ b λn+1 + a θ j (Hager, 2000) ∑ ()⎢ i ∑ j,i ⎥ i=1 ⎣ j=1 ⎦ Consistency (Sandu, 2003) Consider a Runge-Kutta method of order p.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    54 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us