diff erential and diff erential- algebraic systems for the ... · pdf filecontained in these...

15
Guido Buzzi-Ferraris and Flavio Manenti Differential and Differential- Algebraic Systems for the Chemical Engineer Solving Numerical Problems

Upload: nguyenlien

Post on 15-Mar-2018

219 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Diff erential and Diff erential- Algebraic Systems for the ... · PDF filecontained in these books, including this book, to ... 1.5.2 Gauss Formulae 6 ... A.3 Chemical Engineering

Guido Buzzi-Ferraris and Flavio Manenti

Diff erential and Diff erential-Algebraic Systems for the Chemical EngineerSolving Numerical Problems

Page 2: Diff erential and Diff erential- Algebraic Systems for the ... · PDF filecontained in these books, including this book, to ... 1.5.2 Gauss Formulae 6 ... A.3 Chemical Engineering
Page 3: Diff erential and Diff erential- Algebraic Systems for the ... · PDF filecontained in these books, including this book, to ... 1.5.2 Gauss Formulae 6 ... A.3 Chemical Engineering

Guido Buzzi-FerrarisFlavio Manenti

Differential andDifferential-AlgebraicSystems for theChemical Engineer

Page 4: Diff erential and Diff erential- Algebraic Systems for the ... · PDF filecontained in these books, including this book, to ... 1.5.2 Gauss Formulae 6 ... A.3 Chemical Engineering

Related Titles

Buzzi-Ferraris, G., Manenti, F.

Fundamentals and LinearAlgebra for the ChemicalEngineerSolving Numerical Problems

2010

Print ISBN: 978-3-527-32552-8

Buzzi-Ferraris, G., Manenti, F.

Interpolation and RegressionModels for the ChemicalEngineerSolving Numerical Problems

2010

Print ISBN: 978-3-527-32652-5

Buzzi-Ferraris, Guido/Manenti, Flavio

Nonlinear Systems andOptimization for theChemical EngineerSolving Numerical Problems

2013

Print ISBN: 978-3-527-33274-8;

also available in digital formats

Velten, K.

Mathematical Modelingand SimulationIntroduction for Scientists andEngineers

2009

Print ISBN: 978-3-527-40758-3,

also available in digital formats

Page 5: Diff erential and Diff erential- Algebraic Systems for the ... · PDF filecontained in these books, including this book, to ... 1.5.2 Gauss Formulae 6 ... A.3 Chemical Engineering

Guido Buzzi-Ferraris and Flavio Manenti

Differential and Differential-AlgebraicSystems for the Chemical Engineer

Solving Numerical Problems

Page 6: Diff erential and Diff erential- Algebraic Systems for the ... · PDF filecontained in these books, including this book, to ... 1.5.2 Gauss Formulae 6 ... A.3 Chemical Engineering

Authors

Prof. Guido Buzzi-FerrarisPolitecnico di MilanoCMIC Department “Giulio Natta”Piazza Leonardo da Vinci 3220133 MilanoItaly

Prof. Flavio ManentiPolitecnico di MilanoCMIC Department “Giulio Natta”Piazza Leonardo da Vinci 3220133 MilanoItaly

All books published by Wiley-VCH are carefullyproduced. Nevertheless, authors, editors, andpublisher do not warrant the informationcontained in these books, including this book, tobe free of errors. Readers are advised to keepin mind that statements, data, illustrations,procedural details or other items mayinadvertently be inaccurate.

Library of Congress Card No.: applied for

British Library Cataloguing-in-Publication Data

A catalogue record for this book is available fromthe British Library.

Bibliographic information published by theDeutsche Nationalbibliothek

The Deutsche Nationalbibliothek lists this publi-cation in the Deutsche Nationalbibliografie;detailed bibliographic data are available on theInternet at http://dnb.d-nb.de.

2014 Wiley-VCH Verlag GmbH & Co. KGaA,Boschstr. 12, 69469 Weinheim, Germany

All rights reserved (including those of translationinto other languages). No part of this book maybe reproduced in any form – by photoprinting,microfilm, or any other means – nor transmittedor translated into a machine language withoutwritten permission from the publishers.Registered names, trademarks, etc. used in thisbook, even when not specifically marked as such,are not to be considered unprotected by law.

Print ISBN: 978-3-527-33275-5

ePDF ISBN: 978-3-527-66713-0

ePub ISBN: 978-3-527-66712-3

Mobi ISBN: 978-3-527-66711-6

oBook ISBN: 978-3-527-66710-9

Cover Design Adam Design, Weinheim

