50
Dynamic simulation techniques for systems described by AEs/ODEs/PDEs Alain Vande Wouwer Philippe Saucez, William Schiesser, Carlos Vilas, Filip Logist

Dynamic simulation techniques for systems described by AEs

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Dynamic simulation techniques for systems described by AEs

Dynamic simulation techniques for systems described by AEs/ODEs/PDEs

Alain Vande Wouwer

Philippe Saucez, William Schiesser, Carlos Vilas, Filip Logist

Page 2: Dynamic simulation techniques for systems described by AEs

Université de Mons

Outline

Introduction

Simulation environments

Numerical solution of partial differential equationsA brief view of ODE integration

The Method Of Lines (MOL)

Weighted residual methods

Nonlinear discretization schemes

Adaptive gridding (static and dynamic)

Application examples

Conclusions

Page 3: Dynamic simulation techniques for systems described by AEs

Université de Mons

Introduction

Why is it useful to develop simulators ?

to study nonlinear system dynamicsto optimize operating conditions (simulation + optimization)to estimate unknown parameters (simulation+ off-line

experimental data + optimization)to design software sensors (simulation + on-line

experimental data)to test control structuresto design model-based controllers (e.g. NMPC)to train operators

Page 4: Dynamic simulation techniques for systems described by AEs

Université de Mons

Introduction

Many systems from science and engineering are described by mixed sets of:

Ordinary Differential Equations (ODEs) representing lumped parameter systems

Partial Differential Equations (PDEs) representing distributed parameter systems

Algebraic Equations (AEs) representing constraints on the system states

or PDAEs

tx f (x, t)

0 f (x, z, t)

t z zzx f (x, x , x ,..., z, t)

Page 5: Dynamic simulation techniques for systems described by AEs

Université de Mons

IntroductionMany systems are distributed in time and space:

time-varying temperature profiles in a heat exchanger

time-varying temperature and concentration profiles in a tubular reactor,

time-varying car density along a highway,

time-varying deflection profile of a beam subject to external forces,

time-varying shape and velocity of a water wave,

or other independent variable such as “age” or “size” in population models (crystallization, polymerization, grinding, etc.)

Page 6: Dynamic simulation techniques for systems described by AEs

Université de Mons

Simulation environments

There are two main classes of simulation environments:

Graphical environments (block-oriented): Simulink (Matlab)

Outvalve

invalve

tankheight

flushpulse

Tank Inf low

Tank Outf low

Tank Height

Tank Dynamics

Scope

Tank Height

F lush Signal

Flow Rate - Out

Valv e Position

Out Valve

Tank Height

Valv e Position

Valv eFlow

In Valve

Double ClickTo

Flush Me!

AnimationControlProgramming languages (equation-oriented):

Low-level: FORTRAN, C, etc.High-level: Matlab, Octave, Scilab, etc.

Page 7: Dynamic simulation techniques for systems described by AEs

Université de Mons

Simulation environments

Graphical environments are easy-to-use, user-friendly, visual and intuitive, but get cumbersome when handling complex systems

Programming environments are more complex (when using low-level languages), but provides more efficient codes

Graphical environments and high-level programming environments provide many useful algorithms, which however appear often as “black-boxes”

In early developments, these algorithms were sometimes “outdated”, whereas more powerful algorithms were available in public-domain librariesBlack-box algorithms can be very powerful when used in an informed way (i.e. making them less black-box …)

Page 8: Dynamic simulation techniques for systems described by AEs

Université de Mons

Simulation environmentsSimulation environments can include:

Mathematical libraries:Matrix algebra (Blas, LINPACK, LAPACK, etc)

ODE/DAE solvers (ODEPACK, DASSL, VODE, etc.)

Optimization algorithms, etc.

Symbolic ManipulationPreprocessing tools for generating equations, or even a programming code (based on MAPLE, Mathematica, etc.)

Dedicated environmentSBT2: Systems Biology Toolbox (Matlab) provides a dedicated environment for the analysis of biological models

Page 9: Dynamic simulation techniques for systems described by AEs

Université de Mons

A brief view of ODE integration

A ODE system:

Time discretization and integration

the numerical integration is performed by quadrature, for example

t 00x f (x, t) x(t ) x

i 1

i

t

i 1 it

x x f (x, t)dt

i 1

i

t

i it

f (x, t)dt f (x , t ) t

