Synchronous Events in the OpenModelica Compiler with a Petri Net - - PowerPoint PPT Presentation

synchronous events in the openmodelica compiler with a
SMART_READER_LITE
LIVE PREVIEW

Synchronous Events in the OpenModelica Compiler with a Petri Net - - PowerPoint PPT Presentation

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary Synchronous Events in the OpenModelica Compiler with a Petri Net Library Application Simulation hybrid systems in Modelica Willi Braun, Bernhard Bachmann


slide-1
SLIDE 1

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Synchronous Events in the OpenModelica Compiler with a Petri Net Library Application

Simulation hybrid systems in Modelica Willi Braun, Bernhard Bachmann and Sabrina Pross

Department of Applied Mathematics University of Applied Sciences Bielefeld 33609 Bielefeld, Germany

2010-10-03

1 / 19

slide-2
SLIDE 2

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Outline

1

Hybrid models in Modelica

2

Implementation in OpenModelica

3

Examples and results

2 / 19

slide-3
SLIDE 3

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Hybrid models

Hybrid modeling

Hybrid Mixed systems with continuous and discrete components Simulation needs handling with events and discontinuities Applications Switched electric circuits Controlled systems Petri Nets

3 / 19

slide-4
SLIDE 4

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Hybrid models

Hybrid Petri Net

P1 P2 P3 P4 P5 T1

2 1 5

T2

1 3

T3

1 2

Elements of a Petri Net Fundamental items are places and transitions Directed arcs connect items

4 / 19

slide-5
SLIDE 5

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Hybrid models

Hybrid Petri Net

P1 P2 P3 P4 P5 T1

2 1 5

T2

1 3

T3

1 2

Elements of a Petri Net Fundamental items are places and transitions Directed arcs connect items

4 / 19

slide-6
SLIDE 6

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Hybrid models

Hybrid Petri Net

12.5 P1 5 P2 P3 3.1 P4 P5 T1

1 2 P1 1 4 P2 5

T2

1 3

T3

1 2

Elements of a Petri Net Fundamental items are places and transitions Directed arcs connect items Modifications The fireing speed can be discribed by differential equations for continuous behaviour Transistions may have a stochastic delay Edges may have weightings, threshold and inhibition

4 / 19

slide-7
SLIDE 7

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Hybrid models

Hybrid Petri Net

12.5 P1 P2 1 P3 P4 P5 T1

3P1 1 5

T2

2P4 1

T3

1 2

Elements of a Petri Net Fundamental items are places and transitions Directed arcs connect items Modifications The fireing speed can be discribed by differential equations for continuous behaviour Transistions may have a stochastic delay Edges may have weightings, threshold and inhibition ⇒ Hybrid models

4 / 19

slide-8
SLIDE 8

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Hybrid models

Petri Nets in OpenModelica

Library in OpenModelica Continuous, discrete and stochastic places and transitions can be combined Combined Petri Nets are versatile applicable For example: production or biological processes Problems in OpenModelica “when equations”were not treated synchronously

Figure: Elements of the PetriNet-Library Figure: Example network

5 / 19

slide-9
SLIDE 9

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Hybrid models

Modelling events with Modelica model e x a m p l e i f input Real u ; Real y ; equation y = i f u > 0 then 1 e l s e −1; end e x a m p l e i f ;

Conditional expressions like u > 0 trigger events. If events occurs the value is stored twice. In this example y is the right limit and pre(y) is the left limit.

6 / 19

slide-10
SLIDE 10

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Hybrid models

Hybrid Modelica DAE-System

Flatten Modelica model: 0 = F( ˙ x(t), x(t), y(t), u(t), q(te), qpre(te), c(te), p, t) ↓ matching and sorting algorithm transform to z =   ˙ x(t) y(t) q(te)   =   f (x(t), u(t), qpre(te), c(te), p, t) g(x(t), u(t), qpre(te), c(te), p, t) h(x(t), u(t), qpre(te), c(te), p, t)  

7 / 19

slide-11
SLIDE 11

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Hybrid models

Synchronous Data-flow principle

Sorting of when equations