Typesetting Thomson Digital, Noida, India

Printing and Binding Markono Print MediaPte Ltd, Singapore

Printed on acid-free paper

Page 7: Diff erential and Diff erential- Algebraic Systems for the ... · PDF filecontained in these books, including this book, to ... 1.5.2 Gauss Formulae 6 ... A.3 Chemical Engineering

Contents

Preface IX

1 Definite Integrals 11.1 Introduction 11.2 Calculation of Weights 21.3 Accuracy of Numerical Methods 31.4 Modification of the Integration Interval 41.5 Main Integration Methods 51.5.1 Newton–Cotes Formulae 51.5.2 Gauss Formulae 61.6 Algorithms Derived from the Trapezoid Method 91.6.1 Extended Newton–Cotes Formulae 101.6.2 Error in the Extended Formulae 111.6.3 Extrapolation of the Extended Formulae 121.7 Error Control 151.8 Improper Integrals 161.9 Gauss–Kronrod Algorithms 171.10 Adaptive Methods 191.10.1 Method Derived from the Gauss–Kronrod Algorithm 201.10.2 Method Derived from the Extended Trapezoid Algorithm 211.10.3 Method Derived from the Gauss–Lobatto Algorithm 221.11 Parallel Computations 231.12 Classes for Definite Integrals 231.13 Case Study: Optimal Adiabatic Bed Reactors for Sulfur Dioxide with

Cold Shot Cooling 26

2 Ordinary Differential Equations Systems 312.1 Introduction 312.2 Algorithm Accuracy 352.3 Equation and System Conditioning 362.4 Algorithm Stability 402.5 Stiff Systems 48

V

Page 8: Diff erential and Diff erential- Algebraic Systems for the ... · PDF filecontained in these books, including this book, to ... 1.5.2 Gauss Formulae 6 ... A.3 Chemical Engineering

2.6 Multistep and Multivalue Algorithms for Stiff Systems 502.7 Control of the Integration Step 512.8 Runge–Kutta Methods 532.9 Explicit Runge–Kutta Methods 542.9.1 Strategy to Automatically Control the Integration Step 562.9.2 Estimation of the Local Error 582.9.2.1 Runge–Kutta–Merson Algorithm 582.9.2.2 Richardson Extrapolation 592.9.2.3 Embedded Algorithms 592.10 Classes Based on Runge–Kutta Algorithms in the

BzzMath Library 612.11 Semi-Implicit Runge–Kutta Methods 642.12 Implicit and Diagonally Implicit Runge–Kutta Methods 662.13 Multistep Algorithms 682.13.1 Adams–Bashforth Algorithms 702.13.2 Adams–Moulton Algorithms 712.14 Multivalue Algorithms 722.14.1 Control of the Local Error 762.14.2 Change the Integration Step 782.14.3 Changing the Method Order 792.14.4 Strategy for Step and Order Selection 822.14.5 Initializing a Multivalue Method 842.14.6 Selecting the First Integration Step 842.14.7 Selecting the Multivalue Algorithms 842.14.7.1 Adams–Moulton Algorithms 852.14.7.2 Gear Algorithms 852.14.8 Nonlinear System Solution 862.15 Multivalue Algorithms for Nonstiff Problems 882.16 Multivalue Algorithms for Stiff Problems 902.16.1 Robustness in Stiff Problems 932.16.1.1 Eigenvalues with a Very Large Imaginary Part 932.16.1.2 Problems with Hard Discontinuities 932.16.1.3 Variable Constraints 942.16.2 Efficiency in Stiff Problems 952.16.2.1 When to Factorize the Matrix G 952.16.2.2 How to Factorize the Matrix G 962.16.2.3 When to Update the Jacobian J 962.16.2.4 How to Update the Jacobian J 972.17 Multivalue Classes in BzzMath Library 992.18 Extrapolation Methods 1072.19 Some Caveats 108

3 ODE: Case Studies 1113.1 Introduction 1113.2 Nonstiff Problems 111

VI Contents

Page 9: Diff erential and Diff erential- Algebraic Systems for the ... · PDF filecontained in these books, including this book, to ... 1.5.2 Gauss Formulae 6 ... A.3 Chemical Engineering

3.3 Volterra System 1163.4 Simulation of Catalytic Effects 1173.5 Ozone Decomposition 1193.6 Robertson’s Kinetic 1203.7 Belousov’s Reaction 1213.8 Fluidized Bed 1223.9 Problem with Discontinuities 1233.10 Constrained Problem 1243.11 Hires Problem 1263.12 Van der Pol Oscillator 1283.13 Regression Problems with an ODE Model 1293.14 Zero-Crossing Problem 1393.15 Optimization-Crossing Problem 1423.15.1 Optimization of a Batch Reactor 1423.15.2 Maximum Level in a Gravity-Flow Tank in Transient

