Вы находитесь на странице: 1из 11

Computer Application - III

Mansoura University
Faculty of Engineering

Dr. Hossam S.S. AbdelMeguid

Computer Application
in Mechanical Power Engineering - III
by
Dr. Hossam S.S. AbdelMeguid
2013-2014

Mansoura University
Faculty of Engineering

Computer Application
In Mechanical Power Engineering - III
Dr. Hossam S.S. AbdelMeguid

2012-2013

ISBN: 978-977-6005-89-1
DEPOSIT NUMBER: 23598/2012

ii

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
1.3.2

1.4
1.5
1.6

Classification based on thermodynamic principles.......................................................... 3


Classification based on number of phases ...................................................................... 4

Classification of Models.................................................................... 5
State variables and state equations.................................................. 6
Classification of theoretical models .................................................. 6

1.6.1
1.6.2
1.6.3
1.6.4
1.6.5

1.7
1.8

Steady state vs. unsteady state ...................................................................................... 6


Lumped vs. distributed parameters................................................................................ 7
Linear vs. non-linear ...................................................................................................... 7
Continuous vs. discrete.................................................................................................. 8
Deterministic vs. probabilistic ........................................................................................ 8

Building steps for a mathematical model ......................................... 8


Conservation Laws ......................................................................... 10

1.8.1
1.8.2
1.8.3
1.8.4

Total mass balance ...................................................................................................... 11


Component balance .................................................................................................... 12
Momentum balance .................................................................................................... 12
Energy balance ............................................................................................................ 13

1.9 Microscopic balance ....................................................................... 13


1.10
Macroscopic balance .................................................................. 14
1.11
Transport rates ........................................................................... 15
1.11.1
1.11.2
1.11.3

Mass Transport ....................................................................................................... 15


Momentum transport ............................................................................................. 16
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
2.1.2
2.1.3

Liquid Storage Tank ..................................................................................................... 31


Stirred Tank Heater ..................................................................................................... 34
Gas-Phase Pressurized CSTR ........................................................................................ 39

iii

2.1.4
2.1.5
2.1.6

2.2

Mixing Process ............................................................................................................ 41


Heat Exchanger ........................................................................................................... 45
Heat Exchanger with Steam ......................................................................................... 49

Examples of Distributed Parameter Systems................................... 51

2.2.1
2.2.2
2.2.3
2.2.4

Liquid Flow in a Pipe .................................................................................................... 51


Velocity profile inside a pipe ........................................................................................ 53
Temperature profile in a heated cylindrical Rod ........................................................... 55
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
8.1.2

Taylor Series Expansion ............................................................................................. 102


Truncation Errors ...................................................................................................... 103

EULER'S METHOD.................................................................................... 104


9.1 Algorithm of Euler Method ........................................................... 105
10 MODIFIED EULER'S (HEUN'S) METHOD ...................................................... 108
10.1
Algorithm of Heuns 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

11.2
11.2.1

Algorithm of Second Order Runge-Kutta Method .................................................. 114

Fourth Order Runge-Kutta......................................................... 115


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
iv

12.2
12.3
12.4
12.4.1

Algorithm of Euler method to system of ODEs ........................... 122


Matlab code or a coupled system of ODE using Euler method ... 124
Fourth order Runge-Kutta method for system of coupled ODE's 125
Algorithm of Coupled 4th Order Runge-Kutta.......................................................... 125

12.5
Matlab code or a coupled system of ODE using 4 th order RungeKutta 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
16.2.2
16.2.3
16.2.4

16.3
16.4
16.4.1
16.4.2
16.4.3

16.5
16.5.1
16.5.2
16.5.3

Conservation Principles ......................................................................................... 164


Partial Differential Equation (PDE) ......................................................................... 164
From Ordinary to a Partial Differential Equation..................................................... 165
Types and Classification of Partial Differential Equations ........................................ 168

Discretization Methods ............................................................. 172


The Nature of Numerical Methods ............................................ 173
The Task ............................................................................................................... 173
The Discretization Concept .................................................................................... 174
The Structure of the Discretization Equation .......................................................... 175

Methods of Deriving the Discretization Equations ..................... 176


Taylor-Series Formulation...................................................................................... 176
Control-Volume Formulation ................................................................................. 177
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
v

17.2
17.2.1

Forming Finite Differences ........................................................ 184


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 Poissons 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

19.5
19.5.1

Example and Matlab code for unsteady 1D heat conduction .................................. 226

Unsteady Conduction in Two and Three Dimensions ................. 234


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
20.1.2

20.2
20.2.1

20.3
20.3.1

A Preliminary Derivation........................................................................................ 249


The Upwind Scheme.............................................................................................. 250

Unsteady Convection Diffusion with Heat Generation in 1D ...... 252


Example and Matlab codes .................................................................................... 253

Unsteady Convection Diffusion with Heat Generation in 2D ...... 258


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
23.4.2
23.4.3
23.4.4

23.5
23.6

The for loop .......................................................................................................... 274


The while loops ..................................................................................................... 276
The if-else-end constructions................................................................................. 277
The switch-case constructions ............................................................................... 278

Relations and logical operations ............................................... 279


Rounding to integers ................................................................. 280
vi

23.7
23.7.1
23.7.2

Matlab Graphics ....................................................................... 282


2-D graphics .......................................................................................................... 283
3-D graphs ............................................................................................................ 286

23.8
Animation ................................................................................. 287
REFERENCES ............................................................................................... 289

vii

viii

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.
ix

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

Вам также может понравиться