Page 10: Dynamic simulation techniques for systems described by AEs

Université de Mons

A brief view of ODE integration

which leads to the explicit Euler method:

Two central considerations:

• Accuracy error estimation and time-step control

• Stability time step limitationThe explicit Euler method has a limited stability region

i 1 i i ix x f (x , t ) t

t 2

Page 11: Dynamic simulation techniques for systems described by AEs

Université de Mons

A brief view of ODE integration

A more advanced method is the 4th-order Runge-Kuttascheme

where the several stages are computed as follows:

• Accuracy error estimation by comparison with a 5th-order formula

• Stability not much better

i 1 i 1 525 1x x k ... k

216 5

i i1 i 5 1 4 i439 845k f (x , t ) k f (x ( k ... k ), t t)216 4104

t 2.785

Page 12: Dynamic simulation techniques for systems described by AEs

Université de Mons

A brief view of ODE integration

Stiffness ?

The smallest eigenvalue min determines the problemtime scale

The largest eigenvalue max determines the maximumtime step size t max

Euler

RKF45

Stiff problems are characterized by

Explicit methods are computationally inefficient for stiff problems due to their limited stability regions

max maxt 2.785max maxt 2

max

min

1000

Page 13: Dynamic simulation techniques for systems described by AEs

Université de Mons

A brief view of ODE integrationImplicit methods (a simple example: implicit Euler)

Unconditionally stable !

More complicated to implement (Newton’s iteration)

Less efficient on non-stiff problems

More advanced methods: implicit RK methods

Backward differentiation formulas (BDF)

i 1

i

t

i 1 i 1t

f (x, t)dt f (x , t ) t

i 1 i i 1 i 1x x f (x , t )

q 1

i 1 i k i 1k 0 i 1k 0

x x f (x , t ) t

Page 14: Dynamic simulation techniques for systems described by AEs

Université de Mons

A brief view of ODE integration

A ODE system:

Jacobian matrix

The spectrum of eigenvalues of J is determinant for stability considerations

The structure of J (full or dense, banded, sparse), is determinant for the computational efficiency

t 00x f (x, t) x(t ) x

i jJ f / x J(x, t)

Page 15: Dynamic simulation techniques for systems described by AEs

Université de Mons

A brief view of ODE integration

Available ODE/DAE solvers:

ODEPACK

DASSL

VODE

MATLAB ODE suite

SUNDIALS

Etc…

Page 16: Dynamic simulation techniques for systems described by AEs

Université de Mons

The Method Of Lines (MOL)

A two-step procedure:

1. spatial derivatives are first approximated

2. the resulting system of semi-discrete (discrete in space – continuous in time) equations is integrated in time using available ODE solvers

The popularity of the MOL arises from the large collection of readily available ODE solvers

Page 17: Dynamic simulation techniques for systems described by AEs

Université de Mons

MOL

PDE problem

Spatial discretization

DAE problem

tx f (t, z, x, x , x )z zz

0 b(t, z 0, x, x )z

0 b(t, z L, x, x )z

0x(t , z) x (z)0

tx f (t, x)0 b(t, x)

0x(t ) x0

Page 18: Dynamic simulation techniques for systems described by AEs

Université de Mons

Finite DifferencesFinite difference approximations can be obtained from Taylor series expansions

(e.g., three-point centered FDs)

in the spatial domain

at the boundaries

i

2i 1 i 1

z

x(z ) x(z )x O( z )z 2 z

1

21 2 3

z

3x(z ) 4x(z ) x(z )x O( z )z 2 z

zz

N

2N N 1 N 2

z

3x(z ) 4x(z ) x(z )x O( z )z 2 z

i 1z i 1ziz

Page 19: Dynamic simulation techniques for systems described by AEs

Université de Mons

Finite differencesThese formulas can be summarized in a compact way using differentiation matrices (easy to implement in Matlab)

(e.g., three-point centered FDs)

1

2

z 1 i

N 1

N

x3 4 1 0 ... ... 0x1 0 1 0 ... ... 0......

1x D x x0 ... 1 0 1 ... 02 z

......x0 ... ... 0 1 0 1x0 ... ... 0 1 4 3

Page 20: Dynamic simulation techniques for systems described by AEs

Université de Mons

Differentiation matrices

Differentiation matrices: a simple and powerful tool within MATLAB