//known V a r i a b l e : u when y2 > 2 then y3 = f1 ( y4 ) ; end when ; y4 = f2 ( y5 ) ; when y1 > 0 then y5 = f3 ( u ) ; y2 = f4 ( y4 ) ; end when ; y1 = f5 ( u ) ;

Incidence-Matrix y1 y2 y3 y4 y5 y3 = f 1(y4) y4 = f 2(y5) y5 = f 3(u) y2 = f 4(y4) y1 = f 5(u)       1 1 1 1 1 1 1 1 1 1 1      

8 / 19

slide-12
SLIDE 12

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Hybrid models

Synchronous Data-flow principle

Sorting of when equations

//known V a r i a b l e : u y1 = f5 ( u ) ; when y1 > 0 then y5 = f2 ( u ) ; end when ; y4 = f3 ( y5 ) ; when y1 > 0 then y2 = f4 ( y4 ) ; end when ; when y2 > 2 then y3 = f1 ( y4 ) ; end when ;

Incidence-Matrix y1 y5 y4 y2 y3 y1 = f 5(u) y5 = f 3(u) y4 = f 3(y5) y2 = f 4(y4) y3 = f 1(y4)       1 1 1 1 1 1 1 1 1 1 1      

9 / 19

slide-13
SLIDE 13

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Hybrid models

Synchronous Data-flow principle

Sorting of when equations

//known V a r i a b l e : u y1 = f5 ( u ) ; when y1 > 0 then y5 = f2 ( u ) ; end when ; y4 = f3 ( y5 ) ; when y1 > 0 then y2 = f4 ( y4 ) ; end when ; when y2 > 2 then y3 = f1 ( y4 ) ; end when ;

Incidence-Matrix y1 y5 y4 y2 y3 y1 = f 5(u) y5 = f 3(u) y4 = f 3(y5) y2 = f 4(y4) y3 = f 1(y4)       1 1 1 1 1 1 1 1 1 1 1       Sorting equations Sorting is based on all equations due to the correct order of evaluation at all time points.

9 / 19

slide-14
SLIDE 14

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Hybrid models

Hybrid Modelica DAE-System

Flatten Modelica model: 0 = F( ˙ x(t), x(t), y(t), u(t), q(te), qpre(te), c(te), p, t) ↓ matching and sorting algorithm transform to z =   ˙ x(t) y(t) q(te)   =   f (x(t), u(t), qpre(te), c(te), p, t) g(x(t), u(t), qpre(te), c(te), p, t) h(x(t), u(t), qpre(te), c(te), p, t)  

10 / 19

slide-15
SLIDE 15

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Hybrid models

Hybrid Modelica DAE-System

Flatten Modelica model: 0 = F( ˙ x(t), x(t), y(t), u(t), q(te), qpre(te), c(te), p, t) ↓ matching and sorting algorithm transform to z =   ˙ x(t) y(t) q(te)   =   f (x(t), u(t), qpre(te), c(te), p, t) g(x(t), u(t), qpre(te), c(te), p, t) h(x(t), u(t), qpre(te), c(te), p, t)   We get four blocks: continuous f and g → derivative states and algebraic variables discrete h → discrete algebraic variables all z → all three block together An additional block to manage the conditions for events: c(t) → Zero Crossing functions

10 / 19

slide-16
SLIDE 16

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Implementation in OpenModelica

Approach to simulate hybrid models

11 / 19

slide-17
SLIDE 17

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Implementation in OpenModelica

Approach to simulate hybrid models

Intial Step Initial-value problem is solved by a simplex-method Initial Zero-crossing functions and check for initial events

11 / 19

slide-18
SLIDE 18

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Implementation in OpenModelica

Continuous integration

Integration step Integration method: xi+1 = Φ(xi) Calculate for the next step ti+1 the new state vector x(ti+1) Evaluate continuous blocks f and g

˙ x(ti+1) = f (x(ti+1), q(ti), qpre(ti), c(ti+1), t) y(ti+1) = g(x(ti+1), q(ti), qpre(ti), c(ti+1), t)

12 / 19

slide-19
SLIDE 19

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Implementation in OpenModelica

Check for event conditions

