numeric al anal ysis of proces ses

26
NUMERICAL ANALYSIS OF PROCESSES NAP4 NONLINEAR MODELS of systems described by ordinary differential equations Initial problem (Runge Kutta, Adams) Time delay Strange attractors Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

Upload: senona

Post on 13-Jan-2016

61 views

Category:

Documents


0 download

DESCRIPTION

NUMERIC AL ANAL YSIS OF PROCES SES. NAP 4. N ONLINEAR MODELS of systems described by ordinary differential equations Initial problem (Runge Kutta, Adams) Time delay Strange attractors. Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010. Model s ODE initial probl e m. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: NUMERIC AL  ANAL YSIS OF  PROCES SES

NUMERICAL ANALYSIS OF PROCESSES

NAP4

NONLINEAR MODELS of systems described by ordinary differential equations

Initial problem (Runge Kutta, Adams)

Time delay

Strange attractors

Rudolf Žitný, Ústav procesní a zpracovatelské techniky ČVUT FS 2010

Page 2: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4 Models ODE initial problem

Systems which are described by a system of ordinary differential equations and their solutions are fully described by the initial state, are for example integral models of mass and enthalpy balances elementary units ("lumped parameter" or "compartment" models). The aim is to determine the evolution of state variables (concentration, temperature) at the time, so it is an evolutionary problems.

These elementary units may be specific devices (reactors, absorbers, columns, tanks, filters, ...) in "spread sheets" or zones in apparatuses in which the state can be characterized by mean temperature, and the concentration of components (ideal mixers, plug flow zone). An example is the description of a stirred vessel system of ideal mixers below and above a turbine stirrer or a replacement shell and tube heat exchanger by a systém of elementary exchangers between the baffles.

Each elementary unit correspond to ordinary differential equations describing the mass balance (one for each component of the differential equation describing the rate of change of concentration)

and a enthalpy balance (or total energy balance) describing temperature evolution in the department

n

iiicQ

dt

dcV

1

( )

1

ng

p i ii

dTmc m h H

dt

volumetric flowrate from neigbouring compartments

wnthalpic flows from neighbouring compartments

volumetric hear source

Page 3: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4 Models ODE initial problem

