Advertisement

Multi-Mode DAE Models - Challenges, Theory and Implementation

  • Albert Benveniste
  • Benoît Caillaud
  • Hilding Elmqvist
  • Khalil GhorbalEmail author
  • Martin OtterEmail author
  • Marc Pouzet
Chapter
Part of the Lecture Notes in Computer Science book series (LNCS, volume 10000)

Abstract

Our objective is to model and simulate Cyber-Physical Systems (CPS) such as robots, vehicles, and power plants. The structure of CPS models may change during simulation due to the desired operation, due to failure situations or due to changes in physical conditions. Corresponding models are called multi-mode. We are interested in multi-domain, component-oriented modeling as performed, for example, with the modeling language Modelica that leads naturally to Differential Algebraic Equations (DAEs). This paper is thus about multi-mode DAE systems. In particular, new methods are discussed to overcome one key problem that was only solved for specific subclasses of systems before: How to switch from one mode to another one when the number of equations may change and variables may exhibit impulsive behavior? An evaluation is performed both with the experimental modeling and simulation system Modia, a domain specific language extension of the programming language Julia, and with SunDAE, a novel structural analysis library for multi-mode DAE systems.

Keywords

Multi-Mode systems Cyber-Physical Systems CPS Modia Modelica Differential algebraic equations DAE Differential index Structural analysis Operational semantics Constructive semantics Nonstandard analysis 

1 Introduction

Modeling with block diagrams described with Ordinary Differential Equations in state space form (ODE) has become a key pillar in the development of Cyber-Physical Systems (CPS). Block diagrams, however, suffer from a lack of modularity and reuse that is best illustrated in Fig. 1. This figure shows two models of the same system consisting of a simple model of an electrical motor and of the rotational inertia of the motor. On the left hand side a (Modelica) schematic/component diagram of the system is shown that connects physical components through non-directed interactions resulting from the first principles of physics. On the right hand side the same model is shown as a block diagram in which input/output oriented blocks are connected with a directed wiring manually specified by the designer. Adding one more physical component is straightforward in the schematic, whereas it may need a complete redesign in the block diagram.
Fig. 1.

DAE (left) vs. ODE (right) based modeling.

This should not come as a surprise, as the first principles of physics naturally lead to considering acausal models such as the one in Fig. 1-left. Consider, for example, the case of electric circuits. So-called circuit laws such as Kirchhoff laws, are naturally expressed as balance equations: the algebraic sum of currents in a network of conductors meeting at a point is zero; or, the sum of all the voltages around a loop is equal to zero. Similarly, some components (such as, e.g., resistors or capacitors) come with no input/output prespecified orientation. A same circuit can be assigned different input/output status for its variables, depending on which ones are declared as sources. The same situation arises in mechanics or in thermodynamics. Engineers interested in multi-physics modeling have identified this fact since the 70’s by proposing bond graphs [17, 31], in which electric circuits, mechanical systems, and thermodynamical systems, are abstracted to a common framework manipulating efforts, flows, and junctions. To summarize, for systems made of a large number of interconnected components, getting the usual input/output state space model (such as in Simulink block diagrams) becomes intractable, whereas it remains manageable if acausal models are supported.

In addition to being naturally described by an acausal model, a system may have different modes for different reasons. One reason is the physics: mechanical impacts where the bodies may remain in contact after a collision or an active grasping/docking, idealized electrical or hydraulic switching elements, are examples of situations requiring different sets of equations for their modeling. Another reason is the control of complex scenarios like repairing a satellite with robots, changing operations of a system like a power plant with start-up, normal operation and shut down. Finally, safety needs may lead to so-called degraded modes in which the system dynamics may become very different (some components, sensors or actuators getting down for example). Models of this kind are called multi-mode models.
Fig. 2.

A simple clutch with two shafts.

Acausal multi-mode models present, however, subtle difficulties at mode changes. Consider for instance the case of an idealized clutch model, illustrated in Fig. 2. The clutch possesses two modes: released (the two shafts rotate freely) and engaged (the two shafts are in contact). Deriving acausal models from the first principles is simple and rather elegant for each single mode alone. The intuition tells us that, when the clutch gets engaged, the different velocities of the two shafts will, in zero time, merge to a unique identical angular velocity under impulsive torques. One also expects that the resulting common velocity is entirely determined and depends only on the individual inertia and velocity of each shaft, prior to engagement. Determining manually the restart conditions is required if one resorts to using oriented block-diagrams like in Simulink. We argue that such task is difficult for this simple example and becomes even impossible for real-life models. Those restart conditions should rather be synthesized automatically by the compiler and made available at run time to simulate the model. This work advocates therefore the use of acausal modelling languages since they
  1. 1.

    make the specification of large (single mode) Cyber Physical Systems more modular, more elegant, and with better reuse;

     
  2. 2.

    are indispensable to synthesize proper restart conditions at mode changes, for models where this cannot be done manually—the idealized clutch model being a simple example.

     

It should also be clear that classical state space input/output formalisms (such as Simulink block diagrams) do not address the above challenges. Neither does the formalism of hybrid automata [1] used as the model of hybrid systems by several verification tools such as Flow* or SpaceEx.

Causal input/output state space models are based on Ordinary Differential Equations (ODE), of the form \(\dot{x}=f(x,u)\) where x is the state and u the input, whereas acausal models à la Modelica are based on Differential Algebraic Equations (DAE) of the form \(f(\dot{x},x,v)=0\) where x is a state and v an algebraic variable, for which no input or output status can be a priori specified.

In this paper we propose a theory to support the compilation of multi-mode DAE based models in a systematic and mathematically sound way. We want to reject some models that are in some sense spurious. And we want to synthesize (whenever needed, not in all cases) the computation of the restart conditions at mode changes. All of this will be performed at compile time, through a special static analysis called the structural analysis, which is an important topic of this paper. This structural analysis is an essential preprocessing step prior to generating simulation code. We will illustrate our purpose by an example from electro-mechanics that includes a clutch as one of its subsystems. The specification, analysis, compilation, and simulation of this model will be illustrated using the recently proposed experimental modeling language called Modia.

2 State-of-the-Art and Related Work

There exists an extensive body of work related to the numerical solution of single-mode DAEs, especially [9], as well as to the modeling and simulation of single-mode multi-domain models leading to DAEs1.

Mechanical systems featuring impulses are known since the 18th century. A large literature about multi-body systems with contacts and impulses exists, for example [25, 26]. The current research focuses on simulating contacts between many bodies using time stepping methods. Contact equations are usually described approximately on velocity or acceleration level (if contact occurs, the relative velocity or acceleration between the relevant bodies is constrained to be zero). Since the constraints on position level are not explicitly taken into account, typically a drift occurs that is usually not relevant for systems with many contacting bodies but is not acceptable for general multi-mode DAEs. An exception is [29], where constraints on position level are enforced. It is not obvious how the specialized multi-mode methods for multi-body systems can be generalized to any type of multi-mode DAE.

Also for electrical circuits with idealized switches, like ideal diodes, impulses can occur. Again a large literature is available concentrating mostly on specialized electrical circuits such as piecewise-linear networks with idealized switches [2, 16, 32]. Again, it is not obvious how to generalize methods in this specialized area to general multi-mode DAEs.

The paper of Mehrmann et al. [20] contains interesting results regarding numerical techniques to detect chattering between modes. It, however, assumes that consistent reset values are explicitly given for each mode. Such an assumption does not hold in general, especially for a compositional framework where one wants to assemble pre-defined physical components.

In the PhD-thesis of Zimmer [33] variable-structure multi-domain DAEs are defined with a special modeling language and a run-time interpreter is used that processes the DAE equations at run-time, when the structure and/or the index is changing. Limitations of this work are that impulsive behavior is not supported and that the user has to define the transfer of variable values from one mode to the next mode explicitly, which is not practical for large models.

Describing variable structure systems with causal state machines is discussed by Pepper et al. [24].

Elmqvist et al. [13, 19] propose a high level description of multi-mode models as an extension to the synchronous Modelica 3.3 state machines by using continuous-time state machines having continuous-time models as “states”. Besides ODEs as used in hybrid automata, also acausal DAE models with physical connectors can be a “state” of a state machine. Such a state machine is mapped into a form so that the resulting equations can be processed by standard symbolic algorithms supported by Modelica tools. The major restrictions of this approach are that mode changes with impulsive behavior are not supported and that not all types of multi-mode systems can be handled due to the static code generation.

Benveniste et al. [3, 5] tackle the problem of variable structure, varying index DAEs from a fundamental point of view by using a low level description of DAEs with a few language elements only and a precise mathematical description of the semantics based on non-standard analysis. A proof-of-concept mockup, SunDAE, was developed implementing this approach.

