how to simulate in simulink: dae, dae-ekf, mpc & mhefolk.ntnu.no/tamald/24052017.pdf ·...

25
How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE Tamal Das PhD Candidate IKP, NTNU 24th May 2017

Upload: others

Post on 29-Mar-2020

30 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

How to simulate in Simulink: DAE, DAE-EKF,MPC & MHE

Tamal Das

PhD CandidateIKP, NTNU

24th May 2017

Page 2: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

Outline

1 Differential algebraic equations (DAE)

2 Extended Kalman filter (EKF) for DAE

3 Moving horizon estimation (MHE)

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 1 / 24

Page 3: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

Differential algebraic equations (DAE)

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 2 / 24

Page 4: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

Types of DAEs: Fully implicit and Semi-explicit

Notation

x : Differential variables

z : Algebraic variables

y =[xT zT

]

Fully implicit DAE

F

(y ,

dy

dt

)= 0

y (0) = y0

Semi-explicit DAE

dx

dt= f (x , z)

0 = g (x , z)

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 3 / 24

Page 5: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

DAEs in Chemical Engineering

In ChemEng, mathematical models consist of the following:

Dynamic conservation laws [Differential equations]

Mass balanceEnergy balance

Static conservation laws [Algebraic equations]

Constitutive equations [Algebraic equations]

Equation of statePressure drop equationHeat transfer equation

Physical and operating constraints [Algebraic equations]

Desired operationDesign constraints

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 4 / 24

Page 6: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

Index of a DAE

In ChemEng, commonly encountered DAEs are semi-explicit

dx

dt= f (x , z) ; 0 = g (x , z)

Index of DAEs determines how hard it is to solve them

Index 1-DAE∂g∂z is non-singular

det(

∂g∂z

)6= 0

∂g∂z is full rank matrix

Higher index (2,3,. . . -) DAEs

∂g∂z is singular

det(

∂g∂z

)= 0

∂g∂z is not full rank matrix

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 5 / 24

Page 7: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

Examples of DAE indices

Differential variable (x) : c

Algebraic variable (z) : c0

CSTR with volume VResidence time

τ = VF

F, c0

F, c

dcdt = (c0−c)

τ

Index 1-DAE

c0 = γ (t) is specified;∴ g = c0 − γ (t)∂g∂z = ∂g

∂c0= 1 (Full rank)

Higher index (2,3,. . . -) DAEs

c = γ (t) is specified;∴ g = c − γ (t)∂g∂z = ∂g

∂c0= 0 (not full rank)

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 6 / 24

Page 8: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

How to determine DAE index?

Index = Number of differentiations of g (x , z) w.r.t time necessaryto get a differential equation for each algebraic variable

Index 1-DAE

c0 = γ (t) is specified

Derivative 1: dc0dt = γ′ (t)

Index = 1

Higher index (2,3,. . . -) DAEs

c = γ (t) is specified

Derivative 1: dcdt = γ′ (t)

Rearrange: c0−cτ = γ′ (t)

Derivative 2: dc0dt −

dcdt = τγ′′

Rearrange: dc0dt = γ′ + τγ′′

Index = 2

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 7 / 24

Page 9: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

Why is Index of a DAE important?

Index 1-DAEs are easy whereas higher index-DAEs are hard

Higher index DAEs are hard due to initialization of variables(among others)

In ChemEng, DAEs of both kinds are encountered

dx

dt= f (x , z) ; 0 = g (x , z)

det

(∂g

∂z

)6= 0 (Index 1-DAE), or

det

(∂g

∂z

)= 0 (Higher index DAE)

Where does one encounter higher index DAEs in ChemEng

Making simplifications in process modelsConverting simulation problems into control problems

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 8 / 24

Page 10: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

Initialization issues of DAEs

Index 1-DAE (Easy)

Initialize differentialvariables x (0)

Solve g (x (0) , z (0)) = 0 foralgebraic variables z (0)

Higher index DAEs (Hard)

x (0) and z (0) areinterdependent

x (0) and z (0) cannot bespecified independently

If specified independently,leads to inconsistent initialconditions

DAE solver will crash

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 9 / 24

Page 11: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

DAE example: Two component dynamic flash calculation

F, z1, z2

V, y1, y2

L, x1, x2

ML

MV

P, TPout

Volume V

MT = F − V − L

M1 = Fz1 − Vy1 − Lx1

M2 = Fz2 − Vy2 − Lx2

MT = ML + MV

M1 = MLx1 + MV y1

M2 = MLx2 + MV y2

x1 + x2 = y1 + y2

7C

onse

rvat

ion

equ

atio

ns

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 10 / 24

Page 12: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

DAE example: Two component dynamic flash calculation

F, z1, z2

V, y1, y2

L, x1, x2

ML

MV

P, TPout

Volume V

y1 = K1x1

y2 = K2x2

K1 = f K1 (T ,P)

K2 = f K2 (T ,P)

ρL = f L (x1)

ρV = f V (T ,P)

L = hL (ML, ρL)

V = hV (P − Pout)

8C

onst

itu

tive

equ

atio

ns

V =ML

ρL+

MV

ρV

}Design

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 11 / 24

Page 13: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

DAE example: Two component dynamic flash calculation

