Keywords

1 Introduction

INTO-CPS provides an entire tool chain [8] that enables combining different tools and formalisms using co-simulation [6]. This demo provides the theoretical rationale for the stabilization feature of the Co-simulation Orchestration Engine from INTO-CPS called Maestro [12]. The feature will be illustrated with a small case study that is documented online [10].

This demo assumes that the reader is familiar with the main concepts in co-simulation (see, e.g., [7]).

In the next section, we describe the principles of stability analysis for linear Ordinary Differential Equations (ODEs), and linear discrete time systems. Then, in Sect. 3, we apply these principles to analyse the numerical stability of the commonly used Jacobi algorithm within the FMI context, and the stabilization method used in INTO-CPS. While the master algorithms are applicable outside the Functional Mockup Interface (FMI) context, the FMI version 2.0 has constraints that makes the stability analysis not applicable to other contexts.

2 Stability of Linear Systems

This section is based on [7].

Notation. We denote vectors with bold face, and we use capital letters for matrices and vector valued functions. Given a vector \(\varvec{x}\), we denote its transpose as \(\varvec{x}^T\). Furthermore, we denote the i-th element of vector \(\varvec{x}\) by \(x_{i}\), so that \(\varvec{x} = \left[ \begin{matrix} x_{1}&x_{2}&\cdots&x_{n} \end{matrix} \right] ^T\). Similarly, \(F_{i}(\varvec{x})\) denotes the i-th element of the vector returned by \(F(\varvec{x})\).

A linear ODE has the following form:

$$\begin{aligned} \dot{\varvec{x}} = A\varvec{x}, \end{aligned}$$
(1)

where \(\varvec{x}(t)\) is a vector function, and A is a constant matrix. When an initial condition in the form \(\varvec{x}(0)=\varvec{x_0}\) is specified, we denote Eq. (1) as an Initial Value Problem (IVP).

Example 1

The mass-spring-damper system, illustrated in Fig. 1a, is modelled by the following second order ordinary differential equation:

$$ \ddot{x} = \frac{1}{m} (- c x - d \dot{x} + f_e(t)), $$

where x denotes the position of the mass, \(c>0\) is the stiffness coefficient of the spring, \(d>0\) is the damping constant of the damper, t is time, and \(f_e(t)\) denotes an external force exerted on the mass.

The above equation can be put into the form of Eq. (1) by introducing a new variable for velocity, \(v = \dot{x} \), and letting the vector \(\varvec{x} = \left[ \begin{matrix} x&v \end{matrix} \right] ^T\). Given an initial position \(x_0\) and velocity \(v_0\), we obtain the following:

Figure 1b shows the solution of the position component of the mass-spring-damper IVP, introduced in Example 1, and will be explained below. The solution to the velocity component is omitted.

Fig. 1.
figure 1

Position (and its approximations) over time of the mass-spring-damper system. Parameters are: \(h=0.1,m=c=1,d=10^{-4}, f_e(t)=0, \varvec{x}_0= \left[ \begin{matrix} 1&0 \end{matrix} \right] ^T\).

We say that the system in Eq. (1) is asymptotically stable when all its solutions tend to zero as time passes, regardless of the initial value specified. Formally,

$$\begin{aligned} \lim _{t \rightarrow \infty } \left||\varvec{x}(t)\right|| = 0 \text {, for all } x(t) \text { satisfying Eq. (1)}. \end{aligned}$$
(2)

An ODE in the form of Eq. (1) is asymptotically stable, i.e. it satisfies Eq. (2), if the real part of all eigenvalues of A is strictly negative. Formally,

$$\begin{aligned} \forall \lambda \in \text {Eig}(A),\ \mathbb {R}\text {e}\{\lambda \} < 0. \end{aligned}$$
(3)

This condition can be computed easily in most programming languages.

To approximate the solution to the IVP in Example 1, one can use the forward Euler method:

$$\begin{aligned} \varvec{x}(t+h) \approx \varvec{x}(t) + A \varvec{x}(t) h = (I + A h)\varvec{x}(t) \text {, with } \varvec{x}(0)=\varvec{x_0}, \end{aligned}$$
(4)

where I is the identify matrix with the appropriate dimensions, and \(h>0\) is the given simulation step size.

In general, for a given matrix \(\tilde{A}\), a system on the form

$$\begin{aligned} \varvec{x}(t+h) = \tilde{A} \varvec{x}(t), \end{aligned}$$
(5)

is stable if \(\rho (\tilde{A}) < 1\), where \(\rho (\tilde{A})\) is the spectral radius [9] of \(\tilde{A}\).

3 Stability Analysis of FMI Orchestration Algorithms