A system need not be described by ordinary differential equations with only first derivatives. Eg. the equations of vibration include also the second time derivative (acceleration)

)(2

2

tfkydt

dyd

dt

ydm

But every such equation can be replaced by a system of equations with only first derivatives, e.g.

( )dv

m dv ky f tdt

dyv

dt

The initial problem is characterized by the fact that each computed variable corresponds to one differential equation of the first order and to one initial condition (value) corresponding to the initial state.

…or how many equations so many initial conditions corresponding to one value of independent variable.

Page 4: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4 Models ODE initial problemExample of continuous system:

Ci, Ti

Q,x(t) (1+r)Q

(1+r+b)Q

bQ

sQ rQ

1 2

3

4 5 6

7

backmixing model (dispersion, diffusiion)

recirkulation with transport delay

model of stagnant zone

Differential equations for concentrations

)(

)(

)()(

313

3

212

2

1311

1

ccsQdt

dcV

ccQdt

dcV

ccsQcxQdt

dcV

)()(

))(1(

))21()1((

))1((

67

655

6

5645

5

45724

4

tctc

ccbrQdt

dcV

cbrbccbrQdt

dcV

cbrbcrccQdt

dcV

Parameters determining distribution of flowrates (s-stagnant zone, r-recirculation, b-backmixing) must be specified, r-from flowmeter measurement, b-from correlations. Also the volume of individual compartments must be known. These parameters are most frequently identiofied from fit of predicted characteristics (for example RTD - residence time distribution) with experiment. As a result information about the size of dead zones, recirculation zones, shortcuts, intensity of dispersion etc. are obtained.

Page 5: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4 Models ODE Fourier transformThe models can be solved by the Fourier transformation method (see previous lecture NAZP3).

It is not enough to apply only a convolution, because the model includes compartments with back mixing, stagnant zone ... However, you can come out of these differential equations, transformed by FFT. For the Fourier transform of derivation applies (assuming that the concentration at time zero is infinity)

1 1 1 3 1

2 2 1 2

3 3 1 3

2 ( ) ( )

2 ( )

2 ( )

iV fc Q x c sQ c c

iV fc Q c c

iV fc sQ c c

4 4 2 7 5 4

5 5 4 6 5

6 6 5 6

7 6

2 ( (1 ) )

2 ((1 ) (1 2 ) )

2 (1 )( )

exp(2 )

iV fc Q c rc bc r b c

iV fc Q r b c bc r b c

iV fc Q r b c c

c if c

)(~2)(2)( 222 fcifdtetcifetcdtedt

dc iftiftift

This system of algebraic equations (linear!) is already fairly easy to solve, and the result will be the Fourier transform of concentration. Concentration courses in time are then get back by FFT. The solution is accurate and fast (using FFT), but is limited to linear models. The procedure is preferred when the coefficients of the system (r, b, s) are constant. Otherwise, it was necessary to compute the Fourier transform of the product of two functions (and it is not equal to the product of the transformation). In the general case with nonlinear terms is therefore better to stay in the time domain and seek solutions to the numerical integration of the ODE.

Differential equations are transformed to algebraic equations, where instead of time t is frequency f.

Page 6: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4 Models ODE Laplace transform

00 0 initial

valueLaplace transform

( ) ( ) (0) ( )st st stdce dt c t e s c t e dt c sc s

dt

Similar relationships hold also for Laplace transform: the same convolution, correlation and transformation of derivatives

Inverse Laplace transform is usually searched in dictionaries, for example

1)(

!

mtm

s

metL

mmm cccs

cccs

cxcs

~~~...

~~~

~~~

1

212

11

( ) 1L t

Page 7: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4 ODE initial problem numerical solutions

t

c

tk

ck

tk+1

t

c

tk

ck

tk+1

kk ccttctfdt

dc ),(

),(1 kkkk ctfcc1 1 1( , )k k k kc c f t c

fcc kk 1f

Euler method explicit

order of accuracy (first)

stable only for small integration steps

Euler method implicit

order of accuracy (first)

stable, but iterations are necessary (because ck+1 is unknown)

Euler metods are easily programmable

even in Excel

first order of accuracy means that the error is directly

proportional to the step

when you write a Taylor expansion for one time step, the error is O(2), a second-order accuracy. Errors, however, accumulate, so 1/ steps will result in an error O().

One-step methods approximate solution at time tk+1=tk+ by estimating mean value of derivative in interval <tk,tk+1>

Page 8: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4 ODE initial problem numerical solutions

t

c

tk

ck

tk+1

kk ccttctfdt

dc ),(

fcc kk 1

One-step methods approximate solution at time tk+1=tk+ by estimating mean value of derivative in interval <tk,tk+1>f

),(

)2/,2/(

)2/,2/(

),(6336

34

23

12

1

4321

fctff

fctff

fctff

ctff

fffff

kk

kk

kk

kk

Runge Kutta methods calculate mean value of derivative as a weighted average of derivatives f(t,c). The most often used version calculates four points (endpoints tk, tk+1 and two midpoints at tk+1/2)

Weight coefficients (1/6,1/3,1/3,1/6) and increments c are designed so that the order of accuracy is the highest (4th order of accuracy in this case). Generally, the order of accuracy of RK methods is the same as the number of evaluated points.

This variant is implemented in

MATLABu as a function ode45

Page 9: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4 ODE initial problem numerical solutions

11 ),( kkkk ccttccttctfdt

dc

Multistep methods approximate solution at time tk+1 on the basis of several previous values for example at times tk, tk-1 (two), or tk-2 (three-step method).

This is usually a combination of predictor (explicit) and corrector (default formula with higher precision and stable)

)),(),((2

1

)),(),((2

3

111

1121

kkkkkk

kkkkkk

ctfctfcc

ctfctfcc

t

c

tk-1

ck

tk+1tk

ck-1

tk-2

Both formulas are second order accuracy but corrector (implicit formula) has the absolute value of the error about 9-fold lower (implicit formulas tend to have an error less than explicit, even if the order errors is the same).

The disadvantage is that for the first two steps a single-step method, for example RK, must be used. On the other hand, number of computed derivatives is smaller.

it is sufficient to evaluate just one value

Page 10: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4 ODE initial problem numerical solutions

( , ) dc

f t cdt

Dynamic adjustment of integration step

The simplest solution is that each step is performed twice, once with step and then with increments /2 (twice). If the difference is greater than the specified tolerance, the step shrinks. Using the two calculated values (for full and half step) the accuracy of the final value can be improved by so called Aitken extrapolation. MATLAB uses a dynamic choice of the time step automatically.

Stiff problem

When you solve a system of equations may be that the integration step is dictated by the equation with an extremely short time constant, and the stability of the solution then requires extremely short integration step (the calculation time is prohibitively increased). We say that the system is stiff. Some methods of integrating ODE this unpleasant impact suppresses (an example is Gearova method).

Transport delay (time shift)

Time delay was included in the previous example. In this case the solver should remember the whole history of calculated results and not only the last step. Even the values for negative times (before the initial time) have to be defined.

Page 11: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4 ODE initial problem numerical solutions

( , ) dc

f t cdt

Stability analysis

Consider a differential equation describing e.g. the rate of a chemical reaction of the first order

Acdt

dc

Euler explicit integration formula of the first order

kk

kkk

Acc

cAcc

)1(0

11

A

2

1

0

1

(1 )

k k k

k k

c c A c

c cA

Euler implicit integration formula of the first order

1|1| A

stability condition restriction of time step (coef. of gain less

than 1)

1| | 11 A

gain less than 1 for arbitrary

Page 12: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4 ODE examples in MATLAB

ode45, ode23 Runge-Kutta (one step method with different order of accuracy)

ode113 Adams (multistep method)

ode15s Stiff (Gear multistep method with variable accuracy order-suitable for stiff problems)

dde23 transport delay

Page 13: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4 RTD series of mixers 1/4

mtNtNm

NN

etN

tNtE /

1

)!1()(

)(

)(

)(

)(

434

323

212

11

ccV

Q

dt

dc

ccV

Q

dt

dc

ccV

Q

dt

dc

cxV

Q

dt

dc

(t)y(t)

x(t)

c1 c2 c3 c4

tm=2 odpovídá poměru V/Q=0.5 (to

je střední doba prodlení jedné nádoby)

An example has been solved in the previous lectures using FFT. Series 4 ideally mixed vessels (container volume, flow rate Q). The aim is to find the time courses of concentrations c1,…,c4 for arbitrary initial conditions and for arbitrary course of concentration at inlet x(t).

Mass balances

As an initial concentration x(t) is applied impulse response of a set of two mixers (the same volume of tanks) and zero initial concentration in all tanks. The reason for such an assignment is that there is an analytical solution that can be compared with the results of numerical solution of the ODE. Stimulus function x(t) is the impulse response of E (t) for N=2 and tm=1; outlet concentration y(t)=c4(t) shou;ld be impulse response for N=6 and tm=3

Page 14: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4

mtNtNm

NN

etN

tNtE /

1

)!1()(

function dy = serie4(t,y,tm,tmx,nx)dy = zeros(4,1);xx=efun(t,tmx,nx);tm1=tm/4;dy(1)=(xx-y(1))/tm1;dy(2)=(y(1)-y(2))/tm1;dy(3)=(y(2)-y(3))/tm1;dy(4)=(y(3)-y(4))/tm1;

function y=efun(t,tm,n)y=n^n*t^(n-1)/(factorial(n-1)*tm^n)*exp(-t*n/tm);

MATLAB provides for the solution of ODE variety of methods (ode45, ode113, ode15s, ...) which can automatically adjust the integration step so as to achieve the required accuracy. Procedure is always the same, first define a function whose output is the vector of first derivatives for a given value of integration variable (time) and a solution vector.

In our case it is necessary to define a function whose result is a column vector (4x1) of right-hand sides of 4 differential equations. It will be assumed that the stimulus function x(t) is the impulse response of nx series mixers, with a mean time tmx. The parameter tm is the mean time of the modeled system of 4 mixers.

The Efun function can be defined as a sub-function in the m-file serie4.m, but maybe it's better to define it as a separate m-file efun.m

It would probably be smarter if the stimulus function x(t) was directly the next formal

parameter of the function serie4. I have a little problem with that in Matlab, I need

advice.

RTD series of mixers 2/4

Page 15: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4

sol=ode45(@(t,y)serie4(t,y,2,1,1), [0 10] , [0 0 0 0])

Integration ODE by Runge Kutta method

Sol = ode45(function describing right side, time range, initial conditions)

in our case for example

Using a function as an actual parameter looks a bit strange in Matlab. It is not possible to write simply the name of this function (serie4) because ode45

expects only two parameters (t, y) and the function serie4 has 5 parameters. Therefore, the so-called

anonymous function @(t,y)expression.must be used.

Integration from t=0, to t=10. It is not possible to specify a constant

integration step in Matlab

Vector of initial conditions (zero concentrations)

solver: 'ode45' extdata: [1x1 struct] x: [1x29 double] y: [4x29 double] stats: [1x1 struct] idata: [1x1 struct].

Result is the structure sol containing vector of time steps sol.x (in this specific case 29 steps was necessary for prescribed accuracy) and a corresponding matrix sol.y of calculated concentrations (four rows for four concentrations)

RTD series of mixers 3/4

Page 16: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4

mtNtNm

NN

etN

tNtE /

1

)!1()(

e=@(t,tm,n) n^n.*t.^(n-1)./(factorial(n-1)*tm^n).*exp(-n.*t/tm)t=linspace(0,10.23,1024);y=e(t,3,6);

0 2 4 6 8 100

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

0 2 4 6 8 100

0.1

0.2

0.3

0.4

0.5

0.6

0.7

Numerical solution by Runge Kutta (ode45) can be compared with the analytical solution E(t) for N=6 and tm=3

Sy=deval(sol,t)

This is demonstration how to define a one-line function (without using a m-file)

Standard function linspace generates vector of 1024 equidistant time steps

these points are results of ode45 with automatically adjusted integration time

steps function deval interpolates the nonequidistant results sol.y according to the prescribed

time scale t

RTD series of mixers 4/4

Page 17: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4 RTD time delay (transport delay)

In the case that there are time delays (long connecting pipelines, recycles) it is not possible to use the standard integration functions (ode23,ode45,…), but a different „family“ of MATLAB functions which is capable to save previous results (with prescribed vector of time delays 1 2 …)

Page 18: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4 RTD delay in recycle 1/2

Q

(1+r)Q

rQ

1 2

x(t)

Example: continuous system formed by two mixed tanks with time delay in recycle. It is quite common: connecting pipelines are usually modeled by a time delay.

The aim is to find time courses of concentrations c1(t), c2(t), for given flowrate (Q), recirculation ratio (r) and volume of tanks (V1,V2), for prescribed time course of inlet concentration x(t). The system is described by the mass balances:

))()1()()((

))()((

2212

2

11

1

tcrtrctcV

Q

dt

dc

tctxV

Q

dt

dc

time delay

rQ

Vd

Page 19: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4 RTD delay in recycle 2/2

0 2 4 6 8 10 12 14 16 18 200

0.01

0.02

0.03

0.04

0.05

0.06

0.07

0.08

0.09

0.1function dcdt=dclag(t,c,z)q=1;v1=2;v2=1;r=10;if t<.2 x=1;else x=0;enddcdt=zeros(2,1);clag=z(:,1);dcdt(1)=q/v1*(x-c(1));dcdt(2)=q/v2*(c(1)+r*clag(2)-(1+r)*c(2));

sol=dde23(@dclag,1,[0;0],[0,20])

plot(sol.x,sol.y)

Special ODE solvers must be used in MATLAB (dde23 for a constant time delay, and ddesd for variabl;e time delay)

sol=dde23(@derivatives, [1, 2…], history for t<tmin, [tmin,tmax])

vector of delays 1=1 (there is only one delay)

z is the matrix of solutions in times t-k. Column index (1)

is the index in vector of delays

zero history c1=c2=0 for t<0

))()1()()((

))()((

2212

2

11

1

tcrtrctcV

Q

dt

dc

tctxV

Q

dt

dc

q-flowrate,v1,v2 volumes, r-recycle ratio, impulse stimulus function x(t) with duration 0.2 seconds

Page 20: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4 Trajectory of particlesThe initial problem is also description of motion of particles under action of forces. Examples are trajectory of droplets in the spray drying chamber, motion of particles in a fluidized bed, burning coal particles in the combustion chamber, particles in the mixer, a settling tank, etc. The equations of motion are ODE of the type:

guvFdt

udm

)(

acceleration

drag for in fluid moving with velocity v

buoyant, centrifugal, electrical forces

Page 21: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4 Trajectories of particles

In the last lecture of the course we will pay attention to the type of modern methods of DEM (Discrete Element Method), which simulates the dynamic behavior of particulate systems such as hoppers, silos, mills, mixers, separators, solid and fluid bed. Calculations are based on the solution of ordinary differential equations of motion and the consideration of interactions of individual particles.

Verlet integration of dynamic equations

2

2

forces acting upon a particle/acceleration mass of particle

1 12

second derivative substituted by second differences

2 41 1

( )

2( )

2 ( ) ( )

k k kk

k k k k

d xA x

dt

x x xA x

t

x x x t A x O t

Page 22: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4 Theory of chaos strange attractor

Trajectories of particles calculated also the meteorologist E.Lorenz (1963) who tried to model the natural convection in atmosphere, the layer of air that is heated from below and cooled from above.

After drastic simplifications he obtained the three ordinary differential equations for the coordinates x, y, z of a particle in the atmosphere

bzxydt

dz

yxxzdt

dy

xyRadt

dx

Pr

)(

The model has only 3 parameters, Rayleigh number Ra, Prandtl number Pr and the parameter b is a slenderness ratio of rotating cells.

These 3 equations can be solve easily in MATLAB see next slide…

Rayleigh-Bénárdova instability

Page 23: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4

function dy = chaos(t,y)dy = zeros(3,1); dy(1) = 10*(y(2)-y(1));dy(2) = -y(1)*y(3)+28*y(1)-y(2);dy(3) = y(1)*y(2)-8/3*y(3);

sol=ode45(@chaos,[0 30],[.10001 .1 .1])

plot(sol.y(2,:),sol.y(3,:))

tt=linspace(0,30,3000);sy=deval(sol,tt);plot(sy(2,:),sy(3,:))

-30 -20 -10 0 10 20 300

5

10

15

20

25

30

35

40

45

50

-30 -20 -10 0 10 20 300

5

10

15

20

25

30

35

40

45

50

trajektory pf particle fopr Ra=10, Pr=28,

b=8/3

integration up to 30 s initial coordinates

x,y,z

plot graph y-z fro automatically calculated

integration steps

Theory of chaos strange attractor

Page 24: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4

-30 -20 -10 0 10 20 300

5

10

15

20

25

30

35

40

45

50

Numerically calculated trajectories behave erratically for Pr> 1 (they do not converge to a trivial steady steate solution x = y = z = 0), but they create something that looks like a counter-rotating swirls of final dimensions, and these seemingly random trajectories "jump" from the left to the right wing, and never intersect. The trajectories are extremely sensitive to initial conditions and to any disturbances (including approximation errors of numerical integration).

This limiting state is called „strange attractor“

Such behavior (deterministic chaos) appears at nonlinear systems when a stability limit is exceeded (eg Prantl, Reynolds or Rayleigh numbers). Deterministic chaos is typical for turbulent flow.

y

zparametric trajectory of particle

Theory of chaos strange attractor

Page 25: NUMERIC AL  ANAL YSIS OF  PROCES SES

EXAMNAP 4

ODE Initial problem

numerical solutions, stability

Page 26: NUMERIC AL  ANAL YSIS OF  PROCES SES

NAP4

Fourier transform of derivatives 2 2 ( )iftdce dt ifc f

dt

What is it initial problem

What is it order of accuracy O(n)

Explicit and implicit Euler method

Principles of RK and multistep methods (predictor, corrector)

Principle of stability analysis

Principle of integration step optimisation

),(1 kkkk ctfcc

1 1 1( , )k k k kc c f t c

Exam - remember