computer application in mechanical power engineering
DESCRIPTION
Computer Application in mechanical power Engineering byHossam AbdelMeguidTRANSCRIPT
Computer Application in Mechanical Power Engineering - III
by
Dr. Hossam S.S. AbdelMeguid
2013-2014
Mansoura University
Faculty of Engineering
Co
mp
uter A
pp
lication
- III
Dr. H
ossam
S.S
. Ab
delM
egu
id
Mansoura University
Faculty of Engineering
2012-2013
Computer Application In Mechanical Power Engineering - III
Dr. Hossam S.S. AbdelMeguid
ii
ISBN: 978-977-6005-89-1
DEPOSIT NUMBER: 23598/2012
iii
Table of Contents PREFACE .......................................................................................................... IX
PART 1: FUNDAMENTALS ................................................................................ 1
1 FUNDAMENTALS ......................................................................................... 1
1.1 Introduction ..................................................................................... 1
1.2 Incentives for process modelling ....................................................... 1
1.3 Systems ............................................................................................ 3 1.3.1 Classification based on thermodynamic principles .......................................................... 3 1.3.2 Classification based on number of phases ...................................................................... 4
1.4 Classification of Models.................................................................... 5
1.5 State variables and state equations.................................................. 6
1.6 Classification of theoretical models .................................................. 6 1.6.1 Steady state vs. unsteady state ...................................................................................... 6 1.6.2 Lumped vs. distributed parameters................................................................................ 7 1.6.3 Linear vs. non-linear ...................................................................................................... 7 1.6.4 Continuous vs. discrete.................................................................................................. 8 1.6.5 Deterministic vs. probabilistic ........................................................................................ 8
1.7 Building steps for a mathematical model ......................................... 8
1.8 Conservation Laws ......................................................................... 10 1.8.1 Total mass balance ...................................................................................................... 11 1.8.2 Component balance .................................................................................................... 12 1.8.3 Momentum balance .................................................................................................... 12 1.8.4 Energy balance ............................................................................................................ 13
1.9 Microscopic balance ....................................................................... 13
1.10 Macroscopic balance .................................................................. 14
1.11 Transport rates ........................................................................... 15 1.11.1 Mass Transport ....................................................................................................... 15 1.11.2 Momentum transport ............................................................................................. 16 1.11.3 Energy transport ..................................................................................................... 18
.1.1 Thermodynamic relations ........................................................... 20
1.13 Phase Equilibrium ....................................................................... 21
1.14 Chemical kinetics ........................................................................ 24
1.15 Control Laws ............................................................................... 25
1.16 Degrees of Freedom .................................................................... 26
1.17 Model solution ............................................................................ 27
.1.1 Model validation ......................................................................... 28
1.19 Problems ..................................................................................... 29
2 MATHEMATICAL MODELS FOR MECHANICAL AND CHEMICAL PROCESSES ................ 30
2.1 Lumped Parameter Systems ........................................................... 31 2.1.1 Liquid Storage Tank ..................................................................................................... 31 2.1.2 Stirred Tank Heater ..................................................................................................... 34 2.1.3 Gas-Phase Pressurized CSTR ........................................................................................ 39
iv
2.1.4 Mixing Process ............................................................................................................ 41 2.1.5 Heat Exchanger ........................................................................................................... 45 2.1.6 Heat Exchanger with Steam ......................................................................................... 49
2.2 Examples of Distributed Parameter Systems................................... 51 2.2.1 Liquid Flow in a Pipe .................................................................................................... 51 2.2.2 Velocity profile inside a pipe ........................................................................................ 53 2.2.3 Temperature profile in a heated cylindrical Rod ........................................................... 55 2.2.4 Heat Exchanger: Distributed parameter model ............................................................. 58
2.3 Problems ........................................................................................ 60
PART 2: SIMULTANEOUS LINEAR EQUATIONS ............................................... 63
3 INTRODUCTION ......................................................................................... 63
3.1 Special types of matrices? .............................................................. 63
4 SYSTEM OF EQUATIONS .............................................................................. 66
4.1 Solving systems of equations using matrix algebra ......................... 66
4.2 A consistent / inconsistent system of equations.............................. 68
4.3 Distinguish between a consistent and inconsistent system of equations ................................................................................................. 69
4.4 A unique solution of a system of equation ...................................... 75
5 GAUSS-SEIDEL METHOD ............................................................................. 79
5.1 Another method to solve a set of simultaneous linear equations .... 79
5.2 Pitfall of most iterative methods .................................................... 84
5.3 Matlab code for Gauss Seidel ......................................................... 89
6 CASE STUDY (STEADY-STATE ANALYSIS OF A SYSTEM OF REACTORS) ........................ 91
7 PROBLEMS ............................................................................................... 95
PART 3: ORDINARY DIFFERENTIAL EQUATIONS ............................................. 99
8 INTRODUCTION ......................................................................................... 99
8.1 Initial Value Problems .................................................................. 101 8.1.1 Taylor Series Expansion ............................................................................................. 102 8.1.2 Truncation Errors ...................................................................................................... 103
9 EULER'S METHOD.................................................................................... 104
9.1 Algorithm of Euler Method ........................................................... 105
10 MODIFIED EULER'S (HEUN'S) METHOD ...................................................... 108
10.1 Algorithm of Heun’s Method ..................................................... 108
10.2 Matlab code for Euler method .................................................. 111
11 RUNGE-KUTTA METHOD........................................................................ 112
11.1 Runge-Kutta Method of second order ....................................... 112 11.1.1 Algorithm of Second Order Runge-Kutta Method .................................................. 114
11.2 Fourth Order Runge-Kutta ......................................................... 115 11.2.1 Algorithm of Fourth Order Runge-Kutta Method ................................................... 117
11.3 Runge-Kutta with adaptive step size ......................................... 118
11.4 Matlab code for 4th order Runge-Kutta method ........................ 119
12 SYSTEM OF COUPLED ODE'S ............................................................ 121
12.1 Euler's method for system of coupled ODE's .............................. 122
v
12.2 Algorithm of Euler method to system of ODEs ........................... 122
12.3 Matlab code or a coupled system of ODE using Euler method ... 124
12.4 Fourth order Runge-Kutta method for system of coupled ODE's 125 12.4.1 Algorithm of Coupled 4th Order Runge-Kutta .......................................................... 125
12.5 Matlab code or a coupled system of ODE using 4th order Runge-Kutta 128
12.6 Stability of the integration methods .......................................... 129
12.7 Stiff differential equations......................................................... 131
12.8 Other solution techniques ......................................................... 133
13 BOUNDARY VALUE PROBLEM .................................................................. 135
13.1 Introduction .............................................................................. 135
13.2 Numerical methods for the solution of BVP problems................ 138
13.3 Shooting methods ..................................................................... 139 13.3.1 algorithm of the shooting method ......................................................................... 143
13.4 Matlabe code for 4th order Runge-Kutta –shooting method for a linear BVP .............................................................................................. 147
13.5 Finite-Difference Methods ......................................................... 148
13.6 Finite-Difference Methods for Linear Problems ......................... 152
13.7 Handling different types boundary conditions ........................... 154
13.8 Other solution techniques ......................................................... 156
14 CASE STUDY (USING ODES TO ANALYZE THE TRANSIENT RESPONSE OF A REACTOR) . 157
15 PROBLEMS ......................................................................................... 161
PART 4: PARTIAL DIFFERENTIAL EQUATIONS .............................................. 163
16 INTRODUCTION TO PARTIAL DIFFERENTIAL EQUATIONS .................................. 163
16.1 Introduction .............................................................................. 163
16.2 Basics ........................................................................................ 164 16.2.1 Conservation Principles ......................................................................................... 164 16.2.2 Partial Differential Equation (PDE) ......................................................................... 164 16.2.3 From Ordinary to a Partial Differential Equation..................................................... 165 16.2.4 Types and Classification of Partial Differential Equations ........................................ 168
16.3 Discretization Methods ............................................................. 172
16.4 The Nature of Numerical Methods ............................................ 173 16.4.1 The Task ............................................................................................................... 173 16.4.2 The Discretization Concept .................................................................................... 174 16.4.3 The Structure of the Discretization Equation .......................................................... 175
16.5 Methods of Deriving the Discretization Equations ..................... 176 16.5.1 Taylor-Series Formulation...................................................................................... 176 16.5.2 Control-Volume Formulation ................................................................................. 177 16.5.3 An Illustrative Example for Control volume method ............................................... 179
16.6 Basic Rules ................................................................................ 182
16.7 Summery .................................................................................. 183
17 FINITE DIFFERENCE METHODS ................................................................. 184
17.1 Introduction .............................................................................. 184
vi
17.2 Forming Finite Differences ........................................................ 184 17.2.1 Taylor Series ......................................................................................................... 185
18 FINITE DIFFERENCE FORMULATION FOR ELLIPTIC EQUATION ........................... 188
18.1 Laplace's Equation (Steady Conduction) .................................... 188
18.2 The Direct Method of Solving Laplace's Equation ...................... 192 18.2.1 Solving the System of Algebraic Equations ............................................................. 194
18.3 A Numerical Example for Elliptic (Laplace's) Equation ............... 195
18.4 Matlab Code and Script for Elliptic (Laplace's) Equation (Heat Conduction) ........................................................................................... 201
18.5 Poisson's Equation (Steady Heat conduction with Generation) .. 206
18.6 A Numerical Example for Poisson's Equation ............................. 207
18.7 Matlab Code and Script for Poisson’s Equation ......................... 210
19 PARABOLIC EQUATION (UNSTEADY HEAT CONDUCTION) ............................... 219
19.1 Unsteady Conduction ................................................................ 219
19.2 Simple Explicit Scheme .............................................................. 220
19.3 Implicit Schemes ....................................................................... 223
19.4 Numerical example for unsteady 1D heat conduction ............... 224 19.4.1 Example and Matlab code for unsteady 1D heat conduction .................................. 226
19.5 Unsteady Conduction in Two and Three Dimensions ................. 234 19.5.1 Example and Matlab code for 1D and 2D Unsteady Conduction .............................. 235
19.6 Unsteady Conduction in 2D and 3D with Heat generation ......... 243
20 CONVECTION AND DIFFUSION (CONDUCTION) ............................................. 247
20.1 Steady 1-D Convection and Diffusion (conduction) .................... 248 20.1.1 A Preliminary Derivation........................................................................................ 249 20.1.2 The Upwind Scheme.............................................................................................. 250
20.2 Unsteady Convection Diffusion with Heat Generation in 1D ...... 252 20.2.1 Example and Matlab codes .................................................................................... 253
20.3 Unsteady Convection Diffusion with Heat Generation in 2D ...... 258 20.3.1 Example and Matlab codes .................................................................................... 259
21 HYPERBOLIC EQUATION ......................................................................... 265
22 ALTERNATIVE BOUNDARY CONDITIONS ...................................................... 266
PART5: PROGRAMMING WITH MATLAB ..................................................... 267
23 MATLAB BASICS ................................................................................... 267
23.1 The MATLAB Working Environment .......................................... 267
23.2 The m-file .................................................................................. 270
23.3 Inline function ........................................................................... 273
23.4 Control Flow ............................................................................. 274 23.4.1 The for loop .......................................................................................................... 274 23.4.2 The while loops ..................................................................................................... 276 23.4.3 The if-else-end constructions................................................................................. 277 23.4.4 The switch-case constructions ............................................................................... 278
23.5 Relations and logical operations ............................................... 279
23.6 Rounding to integers ................................................................. 280
vii
23.7 Matlab Graphics ....................................................................... 282 23.7.1 2-D graphics .......................................................................................................... 283 23.7.2 3-D graphs ............................................................................................................ 286
23.8 Animation ................................................................................. 287
REFERENCES ............................................................................................... 289
viii
ix
Preface
This book evolved from lecture notes developed last year of teaching this
material, mostly in computer application in mechanical power engineering and
process modelling and simulation at Mansoura University and NDETI. The
course is taken by graduate students, along with post graduate students.
Exercises and assignments are an important aspect of any such course and
many have been developed in conjunction with this book. Rather than
lengthening the text, they are available on the book's webpage:
Https://sites.google.com/site/hssaleh/
The webpage also contains Matlab m-files that illustrate how to implement
different numerical methods for soling ordinary and partial deferential
equations, and that may serve as a starting point for further study of the
methods. A number of the exercises require programming on the part of the
student, or making changes to the Matlab programs provided. Some of these
exercises are fairly simple, designed to enable students to observe first hand
the behaviour of numerical methods described in the text. Others are more
open-ended and could form the basis for a many project.
The book is organized into five main parts. Part 1 deals with fundamentals of
modelling and simulation. Part 2 deals with solving linear system of equation.
Part 3 concerns time-dependent problems, starting with the initial value
problem for ODEs and moving on to initial-boundary value problems. Part 4
concerns the finite difference solution of energy equation in 1, 2 and 3
dimensions, with an emphasis on systems arising from finite difference
approximations. Part 5 gives a brief introduction about the programming with
matlab and explores its main features that will be used in this book.
x
The emphasis is on building an understanding of the essential ideas that
underlie the development, analysis, and practical use of numerical methods
for solving ODE and PDE. Stability theory necessarily plays a large role, and I
have attempted to explain several key concepts, their relation to one another,
and their practical implications. I include some proofs of convergence in order
to motivate the various definitions of "stability" and to show how they relate
to error estimates, but have not attempted to rigorously prove all results in
complete generality. I have also tried to give an indication of some of the more
practical aspects of the algorithms without getting too far into implementation
details. My goal is to form a foundation from which students can approach the
vast literature on more advanced topics and further explore the theory and/or
use of numerical solution methods for ODE and PDE according to their
interests and needs.
I have also been influenced by other books covering these same topics, and
many excellent ones exist at all levels. Advanced books go into more detail on
countless subjects only briefly discussed here, including for example [1-4].
There are also a number of general introductory books that may be useful as a
complement to the presentation found here, including for example [5-9]
Dr. Hossam S.S. AbdelMeguid,
September, 2012