Our aim is to encode the co-simulation as a system in the form of Eq. (5). We perform this for a two-simulator system using two orchestration algorithms: the traditional Jacobi method, and the stabilization method used by INTO-CPS. A two simulator system introduced in [10] is illustrated in Fig. 2. More details about this example are given in [6, Sect. 4]. For more examples of stability analysis in co-simulation, refer to [2,3,4,5].

Fig. 2.
figure 2

Double mass-spring-damper with two subsystems: \(S_1\) and \(S_2\).

3.1 Co-simulation Unit Modelling

In the context of co-simulation, time is discretized into a countable set \(T = \left\{ t_0, t_1, t_2, \ldots \right\} \subset \mathbb {R}\), where \(t_{i+1} = t_i + H_i\) is the time at step i and \(H_i\) is the communication step size at step i, with \(i=0,1,\ldots \)

Simulators exchange outputs only at times \(t \in T\).

In the interval \(t \in \left[ t_i, t_{i+1} \right] \), each simulator \(S_j\) approximates the solution to a linear ODE,

$$\begin{aligned} \begin{aligned} \dot{\varvec{x}} _j&= A_j \varvec{x}_j + B_j \varvec{u}_j \\ \varvec{y}_j&= C_j \varvec{x}_j + D_j \varvec{u}_j \end{aligned} \end{aligned}$$
(6)

where \(\varvec{x}_j\) is the state vector, \(\varvec{y}_j\) is the output vector, \(A_j, B_j, C_j, D_j\) are matrices, the initial state \(\varvec{x}_j(t_i)\) is computed in the most recent co-simulation step, and \(j=1,2\).

Since the simulators only exchange outputs at times \(t_i, t_{i+1} \in T\), the input \(\varvec{u}_j\) has to be extrapolated in the interval \([t_i, t_{i+1})\). In the simplest co-simulation strategyFootnote 1, this extrapolation is often implemented as a zero-order hold: \(\tilde{\varvec{u}}_j(t) = \varvec{u}_j(t_i)\), for \(t \in [t_i, t_{i+1})\). Then, Eq. (6) can be re-written to represent the unforced system being integrated by each simulator:

(7)

We can represent the multiple internal integration steps of Eq. (7), performed by the simulator \(S_j\) in the interval \(t \in \left[ t_i, t_{i+1} \right] \), as

(8)

where, e.g., \(\tilde{A}_j = \mathbf {I} + h_j \left[ \begin{matrix} A_j &{} B_j \\ \mathbf {0} &{} \mathbf {0} \end{matrix} \right] \) for the Forward Euler method, \(k_j=(t_{i+1} - t_i)/h_j\) is the number of internal steps, and \(0 < h_j \le H_i\) is the internal fixed step size that divides \(H_i\).

Therefore, each co-simulation unit can be modelled as a discrete time system:

(9)

with

$$\tilde{A}^{k_j}_j = \left[ \begin{matrix} M_{1,x_j} &{} M_{1,u_j} \\ M_{2,x_j} &{} M_{2,u_j} \end{matrix} \right] .$$

3.2 FMI Jacobi Algorithm

We assume without loss of generality that the two simulators are coupled in a feedback loop, that is,

$$\begin{aligned} \varvec{u}_1 = \varvec{y}_2 \text { and } \varvec{u}_2 = \varvec{y}_1. \end{aligned}$$
(10)

And, to avoid algebraic loops and keep the exposition short, we assume that either \(D_1\) or \(D_2\) (recall Eq. (6)) is the zero matrix. Let \(D_2 = \mathbf {0}\).

The ideal Jacobi coupling would be described by:

(11)

However, due the FMI restrictions [11, Restriction 1], the actual coupling is:

(12)

Applying Eq. (12) to \(t_{i+1}\) and using Eq. (9), yields:

(13)

which can be arranged to the form of Eq. (5):

(14)

3.3 INTO-CPS Method

The method used in INTO-CPS is a sucessive substitution fixed point iteration, described by:

(15)

The above equation can be expanded and simplified to:

(16)

which can be put in matrix form:

(17)

Renaming the above equation to \(\bar{\varvec{x}}_{i+1} = \bar{M}_i \bar{\varvec{x}}_i + \bar{M}_{i+1} \bar{\varvec{x}}_{i+1}\), we get an equation in the form of Eq.  (5):

$$\begin{aligned} \begin{aligned} \bar{\varvec{x}}_{i+1}&= (I - \bar{M}_{i+1}) ^{-1} \bar{M}_i \bar{\varvec{x}}_i \end{aligned} \end{aligned}$$
(18)

In most cases in practice, \(\rho ((I - \bar{M}_{i+1}) ^{-1} \bar{M}_i)\) is smaller than the spectral radius of the matrix in Eq. (14). The practical results of this analysis are shown in the case study described in [10].

This can be generalized. However, in practice, one must be aware of the internal details of each co-simulation unit, which is usually difficult. As such, this analysis can be used to determine the best orchestration algorithm, without providing guarantees.