*4.1. SystemC-AMS*

SystemC-AMS is the extension of SystemC for modeling analog and mixed-signal systems [42]. SystemC-AMS provides three different models of computation (MoC) to cover various domains as indicated in Figure 3.


**Figure 3.** Abstraction levels supported by SystemC-AMS.

*Timed data-flow* (TDF) models are scheduled statically by considering their producer-consumer dependencies in the discrete time domain. Each TDF module is characterized by a simulation time step, which is used by the TDF solver to insert timed activation events in the standard SystemC event queue. This ensures efficient computation, as it avoids any runtime dynamic event management. Continuous time models can be modeled with two abstraction levels. *Linear signal flow* (LSF) supports the modeling of continuous time through a library of pre-defined non-conservative primitive modules [43] (e.g. in Figure 3 derivative and integrative, respectively). The *electrical linear network* (ELN) MoC models the electrical network by connecting the instantiation of predefined primitives (e.g., in Figure 3, capacitor and voltage source, respectively). All such abstraction levels are handled by the same simulation kernel that derives the system of equations to be solved over time and estimates system evolution.

#### *4.2. SystemC-AMS Implementation of the Proposed Solution*

SystemC-AMS is selected as the reference language for heterogeneous modeling for several reasons. The provided multiple abstraction levels unify the modeling work in a wide range of domains by using a single language: models can be built by choosing the most suitable abstraction level, and native converters can be exploited to simulate different abstraction levels simultaneously. SystemC-AMS also has the characteristics of a modular one, in that it divides the definition of interface and implementation, and is a IEEE standard language; thus, it can be easily extended and free from compatibility and reuse issues.

The flexibility of SystemC-AMS allows one to easily integrate the power models and the cost models. Figure 4 shows an example of a component implementation of a battery that is used in the remainder of this section as a reference. Each EES component is instantiated as a SystemC-AMS module (SC\_MODULE, Figure 4, left) that internally instantiates one SystemC-AMS module for the power model and one for the cost model (line 5). This solution avoids forcing the fact that both models follow the same abstraction level and leaves maximum flexibility in the choice of the implementation style. The interface of the top level module includes the layer-specific signals of power (line 2) and cost (line 3) that will be bound to the corresponding ports of the layer-specific buses.

**Figure 4.** Example of SystemC-AMS of a battery: top level module (**left**), power model, implementing a circuit model in ELN (**center**), and a cost model (**right**).

The interface of the power and cost modules includes the layer-specific signals (e.g., in case of the cost layer, one port per cost computed by the component, line 45) and the inter-layer signals, used to communicate with the other layer (line 22 for the signals propagated from the power module to the cost module). This naturally enables inter-layer communication: thanks to the encapsulation of both power and cost models in a single top level SystemC module, inter-layer communication signals are set as TDF signals, binding the property-specific ports of the modules (lines 4 and 14–16).

The implementation of power models in SystemC-AMS has been discussed in many works at the state of the art that proved that SystemC-AMS can find a good trade off between accuracy and simulation time [36,44,45]. The presence of multiple abstraction levels allows one indeed to adopt for each power model the most suitable solution; e.g., ELN for circuit or circuit-equivalent models, TDF for equations, and LSF for dynamic models. In the case of Figure 4, the power model adopted for the battery is the circuit model proposed in [38] that is implemented as a network of connected ELN primitives (e.g., *Ib* is a current source, lines 23 and 30–32; *Cnom* is a capacitor, lines 25 and 34–35).

Modeling the cost equations detailed in Section 3 is straightforward, as they can be easily mapped on C++ functions and primitives, encapsulated by the TDF semantics of SystemC-AMS. The right-hand side of Figure 4 shows a snapshot of code: the processing function of TDF repeatedly evaluates the cost models of the battery over time, in terms of capital cost (line 50), real-time capital cost (line 51), and operation and maintenance cost (line 52).

Note that the separation of the power model and the cost model in two different SystemC-AMS modules allows one to decouple their activation frequency. Power models require a fine grain activation time step (in the order of 1s down to 1ms) to accurately evaluate the internal dynamics of the component. Vice versa, the cost models allow a larger time step, so as to reduce the computation overhead. As a result, the activation time step of the two modules is different (lines 41 and 56, respectively), and the inter-layer signals are handled with a conversion between different time scales.