F, z1, z2

V, y1, y2

L, x1, x2

ML

MV

P, TPout

Volume V

3 differential equations

3 differential variables

13 algebraic equations

13 algebraic variables

We can find an output setfor all the algebraic anddifferential variables

Index 1

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 12 / 24

Page 14: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

DAE example: Modified two component dynamic flash

F, z1, z2

V, y1, y2

L, x1, x2

ML

P, T

ML = F − V − L

M1 = Fz1 − Vy1 − Lx1

M2 = Fz2 − Vy2 − Lx2

M1 = MLx1

M2 = MLx2

x1 + x2 = y1 + y2

6C

onse

rvat

ion

equ

atio

ns

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 13 / 24

Page 15: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

DAE example: Modified two component dynamic flash

F, z1, z2

V, y1, y2

L, x1, x2

ML

P, T

y1 = K1x1

y2 = K2x2

K1 = f K1 (T ,P)

K2 = f K2 (T ,P)

L = hL (ML, ρL)

ρL = f L (x1)

6C

onst

itu

tive

equ

atio

ns

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 14 / 24

Page 16: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

DAE example: Modified two component dynamic flash

F, z1, z2

V, y1, y2

L, x1, x2

ML

P, T 3 differential equations

3 differential variables

9 algebraic equations

9 algebraic variables

We cannot find an outputset for algebraic variable V .

We need to differentiatetwice to get there

Index 2

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 15 / 24

Page 17: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

Solving higher index DAE problems

Reduce index to 1 or 0

Find consistent initial conditions for all the variables of thenew system

Solve the new system as a Index 1 DAE system or 0 indexsystem (ODE system)

The procedure1 is explained on the MATLAB website withadded support functions:

Index / order reduction (’reduceDAEIndex’)Finding consistent initial guesses (’decic’)DAE solvers: ode15i, ode15s, or ode23t

1https://se.mathworks.com/help/symbolic/solve-differential-algebraic-equations.html

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 16 / 24

Page 18: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

Solving index 1-DAE: Robertson DAE in Simulink

A −−⇀↽−− B + C

B → C

dCA

dt= −0.04CA + 104CBCC

dCB

dt= 0.04CA − 104CBCC − 3× 107C 2

B

0 = 1− (CA + CB + CC )

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 17 / 24

Page 19: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

Solving index 1-DAE problem in Simulink: Implementation

InterpretedMATLABFcn

derivatives

1s

Integrator

f(z)z Solvef(z)=0

AlgebraicConstraint

InterpretedMATLABFcn

Algebraics

Algebraicstates

Differentialstates

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 18 / 24

Page 20: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

Solving index 1-DAE problem in Simulink: Result

10-6

10-4

10-2

100

102

104

106

t (sec)

0

0.2

0.4

0.6

0.8

1

Co

ncen

trati

on

[-]

Robertson DAE problem with a Conservation Law, solved by ODE15S

CA

CC

CB

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 19 / 24

Page 21: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

Extended Kalman filter (EKF) for DAE

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 20 / 24

Page 22: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

Continuous-discrete EKF algorithm for DAEdx

dt= f (x , z) + w

0 = g (x , z) ; y = h (x , z) + vxaug =

[xz

]; f aug =

[fg

]

dx

dt= f (x) ; L =

[I

−(∂g∂z

)−1 (∂g∂x

)]dP

dt=

(∂f aug

∂xaug

)P + P

(∂f aug

∂xaug

)T

+ LQLT

Kk = P−k

(∂h

∂xaug

)T(Rk +

(∂h

∂xaug

)P−k

(∂h

∂xaug

)T)−1

xaug ,+k = xaug ,−k + Kk

(yk − hk

(xaug ,−k

))P+k =

(I − Kk

(∂h

∂xaug

))P−k

(I − Kk

(∂h

∂xaug

))T

+ KkRkKTk

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 21 / 24

Page 23: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

Moving horizon estimation (MHE)

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 22 / 24

Page 24: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

MHE is a dynamic optimization problem

At each sample time, a set of past few measurements are usedto provide a state estimate

This problem is discretized to a nonlinear program (NLP) [fornonlinear estimation]

NLP is solved using IPOPT solver in CasADi

CasADi is interfaced with Simulink using system block toprovide online state estimation

Tamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 23 / 24

Page 25: How to simulate in Simulink: DAE, DAE-EKF, MPC & MHEfolk.ntnu.no/tamald/24052017.pdf · 2017-05-20 · Di erential algebraic equations (DAE) Extended Kalman lter (EKF) for DAE Moving

Differential algebraic equations (DAE) Extended Kalman filter (EKF) for DAE Moving horizon estimation (MHE)

Conclusions

DAE systems are hard: particularly higher index DAEs

Two approaches:

simultaneous (Mass matrix solver)sequential (Simulink with Algebraic constraint block)

Estimation for DAE systems: CD-DAE-EKF in Simulink

MPC in Simulink using system block and CasADi

MHE in Simulink using system block and CasADi

For simulation files and this presentation, follow2

Thank you for your attention

2folk.ntnu.no/tamaldTamal Das How to simulate in Simulink: DAE, DAE-EKF, MPC & MHE 24 / 24