Conditions 1453.15.3 Optimization of a Batch Reactor 1483.16 Sparse Systems 1503.17 Use of ODE Systems to Find Steady-State Conditions of Chemical

Processes 1553.18 Industrial Case: Spectrokinetic Modeling 1573.18.1 CATalytic-Post-Processor 1593.18.2 Nonreactive CFD Modeling 1593.18.3 User-Defined Function 1603.18.4 Reactor Modeling 1603.18.5 Numerical Methods 1623.18.6 Dynamic Simulation of an Operando FTIR Cell Used to Study NOx

Storage on a LNT Catalyst 1633.18.7 CAT-PP Simulation Results 1663.18.8 Nomenclature 169

4 Differential and Algebraic Equation Systems 1714.1 Introduction 1714.2 Multivalue Method 1744.3 DAE Classes in the BzzMath Library 175

5 DAE: Case Studies 1875.1 Introduction 1875.2 Van der Pol Oscillator 1875.3 Regression Problems with the DAE Model 1895.4 Sparse Structured Matrices 1935.5 Industrial Case: Distillation Unit 1995.5.1 Management of System Sparsity and Unstructured

Elements 2005.5.2 DAE Solver for Partially Structured Systems 201

Contents VII

Page 10: Diff erential and Diff erential- Algebraic Systems for the ... · PDF filecontained in these books, including this book, to ... 1.5.2 Gauss Formulae 6 ... A.3 Chemical Engineering

5.5.3 Case-Study for Solver Validation: Nonequilibrium DistillationColumn Model 202

5.5.4 Numerical Results 205Notations for Table 5.1 208Subscripts 208Symbols 208

6 Boundary Value Problems 2096.1 Introduction 2096.1.1 Integral Relationships 2116.1.2 Continuation Methods 2126.1.3 Problems with an Unknown Constant Parameter 2146.1.4 Problem with Unknown Boundary 2146.2 Shooting Methods 2156.3 Special Boundary Value Problems 2176.3.1 Runge–Kutta Implicit Methods 2186.4 More General BVP Methods 2216.4.1 Collocation Method 2226.4.2 Galerkin Method 2226.4.3 Momentum Method 2236.4.4 Least-Squares Method 2236.5 Selection of the Approximating Function 2246.6 Which and How Many Support Points Have to Be Considered? 2256.7 Which Variables Should Be Selected as Adaptive Parameters? 2316.8 The BVP Solution Classes in the BzzMath Library 2376.9 Adaptive Mesh Selection 2516.10 Case studies 253

Reference 265

Appendix A: Linking the BzzMath Library to Matlab 269A.1 Introduction 269A.2 BzzSum Function 269A.2.1 Header File 270A.2.2 MEX Function 270A.2.3 C++ Part 271A.2.4 Compiling 272A.3 Chemical Engineering Example 272A.3.1 Definition of a New Class 274A.3.2 Main Program in C++ 275A.3.3 Main Program in Matlab 277

Appendix B: Copyrights 279

Index 281

VIII Contents

Page 11: Diff erential and Diff erential- Algebraic Systems for the ... · PDF filecontained in these books, including this book, to ... 1.5.2 Gauss Formulae 6 ... A.3 Chemical Engineering

Preface

This book is aimed at students and professionals needing to numerically solvescientific problems involving differential and algebraic–differential systems.We assume our readers have the basic familiarity with numerical methods that

any undergraduate student in scientific or engineering disciplines should have.We also recommend at least a basic knowledge of C++ programming.Readers who do not have any of the above should first refer to the companion

books in this series:

� Guido Buzzi-Ferraris (1994), Scientific C++: Building Numerical Libraries,the Object-Oriented Way, 2nd ed., Addison-Wesley, Cambridge UniversityPress, 479 pp, ISBN: 0-201-63192-X.� Guido Buzzi-Ferraris and Flavio Manenti (2010), Fundamentals and LinearAlgebra for the Chemical Engineer: Solving Numerical Problems, Wiley-VCHVerlag GmbH, Weinheim, 360 pp, ISBN: 978-3-527-32552-8.

These books explain and apply the fundamentals of numerical methods inC++.Although many books on differential and algebraic–differential systems