Check for zero-crossing Conditions are converted into zero-crossing functions x < 2 changes from false to true when x − 2 crosses zero If any zero-crossing becomes true an event is fired

13 / 19

slide-20
SLIDE 20

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Implementation in OpenModelica

Find event time

Root-finding method Find root in interval [ti; ti+1] as event time te Bisection is a simple and robust method, but it is also relative slowly All methods approximate the root by setting limits on each side of te Additional we have te − ǫ and te + ǫ

14 / 19

slide-21
SLIDE 21

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Implementation in OpenModelica

Handle event

Handle event

1

Determine states at te − ǫ with interpolation

2

Determine continuous blocks by using functions f and g

3

Save all variables as values for pre() and emit them to result file

˙ x(te−ǫ) = f (x(te−ǫ), q(ti), qpre(ti), c(te−ǫ), t) y(te−ǫ) = g(x(te − ǫ), q(ti), qpre(ti), c(te−ǫ), t)

15 / 19

slide-22
SLIDE 22

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Implementation in OpenModelica

Handle event

Handle event

1

Determine states at te + ǫ with interpolation

2

Evaluate all blocks by using function z

3

Check for changes of discrete variables

4

Event Iteration

z = ˙ x(te + ǫ) y(te + ǫ) q(te + ǫ) = f (x(te + ǫ), qpre(te), c(te), t) g(x(te + ǫ), qpre(te), c(te), t) h(x(te + ǫ), qpre(te), c(te), t)

16 / 19

slide-23
SLIDE 23

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Examples

Example for correct sorting of when-equations

model when sorting Real x ; Real y ; Boolean w( s t a r t=t r u e ) ; Boolean v ( s t a r t=t r u e ) ; Boolean z ( s t a r t=t r u e ) ; equation when sample (0 ,1) then x = pre ( x ) + 1; y = pre ( y ) + 1; end when ; when y > 2 and pre ( z ) then w = f a l s e ; end when ; when x > 2 then z = f a l s e ; end when ; when y > 2 and z then v = f a l s e ; end when ; end when sorting ;

17 / 19

slide-24
SLIDE 24

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Examples

Example for correct sorting of when-equations

model when sorting Real x ; Real y ; Boolean w( s t a r t=t r u e ) ; Boolean v ( s t a r t=t r u e ) ; Boolean z ( s t a r t=t r u e ) ; equation when sample (0 ,1) then x = pre ( x ) + 1; y = pre ( y ) + 1; end when ; when y > 2 and pre ( z ) then w = f a l s e ; end when ; when x > 2 then z = f a l s e ; end when ; when y > 2 and z then v = f a l s e ; end when ; end when sorting ;

Incidence-Matrix y x w z v y = pre(y) + 1 x = pre(x) + 1 w = false z = false v = false       1 1 1 1 1 1 1 1 1 1      

17 / 19

slide-25
SLIDE 25

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Examples

Example for correct sorting of when-equations

model when sorting Real x ; Real y ; Boolean w( s t a r t=t r u e ) ; Boolean v ( s t a r t=t r u e ) ; Boolean z ( s t a r t=t r u e ) ; equation when sample (0 ,1) then x = pre ( x ) + 1; y = pre ( y ) + 1; end when ; when y > 2 and pre ( z ) then w = f a l s e ; end when ; when x > 2 then z = f a l s e ; end when ; when y > 2 and z then v = f a l s e ; end when ; end when sorting ;

17 / 19

slide-26
SLIDE 26

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Examples

Petri Net example for a production process

18 / 19

slide-27
SLIDE 27

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Examples

Petri Net example for a production process

18 / 19

slide-28
SLIDE 28

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Examples

Petri Net example for a production process

18 / 19

slide-29
SLIDE 29

Hybrid models in Modelica Implementation in OpenModelica Examples and results Summary

Summary

With this algorithmic approach we can simulate many synchronously appearing events. The Petri Net Library for OpenModelica has been optimized, so that now events can be specified with the aid of“when-equation” . The performance of the current implementation can be further improved:

by handling time events separately with a suitable step-size control. by achieving more advanced root finding methods.

19 / 19