3 The Modia Language

Modelica [21] is a state-of-the-art modeling language for multi-domain modeling. Recently, an experimental language which is similar to Modelica and called Modia [11, 12] has been designed and implemented. Modia is a domain specific language extension of Julia [8] by means of structured macros, that is, the Julia parser is used to parse Modia models. The Modia language elements will be introduced through a small set of examples.

Elementary Modia Constructs. A model of a rotating inertia can be defined as follows ( Open image in new window start a comment until end of the line):
The Open image in new window macro has one section for declarations and one section for equations and connections. The construct J = 1 defines the parameter J with default value of 1. A variable w with a start value of w0 is introduced by w = Float(start = w0). The construct flange = Flange() calls the constructor for Flange which is defined as follows:
This model consists just of two variable declarations with type Float modeling the interaction when the Inertia is mechanically coupled via a shaft to other mechanical components. The attribute flow = true tells that if several shafts are connected to flange, the internal and external torques are all summed to zero.

The equation J*der(w) = flange.tau is Euler’s equation for the rotational motion of the inertia. The operator der() denotes time derivative.

A model with two rigidly connected inertias can be defined as shown below:
Note that parameters are changed in the Inertia constructor call. The connect() primitive models a physical coupling. In this case the semantics is:
Note, that inertia2 has initial angular velocity of 10 rad/s, whereas inertia1 has the default of 0. The result of simulation shows a constant angular velocity for both inertias of 8 rad/s. Since the initial angular velocities are different there will be a Dirac impulse in the torque to make them equal. The resulting joint angular velocity is according to theory weighted as \(w = (J1*w1 + J2*w2)/(J1+J2) = 8\).
Advanced Modia Constructs. Modia has many other features, such as inheritance, size and type inference, type declarations, component redeclarations, time events, state event, and nested simulations. More information can be found in [11, 12]. It is possible to declare variables with specific SI units. As an example, an electric Pin connector can be defined as shown below using predefined variable constructors Voltage() and Current() with associated SI units (Volt and Ampere):
Fig. 3.

Schematics of MotorAndLoad model.

Modia Multi-mode Modeling: Running Example. We model in Modia a multi-mode DAE system containing the idealized clutch introduced informally in Sect. 1. The model has an electric motor, two load inertia and a clutch, see Fig. 3. The electric motor model is based on a model of the electro-mechanical force (emf). It has two Pin connectors (p and v) and one Flange connector. The specific equations for an emf are:
Note that a Capacitor is connected across the emf.
A simple Clutch model is used which is either engaged or not engaged. It is modeled as two different set of equations:
When the clutch is engaged, the angular velocities of the two flanges are the same and the torques sum to zero. When not engaged, the torques are zero and there are no constraints on the angular velocities. The definition of the input engaged is made in the surrounding environment of the clutch:
The DAE index is changing depending on the state of the clutch. Furthermore, Dirac impulses occur initially and when the mode changes to engaged. The techniques needed to analyze and simulate such models are described in subsequent sections.
Fig. 4.

Simulation results of the MotorAndLoad model.