approach these topics from a theoretical viewpoint only, we wanted to explainthe theoretical aspects in an informal way, by offering an applied approach tothis scientific discipline. In fact, this volume focuses on the solution of concreteproblems and includes many examples, applications, code samples, program-ming, and overall programs, to give readers not only the methodology to tackletheir specific problems but also the structure to implement an appropriate pro-gram and ad hoc algorithms to solve it.The book describes numerical methods, high-performance algorithms, specific

devices, and innovative techniques and strategies, all of which are implementedin a well-established numerical library: the BzzMath library, developed by Prof.Guido Buzzi-Ferraris at the Politecnico di Milano and downloadable from http://www.chem.polimi.it/homes/gbuzzi.This gives readers the invaluable opportunity to use and implement their code

in a numerical library that involves some of the most appealing algorithms in thesolution of differential equations, algebraic systems, optimal problems, data

ix

Page 12: Diff erential and Diff erential- Algebraic Systems for the ... · PDF filecontained in these books, including this book, to ... 1.5.2 Gauss Formulae 6 ... A.3 Chemical Engineering

regressions for linear and nonlinear cases, boundary value problems, linear pro-gramming, and so on.Unfortunately, unlike many other books that cover only theory, all these

numerical contents cannot be explained in a single volume because of theirapplication to real problems and the need for specific code examples. We there-fore decided to split the numerical analysis topics into several distinct areas, eachone covered by an ad hoc book by the same authors and adopting the samephilosophy:

� Vol. I: Buzzi-Ferraris and Manenti (2010), Fundamentals and Linear Alge-bra for the Chemical Engineer: Solving Numerical Problems, Wiley-VCHVerlag GmbH, Weinheim, Germany.� Vol. II: Buzzi-Ferraris and Manenti (2010), Interpolation and RegressionModels for the Chemical Engineer: Solving Numerical Problems, Wiley-VCHVerlag GmbH, Weinheim, Germany.� Vol. III: Buzzi-Ferraris and Manenti (2014) Nonlinear Systems and Optimi-zation for the Chemical Engineer: Solving Numerical Problems, Wiley-VCHVerlag GmbH, Weinheim, Germany.� Vol. IV: Buzzi-Ferraris and Manenti 2014, Differential and Differential–Algebraic Systems for the Chemical Engineer: Solving Numerical Problems,Wiley-VCH Verlag GmbH, Weinheim, Germany.� Vol. V: Buzzi-Ferraris and Manenti, Linear Programming for the ChemicalEngineer: Solving Numerical Problems, Wiley-VCH Verlag GmbH, Wein-heim, Germany, in progress.

This book proposes algorithms and methods to solve differential anddifferential–algebraic systems, whereas the companion books cover linear alge-bra and linear systems, data analysis and regressions, and nonlinear systems andoptimization, respectively. After having introduced the theoretical content, allexplain their application in detail and provide optimized C++ code samples tosolve general problems. This allows readers to use the proposed programs totackle their specific numerical issues more easily by using the BzzMath library.

The BzzMath library can be used in any scientific field in which there is a needto solve numerical problems. Its primary use is in engineering, but it can also beused in statistics, medicine, economics, physics, management, environmental sci-ences, biosciences, and so on.

Outline of This Book

This book deals with the solution of differential and differential–algebraic sys-tems. Analogously to the aforementioned companion books, it proposes a seriesof robust and high-performance algorithms implemented in the BzzMath libraryto tackle these multifaceted and notoriously difficult issues.

x Preface

Page 13: Diff erential and Diff erential- Algebraic Systems for the ... · PDF filecontained in these books, including this book, to ... 1.5.2 Gauss Formulae 6 ... A.3 Chemical Engineering

Definite integrals are solved in Chapter 1. Existing methods and novel alterna-tives are proposed, implemented in the BzzMath library, and adopted to solvesome well-established literature-based tests. Parallel computations are alsointroduced.Ordinary differential equation systems are broached in Chapter 2. Condition-

ing, stability, and stiffness are described in detail by giving specific informationon how to handle them whenever they arise. The BzzMath library also imple-ments a wide set of algorithms to solve classical problems and chemical/processengineering problems.Chapter 3 reports a collection of literature and industrial problems based on

ordinary differential equation systems. The basics of the physical problem aredescribed and the model behind it is given together as the initial conditions.Implementation tricks, special functions of the classes, and suggestions toimprove the solution’s accuracy and efficiency are provided through variousexamples.Differential–algebraic systems are explored in greater depth in Chapter 4.

Special algorithms to handle this family of problems are described and imple-mented in the BzzMath library. Classes to handle the sparsity and structure ofsuch systems typical of chemical engineering are also described.Literature-based examples and industrial case studies are collected in Chapter 5.