Stagewise differentiation:

Direct differentiation: z 1x xD zz 2x xD

z 1x xD zz z1x xD

zzzz 1 1 1 1x ( ( ( x)))D D D D

Page 21: Dynamic simulation techniques for systems described by AEs

Université de Mons

MATMOL: a Matlab MOL LibraryCode template (matrix/vector form)

Main program

Model parametersDifferentiation matrices

InitialisationCall to ODE solver

Static grid adaptationOutput solution

ODE solver

PDE fileSpatial derivativesModel equations

Dynamic grid adaptation

Graphs

Page 22: Dynamic simulation techniques for systems described by AEs

Université de Mons

MATMOL: a Matlab MOL Library

Available Methods:

Finite differences

Spectral methods

Finite elements

Slope limiters

Adaptive gridding

(static and dynamic)

Operator splitting

www.matmol.org

Page 23: Dynamic simulation techniques for systems described by AEs

Université de Mons

Benzene hydrogenation

Poisoning kinetics of Thiophene

A catalytic fixed-bed reactor

Active sectionNi-catalyst

Inert Inert

T(0,t)CB(0,t)CT(0,t)

Poisoning

2cB B B

B B A B2

c c cv D r ( , c ,T)t z z

2cT T T

T T A T2

c c cv D r ( , c ,T)t z z

2G pG eff

w c B A B2p p p p

cT T T 2 ( H)v (T T) r ( , c ,T)t c z c z R c c

Ad A Tr ( , c ,T)

t Bed activation

Page 24: Dynamic simulation techniques for systems described by AEs

Université de Mons

A catalytic fixed-bed reactor%... temporal derivatives

%...

cB1t = -v*cB1z + DB*cB1zz;

cT1t = -v*cT1z + DT*cT1zz;

T1t = -((eps*v*rhog*cpg)/rhocp)*T1z + (leff/rhocp)*T1zz + 2*alpha*(Tw - T1)/(Rr*rhocp);

%...

cB2t = -v*cB2z + DB*cB2zz - rhoc*rB/eps;

cT2t = -v*cT2z + DT*cT2zz - rhoc*rT/eps;

T2t = -((eps*v*rhog*cpg)/rhocp)*T2z + (leff/rhocp)*T2zz + 2*alpha*(Tw - T2)/(Rr*rhocp) + (DH/rhocp)*rhoc*rB;

thetat = -rd;

%...

cB3t = -v*cB3z + DB*cB3zz;

cT3t = -v*cT3z + DT*cT3zz;

T3t = -((eps*v*rhog*cpg)/rhocp)*T3z + (leff/rhocp)*T3zz + 2*alpha*(Tw - T3)/(Rr*rhocp);

Page 25: Dynamic simulation techniques for systems described by AEs

Université de Mons

A catalytic fixed-bed reactor

%...

%... boundary conditions at z = z01

cB1t(1) = - (cB1(1)-cBin);

cT1t(1) = - (cT1(1)-cTin);

T1t(1) = - (T1(1)-Tin);

%...

%... boundary conditions at z = zL1 = z02

cB1t(n1) = cB2z(1) - cB1z(n1);

cT1t(n1) = cT2z(1) - cT1z(n1);

T1t(n1) = T2z(1) - T1z(n1);

%...

cB2t(1) = cB1(n1) - cB2(1);

cT2t(1) = cT1(n1) - cT2(1);

T2t(1) = T1(n1) - T2(1);

%...

%... boundary conditions at z = zL2 = z03

cB2t(n2) = cB3z(1) - cB2z(n2);

cT2t(n2) = cT3z(1) - cT2z(n2);

T2t(n2) = T3z(1) - T2z(n2);

%...

cB3t(1) = cB2(n2) - cB3(1);

cT3t(1) = cT2(n2) - cT3(1);

, T3t(1) = T2(n2) - T3(1);

%...

%... boundary conditions at z = zL

cB3t(n3) = - cB3z(n3);

cT3t(n3) = - cT3z(n3);

T3t(n3) = - T3z(n3);

Algebraic BCs

Page 26: Dynamic simulation techniques for systems described by AEs

Université de Mons

A catalytic fixed-bed reactor

5-point biased-upwind FDs for first derivatives

N1 = 71N2 = 71N3 = 21

Page 27: Dynamic simulation techniques for systems described by AEs

Université de Mons

