Lecture11-10 - Systems and Computer Engineering

Download Report

Transcript Lecture11-10 - Systems and Computer Engineering

Modelling Hybrid systems
Hybrid Systems

Hybrid (combined) Modeling Framework
– Use more than one formalism
– Different formalisms to specify different levels of
abstraction
– Top-down design
– step-wise refinement
– Ex: FSM + Difference equation
Design and Implement the following waveform generator
• Observation
Periodic, say-tooth waveform
Tc : Charging time
Td : Discharging time
• Top-Level Spec in FSM
M=<X, Y, S, , >
S = { Ch, Dis}
X = { charge, discharge}
Y= { 0_to_V, V_to_0}
V
Tc
Td
Example: hierarchical control

Ex. Hierarchical control
Operator
Planning/scheduling
Event-based
control
Discrete Event
Controller
Discrete state
Command
Time-based
control
Supervisory control
PID controller
analog/digital
actuation
Sensor
Plant
Motivation
 Opto-electrical interfaces: transmitter and receiver
 Conversion of electrical current into optical impulses, and
viceversa.
Motivation

Continuous systems analysis:
 Different mathematical formalisms
 Simulation: solutions to particular problems under certain
experimental conditions of interest

Classical methods for continuous systems simulation
 Based on numerical approximation
 Require time discretization => of time
 Inefficient in terms of execution times
 Complex composition; difficulties in integration,
multiresolution models

Benefits of DEVS for continuous system M&S
 Discrete event models specification: continuous time base
 Execution time reduction
 Complex system definition using hierarchical
modular models
 Easier integration with discrete-event models
GDEVS

Generalization of DEVS formalism


Polynomial of any degree to represent piecewise input-output
trajectories
Introduction of a new event concept: coefficient-events
Piecewise linear trajectory
specification

w<t0;tn>  A a trajectory on a continuous time
base
finite set of instants t0, t1,…,tn associated with
constant pairs (ai; bi) such that t  <ti; tj>,
w(t) = ai t + bi, and
w<t0; tn> = w<t0;t1>*w<t1;t2>*…*w<tn-1;tn>

Advantages of GDEVS


Greater accuracy for continuous systems
modeling
Unified approach to model hybrid systems
Discontinuities
Event at t+d
t h
x ( t  h )  x ( t )   f ( x ( τ), u )dτ
t
f1(x,u)
t2h
t-h
dx
 f1 ( x , u )
dt
dx
 f 2 ( x, u )
dt
f2(x,u)
t
t+d t+
h
time  t  d
time  t  d
Overview of Hybrid OO modelling.

f1(x,u)
t2h
t-h
f2(x,u)
t
t+d t+
h


The occurrence of events
should be notified to the
simulation runtime.
Time events: calendar of
events is known
beforehand.
State events: triggered
by state of simulation
Quantized DEVS

Continuous signal represented by crossing of an equal
spaced set of boundaries, separated by a quantum size

Check for boundary crossing for every change in the model

Outputs generated only when a crossing occurs

Substantial reduction of the message updates frequency
Signal Quantization
DEVS Quantized models






Crossings of an equal spaced set of boundaries:
quantum
Quantizer: checks for boundary crossings.
The sender computes a value, and generates outputs.
The number of messages involved is reduced.
The quantizer consumes CPU time.
The receiver will have some error, depending on q.
Theoretical results on quantization
#messages(D) = #messages(1)/D
Error = c D
0 1
Quantum size, D
Dtol = tolerance / c
Tolerance to
error
Q-DEVS with hysteresis



strong stability, convergence and error bound
properties.
If signal changes direction: use n*Q size (proof: n=2
provides best results)
If signal keeps current direction: use Q size
QDEVS based models
Uniform quantizer

Uniform quantizer
with hysteresis
Hysteresis assures legitimate DEVS models’ simulation
Avoids
infinite iterations on finite time interval
Multiple Model Controller
Adaptive Control results
q=0.02
q=0.2
Higher-order Approximations
Complete model

Multiple model controller allowed to
operate as designed, and switch
among plant identifying models

Controller was able to find it and
use its parameters

Error existed only at the period
coinciding w/each jump in
plant
parameters

Only at time 355 did a false model
switch occur (due to two
models having almost
zero error
)
Bond Graphs




Suitable for multiple domains: electrical, mechanical,
hydraulic, etc.
Physical processes: vertices in a directed graph. Edges:
represent ideal exchange of energy between
components.
Interactions: 0-junction (connectors), 1-junction
(interactions between serial components).
Causality: given a pair of elements connected through a
bond, causality determine which component causes
flow, which effort.
SF
R
Bond Graphs Formalism

Exchange of energy and information between
elements of a system can be represented in a
graphical form

Energy is the fundamental feature that is
exchanged between elements of a system
during interaction