Implementation tricks and useful functions to handle very large and sparsesystems with/without parallel computing are introduced.Chapter 6 also introduces a novel general class to solve boundary value prob-

lems. Very stiff problems, such as shock waves and peaks, are automaticallyidentified and the solution strategy self-adapt to such a situation.

Notation

These books contain icons not only to highlight some important featuresand concepts but also to underscore that there is potential for serious errors inprogramming or in selecting the appropriate numerical methods.

New concepts or new ideas. As they may be difficult to understand, it is neces-sary to change the point of view.

Description and remarks on important concepts and smart and interestingideas.

Positive aspects, benefits, and advantages of algorithms, methods, and techniquesin solving a specific problem.

Negative aspects and disadvantages of algorithms, methods, and techniques insolving a specific problem.

Some aspects are intentionally neglected.

Preface xi

Page 14: Diff erential and Diff erential- Algebraic Systems for the ... · PDF filecontained in these books, including this book, to ... 1.5.2 Gauss Formulae 6 ... A.3 Chemical Engineering

Caveat, risk of making sneaky mistakes, and spread errors.

Description of some BzzMath library classes or functions.

Definitions and properties.

Conditioning status of the mathematical formulation.

Algorithm stability.

The algorithm efficiency assessment.

The problem, method, . . . is obsolete.

Example folders collected in WileyVol4.zip or in BzzMath7.zip files availa-ble at http://www.chem.polimi.it/homes/gbuzzi.

BzzMath Library Style

In order to facilitate both implementation and program reading, it was necessaryto diversify the style of the identifiers.C++ is a case-sensitive language and thus distinguishes between capital letters

and small ones. Moreover, C++ identifiers are unlimited in the number of charsfor their name, unlike FORTRAN77 identifiers. It is thus possible, and we feelindispensable, to use these prerogatives by giving every variable, object, constant,function, and so on, an identifier that allows us to immediately recognize whatwe are looking at.Programmers typically use two different styles to characterize an identifier that

consists of two words. One possibility is to separate the word by means of anunderscore, that is, dynamic_viscosity. The other possibility is to begin thesecond word with a capital letter, that is, dynamicViscosity.The style adopted in the BzzMath library is described hereinafter:

� Constants: The identifier should have more than two capital letters. Ifseveral words are to be used, they must be separated by an underscore.Some good examples are MACH_EPS, PI, BZZ_BIG_FLOAT, and

TOLERANCE.Bad examples are A, Tolerance, tolerance, tol, and MachEps.� Variables (standard type, derived type, class object): When the identifier

consists of a single word, it may consist either of different chars startingwith a small letter or of a single char either capitalized or small. On the

xii Preface

Page 15: Diff erential and Diff erential- Algebraic Systems for the ... · PDF filecontained in these books, including this book, to ... 1.5.2 Gauss Formulae 6 ... A.3 Chemical Engineering

other hand, when the identifier consists of more than a single word, eachword should start with a capital letter except for the first one, whereas allthe remaining letters have to be small.Some good examples are machEpsylon, tol, x, A, G, dynamicViscos-

ity, and yDoubleValue.Bad examples are Aa, AA, A_A, Tolerance, tOLerance, MachEps, and

mach_epsilon.� Functions: The identifier should have at least two chars: the first is capital,whereas the others are not. When the identifier consists of more words,each of them has to start with a capital letter.Some good examples are MachEpsilon, Tolerance, Aa, Abcde,

DynamicViscosity, and MyBestFunction.Bad examples are A, F, AA, A_A, tolerance, TOL, and machEps.� New Types of Object: This is similar to the function identifier, but in order

to distinguish it from functions, it is useful to add a prefix. All the classesbelonging to the BzzMath library are characterized by the prefix Bzz.Some good examples are BzzMatrix, BzzVector, BzzMinimum, and

BzzOdeStiff.Bad examples are A, matrix, and Matrix.

Another style-based decision was to standardize the bracket positions at thebeginning and at the end of a block to make C++ programs easier to read.In this case also, programmers adopt two alternatives: some put the first

bracket on the same row where the block starts, while some others put it on thefollowing line with the same indenting of the bracket that closes the block.The former case takes to the following style:

for(i=1;i<=n;i++){. . .

}if(x>1.){

. . .}

whereas the latter case takes to the following style:

for(i=1;i<=n;i++){

. . .}

if(x>1.){

. . .}

This latter alternative is adopted in the BzzMath library.

Preface xiii