A catalytic fixed-bed reactor

5-point biased-upwind FDs for first derivatives

N1 = 71N2 = 71N3 = 21

Page 28: Dynamic simulation techniques for systems described by AEs

Université de Mons

A catalytic fixed-bed reactor

5-point biased-upwind FDs for first derivatives

N1 = 71N2 = 71 N3 = 21

Page 29: Dynamic simulation techniques for systems described by AEs

Université de Mons29

Weighted residual methods

Weighted residual methods use (usually orthonormal)basis functions to represent the solution:

The weighting coefficients are found by solving residual equations, i.e., the PDE residuals are made orthogonal to some (also orthonormal) test functions

N

i ii 1

x̂(t, z) a (t) (z)

t z zzˆ ˆ ˆ ˆR(t, z) x (t, z) f (x, x , x , z, t)

iR(t, z) (z)dz 0 i 1, , N

Page 30: Dynamic simulation techniques for systems described by AEs

Université de Mons30

Weighted residual methods

If the basis functions are global (i.e. cover the wholespatial domain), the methods are usually calledspectral methods

If the basis functions are local (i.e. have a compactsupport, e.g. hat functions), the methods are calledfinite element methods

The finite difference method can be considered as aparticular case of finite element method where thebasis functions are rectangular pulses

1

2

3 5

4 6

Page 31: Dynamic simulation techniques for systems described by AEs

Université de Mons31

Weighted residual methods

Depending on the choice of the test functions, severalparticular methods arise:

• : Galerkin method

• : Collocation method

The rate of convergence of the collocation method canbe accelerated by considering nonuniformdistributions, in which more grid points are clusterednear the boundaries

i i(z) (z) i 1, , N

i i(z) (z z ) i 1, , N

Page 32: Dynamic simulation techniques for systems described by AEs

Université de Mons32

Weighted residual methods

Three main types of basis functions are considered:

• The eigenfunctions of the corresponding linearized,homogeneous, IBVP, when these functions exist andcan be computed

• "Empirical" basis functions (Karhuenen-Loeve or properorthogonal decomposition – construction of solution« snapshots » and solution of an eigenvalue problem )

• Polynomials (As stated in Weiertrass theorem, anycontinuous function can be represented in terms ofpolynomials)

Page 33: Dynamic simulation techniques for systems described by AEs

Université de Mons

Application example (1)

very compact differentiation matrices, e.g. using spectral collocation

A simple algae bloom model

Critical patch size

2

2 r 1t z K

(0, t) (L, t) 0

Lr

Page 34: Dynamic simulation techniques for systems described by AEs

Université de Mons

Application example (1)A simple algae bloom model

Chebyshev collocation with only 6 nodes

rL L

r

2

2 r 1t z K

(0, t) (L, t) 0

Page 35: Dynamic simulation techniques for systems described by AEs

Université de Mons

Application example (2)… and larger ones on more challenging problems, e.g. an extended equal-width wave equation [Hamdi, Enright, Schiesser, Gottlieb, 2003]

and an extended equal-width-Burgers equation

pt z zztu a u u u 0

pt z zz zztu a u u u u 0

Page 36: Dynamic simulation techniques for systems described by AEs

Université de Mons

Application Example (2)

(c = 0.3 - spectral collocation – 100 nodes)

2t z zztu 2u u 4u 0

Page 37: Dynamic simulation techniques for systems described by AEs

Université de Mons

Application Example (2)

(c1 = 0.6 – c2 = 0.1 - spectral collocation – 100 nodes)

2t z zztu 2u u 4u 0

Page 38: Dynamic simulation techniques for systems described by AEs

Université de Mons

Application example (2)

(c1 = 0.6 – c2 = 0.1 - spectral collocation – 100 nodes)

Mass

Energy

« Whitham »

0 20 40 60 80 1000

5

10

15

t

I 1, I2, I

4

Invariants of Motion

I1I2I4

2t z zztu 2u u 4u 0

1I u dz

22 z zI (u u u )dz

44I u dz

Page 39: Dynamic simulation techniques for systems described by AEs

Université de Mons

Application example (2)2

t z zz zztu 2u u 0.5u 4u 0

Page 40: Dynamic simulation techniques for systems described by AEs

Université de Mons

Application example (2)function xt = f(t,x)

%...%... set global variables

global a p mu c;global z0 zL z n D1;

