## 2 Materials and Methods
### Generalised Dynamic System Model  
For the configurable and modular model composition, a generalised microgrid model was developed. The microgrid can consist of photovoltaic power plants (PV), electric vehicles (EV), battery electric storage systems (BESS), a single immutable load representing the total aggregated power demand of a generic production facility (LOAD), and the utility grid connection (GRID). The device types PV, BESS, and EV are not limited to single devices, as usually more than one of these can be found in SMEs and commercial microgrids. These devices are organised in sets \(A\), \(B\), and \(\Gamma\). The utility grid connection is modelled as single instance, as multiple-grid connections are uncommon. The aggregated power demand of the production facility is also modelled as a single instance, as considering the power demand of all electrical loads separately brings no benefit in this modelling approach. The typical system architecture, in which all devices are connected to a common bus, is depicted in Figure 1.  
The utility grid can be used as an energy source with the supply power \(P_{\beta\text{s}}\) or as an energy sink for surplus renewable generation with the feed-in power \(P_{\beta\text{,d}}\). The aggregated power demand of the production facility is modelled as load power \(P_{\text{I}}\). Each PV power plant \(\alpha\in A\) feeds into the common bus (main node) with a power \(P_{\alpha}\), resulting in the summarised PV power  
\[P_{A}=\sum_{\alpha\in A}P_{\alpha}. \tag{1}\]  
Each BESS \(\beta\in B\) has a charging power \(P_{\beta\text{,ch}}\) and a discharging power \(P_{\beta\text{,dc}}\), resulting in summarised charging and discharging powers  
\[P_{\beta\text{,ch}}=\sum_{\beta\in B}P_{\beta\text{,ch}}\quad\text{and}\quad P _{\beta\text{,dc}}=\sum_{\beta\in B}P_{\beta\text{,dc}}. \tag{2}\]  
The energy content of each BESS is \(E_{\beta}\), and the summarised energy content of all BESSs is  
\[E_{\text{B}}=\sum_{\beta\in B}E_{\beta}. \tag{3}\]  
Each EV \(\gamma\in\Gamma\) has a charging power \(P_{\gamma\text{,ch}}\) and a discharging power \(P_{\gamma\text{,dc}}\) with summarised powers  
\[P_{\Gamma\text{,ch}}=\sum_{\gamma\in\Gamma}P_{\gamma\text{,ch}}\quad\text{and} \quad P_{\Gamma\text{,dc}}=\sum_{\gamma\in\Gamma}P_{\gamma\text{,dc}}. \tag{4}\]  
Each EV is discharged by driving during its absence with \(P_{\gamma\text{,a}}\). The summarised EV energy content is  
\[E_{\Gamma}=\sum_{\gamma\in\Gamma}E_{\gamma}. \tag{5}\]  
Figure 1: Block diagram of the controller system model containing multiple devices. The device types PV, EV, and BESS are modelled individually and occur in sets \(A\), \(B\), and \(\Gamma\). The grid connection (GRID) and the aggregated power demand (LOAD) are each modelled as a single instance. The equality constraints of the MPC controller model, given in explicit discrete state space representation, are  
\[P_{A}^{k}+P_{B,\text{dc}}^{k}+P_{\Gamma,\text{dc}}^{k}+P_{S,s}^{k} =P_{1}^{k}+P_{B,\text{ch}}^{k},+P_{\Gamma,\text{ch}}^{k}+P_{\text{ g},t}^{k} \forall\;k\in N, \tag{6}\] \[E_{\beta}^{k+1}-E_{\beta}^{k} =\Delta t(\eta_{\beta,\text{ch}}\times P_{\beta,\text{ch}}^{k}-1/ \eta_{\beta,\text{dc}}\times P_{\beta,\text{dc}}^{k}) \forall\;k\in N,\;\beta\in B,\] (7) \[E_{\gamma}^{k+1}-E_{\gamma}^{k} =\Delta t(\eta_{\gamma,\text{ch}}\times P_{\gamma,\text{ch}}^{k}- 1/\eta_{\gamma,\text{dc}}\times P_{\gamma,\text{dc}}^{k}-P_{\gamma,\text{a}}^{ k}) \forall\;k\in N,\;\gamma\in\Gamma,\] (8) \[P_{A}=\sum_{\alpha\in A}P_{\alpha}. \tag{1}\]0 (9) \[P_{A}=\sum_{\alpha\in A}P_{\alpha}. \tag{1}\]1  
where  
\[P_{A}=\sum_{\alpha\in A}P_{\alpha}. \tag{1}\]2  
denotes the active power of component \(i\in I=\{A,B,\Gamma,l,g\}\) at timestep \(k\), and  
\[P_{A}=\sum_{\alpha\in A}P_{\alpha}. \tag{1}\]3  
are the energy contents of the component i at timestep k. The time interval \(\Delta t\) is the time difference between discretisation steps (sampling interval).