Abstract
Model-based design can shorten the development time of complex systems by the use of simulation techniques. However, it can be hard to simulate the system as a whole if it is developed in a concurrent fashion by multiple and specialized teams. Co-simulation, with the support of the Functional Mockup Interface (FMI) Standard, is proposed as a way to promote tool interoperability while protecting the intellectual property of subsystems. The standard allows uniform communication between subsystem simulators, but does not state how the inputs and outputs should be interpreted, nor how the subsystems should interact correctly.
Semantic adaptations can be quickly made to correct the interactions with subsystem simulators that were produced with different assumptions, and avoid changing those subsystems, their simulators, or the orchestration algorithm that computes the co-simulation. In this work, we explore how to describe common adaptations and what their meaning is in the context of FMI co-simulation.
The result is a sound language that enables the implementation of adaptations with minimal effort. A distinct feature is that it describes adaptations for groups of interconnected subsystem simulators in the same way as for a single simulator, and the implementation is itself a simulator, thanks to a sound definition of hierarchical co-simulation.
This work paves the way for research into the correct combination and interfacing of different adaptations.
Keywords
1. Introduction
The systems we engineer today are characterized by increasing complexity. Model-based design can boost the development of such systems by enabling their analysis at higher levels of abstraction via simulation. However, it can be difficult to simulate the system as a whole if it is developed in a distributed fashion, by multiple and specialized teams. 1
Two factors contribute to this difficulty: (a) specialized teams have their own tools; and (b) some of the components of the system are provided by different suppliers, 2 and have valuable intellectual property (IP).
The first difficulty is a natural consequence of using the most appropriate formalism for a specific domain. 3 The same can be expected from external suppliers. During the development process, if a team wishes to understand how a component being developed behaves when interacting with the rest of the system, it is useful that the tool in use can import and simulate correctly the models created by the other teams (with different tools). As we show shortly, it can be difficult to correctly simulate imported models, as these belong to potentially different domains, each with their own set of specialized simulators. 3
As for the second difficulty, if the team is using externally supplied components and wishes to simulate them, it may not be able to import the components’ models because these contain protected IP. For sufficiently complex components, a “lock-in” contract can be made to allow the team access to those models. However, the team will no longer be free to benchmark components from different competing suppliers.
Co-simulation, with the support of the Functional Mockup Interface (FMI) Standard, 4 is proposed as a way to promote tool interoperability while addressing the IP protection requirement. The models are exported as executable black boxes that receive inputs and produce outputs, allowing for the simulation of the component they stand for. In the FMI, each black box is called a Functional Mockup Unit (FMU), the term adopted in this document.
The standard provides a common interface to allow uniform communication with the black boxes, solving the combinatorial explosion of import–export formats. However, it does not ensure that the black boxes are interacted with in a semantically correct manner.
When a team is given an FMU that does not behave as expected, we say that there is an interaction mismatch between the FMU and the rest of the system. Interaction mismatches can be roughly classified as follows:
Rather than asking the original producer of the FMU to correct an interaction mismatch, it can be useful that the team is able to correct it immediately. Note that any mismatch happens between a given FMU and a usage intent, and therefore it is not necessarily the case that the best correction of a mismatch is done by the producer (if the FMU is to be reused).
In fact, as the work of Arnold et al., Bastian et al., and Gomes et al. show,9,11–13 some mismatches happen as a product of the (incorrect) handling of multiple interacting FMUs, and the correction has to be done for that specific interaction.
The above arguments motivate the need for semantic adaptations, and lead to the following research question:
Informally, we call semantic adaptation of an FMU the set of modifications made to the inputs/outputs and interaction with environment, of the FMU, with the purpose of correcting an interaction mismatch. This concept is formalized later in this work.
Productivity is related to the effort required to describe an adaptation. Modularity refers to the fact that any FMU should be adapted by changing how it is interacted with, and not how it is implemented. Transparency means that any tool that imports FMUs should not have to be changed in order to import, and interact with, an adapted FMU.
The descriptions should be made in an independently developed language because it is impractical that every tool capable of importing FMUs is able to implement the adaptations. Furthermore, one cannot expect that any user of an FMU has the ability to modify the importing tool to support these. Compared to implementing these adaptations manually, a language reduces the accidental complexity, prevents mistakes, and allows soundness analyses to be carried out.
In this paper, we build on prior work14–16 to define a language that allows for the descriptions of the most common semantic adaptations that can be used in FMI co-simulation, surveyed by Gomes et al. 17 A distinct feature of the language proposed here is that it describes adaptations for groups of interconnected FMUs in the same way as for a single FMU, thanks to a sound definition of hierarchical co-simulation.
The definition of hierarchical co-simulation, and the semantics of the language, are presented in a bottom-up approach, as illustrated in Figure 1. In Section 2 we introduce a co-simulation abstraction with simulation units and how these relate to FMUs. Section 4 contains the formal foundations of a special kind of simulation unit that is the template to implement any semantic adaptation. In Section 3 a running example is described, and in Section 5 the language and its semantics are described. Section 6 judges how well we have addressed the research question. Section 7 discusses the flaws of our approach and research opportunities. Finally, Sections 8 and 9 present the related work and conclude, respectively.