%...%... spatial derivatives%...

xz = D1*x;%...%... temporal derivatives%...

xt = -a*(x.^p).*xz;%...

function M = mass(t,x)%...%... set global variables

global a p mu c;global z0 zL z n D1;

%...%... Assemble mass matrix

M = diag(ones(n,1),0)-mu*D1*D1;

Page 41: Dynamic simulation techniques for systems described by AEs

Université de Mons

Application example (3)

[Lazo,1999]

p

2b b b b

b b p,R2b p

c c c (1 ) 3kv D (c c )t z z R

*p p p

p p p p 2p

c c c1(1 ) Dt t R r r

c

p*p n

i pii 1

acc

1 b c

Page 42: Dynamic simulation techniques for systems described by AEs

Université de Mons

Application example (3)

0 2 4 6 80

0.2

0.4

0.6

0.8

1B reak through Curve No.3

D im ens ion les s Tim e

Dim

ensi

onle

ss C

once

ntra

tion

0 0.5 1-0.5

0

0.5

1

1.5P rofiles Ins ide the Colum n

Dim ens ionles s z , bu lk phas e

Dim

ensi

onle

ss C

once

ntra

tion

0 0.5 1

0.998

0.9985

0.999

D im ens ion les s P art ic les Radius

Dim

ensi

onle

ss C

once

ntra

tion

z = 1/2, t= t f/2 Finite element in the bulk phase (Galerkin method – second-order elements)Orthogonal collocation in the particles

Page 43: Dynamic simulation techniques for systems described by AEs

Université de Mons

Nonlinear discretization schemesOf course, other approximation techniques do not cast into the differentiation matrix format, e.g. nonoscillatory schemes such as slope/flux limiters, which are nonlinear

0 0.5 1 1.5 2 2.5 30

0.5

1

1.5

2

2.5

r

(r)

SuperbeeMinmodvan LeerKoren

x(t, z) f (x(t, z))t z

i i 1i

i 1 i

x xrx x

lo ho lof(x) f (x) (r) (f (x) f (x))

Page 44: Dynamic simulation techniques for systems described by AEs

Université de Mons

Application exampleBurgers equation

0 0.5 1 1.5 2 2.5 30

0.5

1

1.5

2

2.5

r

(r)

SuperbeeMinmodvan LeerKoren

Koren limiter2

t z zzu (0.5u ) u

Page 45: Dynamic simulation techniques for systems described by AEs

Université de Mons

Static grid adaptation

Grid Refinement: AGEREGequidistribution of a given monitor function subjectto constraints on the grid regularity

An example: Korteweg-de-Vries equation

Finite differences and stagewise differentiationVery small absolute tolerance on ODE15s

i 1 i 1 i im (x) z m (x) z c

i

i 1

z1 KK z

t z zzzu 6 uu u 0

Page 46: Dynamic simulation techniques for systems described by AEs

Université de Mons

Application example

Average number of nodes = 154

Page 47: Dynamic simulation techniques for systems described by AEs

Université de Mons

Dynamic grid adaptation

Grid Movement: a basic version of MOVGRD [Blom & Zegeling, 1994]

Spatial smoothing

Temporal smoothing

t z zzx f (x, x , x , z, t) z zzzx x z f (x, x , x , z, t)

i i i 1 i

i i i 1 i i 1

n 1/ z 1/ (z z )n n ( 1)(n 2n n )

i 1 i 1 i i

i 1 i

n n n nM M

Page 48: Dynamic simulation techniques for systems described by AEs

Université de Mons

Dynamic grid adaptation

Finite difference approximations

Time integration of the resulting DAEs with ode15s

A simple example: flame propagation

x Dz fB z g

26 4/T

2

2

2

r , (z,0) 1, r 3.52 10 et zT T r , T(z,0) 0.2, T(1, t) f (t)t z

Page 49: Dynamic simulation techniques for systems described by AEs

Université de Mons

Application example

(31 moving nodes)

Page 50: Dynamic simulation techniques for systems described by AEs

Université de Mons

ConclusionsComputational modeling is increasingly used in science (and noteworthy, in emerging fields such as biology or human physiology) and engineering

• commercial software packages• public–domain libraries• equation-oriented or block-oriented environments• numerical algorithms and symbolic manipulations

a vast array of readily available methodsa gap between research and current practice