The results of a simulation are shown in Fig. 4. The initial angular velocity of inertia1 is 0 rad/s and 10 rad/s for inertia2. The capacitor is initially uncharged. The upper two partly overlapping curves are the angular velocities of inertia1 and inertia2. When the clutch is disengaged, the angular velocity of inertia2 is constant. The lower curve shows the voltage over the capacitor. Since the clutch is engaged at initialization, Dirac impulses occur at time = 0 s. As a result, after initialization the angular velocities of the two inertia are identical. The common angular velocity at time = 0 s is not 8 rad/s as in the example TwoInertias, but 6.4 rad/s. The reason is that the capacitor acts in the same way as an additional moment of inertia to inertia1. The effective inertia is \(J1' = J1 + k^2*C = 0.1 + 0.25^2*2 = 0.225\). Thus, the angular velocity at time=0 s becomes \(w = (J1'*w1 + J2*w2)/(J1'+J2) = (0.225*0 + 0.4*10)/(0.225+0.4) = 6.4\) rad/s. There are no Dirac impulses at time = 100 s when the clutch disengages, but again Dirac impulses at time = 300 s when the clutch engages again.

4 Simulating a Restricted Class of Multi-Mode DAEs

In this section, we propose a method to simulate a restricted class of multi-mode DAE systems, encompassing in particular our example of Fig. 3 and its simulation result in Fig. 4.

Throughout this paper, we use the classical notations \(\dot{x}\) and \(\ddot{x}\) to denote the first and second time-derivatives of a function of continuous time \(x:\mathbb {R}\mapsto \mathbb {R}\). When such a notation is not appropriate for readability reasons, we sometimes write instead \(x'\) and \(x''\). The notation for higher order derivatives is indicated when needed. We write vectors and matrices in boldface. The transpose of a matrix \(\varvec{G}\) is written \(\varvec{G}^T\).

4.1 Problem Setting

The goal is to simulate the following class of multi-mode DAE systems:
$$\begin{aligned} \begin{array}{r} \mathbf{if }~\gamma _1(\dot{\varvec{x}}_{\gamma }^{-},\varvec{x}_{\gamma }^{-},t)~\mathbf{then }~\varvec{f}_{1}(\dot{\varvec{x}}_1,\varvec{x}_1,t) = \varvec{0} \\ \mathbf{elseif }~\gamma _2(\dot{\varvec{x}}_{\gamma }^{-},\varvec{x}_{\gamma }^{-},t)~ \mathbf{ then }~\varvec{f}_2(\dot{\varvec{x}}_2,\varvec{x}_2,t) = \varvec{0} \\ \vdots \quad \\ \mathbf{else }~\varvec{f}_m(\dot{\varvec{x}}_m,\varvec{x}_m,t) = \varvec{0} \end{array} \end{aligned}$$
(1)
where
  • vector \(\varvec{x}_{\gamma }\) of length \(n_{\gamma }\) collects variables that are present in all modes and in the predicates \(\gamma _i(\dots )\),

  • vector \(\varvec{x}_i\) of length \(n_i\) collects all variables that are used in mode i (\(\varvec{x}_{\gamma }\) is a subset of \(\varvec{x}_i\)), and

  • \(\gamma _i \in \mathbb {R}^{n_{\gamma }} \times \mathbb {R}^{n_{\gamma }} \times \mathbb {R} \rightarrow \text {Boolean}, \quad \varvec{f}_i \in \mathbb {R}^{n_i} \times \mathbb {R}^{n_i} \times \mathbb {R} \rightarrow \mathbb {R}^{n_i}\).

Hence the considered system switches between different modes, each described by a DAE having \(n_i\) equations and \(n_i\) unknowns. The switching conditions are predicates denoted by \(\gamma _i\) and depend on time and/or on the left limit of the DAE variables assuming they exist and are finite, that is
$$\begin{aligned} \varvec{x}^-_{\gamma }(t) =_{\mathrm{def}}\lim _{\varepsilon \searrow 0} \varvec{x}_{\gamma }(t-\varepsilon ) \text { and } {\dot{\varvec{x}}}^-_{\gamma }(t) =_{\mathrm{def}}\lim _{\varepsilon \searrow 0} \dot{\varvec{x}}_{\gamma }(t-\varepsilon ). \end{aligned}$$
When changing from mode i to mode j it is assumed that the initial conditions \(\varvec{x}^-_\gamma \) are known from the previous mode. A concrete example will be given in Sect. 4.3. we also refer to [13] for a more generic treatment. When changing from one mode to another the set of equations that govern the dynamics of the system may change. Thus, some variables may experience discontinuities or even impulses. Throughout this section we assume that the system spends a strictly positive duration in each mode in such a way that instants of mode changes are cleanly isolated.

Note that the class (1) of multi-mode systems is not compositional as the predicates \(\varvec{x}_\gamma \) are global. We restricted ourselves to this class in order to simplify the exposure below. This restriction is relaxed in the actual implementation in Modia. For instance, Open image in new window Clutch in Sect. 3 has a local definition of the predicate to engage or disengage the clutch and there is no global if-clause. In Sect. 5, where an alternative approach is discussed, such restrictions are not present.

4.2 Handling Mode Changes

In a mode i, an initial value problem \(\varvec{f}_i(\dot{\varvec{x}}_i,\varvec{x}_i,t) = \varvec{0}\) has to be solved. It is well-known that only special classes of DAEs can be directly numerically integrated [9]. For this reason, general DAEs might be first transformed in to a DAE class where reliable integration methods exist. For nonlinear systems such a transformation means that equations of the DAE might need to be (analytically) differentiated. The best integration methods exist for ODEs \(\dot{\varvec{x}} = \bar{\varvec{f}}(\varvec{x},t)\). However, transforming a DAE to this form requires in general to solve nonlinear algebraic equation systems at every model evaluation and therefore the benefit of ODE integration methods might get lost. For this reason, another approach is used in this section where the transformation to a numerically solvable form is performed without solving algebraic equation systems. In Assumption 1 we define the target DAE class for this transformation:

Assumption 1

For each mode i of System (1), the DAE \(\varvec{f}_i(\dot{\varvec{x}}_i,\varvec{x}_i,t)=\varvec{0}\) has the following form (we omit the index i for better readability)

In (2), subscripts “\(_d\)” and “\(_c\)” are reminiscent of “dynamics” and “constraint”, respectively. Condition (3) means that System (2) has differentiation index one.2

Transforming General DAEs to System (2, 3). If the model equations in a given mode are not in the form (2, 3), they are transformed to it. This transformation is non-trivial and it is beyond the scope of this paper to explain the details. Only a short overview is given here: Typically, the Pantelides algorithm [23], or a variant like [27], is used to determine which equations of the original DAE must be differentiated in order that the highest derivative variables can be uniquely determined from the highest derivative equations. By differentiating the corresponding equations analytically it is then possible to transform to ODE form. Hereby, algebraic equation systems might need to be solved. In [22] a new algorithm is proposed to transform every DAE that can be treated with the Pantelides algorithm to the form of Assumption 1 without solving algebraic equation systems. This algorithm is a generalization of [15] that was developed for single-mode multi-body systems. In Sect. 4.3 it is applied to multi-mode multi-body systems.

Simulating System (2, 3). A number of methods exist for solving system (2, 3) numerically. In particular, fixed or variable step-size BDF (Backward Differentiation Formula) methods can be used [9]. In all cases, consistent initial conditions have to be provided that fulfill (2) and the so-called latent equationsobtained by differentiating the constraint \(\varvec{f}_c(\varvec{x},t) = \varvec{0}\), see [9, 23]. Integration methods, including BDF, assume that \(\varvec{x}\) is smooth. Therefore, standard integration methods cannot be applied if \(\varvec{x}\) is discontinuous at a mode change.
Computing Restart Values. We now propose a scheme for computing restart conditions. More precisely, let \(t_{ ev}\) be an instant of mode change of System (1), meaning that one of the guards \(\gamma _i\) changes its value. The objective is to compute consistent restart values
$$\begin{aligned} \varvec{x}^{+} =\varvec{x}(t_{ ev}^{+})=_{\mathrm{def}}\lim _{s\searrow {t_{ ev}}}\varvec{x}(s) \text { and }\dot{\varvec{x}}^{+} =\dot{\varvec{x}}(t_{ ev}^{+})=_{\mathrm{def}}\lim _{s\searrow {t_{ ev}}}\dot{\varvec{x}}(s) \end{aligned}$$
(5)
for the index one system (2, 3), given values
$$\begin{aligned} \varvec{x}^{-} = \varvec{x}(t_{ ev}^{-})=_{\mathrm{def}}\lim _{s\nearrow {t_{ ev}}}\varvec{x}(s) \end{aligned}$$
(6)
just prior to entering the new mode. Note that, since \(\varvec{x}^-\) are variable values in the previous mode, they will not, in general, be consistent for the new mode, that is the second equation of System (2) might not be satisfied by \(\varvec{x}^{-}\). Still, these equations must be satisfied by the (yet unknown) \(\varvec{x}^{+}\). Since \(\varvec{x}(t)\) may be discontinuous at \(t_{ ev}\), the derivative of \(\varvec{x}(t)\) may be a Dirac impulse.

To derive our method for computing the restart values, we first restrict the class of systems with the following additional assumption. We then discuss the general case.

Assumption 2

Assume DAE System (2) has the following special structure:
$$\begin{aligned} \begin{array}{ll} &{}0 = \varvec{A}(\varvec{x}_s,t)\dot{\varvec{x}} + \varvec{b}(\varvec{x},t) \quad \quad (= \varvec{f}_d(\dot{\varvec{x}}, \varvec{x},t)) \\ &{}0 = \varvec{f}_c(\varvec{x},t) \end{array} \end{aligned}$$
(7)
where \(\varvec{x}_s\) collects the smooth elements of \(\varvec{x}\), that is those being continuous and of bounded variation around the mode change.3 Other elements of \(\varvec{x}\) might be discontinuous. Furthermore, we assume that \(\varvec{x},\varvec{A}(\dots ),\varvec{b}(\dots )\) are continuous functions of their arguments and remain bounded around the instant of mode change.

Note that Assumption 2 does not forbid that the triple defining the dynamics (7) actually varies with the mode i, that is has the form \((\varvec{A}_i,\varvec{b}_i,\varvec{f}_{c,i})\). Since elements of \(\varvec{x}\) may be discontinuous, \(\dot{\varvec{x}}\) may have Dirac impulses. In (7) it is therefore assumed that \(\dot{\varvec{x}}\) having potentially Dirac impulses appear linearly and the linear factors are continuous functions without discontinuities.

Under Assumption 2, the mathematical solution of the restart problem can be determined as follows: In a first step, since \(\varvec{x}_s\) is smooth at the instant \(t_{ ev}\) of mode change, the matrix \(\varvec{A}(\varvec{x}_s,t_{ ev})\) is immediately known once a change has been detected at \(t_{ ev}\). To evaluate all the elements of \(\varvec{x}\) right after \(t_{ ev}\) we proceed by integrating (7) over \([t_{ ev}-\varepsilon ,t_{ ev}+\varepsilon ]\) using the well known properties of Lebesgue integrals and Dirac measure. To this end, we decompose
$$ \varvec{x}~=~ \left[ \begin{array}{l} \varvec{x}_s \\ \varvec{x}_{ ns} \end{array}\right] \text { and } \varvec{A} = \left[ \begin{array}{ll} \varvec{A}_s&\varvec{A}_{ ns} \end{array}\right] $$
where \(\varvec{x}_{ ns}\) collects the nonsmooth entries of \(\varvec{x}\) that may experience discontinuities at the instant of mode change and \(\varvec{A}\) is decomposed accordingly. The following approximations hold, where the integrals \(\int _{t_{ ev}-\varepsilon }^{t_{ ev}+\varepsilon }\) mean \(\int _{[t_{ ev}-\varepsilon ,t_{ ev}+\varepsilon ]}\):
$$\begin{aligned} \int _{t_{ ev}-\varepsilon }^{t_{ ev}+\varepsilon }\varvec{f}_{d}(\dot{\varvec{x}}, \varvec{x},t)dt= & {} \underbrace{\int _{t_{ ev}-\varepsilon }^{t_{ ev}+\varepsilon }\left( \varvec{A}_s(\varvec{x}_s,t)\dot{\varvec{x}}_s + \varvec{b}(\varvec{x},t)\right) dt}_{\approx 0 ~\mathrm{by~footnote~3}} + \underbrace{\int _{t_{ ev}-\varepsilon }^{t_{ ev}+\varepsilon }\varvec{A}_{ ns}(\varvec{x}_s,t)\dot{\varvec{x}}_{ ns}dt}_{\dot{\varvec{x}}_{ ns}dt ~\mathrm{is \;a\; Dirac\; at}\; t_{ ev}}\\\approx & {} \varvec{A}_{ ns}(\varvec{x}_s,t_{ ev})\left( \varvec{x}_{ ns}(t_{ ev}+\varepsilon )-\varvec{x}_{ ns}(t_{ ev}-\varepsilon )\right) \\\approx & {} \varvec{A}(\varvec{x}_s,t_{ ev})\left( \varvec{x}(t_{ ev}+\varepsilon )-\varvec{x}(t_{ ev}-\varepsilon )\right) \end{aligned}$$
In the above two approximations, the first one follows from the property of the Dirac measure and the fact that \(t\mapsto \varvec{A}_{ ns}(\varvec{x}_s(t),t)\) is continuous, and the second one follows from the fact that \(\varvec{A}_{ s}(\varvec{x}_s,t_{ ev})\left( \varvec{x}_{ s}(t_{ ev}+\varepsilon )-\varvec{x}_{ s}(t_{ ev}-\varepsilon )\right) \approx {0}\).
This leads to proposing the following scheme for computing the restart values \(\varvec{x}^+\) from \(\varvec{x}^-\) at the instant \(t_{ ev}\) of mode change, cf. Eqs. (5) and (6):
$$\begin{aligned} \begin{array}{ll} &{} 0 = \varvec{A}(\varvec{x}_s,t_{ev})(\varvec{x}^{+} - \varvec{x}^{-}) \\ &{} 0 = \varvec{f}_{c}(\varvec{x}^{+},t_{ev}) \end{array} \end{aligned}$$
(8)
Since (7) may not hold at \(t^-_{ ev}\), and \(\varvec{x}^{+} - \varvec{x}^{-}\) need not to be small, the Implicit Function Theorem cannot be invoked to argue about the existence and uniqueness of a solution around \(\varvec{x}^{-}\). Since the Jacobian \(\frac{\partial \varvec{f}}{\partial \varvec{x}^+}\) of (8) is regular due to (3) and Assumption 2, (8) can be numerically solved with a Newton-type method. Fortunately, in many practical cases (such as a mechanical impact) the nonlinear part of \(\varvec{f}_{c}(\varvec{x},t)\) is often satisfied by \(\varvec{x}^{-}\) and then only a linear equation system needs to be solved for \(\varvec{x}^{+}\), in which case a unique solution exists, see also Sect. 4.3. The physical interpretation of (8) is that we look for restart values that are consistent for the new mode (second equation) and meet the integral of \(\varvec{f}_d(\dots )\) across the mode change (first equation).
In a modeling language such as Modelica or Modia, the model code has the form (2), not the special form (7). It is therefore desirable to compute restart values only with the form (2), without being forced to generate special code that reveals the details of the equations as in (7). On the basis of Assumption 1, we can nevertheless consider the following two systems of equations, where \(\varvec{x}^+\) are the unknowns and \(h>0\) is small:
Schemes (9) only require Assumption 1. Under Assumption 2, Schemes (9) take the form
where we have used the fact that \(\varvec{x}^-_s\approx \varvec{x}^+_s\) since \(\varvec{x}_s\) is smooth. These schemes reduce to (8) for \(h\approx {0}\).

Thus, if Assumption 2 holds, the form (2) for the system model at mode i can be used to numerically compute restart values for this mode: At the instant of the mode change integrate (2) with either mixed explicit/implicit Euler or implicit Euler schemes, from \(\varvec{x}^{-}\) over a small step-size h, thereby scaling the dynamic part of the model, \(\varvec{f}_{d}({..})\), with h. The solution of the nonlinear equation system (9) converges to the solution of the system (8).

Discussing the General Case. Schemes (9) can be applied to any index one system. Such a brute force use without Assumption 2, however, raises questions that we review now:
  • Relaxing the continuity assumption on \(\varvec{A}(\dots )\), so that \(\varvec{A}(\varvec{x},t)\) might have discontinuous elements: As a result the first contribution in the decomposition of the integral \(\int _{t_{ ev}}^{t_{ ev}+\varepsilon }\varvec{f}_{d}(\dot{\varvec{x}}, \varvec{x},t)dt\) is no longer negligible and it is unclear, from the literature, whether a well-defined meaning to this term exists.

  • Removing the linearity assumption on \(\dot{\varvec{x}}\): The solution is no longer a Dirac and it is again unclear whether a well-defined solution exists. It is not even clear that h is the proper scaling factor for \(\varvec{f}_d\). Note that the linearity assumption quite often holds for physical system models, since balance equations in physics are linear in their derivatives.

To summarize, there is some evidence that precautions must be taken when relaxing Assumption 2.

Completing Consistent Restart. After the consistent restart values \(\varvec{x}^{+}\) have been computed, the corresponding consistent restart values of \(\dot{\varvec{x}}^{+}\) can be determined with (4) and the first equation of (2), by solving the following non-linear equation system in the unknowns \(\dot{\varvec{x}}^{+}\) (in case Assumption 2 holds, this is a linear equation system with a regular Jacobian, so a unique solution exists):Addressing Initialization. Note that the combined use of (9) and (11) provides a method for consistent initialization: The initial mode i and guesses for \(\varvec{x}^-_\mathrm{i,init}\) must be provided by the modeler. Afterwards, consistent values \(({\dot{\varvec{x}}^{+}_\mathrm{i,init}},\varvec{x}^{+}_\mathrm{i,init})\) for the initialization are computed with (9, 11).

4.3 A Class of Multi-mode Multi-body Systems Satisfying Assumptions 1 and 2

In this section we exhibit a practically useful class of systems satisfying Assumptions 1 and 2. We consider a multi-body system whose model at each mode i has the following structure:Equation (12) describes a multi-body system with generalized position coordinates \(\varvec{q}\), generalized velocity coordinates \(\varvec{v}\) and generalized constraint forces \(\varvec{\lambda }_i\) due to the constraints \((m_3)\) of the ith mode. Both the constraints \((m_3)\) and the constraint forces \(\varvec{G}_i^T(\varvec{q},t) \varvec{\lambda }_i\) can vary with the mode i. In particular the constraints can also be completely removed. \(\varvec{M}\), however, remains invariant through the different modes. Whenever a set of constraints is changing at a new mode, impulses might occur. In case an impulse is due to an impact, it is assumed that the impact is completely inelastic. We now show that Eq. (12) can be put to a form satisfying Assumptions 1 and 2.
Equation (12) is first transformed to an index two DAE with the method of Gear et al. [15]:In Eq. (14) the constraint equation \((m_3)\) is differentiated once and new auxiliary variables \(\varvec{\mu }_i\) are introduced so that the number of equations and unknowns remain the same. (14) has the same solution as (12) because \(\varvec{\mu }_i = \varvec{0}\) holds as we explain now: Inserting \((m_1^a)\) in \((\dot{m}_3)\) yields:
$$\begin{aligned} \varvec{0} = \varvec{G}_i(\dot{\varvec{q}} - \varvec{G}_i^T \varvec{\mu }_i ) + \varvec{G}_i^{(1)} \end{aligned}$$
(16)
Subtracting the derivative of \((m_3)\) from (16) results in equation \(\varvec{0} = \varvec{G}_i \varvec{G}_i^T \varvec{\mu }_i\). Since \(\varvec{G}_i\) has full row rank according to assumption (13), \(\varvec{G}_i \varvec{G}_i^T\) is regular and therefore \(\varvec{\mu }_i = \varvec{0}\).
As proposed by Gear [14], by using the substitutions (\(\varvec{\lambda }_{ int,i}\) is the integral of \(\varvec{\lambda }_i\) and \(\varvec{\mu }_{ int,i}\) is the integral of \(\varvec{\mu }_i\)):
$$\begin{aligned} \dot{\varvec{\lambda }}_{ int,i} = \varvec{\lambda }_i, \quad \dot{\varvec{\mu }}_{ int,i} = \varvec{\mu }_i \end{aligned}$$
(17)
the DAE (14) which is index 2 in the variables \(\varvec{q},\varvec{v},\varvec{\lambda }_i,\varvec{\mu }_i\) is transformed to the following DAE which is index 1 in the variables \(\varvec{q},\varvec{v},\varvec{\lambda }_{ int,i},\varvec{\mu }_{ int,i}\):(18) has equation structure (7), withThe Jacobian (3) of (18) is (\(\varvec{P}\) is a permutation matrix to exchange \((m_3)\) and \((\dot{m}_3)\) in order that the regularity of the Jacobian is at once visible):As required by Assumption 1, this Jacobian is regular because \(\varvec{M}\) is positive definite and \(\varvec{G}_i\) has full row rank. With reference to Assumption 2, it remains to show that it is legitimate to take \(\varvec{x}_s = \varvec{q}\), which amounts to requiring that \(\varvec{q}\) is continuous and has bounded variation around the instant of mode change. Before an impact occurs, the normal distance \(d_j\) to a constraint surface j is defined as \(d_j = g_j(\varvec{q},t)\) and \(d_j > 0\) when the multi-body system is not in contact with the constraint surface. Contact occurs when \(d_j = 0\) and therefore the constraint \(g_j(\varvec{q},t) = 0\) at the time instant of the impact and \(\varvec{q}\) is continuous. In the fully inelastic impact case, \(\varvec{q}\) has bounded variation because the multi-body system remains in contact with the contact surface after the impact and it is assumed that \(g_j(\varvec{q},t)\) is smooth. The scheme above can be easily extended to elastic impacts. In such a case, \(\varvec{q}\) has bounded variation provided instants of mode changes do not form a Zeno sequence.

4.4 Example: Ideal Clutch with Motor

We will show in this section how the example of Fig. 3 can be simulated with the method developed in the previous sections. The modular description with Modia is mapped to a set of about 25 equations that are first pre-processed (such as performing alias elimination). To avoid overloading the development with unnecessary details, we only show the results after this pre-processing is performed (these equations can also be easily derived manually from the circuit). In the following model, CkJR are constants; \(u_0(t), \gamma (t)\) are given time functions; \(\gamma = \mathtt {T}\) if the clutch is released and \(\mathtt {F}\) if it is engaged:All the following analysis could be performed with (21). To concentrate on the essential details, the equations are further simplified by using the following relationships from (21), as well as the substitution \(\dot{\tau }_{{ int},2} = \tau _2\)
$$\begin{aligned} \begin{array}{ll} &{} \tau _1 := J_1 \dot{\omega }_1 + \tau _2 \\ &{} i_2 := \tau _1/k \; = \; (J_1 \dot{\omega }_1 + \dot{\tau }_{{ int},2})/k \\ &{} i_1 := C \dot{u} \end{array} \end{aligned}$$
(22)
and the equation system (21) can be simplified to the following four equations:
$$\begin{aligned} J_1 \dot{\omega }_1 + \dot{\tau }_{{ int},2} + k C \dot{u} - k(u_0 - u)/R= & {} 0 \nonumber \\ J_2 \dot{\omega }_2 - \dot{\tau }_{{ int},2}= & {} 0 \nonumber \\ \mathbf{if }~ \gamma ~\mathbf{then }~ \dot{\tau }_{int,2} ~\mathbf{else }~ \omega _1-\omega _2= & {} 0 \\ k \omega _1 - u= & {} 0 \nonumber \end{aligned}$$
(23)
With \(\varvec{x}= \left[ u\,;\, \omega _1\,;\, \omega _2\,;\, \tau _{{ int},2}\right] ^T\), (23) is in both modes an index one DAE of the form (7):With (8), or alternatively with (9) and \(h \approx 0\), restart values can be computed:When the clutch is disengaging, the variables are continuous at the mode change. When the clutch is engaging, the variables are discontinuous at the mode change and Dirac impulses occur.

4.5 Implementation of Multi-mode Features in Modia

The implementation of Modia is described in [12]. An extension of Modia to support a restricted class of multi-mode DAE systems along the lines developed in this section is currently under development. Since completely different sets of equations can be present in different modes, the implementation is based on just-in-time symbolic transformations and code generation of residue functions. A dictionary from a Boolean vector of mode flags to functions is used as a cache to avoid symbolic transformations and code generation in case the same modes have been active before and a corresponding function is already available to calculate the residues.

The final values of all variables from one simulation is extracted when a mode change event happens. These are inputs to one very short implicit Euler step with the residue function for the newly enabled modes in order to correctly simulate possible impulses. The new values of the state vector is used to start a new simulation until the next mode change.

5 Structural Analysis of Multi-Mode DAE Systems

In Sect. 4 we proposed an approach to analyze and simulate multi-mode DAE systems based on a generalization of DAE theory.

In this section we propose an alternative approach, more computer science oriented and detailed in [3] (as well as its companion technical report [5]), which works for general multi-mode systems and uses a small number of principles. The key ideas are as follows.

  1. 1.

    Mode changes may result in discontinuous jumps and, therefore, resets must be performed in discrete computation steps. Hence, we first map the original system to discrete time by using a first order Euler scheme. This brings to discrete time both the reset actions and the dynamics within each mode, hence the principles of index analysis uniformly apply, albeit in discrete time. Also, a new principle of mode causality is invoked.

     
  2. 2.

    Mapping the dynamics to discrete time results in approximations. No approximation, however, results if we interpret the Euler scheme via nonstandard analysis [18, 28] by using an infinitesimal time step. The analysis is then performed over the nonstandard reals. A final standardization step is applied to recover an effective numerical scheme.

     
To keep the exposure simple, we develop this on the example of ideal clutch with motor, see Sect. 4.4. More precisely, we consider again (23) where, for simplicity, we substitute \(\dot{\tau }_{{ int},2}\) by \(\tau \):
$$\begin{aligned} J_1 \dot{\omega }_1 + {\tau } + k C \dot{u} - k(u_0 - u)/R= & {} 0 \nonumber \\ J_2 \dot{\omega }_2 - {\tau }= & {} 0 \nonumber \\ k \omega _1 - u= & {} 0 \\ \mathbf{if }~ \gamma ~\mathbf{then }~ {\tau } ~\mathbf{else }~ \omega _1-\omega _2= & {} 0 \nonumber \end{aligned}$$
(26)
We first analyze separately the model for each mode of the clutch.

5.1 Separate Analysis of Each Mode, in Discrete Time

We begin by providing the model for each mode. We highlight in Open image in new window the equations that are unique to the considered mode. Other equations are shared. In the “released” mode, the two shafts are independent. In the “engaged” mode, the velocities of the two shafts are algebraically related.

Following key idea 1, we replace derivatives by their first order explicit Euler scheme, in discrete time with constant step size \(\delta >0\). Let
$$\begin{aligned} \omega ^\bullet (t)=_{\mathrm{def}}\omega (t+\delta ) \end{aligned}$$
(27)
be the forward time shift operator by an amount of \(\delta \). System (26) expands as:Let us first focus on System (26)-released. The state variables are \(u,\omega _1,\omega _2\) and their respective values are known initially. The current step must determine the values of the leading variables \(\tau ,u^\bullet ,\omega ^\bullet _1,\omega ^\bullet _2\).
Towards this, we first form the incidence graph \(\mathcal {G}\) of each system, which is a nondirected bipartite graph having as vertices: the four leading variables, plus the two systems of equations \(\{(e_1),(e_2),(e_3),(e_4)\}\) and \(\{(e_1),(e_2),(e_3),(e_5)\}\). An edge from an equation to a leading variable exists if and only if this variable is involved in that equation. Incidence graphs for models (26-released) and (26-engaged) are:Observe that, for both models, equation \((e_3)\) involves no leading variable: it is a consistency equation, i.e., a constraint that must be satisfied as a result of the execution of previous time steps. Once initialization is performed, \((e_3)\) is indeed satisfied and can thus be seen as a fact for both modes. The same holds for \((e_5)\) in the engaged mode. In turn these equations cannot be used, when determining the leading variables from the state variables. In this case, for the two systems (26), we have 4 variables but only 3 and 2 equations, respectively: one cannot determine the leading variables as functions of the state variables by using System (26). Since the considered models are time-invariant, every solution has also satisfy the equations obtained by shifting forward any equation of the model. Shifting forward equations that do not bring variables that are shifted more than originally present in the system, yields so-called latent equations. For our two models, we add the latent equations, highlighted in Open image in new window :The associated incidence graphs are augmented accordingly and we remove the consistency equations:In the two incidence graphs of (30), we show in Open image in new window a pairing function \(\mathbf{e}\), i.e., a bijection, from the set of variables, to the set of equations, such that \((\mathbf{e}(x),x)\) is a edge of \(\mathcal {G}\) for every leading variables \(\varvec{x}\). This pairing function defines an orientation for \(\mathcal {G}\) as follows: for each edge \((\mathbf{e}(x),x)\in \mathcal {G}\), we set \(\mathbf{e}(x)\rightarrow {x}\) and \(y\rightarrow \mathbf{e}(x)\) for every \(y\ne {x}\) such that \((\mathbf{e}(x),y)\) is a edge of \(\mathcal {G}\). The minimal cycles of the resulting directed graph form blocks of equations to be solved for their assigned variables. The blocks are partially ordered by the directed graph. According to [23], if a pairing function exists for its incidence graph, the system of equations possesses, in a generic sense, a unique solution for its leading variables, assuming consistent values for the state variables. “Generic” here means that the statement holds outside some exceptional numerical values when the non-zero coefficients of the Jacobian of this system of equations vary in a neighborhood.

The above reasoning applies in continuous time where the forward shift is substituted back using differentiation. As far as structural analysis is concerned, we can freely exchange continuous and discrete time using the correspondence \(\dot{\omega }~\leftrightarrow \frac{\omega ^\bullet -\omega }{\delta }\).

5.2 Global Discrete-Time Analysis

In this section, we handle each of the two modes as well as the mode changes in a uniform way. Let’s consider now the discretized version of our two modes System (26):
$$\begin{aligned} \begin{array}{rrl} (e_1):&{}&{} 0= J_1 (\omega ^\bullet _1-\omega _1) + k C (u^\bullet -u) - \delta .(\tau -k(u_0 - u)/R) \\ (e_2):&{}&{} 0= J_2 (\omega ^\bullet _2-\omega _2)-\delta .\tau \\ (e_3):&{}&{} 0= k \omega _1 - u \\ (e_4):&{}{\mathtt {if}\ } \gamma {\ \mathtt {do}}&{} 0= \tau \\ (e_5):&{} {\mathtt {if\;not}\ } \gamma {\ \mathtt {do}}&{} 0= \omega _1-\omega _2 \\ \end{array} \end{aligned}$$
(31)
Notice how model (31) encompasses both the released and engaged modes, as well as the mode changes, in the same uniform setting of discrete time systems. This calls for using similar reasoning to determine the new values of the leading variables regardless of whether the system is evolving in continuous mode or is at an event of mode change. We now detail the how and when the different involved equations are used.

1. Using \((e_1),\dots ,(e_3)\) Those three equations are active in all modes. Equation \((e_3)\) is useless, so we are left with 2 equations and 4 leading variables and no subset of them can be evaluated using the 3 available equations only. We thus have to evaluate the guard \(\gamma \) in order to know which equation among \((e_4)\) or \((e_5)\) is active. We successively analyze the two cases below.

2-released. Case \(\gamma =\text{ t }\) Equation \((e_4)\) is enabled and equation \((e_5)\) is disabled. The reasoning proceeds exactly as for getting the model (29-released). The difference is that we take the consistency equation \((e_3)\) as an assumption, since its satisfaction results from the execution of the previous time step. The resulting model is thus:
$$\begin{aligned} \begin{array}{rcl} \mathtt {assuming} &{}:&{} (e_3): ~0= k \omega _1 - u \\ \mathtt {if}\;\gamma =\text{ t }&{}\mathtt {do}&{} \text {(29-released}\,\setminus \,\{(e_{3})\}) \end{array} \end{aligned}$$
(32)
where (29-released\(\,\setminus \,\{(e_3)\}\)) means that equation \((e_3)\) is removed from system 29-released. Note that model (29-released) applies both within the “released” mode and at the instant of mode change \(\gamma :\text{ f }\rightarrow \text{ t }\).
2-engaged. Case \(\gamma =\text{ f }\) Equation \((e_4)\) is disabled and equation \((e_5)\) is enabled. With reference to system (29-engaged), an important difference occurs: assuming that the consistency equation \((e_5)\) results from having executed the previous time step is not always valid (equation \((e_5)\) is guarded and can thus be disabled). Consequently the following two sub-cases need to be considered:
  • Case \(\omega _1=\omega _2\) follows from previous time step. This corresponds to the case in which the system was already in mode “engaged” at the previous time step. The separate analysis developed for the “engaged” mode in Sect. 5.1 applies with no change. The model, as augmented with the two latent equations \((e_3^\bullet ,e_5^\bullet )\) is (29-engaged), in which \(({e_3},{e_5})\) are taken as assumptions:
    $$\begin{aligned} \begin{array}{rcl} \mathtt {assuming} &{}:&{} \left\{ \begin{array}{rll} (e_3):&{}&{} 0= k \omega _1 - u \\ (e_5):&{}&{} 0= {\omega _1}-{\omega _2} \end{array}\right. \\ \mathtt {if}\;\gamma =\text{ f }&{}\mathtt {do}&{} \text {(29-engaged}\,\setminus \,\{(e_3),(e_5)\}) \end{array} \end{aligned}$$
    (33)
  • Case \(\omega _1=\omega _2\) does not follow from previous time step. This arises if the system is engaged at the current instant t, but was released at the immediate previous time step, \(t-\delta \), i.e., t is an instant of mode change \(\gamma :\text{ t }\rightarrow \text{ f }\). This yields a new situation, not seen in Sect. 5.1. The engaged mode requires the consistency equation \(\omega _1=\omega _2\), whereas \(\omega _1(t)\) and \(\omega _2(t)\) were both evaluated at the previous time step \(t-\delta \), at which \(\omega _1^\bullet (t-\delta )=\omega _2^\bullet (t-\delta )\) was not enforced. As a consequence, equation \((e_5)\) of System (31) is enabled. Unfortunately, \((e_5)\) possesses no dependent variable and the values of the state variables \(\omega _1\) and \(\omega _2\) were set at previous time step \(t-\delta \), with no guarantee that \(\omega _1(t)=\omega _2(t)\) would result. System (31) is thus overdetermined at time t. A first idea would be to reject this kind of model. This would be unfortunate as our original model (26) was natural for our electromechanical system. To overcome this issue, we invoke the following

Principle 1

(Mode Causality Principle). A guard must be evaluated before the equation it controls.

This principle leads to shifting forward equation \((e_5)\) in model (29-engaged). We expect this modification to be very mild since it consists in delaying the satisfaction of the constraint by a small amount of time. Performing this yields:
$$\begin{aligned} \begin{array}{rcl} \mathtt {assuming} &{}:&{} (e_3):~ 0= k \omega _1 - u \\ \mathtt {if}\;\gamma =\text{ f }&{}\mathtt {do}&{} \text {(29-engaged}\,\setminus \,\{(e_3),(e_5)\}) \end{array} \end{aligned}$$
(34)
Systems (33) and (34) possess identical right hand sides but were obtained by different reasoning—the fact that identical right hand sides were obtained is incidental to this example. System (32, 33, 34) replaces the original System (31).
As a final remark, observe that the same analysis would work without changes if the guard \(\gamma \) was a predicate in the state variables \(u,\omega _1,\omega _2\).
Fig. 5.

Structural analysis of System (31): state machine describing the execution scheme of one time step of System (31).

The corresponding complete execution scheme is shown in Fig. 5. In this figure, boxes are the states of the execution scheme and their content specifies the configuration of guard, variables, and equations. For the guard and the variables: \({v}\) (resp. \(\overline{v}\)) means \(v=\text{ t }\) (resp. \(v=\text{ f }\)). For equations, \({e}\) (resp. \(\overline{e}\)) means that e is active (resp. disabled) and \(\sharp {e}\) means that the body of e is assumed from previous time step. Not mentioning a variable or an equation in a box means that this variable is not evaluated yet and this equation is not solved yet; for shifted equations added by the algorithm, however, we mention them underlined. The transitions of the state machine indicate the actions performed when moving to the next state. \(\text{ FS }({e})\) indicates that e is shifted. \(\text{ PR }({e})\) indicates that e is known to be satisfied. \(\text{ LE }({e^\bullet })\) indicates that we add \(e^\bullet \) as a latent equation. Blue (resp. black) transitions belong to a continuous-time (resp. discrete-time) dynamics. The red transition is impulsive. A semicolon is the sequential composition of computations, and the \(+\) sign denotes enabled blocks of equations, ready to be solved. The following comments are in order.

  1. 1.

    Observe first the parallel between the models sitting in the boxes of the diagram of Fig. 5 on the one hand, and the mixed explicit/implicit scheme (9) on the other hand. For this comparison, variables with superscript “\(^+\)” in (9) correspond to shifted variables in Fig. 5 and variables with superscript “\(^-\)” in (9) correspond to non shifted variables in Fig. 5.

     
  2. 2.
    Our development relies on a small set of principles:
    • We map the continuous time multi-mode System (26) to discrete time System (31) by mapping derivatives \(\dot{x}\) to their explicit Euler scheme \(\frac{x^\bullet -x}{\delta }\).

    • Our massaging of the equations only depends on the values taken by the guards, and the assumption regarding the satisfaction/violation of the consistency equations (here \((e_3)\), and \((e_5)\) for the engaged mode). Otherwise, we make no distinction between instants of mode changes and other instants: our treatment is uniform.

    • Our massaging of the equations has two objectives: finding latent equations if needed, and shifting forward equations when required by the principle of mode causality (Principle 1).

    This set of principles is small, clean, and powerful enough to encompass general systems with a structural analysis alike the one we developed here for the clutch example. See [3] for a presentation of this approach for general multi-mode DAE systems.

     
Fig. 6.

Actual simulation code for the clutch.

5.3 Effective Simulation Code

So far the execution scheme of Fig. 5 is not satisfactory, as it uses an explicit first order Euler scheme. From the execution scheme of Fig. 5, however, the actual simulation code shown on Fig. 6 is derived. Observe that it consists of
  • a DAE model of index zero or one for each mode, and

  • code for resetting the state variables at mode changes.

The model for each mode can be simulated, e.g., using a BDF method as proposed in Sect. 4.2. Regarding the resets at mode changes, \(\omega _i^{-}\) is the previous value of state variable \(\omega _i\), which is the left limit of \(\omega _i\) when exiting a mode. Similarly, \(\omega _i^+\) is the reset value for state variable \(\omega _i\) when entering the new mode. Continuous-time dynamics are colored blue; non-impulsive (resp. impulsive) resets are colored black (resp. red). The dynamics in each mode are defined by an over-determined index-1 DAE system consisting of an ODE system coupled to an algebraic constraint. In the transition from mode \(\overline{\gamma }\) to mode \(\gamma \), variable \(\tau \) is impulsive, and its value is not computed—it is set to \(\text{ NaN }\) (Not a Number). Let us explain how the code of Fig. 6 is deduced from the execution scheme of Fig. 5.

Nonstandard Analysis. First, we select the step size \(\delta \) to be infinitesimal in the sense of nonstandard analysis [18, 28], of which we informally recall the background we need.

In nonstandard analysis, the set \(\mathbb {R}\) of real numbers is extended with infinite numbers, which are larger than any real number, and infinitesimal numbers, which are smaller (in absolute value) than any nonzero real number. The resulting set \({^{\star \!}\mathbb {R}}\) is an extension of \(\mathbb {R}\) that keeps its basic properties. In particular, it is an ordered field. We will be writing \(x\approx {y}\) if \(x-y\) is an infinitesimal. Any finite element \(z\in {^{\star \!}\mathbb {R}}\) has a standard part, defined as the unique real number \({ st}(z)\) such that \(z\approx { st}(z)\). Any element of \(\mathbb {R}\) is called standard.

If \(\varvec{x}(t)\) is a standard differentiable function of time, its derivative \(\dot{\varvec{x}}(t)\) satisfies the property that, for any infinitesimal nonzero time step \(\delta \),
$$\begin{aligned} \dot{\varvec{x}}(t) \approx \frac{\varvec{x}(t+\delta )-\varvec{x}(t)}{\delta }. \end{aligned}$$
(35)
That is, taking an explicit first order Euler scheme with infinitesimal step size yields an exact match for an ODE, up to an infinitesimal error. Formally, one says that this Euler scheme standardizes as the solution of the ODE.
DAE Model for Each Mode. Each (blue) mode in Fig. 6 corresponds to a blue cycle in Fig. 5. For instance, the equationwhich, by Eq. (35), standardizes as the ODE \((e_2): 0= J_2 \dot{\omega }_2-\tau \). The reader is referred to [3] for details about standardization.

Computing the Reset Values. As in the development of Sect. 4, one key contribution of our approach is the reset code for the mode transitions. Let us now explain how this part of Fig. 6 is derived from Fig. 5. Here the reasoning is different since we do not target a continuous time dynamics, but rather a finite sequence of discrete time steps implementing the reset actions.

Let’s focus on the transition \(\gamma :\text{ t }\rightarrow \text{ f }\) shown in red in Fig. 6, which originates from the path sitting at the top, from the right- to the left blue cycle in Fig. 5. The corresponding dynamics is (34) and we target a discrete time dynamics involving the forward shift \(^\bullet \) and no differentiation. Hence, in Eq. (34), equations \((e_3^\bullet ),(e_5^\bullet )\) have the convenient form. In turn, one can no longer interpret \((e_1)\) or \((e_2)\) as differential equations. We must rather regard them as difference equations. Since they involve the infinitesimal parameter \(\delta \), standardization must be performed with care. Indeed, due to the equation \((e_5^\bullet )\) of (34) and since \((e_5)\) is not assumed, the velocities \(\omega _i\) experience a discrete jump. By \((e_1)\) and \((e_2)\) and since \(\delta \) is infinitesimal, we infer that \(\tau \) must be impulsive. This propagates throughout the different equations of the system. For impulses, the rescaling
$$ \tau '=_{\mathrm{def}}{\delta }.{\tau } $$
of the system variables is applied, guided by the equations and the incidence graph (30-right) of the system, see the impulse analysis developed in [3]. Using this rescaling, the block of equations of (34) becomesThe term shown in Open image in new window involves state variables and is multiplied by the infinitesimal \(\delta \). Zeroing this blue term in System (36) leaves us with a structurally regular system that we can solve for its dependent variables \(\tau ',u^{\bullet },\omega ^\bullet _1,\omega ^\bullet _2\). Solving (36) yields in particular the reset values for the state variables \(u^+=_{\mathrm{def}}u^{\bullet }\), and \(\omega _i^+=_{\mathrm{def}}\omega ^\bullet _1=\omega ^\bullet _2\). We recover in particular the formulas (25) from Sect. 4.4.

5.4 Constructive Semantics

The essential step in getting the final code of Fig. 6 was the construction of the state machine of Fig. 5. This state machine is called the Constructive Semantics of the original System (31). The notion of constructive semantics was first introduced in the context of reactive synchronous programming languages [4, 6, 7], where it played an important role in grounding compilation on solid mathematical foundations. Essentially, a constructive semantics for a discrete time dynamical system consists of:
  1. 1.

    A specification of the set of atomic actions, which are effective, non interruptible, state transformation operations. Executing an atomic action is often referred to as performing a micro-step;

     
  2. 2.

    A specification of the correct scheduling of the set of micro-steps constituting a reaction, by which discrete time progresses, from the current instant to the next one.

     

The effect of atomic actions is to propagate knowledge regarding the statuses (not evaluated, evaluated) and values of variables. The computation of the constructive semantics of a synchronous program may succeed, and then the execution code is generated. Or it may fail, and then the program is rejected. The decision success/failure is formally sound, see [4, 6, 7].

For synchronous languages, atomic actions are restricted to either (i) the evaluation of a single expression, or (ii) control flow operations.

In contrast, the class of atomic actions for multi-mode difference algebraic equations systems comprises: (i) Evaluating a guard; (ii) Solving a block of numerical equations; (iii) Equation management operations, such as shifting an equation, adding a latent equation, or changing the status involved/not involved of an equation at a given mode.

In [3] we develop in detail the constructive semantics for multi-mode DAE systems. This allows us to formally define which model can be compiled and then simulated, and which cannot. Models that are under- or overdetermined are rejected. In addition, models which are not handled by the Principle 1 of mode causality, are rejected as well. This approach is implemented in the SunDAE proof of concept tool.

The standardization of the constructive semantics remains open in part although its main principles have been clarified. The Standardization, however, requires symbolic processing related to computer algebra.

6 Challenges in DAE Based Modeling Languages

DAE based modeling languages are essential to the design of CPS. The development of such languages raise a number of challenges.

The correct simulation of mode changes and the need for resetting state variables is a first—mostly open—difficulty, particularly when impulses occur. In this paper, we proposed two different approaches for addressing this issue. The first approach relies on a transformation of the system model to a special index one form, followed by the application of a new formula for resetting the state variables. Arguments supporting this formula were given under additional assumptions on the model. The second approach builds on the use of nonstandard analysis, combined with the heritage of synchronous languages in computer science, particularly on the concept of constructive semantics. The classes of accepted/rejected models are well defined and simulation code is always produced for accepted models. In turn, the physical interpretation is understood only for restricted classes of models.

A particular difficulty of DAE based modeling languages is the need for sophisticated symbolic preprocessing of the model, called structural analysis. The Pantelides algorithm for computing the latent equations of a (single-mode) DAE model gave birth to a large body of literature since 1988. Our paper shows that structural analyses are also essential to handle mode changes.

Structural analyses play also a central role in scaling-up to huge models involving millions of equations. The community of High Performance Computing has provided important related contributions, for single-mode DAE systems. Yet, modularity in compilation and simulation remains open.

Overall, we see as a grand challenge the development of a DAE based modeling language and tool with the following features: DAE models with a very large number of modes are supported; accepted/rejected models are formally characterized; huge models are supported and can be handled in a modular way. We see the new language Modia and the SunDAE library as good starting points for tackling such challenges.

Footnotes

  1. 1.

    See the extensive literature available in https://www.modelica.org/publications.

  2. 2.

    A DAE \(\varvec{f}(\dot{\varvec{x}},\varvec{x},t) = 0\) has differentiation index n if one or more equations must be differentiated n-times until the equations can be algebraically transformed to an ODE form \(\dot{\varvec{x}} = \bar{f}(\varvec{x},t)\), see for example [30].

  3. 3.

    A function \(f:\mathbb {R}\mapsto \mathbb {R}\) is said to have bounded variation if it is the primitive of a Lebesgue integrable function [10]. As a consequence, \(\int _t^{t+h}\dot{f}(s)ds\rightarrow {0}\) when \(h\rightarrow {0}\).

Notes

Acknowledgements

The authors want to thank Toivo Henningsson, Lund, Sweden for the collaboration regarding Julia and the design of Modia, as well as the implementation of instantiation and flattening.

References

  1. 1.
    Alur, R., Courcoubetis, C., Henzinger, T.A., Ho, P.-H.: Hybrid automata: an algorithmic approach to the specification and verification of hybrid systems. In: Grossman, R.L., Nerode, A., Ravn, A.P., Rischel, H. (eds.) HS 1991-1992. LNCS, vol. 736, pp. 209–229. Springer, Heidelberg (1993).  https://doi.org/10.1007/3-540-57318-6_30CrossRefGoogle Scholar
  2. 2.
    Barela, M.: A complementarity approach to modeling dynamic electric circuits. Ph.D. thesis, University of Iowa (2016)Google Scholar
  3. 3.
    Benveniste, A., Caillaud, B., Elmqvist, H., Ghorbal, K., Otter, M., Pouzet, M.: Structural analysis of multi-mode DAE systems. In: HSCC, pp. 253–263. ACM (2017)Google Scholar
  4. 4.
    Benveniste, A., Caillaud, B., Guernic, P.L.: Compositionality in dataflow synchronous languages: specification and distributed code generation. Inf. Comput. 163(1), 125–171 (2000)MathSciNetCrossRefGoogle Scholar
  5. 5.
    Benveniste,A., Caillaud, B., Pouzet, M., Elmqvist, H., Otter, M.: Structural analysis of multi-mode DAE systems. Research report RR-8933, Inria, July 2016Google Scholar
  6. 6.
    Benveniste, A., Caspi, P., Edwards, S.A., Halbwachs, N., Guernic, P.L., de Simone, R.: The synchronous languages 12 years later. Proc. IEEE 91(1), 64–83 (2003)CrossRefGoogle Scholar
  7. 7.
    Berry, G.: Constructive semantics of Esterel: from theory to practice (abstract). In: Wirsing, M., Nivat, M. (eds.) AMAST 1996. LNCS, vol. 1101, p. 225. Springer, Heidelberg (1996).  https://doi.org/10.1007/BFb0014318CrossRefGoogle Scholar
  8. 8.
    Bezanson, J., Edelman, A., Karpinski, S., Shah, V.B.: Julia: a fresh approach to numerical computing. SIAM Rev. 59(1), 65–98 (2017)MathSciNetCrossRefGoogle Scholar
  9. 9.
    Brenan, K.E., Campbell, S.L., Petzold, L.R.: Numerical Solution of Initial Value Problems in Differential-Algebraic Equations. SIAM (1996)Google Scholar
  10. 10.
    Dunford, N., Schwartz, J.: Linear Operators, Part I, General Theory. Wiley-Interscience (1958)Google Scholar
  11. 11.
    Elmqvist, H., Henningsson, T., Otter, M.: Systems modeling and programming in a unified environment based on Julia. In: Margaria, T., Steffen, B. (eds.) ISoLA 2016. LNCS, vol. 9953, pp. 198–217. Springer, Cham (2016).  https://doi.org/10.1007/978-3-319-47169-3_15CrossRefGoogle Scholar
  12. 12.
    Elmqvist, H., Henningsson, T., Otter, M.: Innovations for future Modelica. In: Jiri Kofranek, F.C. (ed.) Proceedings of the 12th International Modelica Conference, May 2017. http://www.ep.liu.se/ecp/132/076/ecp17132693.pdf
  13. 13.
    Elmqvist, H., Mattsson, S.-E., Otter, M.: Modelica extensions for multi-mode DAE systems. In: Tummescheit, H., Arzèn, K.-E. (eds.) Proceedings of the 10th International Modelica Conference, Lund, Sweden. Modelica Association, September 2014. http://www.ep.liu.se/ecp/096/019/ecp14096019.pdf
  14. 14.
    Gear, C.W.: Differential-algebraic equation index transformations. SIAM J. Sci. Stat. Comput. 9(1), 39–47 (1988)MathSciNetCrossRefGoogle Scholar
  15. 15.
    Gear, C.W., Leimkuhler, B., Gupta, G.K.: Automatic integration of euler-lagrange equations with constraints. J. Comput. Appl. Math. 12, 77–90 (1985)MathSciNetCrossRefGoogle Scholar
  16. 16.
    Heemels, W.P.M.H., Camlibel, M.K., Schumacher, J.M.: On the dynamic analysis of piecewise-linear networks. IEEE Trans. Circ. Syst. I: Fundam. Theory Appl. 49(3), 315–327 (2002)MathSciNetCrossRefGoogle Scholar
  17. 17.
    Karnopp, D., Margolis, D., Rosenberg, R.: System Dynamics: A Unified Approach. Wiley, Hoboken (1990)Google Scholar
  18. 18.
    Lindstrøm, T.: An invitation to nonstandard analysis. In: Cutland, N. (ed.) Nonstandard Analysis and its Applications, pp. 1–105. Cambridge University Press, Cambridge (1988)Google Scholar
  19. 19.
    Mattsson, S.-E., Otter, M., Elmqvist, H.: Multi-mode DAE systems with varying index. In: Elmqvist, H., Fritzson, P. (eds.) Proceedings of the 11th International Modelica Conference, Versailles, France. Modelica Association, September 2015. http://www.ep.liu.se/ecp/118/009/ecp1511889.pdf
  20. 20.
    Mehrmann, V., Wunderlich, L.: Hybrid systems of differential-algebraic equations - analysis and numerical solution. J. Process Control 19(8), 1218–1228 (2009). Special Section on Hybrid Systems: Modeling, Simulation and OptimizationCrossRefGoogle Scholar
  21. 21.
    Modelica: A unified object-oriented language for systems modeling. Language Specification, Version 3.4. Technical report, Modelica Association, April 2017. https://www.modelica.org/documents/ModelicaSpec34.pdf
  22. 22.
    Otter, M., Elmqvist, H.: Transformation of differential algebraic array equations to index one form. In: Kofranek, J., Casella, F. (eds.) Proceedings of the 12th International Modelica Conference, May 2017. http://www.ep.liu.se/ecp/132/064/ecp17132565.pdf
  23. 23.
    Pantelides, C.: The consistent initialization of differential-algebraic systems. SIAM J. Sci. Stat. Comput. 9(2), 213–231 (1988)MathSciNetCrossRefGoogle Scholar
  24. 24.
    Pepper, P., Mehlhase, A., Höger, C., Scholz, L.: A compositional semantics for Modelica-style variable-structure modeling. In: 4th International Workshop on Equation-Based Object-Oriented Modeling Languages and Tools (2011). http://www.ep.liu.se/ecp/056/006/ecp1105606.pdf
  25. 25.
    Pfeiffer, F.: On non-smooth multibody dynamics. Proc. Inst. Mech. Eng. Part K: J. Multi-body Dyn. 226(2), 147–177 (2012). http://journals.sagepub.com/doi/pdf/10.1177/1464419312438487Google Scholar
  26. 26.
    Pfeiffer, F., Glocker, C.: Multibody Dynamics with Unilateral Contacts. Wiley, Hoboken (2008)zbMATHGoogle Scholar
  27. 27.
    Pryce, J.D.: A simple structural analysis method for DAEs. BIT 41(2), 364–394 (2001)MathSciNetCrossRefGoogle Scholar
  28. 28.
    Robinson, A.: Nonstandard Analysis. Princeton Landmarks in Mathematics (1996). ISBN 0-691-04490-2Google Scholar
  29. 29.
    Schoeder, S., Ulbrich, H., Schindler, T.: Discussion of the Gear-Gupta-Leimkuhler method for impacting mechanical systems. Multibody Sys. Dyn. 31, 477–495 (2013)MathSciNetCrossRefGoogle Scholar
  30. 30.
    Campbell, S.L., Gear, C.W.: The index of general nonlinear DAEs. Numer. Math. 72, 173–196 (1995)MathSciNetCrossRefGoogle Scholar
  31. 31.
    Thoma, J.: Introduction to Bond Graphs and Their Applications. Pergamon International Library of Science, Technology, Engineering and Social Studies. Pergamon Press (1975)Google Scholar
  32. 32.
    Trenn, S.: Distributional differential algebraic equations. Ph.D. thesis, Technischen Universität Ilmenau (2009). https://www.db-thueringen.de/servlets/MCRFileNodeServlet/dbt_derivate_00018071/ilm1-2009000207.pdf
  33. 33.
    Zimmer, D.: Equation-based modeling of variable-structure systems. Ph.D. thesis, ETH Zürich, no. 18924 (2010). http://www.inf.ethz.ch/personal/fcellier/PhD/zimmer_phd.pdf

Copyright information

© Springer Nature Switzerland AG 2019

Authors and Affiliations

  • Albert Benveniste
    • 1
  • Benoît Caillaud
    • 1
  • Hilding Elmqvist
    • 2
  • Khalil Ghorbal
    • 1
    Email author
  • Martin Otter
    • 3
    Email author
  • Marc Pouzet
    • 4
  1. 1.InriaRennesFrance
  2. 2.Mogram ABLundSweden
  3. 3.DLR-SROberpfaffenhofenGermany
  4. 4.ENSParisFrance

Personalised recommendations