Overview of DSL semantics and document structure.
2. Background
In this section we introduce the concepts, terminology, and assumptions used throughout this document. We cover co-simulation, the FMI Standard, semantic adaptation, and domain-specific languages.
2.1. Co-Simulation
We briefly summarize the main concepts related to co-simulation and refer the reader to the work of Gomes et al. for a more detailed introduction of each concept. 17
We use dynamical system to refer to a model that has a notion of state and rules describing the evolution of that state across time, starting from an initial state. Inputs and outputs can be defined to describe the environment.
A simulator is an algorithm that takes a dynamical system and input signals as input, and computes an approximated behavior trace of the dynamical system.
A simulation unit (also known as a simulation application 18 ) is the composition of a simulator together with a dynamical system, essentially representing a mockup of a real system. It accepts input trajectories and produces a behavior trace.
Simulation units (or just units) can be coupled through their inputs and outputs. A coupling restriction (or just couplings) is an output connected to an input. It means that the trajectory computed at that output—for example, a function of the continuous time—must be equal to the one computed at the input, at all times.
The orchestrator (or master) is an algorithm that takes a set of simulation units and their coupling restrictions—that is, a co-simulation scenario—and computes the behavior trace of all units, trying to satisfy the coupling restrictions. In practice, these restrictions can only be satisfied at certain countable points in time, called communication points. These points are agreed upon by the simulation units and the orchestrator.
A basic orchestrator will, at each communication point, copy data points from outputs to inputs, and ask each unit to compute its own behavior trace until the next communication point. The collective behavior trace is called the co-simulation.
We capture the essence of a simulation unit with reference i, using the discrete time system notation, in one of the following four possible ways:
where t denotes the simulated time,
The definition in Equation (1) covers the different kinds of simulation units considered (based on the orchestrators surveyed by Gomes et al.
17
): reactive Mealy, reactive Moore, delayed Mealy, and delayed Moore. The difference is in where and when the unit expects inputs to be provided. For example, a delayed Moore unit can compute its output without requiring an input, and can compute its future state (
We use shortcuts such as
Fi and
The internal definition of
If
Given a set of unique unit references
where
Let
Using the algebraic dependency relationship, one can build a directed graph—called the dataflow graph—with one node
Depending on the coupling function and on the kind of simulation units being coupled, algebraic loops may occur. An algebraic loop includes any input/output/state that depends on itself, at the same time point. 19
If an algebraic loop exists between the units, then it is not possible to compute a topological ordering of the dataflow graph. For now, we assume that such topological order can always be computed for a given co-simulation scenario. We denote that order via a mapping
With a well-defined topological order, the orchestrator only has to provide inputs to, execute, and get outputs from, the units in that order. Algorithm 1 formalizes what is known in the state of the art as the Gauss–Seidel orchestrator. It computes the behavior trace of a given co-simulation scenario as described in Equation (2). To be concise, we abbreviate the output and state transition function calls, which depend on the kind of unit (lines 11, 19, and 21). Furthermore, the orchestrator provides the inputs (
Without loss of generality, we assume the most basic step size control policy in Algorithm 1: the communication step size is never increased after being rejected by some unit. a The orchestrator uses the most recent consistent state.
2.2. FMI Standard
The FMI Standard 4 defines the interface and interaction pattern that allows simulation units to communicate. In the standard, a simulation unit is called a Functional Mockup Unit (FMU).
2.2.1. FMUs and simulation units
This subsection establishes the equivalence between FMUs and simulation units (recall Figure 1), and the assumptions we make throughout this paper.
Given a simulation unit i (described in Equation (1)), we define its equivalent FMU, and vice versa, as follows:
It is the role of the orchestrator to set the appropriate inputs depending on whether the FMU is reactive or delayed, or Mealy or Moore.
We define the type of the FMU by applying the following rules, in order:
If the unit does not disclose any input-to-output feedthrough, it is assumed to be Mealy.
If at least one output variable depends instantaneously on an input variable, we assume that the unit is Mealy.
If the previous two rules do not apply, the unit is assumed to be Moore.
If the capability flag canInterpolateInputs is set, then the unit is reactive.
Otherwise, the unit is delayed.
To establish the equivalence of the couplings restrictions of units and those of FMUs, we note that the definition of algebraic dependency remains the same between FMUs. Thus, the dataflow graph can be built as described in the previous subsection.
Having established the equivalence between simulation units and FMUs, we will henceforth use the two terms interchangeably.
2.3. Semantic adaptation
The interface of an FMU (or of a simulation unit) comprises not only the specification of the inputs and outputs, but also how it is to be interacted with. 14 It may be the case that in different co-simulation scenarios, the same FMU has to be interacted with differently (e.g., for accuracy/performance concerns). While modifying the orchestrator to support a new interaction pattern will solve the problem, it is not ideal since: (a) the interaction pattern may be specific to a single FMU (therefore not reusable); and (b) modifications to the orchestrator may require extensive testing to ensure that it retains its correctness properties (e.g., see the work of Gheorghe et al. 22 ).
Our work avoids changes to the underlying orchestration algorithm, and focuses on those changes around the FMU itself in the form of semantic adaptations, using hierarchical co-simulation.
An adaptation targets an FMU, or group of FMUs, which we will call the internal FMU(s), and the end result of an adaptation is a new FMU, which we call the external FMU. The external FMU interacts with the internal FMU(s) without requiring them to be modified (modularity). The adjectives internal and external reflect the hierarchical nature of our approach and are illustrated in Figure 2.

Internal FMUs, external FMU, and semantic adaptation.
We introduce below a non-exhaustive list of semantic adaptations that can be classified according to the interaction mismatch they intend to correct:
See the work of Gomes et al., and references thereof, for variants of these adaptations.8,17
2.3.1. Conversion of units and reference frame translation
The conversion of units and reference frame adaptations take an internal FMU and create an external FMU whose inputs/outputs are algebraic transformations of the input/outputs of the internal FMU.
2.3.2. Interpolation/extrapolation of inputs
An FMU that stands for a continuous system, such as a DC motor, approximates its behavior trace by discretizing the time continuum into a finite set of points 23 and applying a numerical method at each of those points.
In co-simulation, when the orchestrator asks an FMU to compute the behavior trace over an interval of time, from t to
Instead of reducing H, it is possible to adapt the FMU to better approximate its inputs. Essentially, the external FMU discretizes the interval
2.3.3 Fixed-point iteration
If an algebraic loop exists, then the involved units will belong to the same cycle in the corresponding dependency graph.
As proposed by Gomes and by Van Acker et al.,8,16 given a co-simulation scenario (recall Equation (2)) that has one cycle involving at least two simulation units (non-trivial), it is possible to create an external FMU that replaces all the units in the cycle. All the couplings external to the cycle become couplings to the hierarchical simulation unit.
At each state transition of the external FMU, a fixed-point iteration technique is applied to the inputs/outputs of the internal FMUs.
If a scenario has multiple non-trivial cycles, this adaptation can be applied to reduce the scenario to one in which all the algebraic loops are solved. 16 Algorithm 1 can then be applied to compute the co-simulation.
2.3.4. Multi-rate adaptation
For FMUs simulating first-order ordinary differential equations (ODEs), the larger the interval between the points, the less accurate the computed behavior trace will be. 27
The multi-rate adaptation is used to increase the accuracy while not sacrificing the performance in a co-simulation. Applied to co-simulation, the technique, well known in the circuit simulation domain, 28 consists of groups of interconnected internal FMUs that communicate more frequently.16,29 This can serve two purposes: optimize the communication cost between the internal units; 8 or optimize the accuracy of the co-simulation (especially when the internal units are physically tightly coupled 17 ).
Similarly to the input extrapolation adaptation, the state transition function of the external unit instructs the internal units to perform multiple steps and exchange values at each of those steps. The higher the rate of the adaptation, the higher the number of internal steps performed.
This adaptation can be combined with the approximation of inputs adaptation to provide for approximated inputs at each of the internal state transition invocations.
2.3.5. Time and partial derivative adaptation
Time and partial derivative information about each simulation unit’s outputs can be used to optimize the co-simulation process in many different ways (e.g., see Sicklinger et al.’s article 30 ).
In the FMI Standard, since the FMUs can optionally provide time and partial derivative information, it is often the case that some units do not support it. To mitigate this, a derivative adaptation can be used to produce an external FMU that provides (numerically estimated) partial and time derivatives.
2.3.6. Accurate threshold crossing
A co-simulation trace is more accurate if all units exchange values at the time when a certain signal crosses a given threshold. The problem of accurately finding that time is well known in the hybrid system simulation domain,31,32 and many techniques exist to address it.23,27 In FMI co-simulation, the most basic technique to accurately locate a crossing consists of rejecting a step size and proposing a new one, that possibly coincides with the threshold crossing moment.
The accurate zero crossing adaptation ensures that the external FMU rejects the proposed step size when one of the inputs of the internal FMU crosses a significant threshold too late. 15
2.3.7. Re-initialization
An internal FMU that is expecting a smooth input signal may yield unexpected behavior traces when given a discontinuous signal (we consider a discontinuous signal to be a sufficiently rapidly changing one in between co-simulation communication points).10,33,34 For example, an FMU that is using a multi-step numerical solver that assumes the input to be continuous (see Andersson et al. for a possible solution to this problem 35 ).
A re-initialization adaptation ensures that the external unit: (a) locates accurately the time of the discontinuity (e.g., in the same manner as the accurate crossing adaptation); and (b) the external unit is properly reset before handling the new value of the input. In the FMI Standard, item (b) requires three steps: save the unit state; reset and initialize the unit; and restore the state.
2.3.8. Quantization
Quantization is an adaptation commonly used to convert a continuous signal into a discrete event one. The (continuous) set of possible input values is discretized into regions and, during the co-simulation, whenever the continuous signal enters a new region, an event is produced.36,37
In co-simulation, this adaptation transforms an internal FMU that expects continuous inputs and produces continuous outputs, into an external FMU that deals with events (see the works by Awais et al., Bolduc and Vangheluwe, Camus et al., and Quesnel et al.38–41).
The realization of this adaptation is very similar to the zero crossing one, except that the thresholds to locate are induced by the input space discretization.
2.3.9. Hold
The hold family of adaptations can be seen as the dual of the multi-rate adaptations.
If an internal FMU should run slower than the rest of the simulation units, then it can be adapted with a hold adaptation. The external FMU will trick the orchestrator and obey the proposed step sizes, but will avoid executing the internal FMU every time a step is requested. For example, if a zero-order hold adaptation is used, then the external unit will produce an output that is equal to the most recent output produced by the internal unit.
There are many variants of this adaptation, with varying degrees of accuracy, borrowed from well-known approximation techniques. 27
The two adaptations below are novel in FMI-based co-simulation domain, but well known in the discrete event domain.
2.3.10. Data-triggered execution
The data-triggered execution is an adaptation most useful when the modeler knows that a particular internal FMU will only produce relevant behavior when certain conditions are true over its inputs. The adaptation executes the internal FMU only when these conditions are met.
2.3.11. Timed transitions
The time transition adaptation can be used when the internal FMU is known to have internal state changes, triggered after a known amount of time. The adaptation will query the internal FMU to know when exactly the next state transition function call should take place, and will call it only when that time arrives. It can be combined with the data-triggered execution to achieve a lazy execution of units.
Each of the semantic adaptations described above has many variants that make their ad-hoc implementation not only error prone, but also tedious. Additionally, one can extract the shared commonalities in the implementation of all semantic adaptations. The interplay between many small variants and shared commonalities is one of the motivating factors to use a domain-specific language (DSL) for the description of the adaptations.
2.4. Domain-specific languages
DSLs offer a way to deal with the essential complexity of a given domain, while avoiding its accidental complexity. 42
We highlight two important advantages that come from the use of a DSL in the context of our contribution:
The most common tasks in the target domain are performed in a very simple, productive, and intuitive manner (for a trained domain expert)—the descriptions made in our DSL do not deal with the idiosyncrasies of an implementation of the FMI Standard, even though an FMI-compliant external FMU can be generated.
By maximally constraining the user, a DSL ensures that he or she makes fewer mistakes and allows domain-level validation—our DSL allows the user to specify extra information that can be used to detect mistakes (a simple validation being the compatibility of units in inputs/outputs).
3. Running example
To showcase the language, the case study we present is adapted from a power window system, described by Prabhu and Mosterman 43 and Denil. 44 This system is the familiar automated car window, which responds to the driver/passenger pressing up/down buttons to raise/lower it. If an obstruction is detected, the window retracts for a few moments to avoid injury. This example was chosen for its heterogeneity and need for semantic adaptations.
3.1. The example scenario
Figure 3 shows the co-simulation scenario of the power window, consisting of five FMUs, with the illustrated input and output ports. The figure is a block representation of a co-simulation scenario as described in Equation (2). The FMUs were produced by the authors using independent tools.

Power window co-simulation scenario.
The environment FMU, coded manually, is an abstraction of the behavior of the driver and passenger. Whenever the driver/passenger pushes a button up/down, the respective output will pulse to signal the event. When the button is released, the stop output pulses.
The
The
The
An object is detected when the
As illustrated in the figure, all units in this example are reactive, so the
Figure 4 shows the behavior trace of the example produced via a monolithic model produced in OpenModelica.
45
In the figure, the driver continuously pushes the up button, asking the

Power window monolithic simulation results.
3.2. Semantic adaptations
The scenario presented in Figure 3 cannot be used as is to compute a co-simulation such as the one shown in Figure 4 because the FMUs are incompatible.
The adaptations that need to be made were introduced in Section 2, and are detailed in the list below and illustrated in Figure 5. These will be referred to throughout this paper.
execute only if the inputs change (data-triggered execution); execute only when its state transition needs to be called (timed transition adaptation) due to internal triggers. In FMI, this information can be obtained by asking controller to perform a very large step; zero-order hold its outputs.
map the convert output, taking into account the stop signal.
negate the convert the units of height from centimeters to meters.
ignore the algebraic loop between
solve the algebraic loop between
use a multi-rate adaptation, where interpolate the input signal

The modeled adaptations in the power window example.
4. Hierarchical co-simulation for semantic adaptation
The most straightforward way of dealing with semantic adaptations is by creating a master algorithm that implements them. There are multiple problems with this approach: (a) it forces the master algorithm to be specific to the scenario, which hinders the potential for reuse; and (b) it violates the transparency principle by not allowing the FMU (plus adaptations) to be easily imported onto other tools that perform co-simulation, such as Simulink®, INTO-CPS, 46 or DACCOSIM. 47
To avoid these problems, we implement the semantic adaptations as FMUs in a hierarchical way. In fact, our language defines semantic adaptations (plus internal FMUs) as FMUs themselves, allowing for adaptations to be described “on top of” other adaptations. This way, the orchestrator and semantic adaptations can be clearly separated, as well as the semantic adaptations between themselves.
As part of our contribution, we extend the definitions provided in Section 2 to explain what hierarchical co-simulation is, and we give an overview on how the main semantic adaptations are implemented.
4.1. Hierarchical co-simulation
Before giving the formal definition of hierarchical co-simulation, we start with an example of what a “default” hierarchical co-simulation unit is and what it does.
A default hierarchical simulation unit is one that wraps a set of connected internal units, along with their interdependencies, and behaves in a manner that is indistinguishable from any other simulation unit. The internal FMUs have internal inputs/outputs (in between the units) and external inputs/outputs. This is called the default hierarchical unit because it does not adapt the behavior of the internal units. It merely wraps them.
To give details about how the default hierarchical unit is constructed, we extend the definition of the co-simulation scenario to make the distinction between internal and external inputs. Let
Given a co-simulation scenario as defined in Equation (3), and assuming that the topological order
Aggregate the state
Implementing the state transition function as a single co-simulation step of Algorithm 1.
Formally, the unit is defined as in Equation (4):
where:
The construction of the default hierarchical reactive Moore, delayed Mealy, or delayed Moore is done similarly and we omit it. The next subsection presents similar constructions for all kinds of units, incorporating adaptations.
The default hierarchical unit gives the basic transformation that underlies the semantic adaptation of one, or a connected group of, internal FMU(s). In the following subsection we describe the generic mechanism that enables the creation of hierarchical units with semantic adaptations.
4.2. Generic semantic adaptation
Previous work14,15 supports the hypothesis that any semantic adaptation can be described by the following elements that mediate the interactions of the external FMU with the internal units:
external input rules, describing how the inputs provided to the external FMU are stored in the state of the external FMU;
internal input rules, detailing how the values stored internally are mapped into inputs of the internal FMUs;
control rules, determining what happens when the state transition function of the external FMU is invoked;
internal output rules, describing how the outputs of the internal FMUs are stored in the state of the external FMU;
external output rules, detailing how the values stored in the state of the external FMU are mapped to output values of the external FMU.
This subsection formalizes how a generic external FMU incorporating the above rules is constructed.
To formalize the above rules, we define the state of the external FMU. The external FMU is constructed from a given co-simulation scenario, defined in Equation (3), with
Depending on the kind of external FMU being constructed, its initial state is computed by
where
We now introduce the formal representation of the semantic adaptation rules, introduced at the beginning of this subsection:
The application of the external input rules to the provided input is
The application of the internal input rules to create the internal input vector is denoted as
This function is used whenever the input to any of the internal units needs to be computed. It is used in the Ctrl rules (defined next) and in the output function of the external unit. In most adaptations, this function is invoked immediately before a call to the state transition function
The application of the control rules, to compute the new state
This function invokes the MapIn/MapOut functions before/after a state transition of an internal unit is invoked.
The application of the internal output rules
Analogously to MapIn, the invocation of this function is controlled by Ctrl. Parameters h and dt denote the communication step size and time displacement, passed as arguments to the most recently invoked state transition function
The application of the external output rules to compute the external outputs, from the semantic adaptation state
Intuitively, the internal input/output functions serve to decouple the rate of execution of the internal units from the rate of execution of the external FMU.
A semantic adaptation is a concrete definition of:
storage structure—
initialization—
external input rules—In;
internal input rules—MapIn;
control rules—Ctrl;
internal output rules—MapOut;
external output rules—Out;
We now describe how these functions are used in the specification of an external FMU.
The generic external unit is defined exactly as a simulation unit (recall Equation (1)):
where
In Algorithm 6, we stress the following:
The definitions take into account that it may not be possible to sort the internal units topologically, so the semantic adaptations support dependency cycles.
Multiple calls to G can be made without changing the state of the external unit.
If a Moore external FMU has at least one internal unit that depends on external input, then this input must be stored in the input storage
To make these definitions easier to understand, we provide two examples: the default reactive Mealy hierarchical unit presented in the previous subsection, and the algebraic loop semantic adaptation that involves the
The default reactive Mealy hierarchical unit can be informally described as follows:
The state
The Init function is analog to the one described in Algorithm 2.
The In, MapIn, MapOut, and Out are roughly identity functions.
The Ctrl function implements the body of F in Algorithm 4.
Formally, functions Init and Ctrl are defined in Algorithm 7, and:
The second example refers to the adaptation
The external FMU, called
Section 5 describes a DSL for the definition of such semantic adaptations. The examples provided there clarify the need for the semantic adaptation functions defined in the current section.
Ctrl is defined in Algorithm 8.
5. A DSL for semantic adaptation
We introduce a DSL for the specification of the set of rules introduced in Section 4 (which form a semantic adaptation). Since research in semantic adaptation is ongoing, the language should be expressive enough to cover future semantic adaptations. Additionally, the implementation should not violate the modularity and transparency principles.
To these ends, the DSL—named
The language and the examples used in this paper are available for download. c
The remainder of this section is organized as follows. First, the
5.1. The baseSA DSL
Listing 1 shows the

The simple data adaptation
Following that, the internal scenario is declared. The example listing (lines 4–7) declares a single internal FMU and its ports.
Lines 11–15 declare the output rules. These specify how the
Following the exclusion principle, Listing 1 omits several bits of information about the external FMU that are required for a full definition of a semantic adaptation: input ports; Init function; In function; MapIn function; and Ctrl function.
In general, this information is assumed by applying multiple conventions, detailed in Section 5.3. The intended behavior is to follow the default hierarchical unit definition wherever the information is omitted (recall Equation (6) and Algorithm 7). For the example in Listing 1, the following is applicable:
The external FMU (
Each of the input ports of the internal FMU that have no incoming connections gets its value from the corresponding external input port declared by the previous convention. The implementation of bindings is made via a storage variable. In Listing 1, this means that an extra input rule is created to encode the transfer of values. The input storage variables are also created.
Any output variable bindings are realized in a manner similar to the previous convention: add an output rule and declare the necessary output variables to perform the transfer of values.
Any expression referring to the output of any internal FMU, in the Out part of an output rule, is assumed to refer to the storage variable with the most recent value of that output (output variables are created for the outputs of each internal FMU). In Listing 1, this means that
After applying the previous two conventions, the implicit bindings are removed.
Listing 2 shows the same adaptation as Listing 1, after applying the conventions introduced above:
All input ports and output ports of the external FMU are declared, with no implicit bindings defined.
Input storage variables, and their initial values, are declared (
Output storage variables, and their initial values, are declared (
A parameter per storage variable is added to allow the configuration of the initial value of that variable (technical detail: the parameters are mapped to FMI parameters).
Input rules, as the one in lines 31–41, are in general composed of two parts: the InRule part, which in the example assigns values to the input storage variables; and the MapInRule part, which assigns the stored values to the input ports of the internal FMUs in the example. These make up the respective functions In and MapIn.
The control rules make use of the special function
Output rules define the functions MapOut (which stores the outputs of

The adaptation
In any
Listing 3 describes the adaptation defining the external FMU

Adaptation that generates
Notice that the external FMU is declared as reactive Moore, and that the internal FMUs cannot be topologically sorted. Whenever this is the case, when the external output function is called, the values of the output ports returned (in the example, the value of
The control block of Listing 3 implements Algorithm 8 with the following differences.
As part of the semantics of the
The convergence test (line 33) is made only in the
The state manipulation of the internal FMUs is facilitated by the use of the
The

Adaptation that generates
Listing 5 implements adaptation

Adaptation that generates
In general, every reference to an input port of the external FMU, made outside of the In block, is replaced with a reference to the variable that stores the most recently given value of that. For example, the expression
The adaptation in Listing 5 performs two tasks: it keeps track of the previous value of each signal, and invokes the internal unit state transition function (i.e., the
The adaptation

Adaptation that generates
This example shows how the conditions in the output rules can be used to select which rules are applied. Informally, in general, at the end of each external state transition, when MapOut is invoked, all the conditions in the rules are evaluated. The ones that evaluate to true are recorded as part of the
The
The above adaptations generate the FMUs for the co-simulation scenario illustrated in Figure 5. The orchestrator in Algorithm 1 then computes the results shown in Figure 6. Comparing these results with the ones in Figure 4, one sees that they are similar, except for the fact that the armature current has a higher peak in the co-simulation. This is because the threshold crossing adaptation was disabled, since the power FMU does not support rollback.

Power window co-simulation results.
In the following subsections, we describe the language (syntax and semantics) in more detail. The syntax is described using extended Backus–Naur form (EBNF),
48
and the semantics are presented informally by describing a transformation of
5.2. Syntax
The partial syntax of
ID is an identifier;
URL is a URL;
PhysicalUnit denotes any physical unit;
Expression is an expression that defines a value—for example, comparison, addition, constant, variable reference, etc.
Statement is a programming language statement. It includes if-statement, static for loop, local variable declarations, assignments, references to variables/parameters, built-in function calls, etc.

The (partial) EBNF grammar of
Table 1 summarizes the special functions and variables.
List of built-in symbols and their meaning.
The full grammar definition, and an editor of

The
5.3. Semantics
In this subsection, we define the semantics by describing informally how each syntactic construction in
5.3.1 Reduction to explicit form
Let
In order to reduce the given
Listing 2 is the result of applying the above rules to Listing 1.
5.3.2. Mapping to generic semantic adaptation
Given a
the space of
Each of the above elements are now defined.
Part of
Analogously to
The control storage vector
The external input function
is defined to perform the following steps in order:
Evaluate all conditions of the input rules in the order that they are declared, and for each condition, mark the corresponding location of
For the input rules whose conditions evaluated to true in the previous step, execute the InRule part, in the order that the rules are declared (this computes the remainder of
Function
executes the MapInRule part of the input rules whose condition evaluated to true (this information is stored in
Function
is analogous to In. It evaluates all the conditions of the output rules in the order that they are declared, and for each of those conditions, marks the appropriate location of
Function
is analogous to MapIn. It executes the OutRule part of the output rules whose condition evaluated to true (in the order in which they are declared) to compute the output vector
The role of the initialization function (derived automatically from the
First, the parts of
If it exists, the part of
Function
runs the instructions declared in the control rules block in the order that they are declared. The assignments performed to control variables make up part of the output vector
Any variable reference in the control rules block refers to the most recently given value of that variable.
Each instruction
Invoke MapIn function to compute the external input of unit i:
Note that
Merge the input vector
Invoke the state transition function of the unit:
Get the output of the unit:
Invoke the MapOut function to compute an updated output storage vector:
Finally, upon returning, if the external FMU is a reactive unit, and the initial
6. Evaluation
In this section we judge how well our approach answers the research question posed in this work.
The requirements set by the research question are:
6.1. Productivity
In general, DSLs have the potential to boost users’ productivity.42,50 For
6.1.1. Goals
Productivity is measured by comparing the time it takes for a trained user to: (a) create an external FMU using our DSL; and (b) code the same external FMU.
As a surrogate measure, we compare the approximate number of lines of code (LOCs) required for a semantic adaptation coded by hand, with the LOCs of the corresponding semantic adaptation expressed in
6.1.2. Experimental setup
As part of the development of the code generator, all semantic adaptations identified in Figure 5, except
6.1.3. Results
Table 2 shows the adaptation, the approximated LOCs, and the effort in coding the semantic adaptations in C.
Effort in hand-coding hierarchical semantic adaptations.
As Table 2 shows, even though the semantic adaptations differ in complexity, they have a similar number of LOCs. This is evidence that there is a large portion of code dedicated to common FMI-related management tasks. With
Memory management: the inputs, outputs, and local variables of the external FMU are stored in dynamically allocated memory.
Variable dereferencing: to set/get values to/from an internal FMU, a list of value references (integers which identify a variable) has to be provided. Any mistake here may cause the internal FMU to give the wrong results, but not necessarily crash, which makes it hard to debug.
State management: the external FMU has to support rollback, and for that the state variables must be properly serialized and deserialized. In the case study, each semantic adaptation requires approximately 140 LOCs to implement the set/get state.
Consistent inputs management: the external FMU, which is reactive and has internal delayed units, has to keep track of the previous inputs to these.
6.1.4. Threats to validity
LOCs is only a surrogate measure for the productivity of a DSL, albeit a common one,
51
and depends on the programmer. However, the tasks described in the above list are handled automatically by the code generator of
The values provided in Table 2 lack external validation. We intend to perform a second round of experiments in which we will ask a participant to code a semantic adaptation, then train him or her and measure the effort it takes to code the same adaptation in
6.2. Expressivity
The
To provide evidence for this, we describe how the adaptations used in the case study are representative of the semantic adaptations and coupling algorithms surveyed by Gomes et al. 17
We do restrict the expressiveness of the language, with the intent of guaranteeing that it terminates:
No function definitions are allowed.
No recursive definitions of semantic adaptations are allowed.
These restrictions make expressing some of the above techniques more cumbersome, but not impossible.
6.3. Modularity
The simulation unit specification, introduced in Equation (1), was shown to be a valid abstraction of an implementation of an FMU in Section 2. Furthermore, it is clear that changing the implementation of any of the functions
6.4. Transparency
Section 4 describes how a generic semantic adaptation forms a simulation unit that obeys the definition in Equation (1) (see Equation (5)). Furthermore, Section 5.3 describes how
7. Discussion and future work
This section discusses some of the characteristics and limitations of our contribution, and research opportunities for the future.
Automatic semantic adaptation identification. Throughout this work, we assumed that the user knows that an adaptation is required in order to make the co-simulation possible. An interesting research direction is to explore what means can be employed in trying to identify the need for specific semantic adaptations.
Runtime performance. Despite not being our primary goal, the performance of the generated FMU should be similar to a custom-coded one. To this end, the code generator under development performs most tasks at compile time. However, we have not carried out any experiments to measure the performance of the generated code.
A research direction is to explore how to merge multiple adaptations, to avoid generating the intermediate hierarchical FMUs. For example, in Figure 5, adaptations
Solving this problem brings a performance benefit, but also provides new insights into the nature of adaptations. In addition, one can ask: If two semantic adaptations can be combined, are they commutative? This question is important because it allows us to optimize. If there is a semantic adaptation that will cause rollbacks, we want it to be the first to execute, to avoid wasting computation. An example of this is the
Trying to answer the above questions will inevitably lead to another question: What is the right level of abstraction to analyze the combination of semantic adaptations? This question is related to the next discussion topic.
Usability and productivity. As part of trying to find out what is the right level of abstraction to analyze semantic adaptations, we are developing a new language that allows for a more declarative description of semantic adaptations. This language, as opposed to
The descriptions made in this language compile to
The main benefits of using this language are:
The user does not need to know how semantic adaptations are implemented.
It is minimal, meaning that it enables the user to specify common semantic adaptations (e.g., multi-rate, successive substitution) as concisely as describing them in natural language.
It further restricts the user into using well-known semantic adaptations, which prevents mistakes.
It may provide insight into the research questions identified in the previous subsection.
Listing 8 shows an example of what such a DSL looks like. The syntax reuses part of the syntax of

Example description in higher-level semantic adaptation domain-specific language.
Each adaptation has some degree of configuration. For example, the multi-rate is configurable with an input approximation adaptation. This highlights another interesting research direction, related to the combination of semantic adaptations: How and when can semantic adaptations interface with each other? In this example, it is clear that any input approximation adaptations can complement a multi-rate adaptation, but what are the essential characteristics of input approximation and multi-rate adaptations that make them so compatible? The same question applies to output approximation adaptations (the family of hold adaptations) and the lazy-related ones. A possible direction to explore is to look at the object-oriented world, and study how can semantic adaptations define interfaces and specialization, so that their interaction is well defined.
Discrete event FMU implementation. The current version of the FMI Standard (version 2.0) lacks essential features to enable accurate hybrid co-simulation.70–74
Until new extensions are made, there are many different ways in which a cyber system (e.g., a state chart) can be simulated in an FMU.7,73–77 At least one of the implementations the authors used before (the Stategraph 7 ) already includes semantic adaptations to facilitate its integration with the FMI.
Our work shows that, when implementing an FMU that simulates a cyber system, it is best to leave out as many semantic adaptations as possible. The more adaptations an FMU already contains, the harder it is to adapt to other contexts.
8. Related work
Outside the context of FMI, the problem of composing and adapting operational semantics of multiple languages is discussed in numerous papers and references therein.14,78–84
Within the context of FMI, we can divide the related works into two categories: (a) those whose prime purpose is to describe co-simulation scenarios; and (b) those that target the description of orchestration algorithms. Neither of these categories target primarily the description of semantic adaptations, but can potentially be extended to include simple descriptions. Due to our pure hierarchical co-simulation approach, our contribution complements any of these works.
Under Category (a), we highlight the work of Van Acker et al., 16 Larsen et al., 46 Galtier et al., 47 and Campagna et al. 85 These works introduce a language for the description of a co-simulation scenario, with the purpose of running a co-simulation. The work of Larsen et al. 46 and Galtier et al. 47 assumes that a generic orchestration algorithm is used, whereas Van Acker et al. 16 and Campagna et al. 85 aim at generating an orchestrator that is specific to the scenario described. Our DSL allows for the description of a co-simulation scenario, and a specific master algorithm can be generated from that description.
DACCOSIM 47 follows a related approach with respect to hierarchical co-simulation, allowing the scenario to be grouped by computational nodes. In contrast to our work, this hierarchy is computational and not functional. Moreover, it is not transparent, as the distinction is made between local (internal to computational nodes) and global orchestrators. Nevertheless, each FMU is wrapped with code that performs error control, highlighting the need for semantic adaptation.
In Category (2), we highlight Campagna et al., 85 Gheorghe, 22 and Aslan et al. 86 The work by Campagna et al. 85 allows the description of master algorithms using the business process modeling notation. We argue that the visual notation for the description of an orchestration algorithm works well for simple cases, with two units. However, when multiple semantic adaptations become necessary, or the number of simulation units increases, the visual notation rapidly becomes cluttered. The work does not describe any intention to use the notation to describe semantic adaptations, but the notation has an extension mechanism that can in principle be used to describe simple semantic adaptations.
The most related to our own is the work of Aslan et al. 86 This introduces an object-oriented framework for co-simulation that allows for both the development of FMUs and for orchestration algorithms, in C++. Class specialization is used extensively to maximize reuse, sharing some of the benefits with our contribution. The main difference to our work is the level of abstraction and the intention to use semantic adaptations. While their work is capable of expressing semantic adaptations, our work is targeted toward that purpose. One can position their work as helping develop FMUs for simulators that need to support the FMI Standard, and our work can be used to adapt already-existing FMUs. Furthermore, the description of a complex adaptation such as rate_sa is more compact in our DSL.
9. Conclusion
This paper addressed the problem of describing the most common semantic adaptations on multiple types of black box simulation units in a productive manner while avoiding the modification of the units (modularity) and tools for co-simulation (transparency).
To make this possible, we propose a DSL, available for download, c that is both expressive (due to its imperative nature) but also productive (due to its conventions and high-level constructs). Each description refers to a group of interconnected FMUs and dictates how those FMUs interact with the environment.
The essential mechanism that enables the semantic adaptations is the concept of hierarchical co-simulation, formalized in this work. The meaning of each adaptation is given by mapping it onto hierarchical co-simulation units, which in turn are mapped to units and FMUs, as illustrated in Figure 1.
The main distinguishing factor from the related work is our focus on semantic adaptations for FMI-based co-simulation, which imposes the modularity and transparency requirements.
This work opens up new opportunities for research into semantic adaptations—for example, how to find higher levels of abstraction to describe semantic adaptations, and explore how different semantic adaptations can interface and complement each other. We intend to explore these in the future.
Footnotes
Acknowledgements
We are grateful to Prof. Peter Gorm Larsen (Aarhus University) for the in-depth discussions regarding the potential applications of our work. Furthermore, we are in debt to the reviewers for the in-depth improvements made to this manuscript.
Funding
This research was partially supported by Flanders Make vzw, the strategic research center for the manufacturing industry, a PhD fellowship grant from the Agency for Innovation by Science and Technology in Flanders (IWT, dossier number 151067), and by the INTO-CPS project, funded by the European Commission’s Horizon 2020 program (grant number 664047).
