# Optimal Sizing of Battery Energy Storage System for Implicit Flexibility in Multi-Energy Microgrids
## 2 Methodology  
In this study, we develop an energy management system (EMS) for the optimal daily scheduling of a multi-energy system (MES), named HOMES. HOMES adopts a block-based modeling approach, implemented using the Pyomo library [32]. This modeling framework enables the construction of hierarchical models, where components at the base level can be defined individually and independently in terms of sets, parameters, variables, and constraints, reflecting their physical characteristics. At a higher level, these components can be interconnected according to the physical and operational logic of the system under analysis. Figure 1 provides a graphical representation of how the block-based modeling approach can be applied to an MES encompassing multiple energy vectors, such as electricity, heat, cooling, and natural gas. On the right-hand side of the figure, we illustrate the base level of the hierarchical model, which includes a block for each type of component that could be present in a generic MES:  
* Loads: _EL_LOAD_ (non-dispatchable electrical load), _EV_ (electric vehicle charging demand), _TH_LOAD_ (non-dispatchable thermal load), and _COOL_LOAD_ (non-dispatchable cooling load). * Generation units: _PV_ (photovoltaic power plant), _WIND_ (wind turbine), _BOILER_ (industrial boiler), _CHP_ (combined heat and power; e.g., cogenerating internal combustion engine), _GENSET_ (fossil-fuel-based electric generator), _CCHP_ (combined cooling, heat, and power unit; e.g., cogenerating internal combustion engine combined with an absorption chiller), and _HP_ (heat pump). * Storage units: _BESS_ (electrochemical battery storage) and _TES_ (thermal energy storage). * Interface units with external networks: _POD_ (point of delivery), which represents the connection with the electricity grid and enables the modeling of electricity market interactions, and _PDR_ (\"Punto Di Riconsega\") which represents the connection with the natural gas grid, similarly supporting market modeling for gas exchanges. Each of these blocks can be defined independently using a dedicated collection of sets, parameters, variables, and constraints. The operational logic of each component is fully modular and does not depend on the definition of other components. On the left-hand side of Figure 1, we illustrate a set of higher-level blocks that define the specific configuration of the MES under consideration. These blocks establish the interconnections between the base-level components for each energy vector:  
* _EL_Circuit_ models the electricity balances, at a physical and commercial level. * _TH_Circuit_ models the thermal energy balances. * _COOL_Circuit_ models the cooling energy flows. * _NG_Circuit_ models the natural gas flows. The key variables from both the device blocks and the circuit blocks are incorporated into an objective function, which is formulated to either minimize (e.g., operational costs, CO\({}_{2}\), or pollutant emissions) or maximize (e.g., self-consumption, revenues, comfort) a given performance metric depending on the specific optimization goals of the EMS. The adoption of this block-based modeling approach is motivated by its high degree of flexibility, which allows the physical behavior of each component to be described generically and then integrated into a wide range of MES configurations. This enables the evaluation of the operational and economic impacts of adding or removing a component with minimal effort. For instance, it becomes straightforward to assess how the system's performance and costs would change if a new technology were introduced or an existing one removed. In the following sections, we provide a detailed description of HOMES, presenting the main equations used to model each component and circuit of the block-based framework developed for our case study, which will be introduced in Section 3. Figure 1: Block-based modeling framework for a generic multi-energy system.