Constrained interactions in Bond Graphs are
represented by junctions
–
–
constraint equalizes the flow in the elements 1junction
constraint equalizes the effort in the elements 0junction
A library for Bond Graph development on
DEVS

Model library: modular approach to build systems; code reuse

Bond Graph library built to model and simulate continuous
systems on different domains

Library designed using GDEVS formalism concepts
 BG components developed as atomic GDEVS models of
degree one
 Multicomponent systems can be built as coupled
DEVS components
 Models implemented using the CD++ tool
GDEVS Capacitor model

Equations:
Flow arrives at component:
ext.
- Calculates effort: integrate
input flow data (generate
Capacitor’s load).
- Value computed according
to the elapsed time since
last transition.
- Output function transmits
the previously computed
value yout.
- Internal transition:
computes next state
using a polynomial
approximation.
External transition
. . .
// time since last transition
elapsedTime=msg.time().asMsecs()- time;
// calculates load value
c = c+a1/2*pow(elapsedTime,2)+a0*elapsedTime;
. . .
yout->updElementAtPos(1, c);
yout->updElementAtPos(2, a1/2*dt + a0);
holdIn( active, Time::Zero );
Internal transition
// approximates load using order 1 polynomial.
if ( a1 != 0 ) {
// next state calculated using coefficients
c = c + a1/2 * pow(dt,2) + a0*dt;
a0 = a1*dt + a0;
// coefficient values to send when dt elapsed
yout->updElementAtPos(1,c);
yout->updElementAtPos(2,a1/2*dt+a0);
holdIn(active, Time(dt));
}
else { passivate(); // slope is null }
BG library class hierarchy
Model execution examples

Electrical Circuit Simulation
Bond Graph model construction of the electrical circuit
Electrical circuit
Bond Graph representation
Electrical circuit simulation
GDEVS Bond Graph model representation
Bond-Graph model simulation in CD++
•Resistance (R1)=1
•Inductors: L1 = 48; L2 = 48.
•Capacitance: C = 65.
•Conductance: R2 = 0.001
•EffortSource: emits pulses; period = 2500 ms; duration = 2 ms.
Pulse amplitude= 220 V
0.003
0.002
0.001
0
0
500
1000
1500
2000
2500
-0.001
-0.002
-0.003
Circuit current
3000
3500
Model execution – Comparing Quantizers

Uniform quantizer vs. HQ (Quantizer with hysteresis)
Test cases - Evaluation functions
Function
Interval
Q
Hyst.
f(x) = sine(x)
0.1
0.1
[0,2]
f(x) = 0.9–10-5.(x mod 2) [1,10001] 0.001 0.001
f(x) = x
[0,1]
0.1
0.1
-2 2
-2
f(x) = 10 x + 10 x + 1 [-100,100]
0.1
0.1
2
f(x) = ( 1/ x ) . cosine(x) [0.0001,1] 0.001 0.001
f(x) = - log x
[0.1,1.1]
0.01
0.01
f(x) = 1/x
[0,1000] 0.0001 0.0001
x
4
f(x) = (-1) . 1/(ln(x))
[2,100] 0.0001 0.0001
1.5
1
0.5
0
-0.5
-1
-1.5
Modelica

object-oriented language for modeling physical systems

designed to support library development and model exchange

Modelica supports different formalisms such as:
–
–
–
–
–
ODEs
finite state automata
Petri nets
discrete events
bond graphs
Creating Models in Modelica/CD++
Model circuit
Modelica.Electrical.Analog.Sources.SineVoltage
V(V=15,freqHz=60);
Modelica.Electrical.Analog.Basic.Resistor
R1(R=10);
Modelica.Electrical.Analog.Basic.Ground Gnd;
equation
connect(V.p, R1.p);
connect(R1.n, V.n);
connect(R1.n, Gnd.p);
end circuit1;
Current and Voltage on R1
20
15
10
5
V,
0
C
-5 1
-10
-15
-20
5
9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 73
time
Current
Voltage
M/CD++ Execution Example: Modelica model
model circuit
Modelica.Electrical.Analog.Sources.
PulseVoltage V(V=10,width=50, period=2.5);
Modelica.Electrical.Analog.Basic.Resistor
R1(R=0.001);
Modelica.Electrical.Analog.Basic.Inductor
I1(L=500);
Modelica.Electrical.Analog.Basic.Inductor
I2(L=2000);
Modelica.Electrical.Analog.Basic.Capacitor
C(C=10);
Modelica.Electrical.Analog.Basic.Resistor
R2(R=1000);
Modelica.Electrical.Analog.Basic.Ground Gnd;
equation
connect(V.p, R1.p); connect(R1.n, I1.p);
connect(R1.n, I2.p); connect(I2.n, C.p);
connect(I2.n, R2.p); connect(C.n, I1.n);
connect(R2.n, C.n); connect(I1.n, V.n);
connect(V.n, Gnd.p);
end circuit;
M/CD++ Execution Example: The results
Capacitor.v curves comparison
1.60E-02
1.40E-02
Capacitor.v
1.20E-02
1.00E-02
8.00E-03
6.00E-03
4.00E-03
2.00E-03
0.00E+00
0.00
2.00
4.00
6.00
8.00
10.00
Time (sec)
MCD++ interpolated by Dymola
MCD++
12.00
M/CD++ Execution Example: The results
Inductor1.i curves comparison
1.20E-01
Inductor1.i
1.00E-01
8.00E-02
6.00E-02
4.00E-02
2.00E-02
0.00E+00
0.00
2.00
4.00
6.00
8.00
Time (sec)
MCD++ interpolated by Dymola
MCD++
10.00
Modelica/DEVSLib Model
 Transmitter model
 The received electrical current (continuous) is translated
into optical impulses (discrete).
 The driver model can include any modulation and
polarization circuit. No actions performed in this case, to
simplify the model.
 The laser translates the electrical signal into events using
the crossUP model included in DEVSLib.
Modelica/DEVSLib Model
Detail of the crossUP model
when (u > Value-Threshold) and x > 0 and time > 0 then
e.Type := EType;
e.Value := u;
e.Port := 1;
sendEvent(outport.queue, e);
outport.event := pre(outport.event) + 1;
end when;
Cell-DEVS quantization
Quantized Cell-DEVS
• Every cell includes a quantizer.
• The value produced by the local
computing function is quantized.
• The quantized value is compared
with the quantum threshold.
• If the threshold bound was reached, an output is provided.
The output is delayed using transport or inertial delays.
• If the threshold was not reached, the change is not sent to
other models.
Experimental results
(a) Heat diffusion: two-dimensional model (10x10 cells).
One "hot" cell.
(b) Heat model with 87% of active cells.
(c) Three-dimensional extension of the previous model.
(d) Three-dimensional modification of the Life game
(e) Four dimensional extension of the previous model.
(f) Dynamic heat seeker: a three dimensional model
consisting of two adjacent planes.
Number of messages involved
10000
8000
6000
4000
2000
0
0
0.001 0.01
Quantized
0.1
0.5
Non Q.
1
30000
25000
20000
15000
10000
5000
0
0
0.001
0.01
0.1
Quantized
f(x) = 1860x-0.15
0.5
1
Non Q.
f(x) = 4790 x-0.32
 Smaller reduction in (b): higher active initial cells.
 Model (c): higher number of messages (neighborhood, cell space).
Smaller proportion of active cells. Similar results for model (e) (4-D).
 Model (d): 60% of active cells. N = 7 cells. Shorter simulation (33%).
 Model (f): initial reduction 1% - 5%. Initial precision: 0.1 degrees. Avg.
temperature differs in 0.01 or 0.001 only after long execution time.
Error behavior
1.5
0.2
0.15
1
0.1
0.5
0.05
0
0
0
0.001
0.01
0.1
1
(a) f(x) = 0.1 x0.63
10
0
0.001
0.01
0.1
0.5
(b) f(x) = 1.58 x0.77
(a) non-quantized and q=0.001; (b) q=0.1; (c) q=1.
1
Cell-DEVS w/Dynamic Quantization

Reduce error (improving precision) in each cell.

Rationale: active cell can appear
as quiescent (Q size covering activity area).
Q dynamically adjusted -> smaller error.

Dynamic increase Q in cells with steep
functions: execution improved at a low cost.

Strategy 1: reduce Q if cell's update does not
cross threshold (increase precision).
Strategy 2: reduce Q if threshold is crossed (2nd chance in
case of oscillations; higher precision).

update
Test cases: a heart tissue model


Heart muscle excitable; responds to external
stimuli by contracting muscular cells.
Equations defined by Hodgkin and Huxley
A Watershed model
Excedent water
to neighbor
flowing
lands lvs(t)
Rain
Water
l(t)
Surface vegetation
Effective water
Water received
byfrom the
neighbors
lve(t)
le(t)
Acumulated water
Ac(t)
Land absortion
water f(t)
WSHED - Topology - Time 0
95-100
WSHED - Quantum Hys 1.0 - After 10'
95-100
90-95
90-95
85-90
85-90
80-85
80-85
75-80
75-80
70-75
70-75
65-70
65-70
60-65
60-65
55-60
55-60
50-55
50-55
45-50
45-50
40-45
40-45
35-40
35-40
30-35
30-35
25-30
25-30
20-25
20-25
Flow Injection Analysis Model
No Quantum, 120ms
Q-DEVS 0.1, 120ms
Quantum Standard 0.7 Dynamic 1 - 0.05, 120ms
Approximating the Corsica fire model