Index Theory and Structural Analysis for multi-mode DAE Systems Albert Benveniste (Inria, Rennes) Benoît Caillaud (Inria, Rennes) Marc Pouzet (ENS, Paris) Hilding Elmqvist (Mogram, Lund) Martin Otter (DRL, Munich) INRIA and ENS, France May 27, 2016 1 / 34 Motivation: physical system modeling Background: Exact and Structural DAE index Using NonStandard Analysis, DAE become dAE and index is preserved Structural analysis of multi-mode DAE systems: approach Examples Discrete time multi-mode dAE Continuous time multi-mode DAE Formalization: Structural Analysis of multi-mode dAE systems Formalization: Structural Analysis of multi-mode DAE and Pantelides Standardization Conclusions 2 / 34 Compositionality and reuse: Simulink → Modelica Simulink has become a central tool in systems design: Block Diagram 3 / 34 Compositionality and reuse: Simulink → Modelica From Block Diagram to Component Diagram 3 / 34 Compositionality and reuse: ODE → DAE 0 x = f (x , u ) y = g (x , u ) from Simulink (ODE): HS in state space form the state space form depends on the context reuse is difficult −→ to Modelica (DAE): HS as physical balance equations 0 = f (x 0 , x , u ) 0 = g (x , u ) Ohm & Kirchhoff laws, bond graphs, multi-body mechanical systems; DAE are context-free reuse is much easier 4 / 34 Compositionality and reuse: ODE → DAE I Modeling tools supporting DAE I Some modeling tools provide a library of predefined models ready for assembly (e.g., LMS/AmeSim) ; I Spice is a popular language dedicated to EDA I Mathworks/Simscape reuses Matlab as a programming language, in which “=” has been replaced by “==”, indicating a constraint I Modelica comes with a full programming language that is a public standard https://www.modelica.org/ 5 / 34 A sketch of Modelica and its semantics [Fritzson] Summary model SimpleDrive ..Rotational.Inertia Inertia1 (J=0.002); ..Rotational.IdealGear IdealGear1(ratio=100) ..Basic.Resistor Resistor1 (R=0.2) ... equation connect(Inertia1.flange_b, IdealGear1.flange_a); connect(Resistor1.n, Inductor1.p); ... end SimpleDrive; model Resistor package SIunits = Modelica.SIunits; type Voltage = Real(quantity="Voltage", parameter SIunits.Resistance R = 1; unit ="V"); SIunits.Voltage v; ..Interfaces.PositivePin p; ..Interfaces.NegativePin n; connector PositivePin equation package SIunits = Modelica.SIunits; 0 = p.i + n.i; SIunits.Voltage v; v = p.v - n.v; flow SIunits.Current i; v = R*p.i; end PositivePin; end Resistor; Sunday, October 12, 2003 Multi-domain Modeling and Simulation with Modelica 35 6 / 34 A sketch of Modelica and its semantics [Fritzson] I Modelica Reference v3.3: “The semantics of the Modelica language is specified by means of a set of rules for translating any class described in the Modelica language to a flat Modelica structure” I the good: I Semantics of continuous-time 1-mode Modelica models: Cauchy problem on the DAE resulting from the inlining of all components I Modelica supports multi-mode systems x*x + y*y = 1; der(x) + x + y = 0; when x <= 0 do reinit(x,1); end; when y <= 0 do reinit(y,x); end; I the bad: What about the semantics of multi-mode systems? I and . . . : Questionable simulations [Tim Bourke and Marc Pouzet] 6 / 34 Examples of multi-mode systems Cup-and-Ball game (a two-mode extension of the pendulum) A Clutch A Circuit Breaker 7 / 34 Motivation: physical system modeling Background: Exact and Structural DAE index Using NonStandard Analysis, DAE become dAE and index is preserved Structural analysis of multi-mode DAE systems: approach Examples Discrete time multi-mode dAE Continuous time multi-mode DAE Formalization: Structural Analysis of multi-mode dAE systems Formalization: Structural Analysis of multi-mode DAE and Pantelides Standardization Conclusions 8 / 34 A key notion in DAE/dAE Systems: the index I Differential Algebraic Equations systems (DAE, continuous time) may involve more constraints than specified: x 0 0 = = f (x , u ) g (x ) differentiating =⇒ substituting =⇒ 0 x 0 0 0 x 0 0 = f (x , u ) = g (x ) = gx0 (x )x 0 = = = f (x , u ) g (x ) gx0 (x )f (x , u ) (e 1 ) (e2 ) (e3 ) I What is the consequence for execution schemes? 9 / 34 A key notion in DAE/dAE Systems: the index I difference Algebraic Equations systems (dAE, discrete time) may involve more constraints than specified: x 0 • = f (x , u ) = g (x ) shifting =⇒ substituting =⇒ • x 0 0 • x 0 0 = f (x , u ) = g (x ) = g (x • ) = f (x , u ) = g (x ) = g (f (x , u )) (e1 ) (e2 ) (e3 ) 9 / 34 A key notion in DAE/dAE Systems: the index I difference Algebraic Equations systems (dAE, discrete time) may involve more constraints than specified: x 0 • = f (x , u ) = g (x ) shifting =⇒ substituting =⇒ • x 0 0 • x 0 0 = f (x , u ) = g (x ) = g (x • ) = f (x , u ) = g (x ) = g (f (x , u )) (e1 ) (e2 ) (e3 ) I Execution scheme: 1. Given x such that g (x ) = 0 2. Use (e3 ) to evaluate u (constraint solver needed) 3. Use (e1 ) to evaluate x • , which satisfies g (x • ) = 0, and repeat Adding (e3 ) essential in deriving the execution scheme of each step 9 / 34 A key notion in DAE/dAE Systems: the index I difference Algebraic Equations systems (dAE, discrete time) may involve more constraints than specified: x 0 • = = f (x , u ) g (x ) shifting =⇒ shifting twice =⇒ • x 0 0 • x 0 0 0 = = = f (x , u ) g (x ) g (x • ) = = = = f (x , u ) g (x ) g (x • ) g (x •2 ) (e1 ) (e2 ) (e3 ) (e4 ) I Shifting twice is useless since the second shifting introduces 1. eqn (e4 ) but also 2. the fresh variable x •2 Thus, adding (e4 ) does not help getting the value of x • 9 / 34 A key notion in DAE/dAE Systems: the index I difference Algebraic Equations systems (dAE, discrete time) may involve more constraints than specified: x 0 •2 = = f (x , u ) g (x ) shifting =⇒ shifting twice =⇒ •2 x 0 0 •2 x 0 0 0 = f (x , u ) = g (x ) = g (x • ) = = = = f (x , u ) g (x ) g (x • ) g ( x •2 ) (e1 ) (e2 ) (e3 ) (e4 ) I This time, shifting twice is useful since the second shifting introduces 1. eqn (e4 ) and 2. the variable x •2 , which is not fresh but already there 9 / 34 A key notion in DAE/dAE Systems: the index I Differential Algebraic Equations systems (DAE, continuous time) may involve more constraints than specified: x 0 0 = f (x , u ) = g (x ) differentiating =⇒ substituting =⇒ I 0 x 0 0 0 x 0 0 = f (x , u ) = g (x ) = gx0 (x )x 0 = f (x , u ) (e1 ) = g (x ) (e2 ) = gx0 (x )f (x , u ) (e3 ) ∼ ODE if we have a constraint solver providing x → u by using (e3 ) 9 / 34 A key notion in DAE/dAE Systems: the index I differentiations shiftings make DAE dAE becoming ODE TS -like (TS: transition system) I Define the differentiation / difference index as being the minimal number of differentiations shiftings needed until no further differentiation no further shifting can reveal additional latent constraints. I The differentiation index emerged in the late 1980’s in the applied math community; other notions of index were proposed [Campbell & Gear 1995]. I Yet, no notion of index was formally defined for multi-mode DAE systems. 9 / 34 Differentiation/Difference Index: (1) exact F (x , x 0 ) = 0 F (x , x • ) = 0 Fk (x ,v ,w ) z F (x , x 0 ) d F (x , x 0 ) dt .. .x , x 0 ) k d F (x , x 0 ) dt k F (x , x • ) F • (x , x • ) .. • ., x ) F •k ( x , x • ) =def =def | [Campbell & Gear 1995]: F (0) (x , x 0 , w ) F (1) (x , x 0 , w ) .. .x , x 0 , w ) (k ) F (x , x 0 , w ) }| { F (0) (x , x • , w ) F (1) (x , x • , w ) .. • ., x , w ) F (k ) (x , x • , w ) {z } Fk (x ,v ,w ) , v =def x 0 w =def (x (2) , . . . , x (k +1) ) v =def x • , w =def (x •2 , . . . , x •k +1 ) The index is the smallest k such that solving Fk (x , v , w ) = 0 while eliminating w uniquely determines v as a partial function of x 10 / 34 Differentiation/Difference Index: (1) exact 0 0 = = x 0 − f (x , u ) g (x ) set S (x , v ) =def x 0 − f (x , u ) g (x ) where x is the state and v =def (x 0 , u ); consider the Jacobian J =def dS /dv = 1 0 −fu0 (x , u ) is structurally singular 0 v cannot be determined and S has index > 0. Set w = (x 00 , u 0 ) and consider 0 x 0 − f (x , u ) x − f (x , u ) g (x ) ⇒ g (x ) = g 0 (x )x 0 g 0 (x )x 0 00 d x − dt f (x , u ) S 1 (x , v , w ) =def S (x , v ) d S (x , v , w ) dt J1 =def 1 dS1 /dv = 0 1 −fu0 (x , u ) 0 0 ⇒ 1 1 −fu0 (x , u ) 0 invertible MMMhhhhh, only structurally invertible — it may happen that fu0 (x , u ) = 0 11 / 34 Differentiation/Difference Index: (1) exact 0 0 = = x 0 − f (x , u ) g (x ) set S (x , v ) =def x 0 − f (x , u ) g (x ) where x is the state and v =def (x 0 , u ); consider the Jacobian J =def dS /dv = 1 0 −fu0 (x , u ) is structurally singular 0 v cannot be determined and S has index > 0. Set w = (x 00 , u 0 ) and consider 0 x 0 − f (x , u ) x − f (x , u ) g (x ) ⇒ g (x ) = g 0 (x )x 0 g 0 (x )x 0 00 d x − dt f (x , u ) S 1 (x , v , w ) =def S (x , v ) d S (x , v , w ) dt J1 =def 1 dS1 /dv = 0 1 −fu0 (x , u ) 0 0 ⇒ 1 1 −fu0 (x , u ) 0 invertible MMMhhhhh, only structurally invertible — it may happen that fu0 (x , u ) = 0 11 / 34 Differentiation/Difference Index: (2) structural E 0 E1 E 2 E3 : : : : x0 0 0 0 =def = = = 1 • − x) x − f (x , u ) g (x ) g 0 (x )x 0 ∂ (x 0 E1 x E1 x E2 u E2 u E3 x0 E3 x0 structural pivoting (Pantelides algorithm) ⇔ searching for a consistent orientation of the incidence graph 12 / 34 Differentiation/Difference Index: (2) structural E 0 E1 E 2 E3 : : : : x0 0 0 0 =def = = = 1 • − x) x − f (x , u ) g (x ) g (x • ) ∂ (x 0 E1 x E1 x E2 u E2 u E3 x• E3 x• structural pivoting (Pantelides algorithm) ⇔ searching for a consistent orientation of the incidence graph 12 / 34 Differentiation/Difference Index: (2) structural I Exact differentiation/difference index: I adding differentiated/shifted versions of subsets of equations I until leading variables can be determined from other variables I Structural differentiation/difference index: I adding differentiated/shifted versions of subsets of equations I until leading variables can be determined from other variables, almost everywhere I Theorem: the graph-based structural analysis finds the structural index. 12 / 34 Motivation: physical system modeling Background: Exact and Structural DAE index Using NonStandard Analysis, DAE become dAE and index is preserved Structural analysis of multi-mode DAE systems: approach Examples Discrete time multi-mode dAE Continuous time multi-mode DAE Formalization: Structural Analysis of multi-mode dAE systems Formalization: Structural Analysis of multi-mode DAE and Pantelides Standardization Conclusions 13 / 34 Recall: structural Differentiation/Difference Index E 0 E1 E 2 E3 : : : : x0 0 0 0 =def = = = 1 • − x) x − f (x , u ) g (x ) g 0 (x )x 0 ∂ (x 0 E1 x E1 x E2 u E2 u E3 x0 E3 x0 structural pivoting (Pantelides algorithm) ⇔ searching for a consistent orientation of the incidence graph 14 / 34 Recall: structural Differentiation/Difference Index E 0 E1 E 2 E3 : : : : x0 0 0 0 =def = = = 1 • − x) x − f (x , u ) g (x ) g (x • ) ∂ (x 0 E1 x E1 x E2 u E2 u E3 x• E3 x• structural pivoting (Pantelides algorithm) ⇔ searching for a consistent orientation of the incidence graph 14 / 34 Recall: structural Differentiation/Difference Index For the previous example, I the DAE system and I its 1st -order Euler expansion (a dAE system) possess identical structural analyses. I Theorem: This result is true in general ∂ infinitesimal in the sense of non-standard analysis, yields an exact representation of the DAE system, not an approximation of it I Taking, in the Euler approximation, 14 / 34 Motivation: physical system modeling Background: Exact and Structural DAE index Using NonStandard Analysis, DAE become dAE and index is preserved Structural analysis of multi-mode DAE systems: approach Examples Discrete time multi-mode dAE Continuous time multi-mode DAE Formalization: Structural Analysis of multi-mode dAE systems Formalization: Structural Analysis of multi-mode DAE and Pantelides Standardization Conclusions 15 / 34 Structural analysis of single-mode dAE systems I Classify the system variables into I leading variables (of max differentiation/shifting degree) I other variables I Execution principle: I at initialization: evaluate all variables I otherwise: evaluate leading variables 16 / 34 Structural analysis of single-mode dAE systems Pantelides (outside initialization): I In order to find latent equations of a system S involving n equations n variables 1. Fill a bag BS with all equations of S and their shifted versions; 2. Let BS be the collection I of all subsets of n or more equations from BS I ensuring the evaluation of all the leading variables of S 3. Select an element of BS such that the max shift used is minimal. 16 / 34 Structural analysis of multi-mode DAE systems non-standard interpretation (removing logico-numerical fixpoints) mDAE mdAE Applying Pantelides (adding mode-dependent latent equations) standardizing (within modes and at mode changes) standard domain non-standard domain Approach : translating s ↔ ns 17 / 34 Motivation: physical system modeling Background: Exact and Structural DAE index Using NonStandard Analysis, DAE become dAE and index is preserved Structural analysis of multi-mode DAE systems: approach Examples Discrete time multi-mode dAE Continuous time multi-mode DAE Formalization: Structural Analysis of multi-mode dAE systems Formalization: Structural Analysis of multi-mode DAE and Pantelides Standardization Conclusions 18 / 34 A simple unilateral constraint in discrete time x • 0 = ≤ f (x , u ) g (x ) expands as x • = f (x , u ) γ = [ 0≥g (x )] when γ do g (x )=0 (e1 ) (γ ) (e3 ) We apply our approach: 1. Check if we can find a successful execution scheme 2. Find countermeasures in case of failure 19 / 34 A simple unilateral constraint in discrete time x • 0 = ≤ f (x , u ) g (x ) T F ⊥ ? = = = = expands as evaluated or true false dead code not evaluated yet x • = f (x , u ) γ = [ 0≥g (x )] when γ do g (x )=0 in (e1 ) (γ ) (e3 ) e1 (x • , u , x ) γ(x ) when γ do e3 (x ) 19 / 34 A simple unilateral constraint in discrete time x • 0 = ≤ f (x , u ) g (x ) = F = ⊥ = ? = T expands as evaluated or true false dead code not evaluated yet x • = f (x , u ) γ = [ 0≥g (x )] when γ do g (x )=0 in x , γ known from previous step stuck at e3 (.) with no variable left : (e1 ) (γ ) (e3 ) e1 (x • , u , x ) γ(x ) when γ do e3 (x ) e1 (x • , u , x ) γ(x ) when γ do e3 (x ) I fixpoint involving a guard; we must break this fixpoint I principle: have guards acting on leading variables I hence we replace e3 (x ) by e3 (x • ) 19 / 34 A simple unilateral constraint in discrete time x • 0 = ≤ f (x , u ) g (x ) = F = ⊥ = ? = T expands as evaluated or true false dead code not evaluated yet x • = f (x , u ) γ = [ 0≥g (x )] when γ do g (x )=0 in (e1 ) (γ ) (e3 ) e 1 (x • , u , x ) γ(x ) when γ do e3 (x • ) e 1 (x • , u , x ) γ(x ) when γ do e3 (x • ) success in case γ = T failure in case γ = F by having 1 equation and 2 variables e 1 (x • , u , x ) γ(x ) when γ do e3 (x • ) e 1 (x • , u , x ) γ(x ) when γ do ⊥ 19 / 34 A simple unilateral constraint in discrete time x • = ≤ 0 T F ⊥ ? = = = = f (x , u ) g (x ) expands as evaluated or true false dead code not evaluated yet x • = f (x , u ) γ = [ 0≥g (x )] when γ do g (x )=0 in added stub (state feedback) success in case γ = F success in case γ = T : (e1 ) (γ ) (e3 ) e 1 (x • , u , x ) γ(x ) • when γ do e 3 (x ) when not γ do e4 (u , x ) when not γ do h(x , u ) = 0 e1 (x • , u , x ) γ(x ) when γ do ⊥ when not γ do e4 (u , x ) e1 (x • , u , x ) γ(x ) • when γ do e 3 (x ) when not γ do ⊥ 19 / 34 A simple unilateral constraint in discrete time x • 0 = ≤ f (x , u ) g (x ) expands as complementarity condition in the tuple (u , x • ), with the stub x • = f (x , u ) γ = [ 0≥g (x )] when γ do g (x )=0 (e1 ) (γ ) (e3 ) • x −f ( x , u ) = 0 0≤g (x • ) ⊥ |h(x , u )| ≥0 {z } | : • g (x ) ≥ 0 |h(x , u )| ≥ 0 expands as: • g (x )×|h(x , u )| = 0 I Alternative approach: using complementarity conditions as atomic actions for handling by non-smooth systems solvers [Acary & Brogliato] I For the structural analysis: complementarity conditions ≡ regular systems of smooth equations I Our structural analysis regards as blocks both: I I regular systems of smooth equations and complementarity conditions 19 / 34 Cup-and-ball in continuous time Two-mode pendulum z 00 = when when 00 γ not γ do do 1 ∂ 2 (z •2 − 2z • + z ) x = fx y 00 = fy − g γ = [ x 2 + y 2 ≥ L2 ] x 2 + y 2 = L2 f =0 (e0 ) (e1 ) (e2 ) (γ ) (e4 ) (e5 ) 20 / 34 Cup-and-ball in continuous time Recalling our approach: non-standard interpretation (removing logico-numerical fixpoints) mDAE mdAE Applying Pantelides (adding mode-dependent latent equations) standardizing (within modes and at mode changes) 20 / 34 Cup-and-ball in continuous time Two-mode pendulum in non-standard analysis z 00 = when when I 1 ∂ 2 (z •2 − 2z • + z ) 00 γ not γ do do x = fx y 00 = fy − g γ = [ x 2 + y 2 ≥ L2 ] x 2 + y 2 = L2 f =0 (e0 ) (e1 ) (e2 ) (γ ) (e4 ) (e5 ) (e0 ) is a generic expansion that applies to each second derivative I Stuck by a causality fixpoint for the pair (γ, e4 ) I Countermeasure: let the equations (e4 , e5 ) act on leading variables I I (e5 ): OK (e4 ): shift (x , y ) two times forward 20 / 34 Cup-and-ball in continuous time Performing this yields: z 00 = when when 00 γ not γ do do 1 ∂ 2 (z •2 − 2z • + z ) x = fx y 00 = fy − g γ = [ x 2+ y 2 ≥ L2 ] x 2 + y 2 •2 = L2 f =0 (e0 ) (e1 ) (e2 ) (γ ) (e4•2 ) (e5 ) 20 / 34 Cup-and-ball in continuous time Performing this yields: z 00 = 1 ∂ 2 (z •2 − 2z • + z ) (e0 ) 00 when when γ not γ do do x = fx y 00 = fy − g γ = [ x 2+ y 2 ≥ L2 ] x 2 + y 2 •2 = L2 f =0 tick (e1 ) (e2 ) (γ ) (e4•2 ) (e5 ) x = x0 = y = y0 = T γ= γ= T (e1 , e2 , e4•2 ) = x 00 = y 00 = f = T F e5 = f = T tick e1 = x 00 = T e2 = y 00 = T The evaluation scheme succeeds 20 / 34 Cup-and-ball in continuous time Performing this yields: z 00 = when when 1 ∂ 2 (z •2 − 2z • + z ) 00 γ not γ do do x = fx y 00 = fy − g γ = [ x 2+ y 2 ≥ L2 ] x 2 + y 2 •2 = L2 f =0 (e0 ) (e1 ) (e2 ) (γ ) (e4•2 ) (e5 ) We proceed to standardization: (. . . )•2 in (e4•2 ) since forward shifts have no standard counterpart I Within continuous modes we must get rid of the I At an event t of mode change, map the forward shift to super-dense time • • • • t ≡ (t , 0) → (t , 1) → (t , 2) → . . . → (t , nt ) But we must get rid of second derivatives in (e1 , e2 ) since they involve ∂ 20 / 34 Cup-and-ball in continuous time Standardization within continuous modes: Taylor expansion of (. . . )•2 in (e4•2 ) x2 + y2 0= expands as 0= +2∂ +2∂ 2 • 2 − L2 (x 2 + y 2 − L2 ) . (xx 0 + yy 0 ) 2 2 (xx 00 + yy 00 + x 0 + y 0 ) The second equation must hold structurally w.r.t. ∂ , hence the standardization is: when γ when not γ do and and do x 00 = fx y 00 = fy − g γ = [ x 2 + y 2 ≥ L2 ] x 2 + y 2 = L2 xx 0 + yy 0 = 0 2 2 xx 00 + yy 00 + x 0 + y 0 = 0 f =0 (e1 ) (e2 ) (γ ) (e4 ) (e40 ) (e400 ) (e5 ) which coincides with the equations of the pendulum 20 / 34 Cup-and-ball in continuous time Standardization at events: non-standard expansion of second derivatives in (e1 , e2 ) in terms of forward shifts and positions x , y x •2 − 2x • + x = ∂ 2 fx y •2 − 2y • + y = ∂ 2 (fy − g ) γ = [ x 2 + y 2 ≥ L2 ] when when γ not γ do x 2 + y 2 do f = 0 • 2 = L2 (e1 ) (e2 ) (γ ) (e4•2 ) (e5 ) (γ, e4•2 , e5 ) are fine but we must get rid of ∂ 2 in (e1 , e2 ): I at the event γ: T → F: we eliminate f by substituting f = 0 in (e1 , e2 ); x •2 − 2x • + x = 0 y •2 − 2y • + y = 0 which we solve for the leading variables x •2 , y •2 20 / 34 Cup-and-ball in continuous time Standardization at events: non-standard expansion of second derivatives in (e1 , e2 ) in terms of forward shifts and positions x , y x •2 − 2x • + x = ∂ 2 fx y •2 − 2y • + y = ∂ 2 (fy − g ) γ = [ x 2 + y 2 ≥ L2 ] when when γ not γ do x 2 + y 2 do f = 0 • 2 = L2 (e1 ) (e2 ) (γ ) (e4•2 ) (e5 ) (γ, e4•2 , e5 ) are fine but we must get rid of ∂ 2 in (e1 , e2 ): I at the event γ: F → T: we eliminate f from (e1 , e2 ): (x •2 − 2x • + x )y − (y •2 − 2y • + y )x = 0 • 2 x2 + y2 − L2 = 0 (e12 ) (e4•2 ) which we solve for the leading variables x •2 , y •2 (f is impulsive) So far we got the positions at (t , 2), if t = (t , 0) is the instant of mode change. In addition we need the velocities. 20 / 34 Cup-and-ball in continuous time Standardization at events: non-standard expansion of second derivatives in (e1 , e2 ) in terms of forward shifts and velocities x 0 , y 0 when when γ not γ do do x 0• − x 0 = ∂ fx y 0• − y 0 = ∂(fy − g ) γ = [ x 2 + y 2 ≥ L2 ] • (xx 0 + yy 0 ) = 0 f =0 (e1 ) (e2 ) (γ ) • (e40 ) (e5 ) • (γ, e40 , e5 ) are fine but we must get rid of ∂ 2 in (e1 , e2 ): I at the event γ: T → F: we eliminate f by substituting f = 0 in (e1 , e2 ); x 0• − x 0 = 0 y 0• − y 0 = 0 which we solve for the leading variables x 0• , y 0• 20 / 34 Cup-and-ball in continuous time Standardization at events: non-standard expansion of second derivatives in (e1 , e2 ) in terms of forward shifts and velocities x 0 , y 0 when when γ not γ do do x 0• − x 0 = ∂ fx y 0• − y 0 = ∂(fy − g ) γ = [ x 2 + y 2 ≥ L2 ] • (xx 0 + yy 0 ) = 0 f =0 (e1 ) (e2 ) (γ ) • (e40 ) (e5 ) • (γ, e40 , e5 ) are fine but we must get rid of ∂ 2 in (e1 , e2 ): I at the event γ: F → T: we eliminate f from (e1 , e2 ): (x 0• − x 0 )y − (y 0• − y 0 )x = 0 • (xx 0 + yy 0 ) = 0 which we solve for the leading variables x 0• , y 0• (f is impulsive) Applying this at (t , 1) yields the velocities at (t , 2). We have eveything we need for the initialization of the new continuous mode. 20 / 34 Cup-and-ball in continuous time Problem with the above approach: we used elimination based on computer algebra. Not always possible. Here is a first approach to cope with this. S : x •2 − 2x • + x = ∂ 2 fx y •2 − 2y • + y = ∂ 2 (fy − g ) γ = [ x 2 + y 2 ≥ L2 ] when when do x 2 + y 2 do f = 0 γ not γ • 2 = L2 (e1 ) (e2 ) (γ ) (e4•2 ) (e5 ) Suppose that all expressions involved in the system are polynomial in the variables (it is the case here). Expand the tension f as a polynomial in ∂ −1 : f = f0 + f1 ∂ −1 + f2 ∂ −2 and we are left with the following three systems when (e4•2 ) is active: f0 = f1 = 0 , •2 • x − 2x + x = f2 x •2 y − 2y • + y = f2 y •2 x2 + y2 = L2 20 / 34 Cup-and-ball in continuous time Problem with the above approach: we used elimination based on computer algebra. Not always possible. Here is a second approach to cope with this. We can always instead compute the following two steps with ∂ > 0 a small (standard) step size and solve for the leading variables: at t at t + ∂ : : x •2 − 2x • + x = ∂ 2 f x y •2 − 2y • + y = ∂ 2 (f y − g ) γ = [ x 2 + y 2 ≥ L2 ] when γ when not γ do x 2 + y 2 do f = 0 when γ when not γ do do • 2 = L2 x 0• − x 0 = ∂ f x y 0• − y 0 = ∂(f y − g ) γ = [ x 2 + y 2 ≥ L2 ] • (xx 0 + y y 0 ) = 0 f =0 This way we obtain at t + 2∂ a consistent value for the positions and velocities and can restart the continuous time mode. 20 / 34 Cup-and-ball in continuous time Summary: z 00 = 1 ∂ 2 (z •2 − 2z • + z ) 00 when when γ not γ do do x = fx y 00 = fy − g γ = [ x 2+ y 2 ≥ L2 ] x 2 + y 2 •2 = L2 f =0 entering tight rope continuous time mode with γ = F (t , 1) mode change and reset discrete time (t , 2) (t , 1) (e0 ) (e1 ) (e2 ) (γ ) (e4•2 ) (e5 ) (t , 2) continuous time mode with γ = T exiting tight rope 20 / 34 Cup-and-ball in continuous time Using complementarity conditions: z 00 = ∂12 (z •2 − 2z • + z ) 00 x = fx y 00 = fy − g 0≤ (x •2 )2 +(y •2 )2 −L2 (e0 ) ⊥ f ≥0 (e1 ) (e2 ) (e3 ) Again, we standardize by eliminating the shifts using Taylor expansions to get the code for continuous time modes: 00 x = fx y 00 = fy 2− g 2 x + y − L2 0≤ xx 0 + yy 0 00 00 02 02 xx + yy + x + y (e1 ) (e2 ) ⊥ f ≥0 (e3 ) For the first vector, we equip R3 with the lexicographic order: (u , v , w ) > 0 iff either [u > 0] or [u = 0 and v > 0] or [u = v = 0 and w > 0] 20 / 34 A simple clutch (continuous time) when when when when I ui /ci I γ γ not γ not γ do do do do z 0 = ∂1 (z • − z ) u10 = f1 (u1 , c1 ) u20 = f2 (u2 , c2 ) u1 = u2 c1 + c2 = 0 c1 = 0 c2 = 0 (e0 ) (e1 ) (e2 ) (e3 ) (e4 ) (e5 ) (e6 ) areare the two speeds/torques γ = F/T is an input representing the pressed/released mode 21 / 34 A simple clutch (continuous time) when when when when γ γ not γ not γ do do do do z 0 = ∂1 (z • − z ) u10 = f1 (u1 , c1 ) u20 = f2 (u2 , c2 ) u1 = u2 c1 + c2 = 0 c1 = 0 c2 = 0 (e0 ) (e1 ) (e2 ) (e3 ) (e4 ) (e5 ) (e6 ) I Fails by not having guards acting on leading variables I Counter-measure: shifting forward u1 , u2 21 / 34 A simple clutch (continuous time) when when when when tick γ γ not γ not γ γ = z 0 = ∂1 (z • − z ) u10 = f1 (u1 , c1 ) u20 = f2 (u2 , c2 ) u1• = u2• c1 + c2 = 0 c1 = 0 c2 = 0 do do do do γ = T γ = T, u1 = u2 = T c1 = c2 = T, u1• = u2• = tick F γ = F, u1 = u2 = T e1 = e2 = e3• = e4 = (e0 ) (e1 ) (e2 ) (e3• ) (e4 ) (e5 ) (e6 ) e5 = c1 = T e6 = c2 = T T T e1 = e2 = T, u1• = u2• = T The execution scheme succeeds 21 / 34 A simple clutch (continuous time) when when when when γ γ not γ not γ do do do do z 0 = ∂1 (z • − z ) u10 = f1 (u1 , c1 ) u20 = f2 (u2 , c2 ) u1• = u2• c1 + c2 = 0 c1 = 0 c2 = 0 (e0 ) (e1 ) (e2 ) (e3• ) (e4 ) (e5 ) (e6 ) Standardization is performed as for the previous example: super-dense time at reset events get rid of ∂ in (e1 , e2 ) • • u1 = u2 u10 = f1 (u1 , c1 ) u20 = f2 (u2 , c2 ) u1 = u2 u10 = u20 ↔ ↔ Taylor expansion in continuous modes 21 / 34 Motivation: physical system modeling Background: Exact and Structural DAE index Using NonStandard Analysis, DAE become dAE and index is preserved Structural analysis of multi-mode DAE systems: approach Examples Discrete time multi-mode dAE Continuous time multi-mode DAE Formalization: Structural Analysis of multi-mode dAE systems Formalization: Structural Analysis of multi-mode DAE and Pantelides Standardization Conclusions 22 / 34 Approach inherited from Synchronous Languages I The structural analysis consists in searching for I a mode-dependent assignment variable ←− equation I such that the variable can be evaluated using its assigned equation; I blocks of {variables, equations} may be needed I This turns out to be an extension of the constructive semantics [Berry1996, Benveniste et al.2003], which served as a mathematical basis for the code generation from synchronous languages 23 / 34 A multi-mode dAE language and its abstraction var prop num pred eqn term def system ::= X | var • ::= T | F | var | not prop | prop and prop ::= num ::= pred “predicate on var ” ::= ::= ::= ::= when prop do “equation on var ” num | pred | eqn var : term def | def ; system Similar to the intermediate format in Modelica compilers Questions regarding the structural analysis: 1. How to schedule (blocks of) equations depending on the mode? 2. How to deal with mode changes & varying dimension? 24 / 34 A multi-mode dAE language and its abstraction var vars prop num pred inv eqn term def system X | var • var | var ,vars T | F | var | not prop | prop and prop ::= ::= ::= ::= ::= ::= ::= ::= ::= ::= num pred (vars) inv prop when prop do (vars) num | pred | inv | eqn var : term def | def ; system I Structural abstraction of the hybrid DAE language I “something(vars )”: I “inv ” captures causality constraints : invariants as predicate abstraction 24 / 34 Scott domain of values for the structural analysis Scott domain: D = { T, F, ⊥, ? } with ? < ⊥, T, I F : false I T : evaluated/true (for prop only) (for prop only) I ⊥ : dead (like in “dead code”: not involved in the current mode) I ? : undefined (“not evaluated yet”) I consistency: x = ? in y : pred /eqn/inv (x , . . . ) ⇒ y = ? I execution scheme: moving tuple X I I I I F : vars from (?, . . . , ?) to ξ ∈ { ⊥, T, F }X by following an increasing path in DX while meeting consistency 25 / 34 Scott domain of values for the structural analysis Scott domain: D = { T, F, ⊥, ? } with ? < ⊥, T, I F : false I T : evaluated/true (for prop only) (for prop only) I ⊥ : dead (like in “dead code”: not involved in the current mode) I ? : undefined (“not evaluated yet”) I consistency: x = ? in y : pred /eqn/inv (x , . . . ) ⇒ y = ? I execution scheme: moving tuple X I I I I F : vars from (?, . . . , ?) to ξ ∈ { ⊥, T, F }X by following an increasing path in DX while meeting consistency 25 / 34 Scott domain of values for the structural analysis Scott domain: D = { T, F, ⊥, ? } with ? < ⊥, T, I F : false I T : evaluated/true (for prop only) (for prop only) I ⊥ : dead (like in “dead code”: not involved in the current mode) I ? : undefined (“not evaluated yet”) I consistency: x = ? in y : pred /eqn/inv (x , . . . ) ⇒ y = ? I execution scheme: moving tuple X I I I I F : vars from (?, . . . , ?) to ξ ∈ { ⊥, T, F }X by following an increasing path in DX while meeting consistency 25 / 34 Scott domain of values for the structural analysis Scott domain: D = { T, F, ⊥, ? } with ? < ⊥, T, I F : false I T : evaluated/true (for prop only) (for prop only) I ⊥ : dead (like in “dead code”: not involved in the current mode) I ? : undefined (“not evaluated yet”) I consistency: x = ? in y : pred /eqn/inv (x , . . . ) ⇒ y = ? I execution scheme: moving tuple X I I I I F : vars from (?, . . . , ?) to ξ ∈ { ⊥, T, F }X by following an increasing path in DX while meeting consistency 25 / 34 Scott domain of values for the structural analysis Scott domain: D = { T, F, ⊥, ? } with ? < ⊥, T, I F : false I T : evaluated/true (for prop only) (for prop only) I ⊥ : dead (like in “dead code”: not involved in the current mode) I ? : undefined (“not evaluated yet”) I consistency: x = ? in y : pred /eqn/inv (x , . . . ) ⇒ y = ? I execution scheme: moving tuple X I I I I F : vars from (?, . . . , ?) to ξ ∈ { ⊥, T, F }X by following an increasing path in DX while meeting consistency 25 / 34 Scott domain of values for the structural analysis Scott domain: D = { T, F, ⊥, ? } with ? < ⊥, T, I F : false I T : evaluated/true (for prop only) (for prop only) I ⊥ : dead (like in “dead code”: not involved in the current mode) I ? : undefined (“not evaluated yet”) I consistency: x = ? in y : pred /eqn/inv (x , . . . ) ⇒ y = ? I execution scheme: moving tuple X I I I I F : vars from (?, . . . , ?) to ξ ∈ { ⊥, T, F }X by following an increasing path in DX while meeting consistency 25 / 34 Structural Analysis: non-det. transition system I hot/cold initialization of the step assigns a value from { ⊥, T, F} to every non-leading num-variable and assigns ? to other vars I transitions: I x = ? in y : pred /eqn/inv (x , . . . ) ⇒ y = ? I x = ⊥ in y : pred /eqn/inv (x , . . . ) ⇒ set y := ⊥ I X = T in y : pred (X ) ⇒ set y := T / y := I p = ⊥ or p = F in when p do e ⇒ set e := ⊥ I (consistency ) F (non-det.) pi = T xi = ? in yi : when pi do ei (x1 , . . . , xn , Zi ) ⇒ set xi , yi := T Zi = T where i = 1, . . . , n (solving enabled blocks of n eqns/vars) I termination by making a tick I I requires success, i.e., all leading variables have been evaluated; completes the current step and sets the initialization for the next step 26 / 34 Structural Analysis: non-det. transition system I hot/cold initialization of the step assigns a value from { ⊥, T, F} to every non-leading num-variable and assigns ? to other vars I transitions: I x = ? in y : pred /eqn/inv (x , . . . ) ⇒ y = ? I x = ⊥ in y : pred /eqn/inv (x , . . . ) ⇒ set y := ⊥ I X = T in y : pred (X ) ⇒ set y := T / y := I p = ⊥ or p = F in when p do e ⇒ set e := ⊥ I (consistency ) F (non-det.) pi = T xi = ? in yi : when pi do ei (x1 , . . . , xn , Zi ) ⇒ set xi , yi := T Zi = T where i = 1, . . . , n (solving enabled blocks of n eqns/vars) I termination by making a tick I I requires success, i.e., all leading variables have been evaluated; completes the current step and sets the initialization for the next step 26 / 34 Structural Analysis: non-det. transition system I hot/cold initialization of the step assigns a value from { ⊥, T, F} to every non-leading num-variable and assigns ? to other vars I transitions: I x = ? in y : pred /eqn/inv (x , . . . ) ⇒ y = ? I x = ⊥ in y : pred /eqn/inv (x , . . . ) ⇒ set y := ⊥ I X = T in y : pred (X ) ⇒ set y := T / y := I p = ⊥ or p = F in when p do e ⇒ set e := ⊥ I (consistency ) F (non-det.) pi = T xi = ? in yi : when pi do ei (x1 , . . . , xn , Zi ) ⇒ set xi , yi := T Zi = T where i = 1, . . . , n (solving enabled blocks of n eqns/vars) I termination by making a tick I I requires success, i.e., all leading variables have been evaluated; completes the current step and sets the initialization for the next step 26 / 34 Structural Analysis: theoretical results I The transition system is non-deterministic (i) evaluation of predicates yields T/F (ii) selection of one among all enabled moves Lemma 1: Given the value of predicates, the transition system is confluent I Partial order reduction: I I Priority: tick > inv > block > pred (to avoid enumerating modes) Priorize minimal blocks with respect to Pryce order on variables I Perform backward pruning of paths reaching a configuration violating an inv I Lemma 2: There exists reachable deadlocks if and only if I I either the system is over-/under-constrained at some reachable mode or the initial configuration is inconsistent 27 / 34 Structural Analysis: theoretical results I The transition system is non-deterministic (i) evaluation of predicates yields T/F (ii) selection of one among all enabled moves Lemma 1: Given the value of predicates, the transition system is confluent I Partial order reduction: I I Priority: tick > inv > block > pred (to avoid enumerating modes) Priorize minimal blocks with respect to Pryce order on variables I Perform backward pruning of paths reaching a configuration violating an inv I Lemma 2: There exists reachable deadlocks if and only if I I either the system is over-/under-constrained at some reachable mode or the initial configuration is inconsistent 27 / 34 Structural Analysis: theoretical results I The transition system is non-deterministic (i) evaluation of predicates yields T/F (ii) selection of one among all enabled moves Lemma 1: Given the value of predicates, the transition system is confluent I Partial order reduction: I I Priority: tick > inv > block > pred (to avoid enumerating modes) Priorize minimal blocks with respect to Pryce order on variables I Perform backward pruning of paths reaching a configuration violating an inv I Lemma 2: There exists reachable deadlocks if and only if I I either the system is over-/under-constrained at some reachable mode or the initial configuration is inconsistent 27 / 34 Structural Analysis: theoretical results I The transition system is non-deterministic (i) evaluation of predicates yields T/F (ii) selection of one among all enabled moves Lemma 1: Given the value of predicates, the transition system is confluent I Partial order reduction: I I Priority: tick > inv > block > pred (to avoid enumerating modes) Priorize minimal blocks with respect to Pryce order on variables I Perform backward pruning of paths reaching a configuration violating an inv I Lemma 2: There exists reachable deadlocks if and only if I I either the system is over-/under-constrained at some reachable mode or the initial configuration is inconsistent 27 / 34 Motivation: physical system modeling Background: Exact and Structural DAE index Using NonStandard Analysis, DAE become dAE and index is preserved Structural analysis of multi-mode DAE systems: approach Examples Discrete time multi-mode dAE Continuous time multi-mode DAE Formalization: Structural Analysis of multi-mode dAE systems Formalization: Structural Analysis of multi-mode DAE and Pantelides Standardization Conclusions 28 / 34 Multi-mode DAE and Pantelides ∆ var vars prop num pred inv eqn term def system ::= ::= ::= ::= ::= ::= ::= ::= ::= ::= ::= o | + (zero|positive duration) X | var + | var 0 var | var ,vars T | F | var | not prop | prop and prop num pred (vars) inv prop when (prop, ∆) do (vars) num | pred | inv | eqn var : term def | def ; system I x + : right-limit (used for resets); x + is mapped to x • I x 0 : derivative; x 0 is mapped to 1 (x • ∂ I − x) ∆: duration type (zero | positive) I This way every mDAE system is mapped to an mdAE system, which is then submitted to the constructive semantics 29 / 34 Multi-mode DAE and Pantelides I Until the constructive semantics succeeds, do 1. chose non-deterministically a guarded equation “when γ do e(.)” starving from dependent variables and replace it by “when γ do e• (.)” (unlocking action) 2. chose non-deterministically I I •` •` a tuple (x1 1 , . . . , xk k ) of leading variables that is starving from equations for its evaluation and a numerical equation e(.) that depends on a subset of the set •`0i {xi | i = 1, . . . , k ; `0i < `i } of variables, and shift e(.) to e• (.) (Pantelides action) I This algorithm may not terminate, in which case the compilation fails I If this algorithm terminates, we can move to the standardization phase 29 / 34 Motivation: physical system modeling Background: Exact and Structural DAE index Using NonStandard Analysis, DAE become dAE and index is preserved Structural analysis of multi-mode DAE systems: approach Examples Discrete time multi-mode dAE Continuous time multi-mode DAE Formalization: Structural Analysis of multi-mode dAE systems Formalization: Structural Analysis of multi-mode DAE and Pantelides Standardization Conclusions 30 / 34 Structural Analysis: standardization I At events: I map discrete non-standard time to Ed Lee’s superdense-time I map x(•t ,k ) to x(t ,k +1) I get rid of the infinitesimal ∂ arising in the non-standard expansion of derivatives and compute a consistent reset state for the next continuous mode I Within continuous time modes: I use Taylor expansion to replace a constraint [f (x )]• = 0 by the pair f (x ) = 0 f 0 (x ).x 0 = 0 31 / 34 Structural Analysis: standardization I At events: I map discrete non-standard time to Ed Lee’s superdense-time I map x(•t ,k ) to x(t ,k +1) I get rid of the infinitesimal ∂ arising in the non-standard expansion of derivatives and compute a consistent reset state for the next continuous mode I Within continuous time modes: I use Taylor expansion to replace a constraint [f (x )]• = 0 by the pair f (x ) = 0 f 0 (x ).x 0 = 0 31 / 34 Structural Analysis: standardization I At events: I map discrete non-standard time to Ed Lee’s superdense-time I map x(•t ,k ) to x(t ,k +1) I get rid of the infinitesimal ∂ arising in the non-standard expansion of derivatives and compute a consistent reset state for the next continuous mode I Within continuous time modes: I use Taylor expansion to replace a constraint [f (x )]• = 0 by the pair f (x ) = 0 f 0 (x ).x 0 = 0 31 / 34 Motivation: physical system modeling Background: Exact and Structural DAE index Using NonStandard Analysis, DAE become dAE and index is preserved Structural analysis of multi-mode DAE systems: approach Examples Discrete time multi-mode dAE Continuous time multi-mode DAE Formalization: Structural Analysis of multi-mode dAE systems Formalization: Structural Analysis of multi-mode DAE and Pantelides Standardization Conclusions 32 / 34 Conclusions I Modelica is much more powerful than classical (Simulink-like) modeling: I I models for simulation by assembling sub-models from libraries DAEs, multi-mode I The compilation of Modelica with its multi-mode extension is difficult I I problems in Modelica tools we proposed a systematic approach I Other uses of Modelica I Requirements: expressing abstract properties of systems as an early phase of system design. Requires supporting under-determined multi-mode DAE systems (less equations than variables) I Fault detection and diagnosis: generating parity models F (X and derivatives, Y , U ) where some of the Y ’s and U’s are observed; check if F = 0 holds when feeding with measurements. Requires extensions of Modelica compilation techniques. 33 / 34 Conclusions I Modelica is much more powerful than classical (Simulink-like) modeling: I I models for simulation by assembling sub-models from libraries DAEs, multi-mode I The compilation of Modelica with its multi-mode extension is difficult I I problems in Modelica tools we proposed a systematic approach I Other uses of Modelica I Requirements: expressing abstract properties of systems as an early phase of system design. Requires supporting under-determined multi-mode DAE systems (less equations than variables) I Fault detection and diagnosis: generating parity models F (X and derivatives, Y , U ) where some of the Y ’s and U’s are observed; check if F = 0 holds when feeding with measurements. Requires extensions of Modelica compilation techniques. 33 / 34 Conclusions I Modelica is much more powerful than classical (Simulink-like) modeling: I I models for simulation by assembling sub-models from libraries DAEs, multi-mode I The compilation of Modelica with its multi-mode extension is difficult I I problems in Modelica tools we proposed a systematic approach I Other uses of Modelica I Requirements: expressing abstract properties of systems as an early phase of system design. Requires supporting under-determined multi-mode DAE systems (less equations than variables) I Fault detection and diagnosis: generating parity models F (X and derivatives, Y , U ) where some of the Y ’s and U’s are observed; check if F = 0 holds when feeding with measurements. Requires extensions of Modelica compilation techniques. 33 / 34 Conclusions I Modelica is much more powerful than classical (Simulink-like) modeling: I I models for simulation by assembling sub-models from libraries DAEs, multi-mode I The compilation of Modelica with its multi-mode extension is difficult I I problems in Modelica tools we proposed a systematic approach I Other uses of Modelica I Requirements: expressing abstract properties of systems as an early phase of system design. Requires supporting under-determined multi-mode DAE systems (less equations than variables) I Fault detection and diagnosis: generating parity models F (X and derivatives, Y , U ) where some of the Y ’s and U’s are observed; check if F = 0 holds when feeding with measurements. Requires extensions of Modelica compilation techniques. 33 / 34 Conclusions I Modelica is much more powerful than classical (Simulink-like) modeling: I I models for simulation by assembling sub-models from libraries DAEs, multi-mode I The compilation of Modelica with its multi-mode extension is difficult I I problems in Modelica tools we proposed a systematic approach I Other uses of Modelica I Requirements: expressing abstract properties of systems as an early phase of system design. Requires supporting under-determined multi-mode DAE systems (less equations than variables) I Fault detection and diagnosis: generating parity models F (X and derivatives, Y , U ) where some of the Y ’s and U’s are observed; check if F = 0 holds when feeding with measurements. Requires extensions of Modelica compilation techniques. 33 / 34 Conclusions I Formal definition of the structural analysis I Ideas from synchronous languages and their constructive semantics I Can be used to compute at compile time: (i) the “index” and (ii) a mode-dependent static scheduling of blocks of equations I Formal definition of when and why the analysis may fail I Implementation: S UNDAE determines index, computes static scheduling I Future: import {Modelica intermediate format} → S UNDAE I Open issues and extensions: 1. Efficient compilation algorithms 2. Generating efficient code 3. Handling under/over-constrained models for I I partial designs parity models in diagnosis 34 / 34 Conclusions I Formal definition of the structural analysis I Ideas from synchronous languages and their constructive semantics I Can be used to compute at compile time: (i) the “index” and (ii) a mode-dependent static scheduling of blocks of equations I Formal definition of when and why the analysis may fail I Implementation: S UNDAE determines index, computes static scheduling I Future: import {Modelica intermediate format} → S UNDAE I Open issues and extensions: 1. Efficient compilation algorithms 2. Generating efficient code 3. Handling under/over-constrained models for I I partial designs parity models in diagnosis 34 / 34 Conclusions I Formal definition of the structural analysis I Ideas from synchronous languages and their constructive semantics I Can be used to compute at compile time: (i) the “index” and (ii) a mode-dependent static scheduling of blocks of equations I Formal definition of when and why the analysis may fail I Implementation: S UNDAE determines index, computes static scheduling I Future: import {Modelica intermediate format} → S UNDAE I Open issues and extensions: 1. Efficient compilation algorithms 2. Generating efficient code 3. Handling under/over-constrained models for I I partial designs parity models in diagnosis 34 / 34