scieee AI-readable full text Open interactive document viewer

Modelica-based model predictive control for a CO2 heat pumpsystem: Case study in Oslo

Song, Ge; Filonenko, Konstantin; Wen, Xiaoqiao; Ebrahimy, Razgar; Nord, Natasa

Abstract

The proliferation of renewable energy technologies challenges the stability of the energy supply, requiring more flexibility from the energy demand. Consequently, methods for controlling heat pumps have received increasing attention. This study presents a Modelica-based Model Predictive Control (MPC) approach designed to maintain the supply water temperature within the 55 ◦C–75 ◦C range, while minimizing energy use and electricity costs over a one-year period. A detailed and high-fidelity model of a school building in Oslo, Norway, was developed in Modelica and exported as a Functional Mock-up Unit (FMU) to enable seamless integration with MATLAB/ Simulink for the real time simulation and control implementation. The results demonstrated that the MPC strategy achieved annual electricity savings of 8.0 MWh (3.2 %) and 11,479 NOK (6.7 %) compared to a Proportional-Integral (PI) controller, and 85.07 MWh (25.9 %) and 46,967 NOK (22.8 %) compared to a fixed rule-based baseline controller. These savings were primarily attributed to the ability of MPC to anticipate and respond to future electricity price variations. The findings underscored the effectiveness of MPC as a robust and energy-efficient solution for thermal energy management systems.

Full text

Modelica-based model predictive control for a CO 2 heat pump system: Case study in Oslo ☆ Ge Song a,* , Konstantin Filonenko b , Xiaoqiao Wen c , Razgar Ebrahimy b , Natasa Nord a a Energy and Process Technology, Norwegian University of Science and Technology, Kolbjørn Hejes vei 1 B, Trondheim, 7491, Norway b Department of Applied Mathematics and Computer Science, Technical University of Denmark, 2800 Kongens Lyngby, Denmark c School of Energy, Power and Mechanical Engineering, North China Electric Power University, Beijing, 102206, China ARTICLE INFO Keywords: Heat pump system Thermal tank Model predictive control Modelica Functional mock-up interface Building flexibility ABSTRACT The proliferation of renewable energy technologies challenges the stability of the energy supply, requiring more flexibility from the energy demand. Consequently, methods for controlling heat pumps have received increasing attention. This study presents a Modelica-based Model Predictive Control (MPC) approach designed to maintain the supply water temperature within the 55 ◦C–75 ◦C range, while minimizing energy use and electricity costs over a one-year period. A detailed and high-fidelity model of a school building in Oslo, Norway, was developed in Modelica and exported as a Functional Mock-up Unit (FMU) to enable seamless integration with MATLAB/ Simulink for the real time simulation and control implementation. The results demonstrated that the MPC strategy achieved annual electricity savings of 8.0 MWh (3.2 %) and 11,479 NOK (6.7 %) compared to a Proportional-Integral (PI) controller, and 85.07 MWh (25.9 %) and 46,967 NOK (22.8 %) compared to a fixed rule-based baseline controller. These savings were primarily attributed to the ability of MPC to anticipate and respond to future electricity price variations. The findings underscored the effectiveness of MPC as a robust and energy-efficient solution for thermal energy management systems. 1. Introduction The transition towards sustainable energy solutions has brought forth the need for innovative approaches in heating systems, particularly in buildings. This paper focused on enhancing the flexibility of a CO 2 heat pump system in school buildings, with a particular emphasis on economic benefits and overcoming existing barriers by analyzing the economic viability of electricity pricebased control strategies for the CO 2 heat pumps in Oslo, Norway. 1.1. Motivation Use of renewable energies has seen significant growth over the past decade. According to reports, 2023 experienced the fastest rate of renewable capacity additions in two decades, with an increase of nearly 50 %, reaching close to 510 GW [1]. By 2028, it is estimated ☆ The currency rate between NOK and EUR can be found from https://www.xe.com/, in this study 1 EUR =10 NOK. * Corresponding author. E-mail address: [email protected] (G. Song). Contents lists available at ScienceDirect Journal of Building Engineering journal homepage: www.elsevier.com/locate/jobe https://doi.org/10.1016/j.jobe.2025.114501 Received 12 July 2025; Received in revised form 10 October 2025; Accepted 27 October 2025 Journal of Building Engineering 115 (2025) 114501 Available online 29 October 2025 2352-7102/© 2025 The Author(s). Published by Elsevier Ltd. This is an open access article under the CC BY license ( http://creativecommons.org/licenses/by/4.0/ ). that renewable energy sources will account for 42 % of global electricity generation, with wind and solar PV contributing 25 % of that total [1]. In Norway, which boasts one of the highest shares of electricity production from renewable sources, approximately 136.49 TWh of electricity is generated from hydropower in a typical year, representing about 88 % of the country total power generation. Additionally, wind and solar power generated 15,051 GWh, making up about 10 % of the Norwegian electricity generation, with a total capacity of 5372 MW at the start of 2023 [2]. The integration of a high share of renewable energy sources can result in unstable electricity generation, as wind and solar generation are highly dependent on weather conditions. To address this issue, flexible energy systems are frequently suggested as a solution [3]. Flexibility may have various definitions and exhibits different impacts depending on the context, and thus it is quantified in several ways. For instance, system flexibility can refer to the ability to shift energy use from high-price to low-price periods [4]. Additionally, a flexible system can help mitigate both peak grid loads and peak electricity demands [5]. Further, flexibility means the ability to adjust its operation strategies to meet a given objective [6]. In a general way, a system with flexibility allows significant load control [7]. As an efficient electro-thermal device, utilizing heat pump in energy system is a promising way to increase system flexibility [8]. The dynamic operation of heat pumps enables thermal management and offers a degree of flexibility [9]. Heat pump systems allow the decoupling of energy supply from energy demand, as they can be paired with thermal energy storage [10]. Several studies have investigated the role of heat pumps in energy systems, particularly in heating systems. For instance, heating systems with heat pumps and thermal storage have been shown to achieve greater profitability in the German intraday market [11]. Additionally, households utilizing heat pumps can reduce costs by taking advantage of local energy markets through the inherent flexibility of heat pump systems [12]. However, incorporating larger storage into the system may result in delayed response times when adjusting the heating system, which challenges the ability to fully exploit the flexibility of heat pumps at the control level. To address this, MPC has been widely recognized as an effective solution [13]. Both short-term and long-term experiments have been conducted to compare the impact of MPC on heat pump and storage systems against standard heat pump controllers [14,15]. The findings indicate that MPC improves the coefficient of performance (COP) of the heat pump and reduces overall costs in both scenarios. Additionally, MPC has shown significant potential in domestic hot water (DHW) systems, where energy use decreases, and COP increases, while maintaining user comfort, regardless of prediction accuracy [16]. These studies highlight that MPC can effectively shift loads, reduce costs, and enhance efficiency in systems with heat pumps and energy storage. 1.2. State-of-the-art Flexibility is crucial for the effective operation of energy systems, particularly when faced with challenges such as fluctuating weather conditions and electricity prices. Several studies have focused on how to evaluate and achieve flexibility in energy systems, revealing that heat pumps and energy storage often play a central role in enhancing the system flexibility. Walden et al. explored the flexibility of heat pumps, finding that the economic benefits increase as the operational load range of the heat pump expands [17]. However, they also identified a flexibility threshold, beyond which additional load flexibility provides diminishing returns. In one case study, a heat pump with a minimum load of 55 % exhibited a 19.3 % increase in net value compared to a heat pump without flexibility. Additionally, flexibility in energy systems can be analyzed in terms of time, power, and energy, rather than relying on a single indicator. The flexibility of a domestic energy system using a heat pump and thermal storage was analyzed under different energy supply scenarios in Ref. [18]. The system was simulated in three cases with varying wind energy shares of 7 %, 25 %, and 60 %, along with real-time electricity prices. The operation cost was optimized by adjusting the heat pump power and storage capacity, and the flexibility potential was quantified. The results indicated that 33 %–100 % of electric loads could be shifted to different times, with both flexibility potential and operational costs being highly sensitive to system design [18]. A thermal energy supply system incorporating a high-temperature heat pump and thermal energy storage was developed to respond to the variability in renewable energy generation and electricity prices in Ref. [19]. The system demonstrated flexible heat pump operation, using thermal storage to buffer the fluctuations in renewable energy and electricity costs. After the optimization to minimize the operational costs or emissions, the system achieved a 6 % cost reduction compared to a rule-based control strategy. Li et al. focused on optimizing the size and operation of an energy system comprising a heat pump, thermal energy storage, and photovoltaic (PV) panels to achieve energy and cost savings in Ref. [20]. Their findings showed that self-consumption and annual costs were reduced by 2.39 % and 6.61 %, respectively. Similarly, Gaucher-Loksts et al. compared three configurations based on Building Integrated Photovoltaic and an air source heat pump for powering a household, aiming to maximize energy savings in Ref. [21]. MPC has emerged as a powerful method for managing the complexity of building energy systems, which must handle thermal inertia and rapid environmental fluctuations. Its ability to forecast and optimize system behavior makes it well-suited for improving both energy efficiency and operational flexibility. Several studies have demonstrated the advantages of MPC over the rule-based or traditional control. For instance, MPC for a seasonal storage reduced annual heat losses to just 4 %, while supplying 80 % of heating demand in a district heating network [22]. Implementation of MPC in a multi-heat pump HVAC system achieved up to 37.3 % energy savings and significantly reduced occupant discomfort [23]. MPC has also proven superior in reducing peak loads and improving control stability when compared with feedback and fuzzy control methods [24]. Advanced frameworks, such as those in Refs. [25–27], further demonstrate MPC potential by integrating economic optimization, adaptive scheduling, and robust forecasting to enhance energy system performance. Collectively, these studies confirm that MPC is a key enabler for smarter and efficient energy management. Although numerous studies have explored the application of MPC in building energy systems, its practical implementation — G. Song et al. Journal of Building Engineering 115 (2025) 114501 2 particularly with real-time interaction — remains in the early stages. One of the most significant challenges is developing user-friendly, control-oriented, accurate, and computationally efficient building model [28]. To address this, open-source Modelica libraries such as Buildings [29] and IDEAS [30] offer valuable templates for model development. Some previous studies have used Modelica for real-time or control-oriented purposes [31,32], while others have applied MPC within real-time environments [33,34]. However, these works typically rely on simplified models and lack the integration of physically detailed, high-fidelity systems. For instance, MPC with Modelica was implemented in Ref. [35], but it was limited to basic thermal models, excluding hydraulics and thermodynamic cycles. In contrast, the current study represents a significant advancement by integrating MPC with a high-fidelity Modelica model that runs in real-time. This includes comprehensive modeling of hydraulic networks and thermodynamic behavior, enabling more realistic system responses and control decisions. The resulting framework bridges the gap between simulation and control, offering a novel and practical approach to real-time building energy optimization. 1.3. Research contributions Integrating MPC with high-fidelity Modelica-based system models in real-time applications presents significant challenges, particularly in complex heating systems. Previous research has explored the use of Modelica for real-time simulation and controloriented modeling, as well as the implementation of MPC within real-time simulation environments. However, the coupling of detailed, high-fidelity thermodynamic model with MPC frameworks remains limited. For instance, existing studies often apply MPC to simplified thermal models without incorporating intricate hydraulic or thermodynamic processes. This gap suggests that the seamless integration of detailed, high-fidelity system models with MPC remains relatively underexplored. In response to this gap, recent studies have started to employ Functional Mock-up Unit (FMU)s as an interface for co-simulation between high-fidelity Modelica models and external MPC frameworks. For example, Erfani et al. developed an FMU-based co-simulation where a residential building model was coupled with MATLAB/Simulink MPC [36]. While these contributions illustrate the potential of FMU-based MPC integration, applications have largely focused on residential comfort-driven scenarios. By contrast, the present study extends this line of work by targeting system-level actuation and incorporating detailed thermodynamic processes in a CO 2 heat pump with thermal storage. In this study, the use of the FMU technology enabling seamless interaction between a comprehensive Modelica-based system model and MATLAB/Simulink allowed this real-time data exchange and dynamic control updates. To the best of current knowledge, few studies have reported comparable implementations for complex heating systems, highlighting the novelty and practical relevance of the proposed framework. Specifically, the aim of this work was to optimize the operation of a school building energy system in Oslo, Norway, comprising a CO 2 heat pump and a thermal storage tank, thereby bridging the gap between theoretical control strategies and practical system deployment. The paper is organized as follows. Section 2details the methodology, including model development and control implementation. Section 3presents the case study setup and simulation results. Section 4discusses the findings and their implications. Section 5 concludes the study with key insights and recommendations for the future work. 2. Methodology The study is based on the Norwegian demo case at Voldsløkka School and Cultural area, located in the mid/northern part of Oslo, shown in Fig. 1. This demo includes a newly constructed secondary school building (S-building) and the retrofitting of an existing cement factory (the Heidenreich building, H-building) to accommodate 810 pupils. The S-building and H-building are connected via a bridge on the second floor. The demo also features a cultural center, a cultural hall, and a sports hall. The school and cultural activities cover an area of 11,100 m 2 in the new construction and 2900 m 2 in the H-building. The school utilizes an innovative heating system that combines geothermal energy and a CO 2 heat pump to supply space heating. The CO 2 heat pump was designed to cover approximately 80–90 % of the space heating demand of the S-building, with district heating serving for peak loads, warming up Fig. 1. Voldsløkka school. G. Song et al. Journal of Building Engineering 115 (2025) 114501 3 domestic hot water, and as a backup. The CO 2 heat pump extracts heat from the boreholes and upgrades it for use in the building from two gas coolers, high temperature gas cooler and low temperature gas cooler. A 400L water tank serves as a buffer to store heat produced by the high temperature gas cooler. The system delivers hot water at three distinct temperature levels: 55 ◦C supply and 45 ◦C return for the radiator heating, 35 ◦C supply and 30 ◦C return for the floor heating (both from the high temperature gas cooler), and 28 ◦C supply and 24.1 ◦C return in summer, 14 ◦C supply and 18.8 ◦C return in winter for ventilation heating and cooling (from the low temperature gas cooler). Domestic hot water is delivered on demand via a separate line connected to the water storage tank. Valves and sensors are integrated throughout the system to enable desired temperature control. The schematic of the heating and cooling configuration is illustrated in Fig. 2. In this study, the supply temperature of the high temperature gas cooler of the heat pump and the tank temperature were selected as control variables in the MPC design. The methodology of this study involved the integration of an MPC system with a Dymola-based simulation environment to optimize the operation of the CO 2 heat pump system in the observed building. As shown in Fig. 3, the MPC controller consists of a grey-box heat pump model and an optimization algorithm. The electricity price forecast was used as an economic signal for the objective function, while the tank temperature was introduced as a system constraint. These inputs were processed by the grey-box model and the optimization algorithm to compute the optimal compressor power. This control signal was then sent to a white-box heat pump model in the Dymola environment, which simulated the detailed thermodynamic behavior of the system. The white-box model interacted with a building model to reflect the overall thermal response of the building. In the co-simulation setup, the MPC (implemented in MATLAB/ Simulink) exchanges inputs and outputs with the Modelica-based plant through the FMU interface at each control step, enabling realtime optimization under realistic system dynamics driven by varying electricity prices and thermal constraints. It is important to note that the RC building model representation was applied only within the model developed in Modelica. The predictive grey-box model used for MPC focuses on the CO 2 heat pump and water storage subsystem. This model was formulated at the system level, describing the energy balance and temperature evolution of the tank and the heat pump operation, while the building’s thermal dynamics were captured through the FMU interface. 2.1. Detailed simulation model The thermal energy system for the Voldsløkka School and Cultural area was designed with the ground source CO 2 heat pump as the Fig. 2. Diagram of the components that were assessed in this study. G. Song et al. Journal of Building Engineering 115 (2025) 114501 4 core of the heating and cooling system. Boreholes serve as the primary source of energy, providing free cooling and storing excess heat, while district heating is used to cover peak heating loads when required. Fig. 4 a illustrates the detailed Modelica model of the school heating system, capturing each subsystem and their interconnections. The system includes the five main components. 1. District Heating Model: This supplies supplemental heat during heat peak demand periods. 2. Building Model: Represents the thermal characteristics of the building and the heating and cooling demands. 3. Thermal Tank Model: Used for thermal energy storage, allowing the system to balance heating loads efficiently. 4. CO 2 Heat Pump Model: The core of the system that meets both heating and cooling demands by extracting energy from the boreholes. 5. Borehole Model: A model of the ground wells used to extract heat for the heat pump and store excess heat. The detailed Modelica model of the observed system is shown in Fig. 4 a, where district heating and boreholes are connected to the CO 2 heat pump and thermal tank, which then distribute the heating and cooling throughout the building. The interaction between components follows the system layout, with heat and cooling being transferred based on real-time demand and energy availability. Fig. 4 b shows the simplified system model, highlighting only the key components that were used in the MPC framework. These included the thermal tank, the CO 2 heat pump, and the building. The boreholes and district heating were not included in the simplified version used for control purposes, streamlining the system for MPC optimization. This simplified structure allowed efficient control of the heat pump without overcomplicating the MPC algorithm, focusing on the most critical elements of the system using electricity. Since the electricity price was used as the objective function for the optimization, only this core elements contributing to thus were used for the MPC development. The CO 2 heat pump system features a single evaporator and two gas coolers, each supplying different temperature levels for heating and cooling. The evaporator operates with inlet temperatures of 3 ◦C in winter and 17 ◦C in summer, and outlet temperatures of 0 ◦C Fig. 3. MPC applied to heat pump control in buildings. Fig. 4. Modelica Simulation and Simplified MPC Structure of the CO 2 Heat Pump System. a. Detailed Modelica simulation of the thermal energy system. b. Simplified structure used for MPC. G. Song et al. Journal of Building Engineering 115 (2025) 114501 5 and 12 ◦C, respectively. The high-temperature gas cooler supplies water at 55 ◦C and returns it at 30 ◦C, connected to radiators and the floor heating system, ensuring efficient heat distribution for space heating. The low-temperature gas cooler supplies water at 28 ◦C and returns it at 23 ◦C, integrated into the ventilation system for lower temperature heating and cooling needs. The Modelica IDEAS library was utilized to simulate the system. The main component of the heat pump was modeled using the IDEAS.Fluid.HeatPumps.Carnot_y module from the IDEAS library. To model the two gas coolers as shown in Fig. 2, two heat exchanger components from the standard Modelica library were connected to the heat pump model to simulate the high temperature gas cooler and the low temperature gas cooler. By integrating these components, the model effectively captures the performance and efficiency of the CO 2 heat pump system under various operational conditions. The parameters of the heat pump model are shown in Table 1. After constructing the model, the validation was carried out by inputting the actual measured inlet temperatures of the evaporator and the two gas coolers over a period of seven days. The comparison between the actual measured outlet temperature of the hightemperature gas cooler and the simulated value is shown in Fig. 5 The blue line represents the Modelica simulation results and the orange line represents the actual measured values. The close agreement between these results demonstrated the accuracy of the model, thereby completing the model validation. The validation was quantified according to ASHRAE Guideline 14–2014, with the coefficient of variation of the root mean square error (CV-RMSE) of 3.3 %, normalized mean bias error (NMBE) of 0.009 %, and an R 2 value of 96 %. All the model calibration paramters were within the recommended range and thereby the CO 2 heat pump model was estimated reliable for further use [37]. The building model was developed using the five key modules: the building envelope, internal heat gain, space heating system, ventilation system, and weather conditions. The building envelope module was developed using the TwoElements component from the IDEAS library [38], utilizing an RC thermal network to simulate heat transfer processes. The detailed parameters of the ThermalZoneTwoElements component are provided in Table A1 in Appendix. A constant internal heat gain of 130 kW (11.8 W/m 2 for the 11, 000 m 2 floor area) was applied based on the national standard for energy demand calculation in buildings, Ns3031 [39]to represent the heat generated by equipment, lighting, and building occupants. The internal gain item in the model was calculated by summing all the three internal gains and considering the coincidence of these loads. To enhance computational efficiency for MPC purposes, the model focused solely on the high-temperature gas cooler from the CO 2 heat pump, which was responsible for space heating. The ventilation system was modeled as a mechanical air supply delivering 25 kg/s to maintain basic indoor air quality requirements, and domestic hot water was excluded as it was supplied by the district heating system. The building model in Modelica is shown in Fig. 6 a, and the validation against the measured data for the return water temperature from the building space heating system is depicted in Fig. 6 b. The Modelica model was initialized with a return water temperature of 20 ◦C, resulting in a short transient period at the beginning of the simulation. Validation metrics were calculated over the 60-day dataset, after the system reached steady operation. The resulting calibration parameters for the return water temperature were obtained as the following: CV-RMSE of 8.53 %, NMBE of −0.12 %, and R 2 of 87.54 %. Since all the model calibration parameters were within the recommended range, the building model was estimated reliable for further use [37]. 2.2. Functional Mock-up interface for integrating modelica with MATLAB/simulink To enable the integration of the Modelica model with MATLAB/Simulink for the MPC implementation, the FMU were utilized. An FMU is a package model that follows FMI standard, allowing dynamic models developed in Modelica or other simulation tools to be exported and used in various simulation environments such as MATLAB/Simulink. The process of using this method involves exporting the Modelica model as an FMU file using the Modelica modeling environment, which encapsulates the model equations, parameters, and solver settings. This FMU is then imported into MATLAB/Simulink using the FMI Toolbox allowing it to function as a Simulink block that interacts with MATLAB scripts, control logic, and other system components. In this study, the Modelica model of the heating system, which included the CO 2 heat pump, building model, and thermal tank, was converted into an FMU file as shown in Fig. 7 a. The FMU computed the heating demand for the space heating, ˙ Qdemand, the outlet water temperature of the CO 2 heat pump high temperature gas cooler Thp, and the water storage tank temperature Ttank at the previous time step t−1. The MPC model, implemented in MATLAB, received these FMU outputs as inputs, optimizing system operation based on electricity price signals and past system states. The MPC model calculated the required heat pump compressor power, ˙ P, for the current time step, t, which was fed back into the FMU to update the heating load for the next time step. This iterative process ensured real-time coordination between the real-time simulation and MPC for the optimal control. One of the key benefits of this approach is the ability to use the advanced optimization capabilities of MATLAB for the MPC algorithm while still leveraging the detailed physics-based modeling of the heating system in Modelica. The FMU allowed the system to run in a co-simulation environment where the control actions from the MPC were executed on the Modelica model in real time. This combined framework enhanced flexibility and accuracy while supporting a modular approach to system development. To validate the effectiveness of the FMU approach, the simulation results from the FMU were compared to the Table 1 Parameters of the heat pump model. Parameters Value Maximum Heating Capacity 152.3 kW (Winter) Rated COP – Heating (Winter) 4.27 Max Discharge Pressure 100–110 bar Compressor Modulation 10 %–100 % G. Song et al. Journal of Building Engineering 115 (2025) 114501 6 original results from the Modelica model. The validation process ensured that the exported FMU preserved the dynamic behavior and thermal response of the system. The comparison of the results showed strong alignment, confirming that the FMU-based model accurately replicated the performance of the original Modelica model. This validation step was essential to ensure that no significant deviations occur during the translation process. The validation results for the supply and return temperature, TB,in and TB,out, to the space heating of the building model are presented in Fig. 7 b, where the outputs of the FMU and the Modelica model are plotted. The close agreement between the two sets of results demonstrates the reliability of the FMU-based approach for use in integrated MPC simulations. Fig. 5. Heat Pump Model Structure and Validation of time series High-Temperature Gas Cooler return temperature a. Heat pump model developed in Modelica. b. Validation of simulated time series compared to measured data over time. G. Song et al. Journal of Building Engineering 115 (2025) 114501 7 2.3. Model predictive control In this study, an MPC strategy was developed to optimize the operation of a hydronic heating system incorporating the CO 2 heat pump. The objective of the MPC was to improve system efficiency, reduce operational costs and enhance the flexibility of the heating system. The development and implementation of the MPC involved several key steps, which are detailed below. The methodology began with the creation of a simulation model for the entire heating system, which included the CO 2 heat pump, water storage tank, and associated heating system components. The model was built using the IDEAS library in Modelica. The CO 2 heat pump model captures dynamic behaviors such as variations in mass flow rates and temperature differentials throughout the cycle. Additionally, a simplified CO 2 heat pump cycle model was established for the state space function of MPC. The mathematical representation of the CO 2 heat pump system was based on the following fundamental energy and mass balance equations. An hourly control and sampling interval was chosen to capture the main thermal dynamics while keeping the MPC computation manageable [40]: Heat pump energy balance: ˙ mhp ⋅cp dThp dt =˙ mflow ⋅cp⋅(Thp −Tin)+ ˙ Qin (1) Water tank energy balance: ˙ mtank ⋅cp dTtank dt =˙ mflow ⋅cp⋅(Thp −Ttank)− ˙ Qdemand (2) Fig. 6. Building Model Structure and Validation: a. Building model developed in Modelica. b. Validation of simulated the return water temperature from the building model compared to measured data over time. Fig. 7. Integration of Modelica-Based FMU with MPC for Real-Time Control: a. FMU Co-Simulation Framework. b. Validation of FMU Model Against Modelica Results for Supply and Return Temperatures in Space Heating. G. Song et al. Journal of Building Engineering 115 (2025) 114501 8 COP of the CO 2 heat pump: COP= ˙ Qin ˙ P(3) where cp is the specific heat capacity of the working fluid. ˙ mhp and ˙ mtank are the mass flow rate of the fluid, from the outlet of the gas cooler into the water tank and from the tank to the space heating system. Thp, the heat pump temperature, is the outlet temperature of the heat pump gas cooler entering the water tank, and Ttank, the tank temperature, is the outlet temperature of the water tank supplying the space heating system. Tin represents the inlet temperature to the gas cooler. ˙ mflow is the mass flow rate of the fluid, both fluid out from the gas cooler to the tank and out from the tank to the space heating are the same, ˙ Qin denotes the thermal heat rate transferred from the heat pump to the water tank, while ˙ Qdemand represents the thermal demand of the space heating system. The grey-box model used in the MPC represents the thermal behavior of the CO 2 heat pump and storage system. A constant COP value of 4.27 was used in this model, corresponding to the rated performance of the heat pump under standard winter conditions, as listed in Table 1. Dynamic variations in COP were not explicitly modeled, as the focus of this work was on demonstrating the FMU–MPC integration and systemlevel control framework. For the MPC implementation, a reduced-order state-space model of the CO 2 heat pump and water storage tank was derived from the energy and mass balance Equations (1)–(3). The nonlinear equations were linearized around the nominal operating point corresponding to the rated heat pump capacity and the steady-state tank temperature. The resulting linearized model was be expressed as: ⎡ ⎢ ⎢ ⎣ dThp dt dTtank dt ⎤ ⎥ ⎥ ⎦ =[a11 a12 a21 a22 ][ Thp Ttank ]+[b1 b2]˙ Qin +[e1 e2]˙ Qdemand (4) The coefficients aij, bi, ei were obtained by taking partial derivatives of the nonlinear energy balance equations with respect to Thp, Ttank, ˙ Qin, and ˙ Qdemand at the nominal operating point. The continuous-time model was then discretized using an 1-h sampling interval to yield the discrete state-space form as the following: xk+1=Axk+Buk+Edk(5) x=[Thp Ttank ](6) u= ˙ Qin (7) d= ˙ Qdemand (8) This reduced model served as the internal predictive model within the MPC, while the detailed Modelica model was used for closedloop co-simulation and validation via the FMU interface. A data-driven identification approach using input–output data from the Modelica model was not adopted, as the governing equations were already validated. The analytical derivation ensures full physical consistency and transparency between the predictive and simulation models, which is particularly important for the FMU-based MPC applications. 2.4. Cost-optimized predictive control approach The objective of the MPC strategy for the CO 2 heat pump system was to minimize operational costs while maintaining system efficiency and the tank temperature. To achieve this, the control strategy considers the impact of time-varying electricity prices, tank temperature, and heating demand. The MPC controller predicts system behavior over a future horizon and computes optimal control actions to achieve cost-effective and energy-efficient operation. In this study, the electricity cost was calculated as the product of the time-varying electricity price and the electricity use of the heat pump compressor. The objective function J, minimized over a prediction horizon N, was defined as: J=∫Tp 0(EP(t)⋅ ˙ P(t) + λ(Tset −Tc(t))2)dt (9) Subject to: x(0) = A(10) x(t) − F(x(t),u(t)) = 0 (11) ˙ P(t) ≤ ˙ Pp(12) G. Song et al. Journal of Building Engineering 115 (2025) 114501 9 Table A1 (continued) Parameter Description Value Unit g Win Solar energy transmittance of windows 0.4 – ratio WinConRad Ratio of convective to radiative heat emission for windows 0.09 – A Ext Exterior wall area (by orientation) (10,000, 2000) m 2 α Ext Convective coefficient for exterior walls 8.7 W/(m 2 ⋅K) n Ext Number of RC elements (exterior walls) 1 – R Ext Thermal resistance (wall, inside to outside) 1 ×10 −3 K/W R ExtRem Remaining resistance between capacity and outer surface 0.1 ×10 −6 K/W C Ext Heat capacity of exterior wall 3.8 ×10 7 J/K A Int Interior wall area 16,965 m 2 α Int Convective coefficient for interior walls 8.8 W/(m 2 ⋅K) n Int Number of RC elements (interior walls) 1 – R Int Thermal resistance of interior walls 9 ×10 −8 K/W C Int Heat capacity of interior walls 1.7 ×10 7 J/K Table A2 Quantitative comparison of control performance metrics among MPC, PI, and baseline strategies Metric MPC PI Baseline Annual electricity use (MWh) 243 251 328 Electricity cost (kNOK) 159.4 170.9 206.4 Energy reduction vs. Baseline (%) 25.9 % 23.5 % – Cost reduction vs. Baseline (%) 22.8 % 17.2 % – Energy reduction vs. PI (%) 3.2 % – – Cost reduction vs. PI (%) 6.7 % – – Control simulation time (h) ~2.5 ~1.8 ~1.2 Peak tank temperature deviation (◦C) 15 3 5 RMSE of tank temperature (◦C) 4.5 2.2 3.8 Data availability The authors do not have permission to share data. References [1] IEA, Renewables 2023, IEA, Paris, 2024. [2] Norwegian Ministry of Energy, Energy Facts Norway (2024), Available at: https://www.energifaktanorge.no. [3] G. Reynders, R. Amaral Lopes, A. Marszal-Pomianowska, D. Aelenei, J. Martins, D. Saelens, Energy flexible buildings: an evaluation of definitions and quantification methodologies applied to thermal storage, Energy Build. 166 (2018) 372–390. [4] J. Le Dr´ eau, P. Heiselberg, Energy flexibility of residential buildings using short term heat storage in the thermal mass, Energy 111 (2016) 991–1002. [5] F. Oldewurtel, A. Ulbig, A. Parisio, G. Andersson, M. Morari, Reducing peak electricity demand in building climate control using real-time pricing and model predictive control, in: 49th IEEE Conference on Decision and Control, CDC), 2010, pp. 1927–1932. [6] Z. Tian, X. Li, J. Niu, R. Zhou, F. Li, Enhancing operation flexibility of distributed energy systems: a flexible multi-objective optimization planning method considering long-term and temporary objectives, Energy 288 (2024) 129612. [7] A. Arteconi, D. Costola, P. Hoes, J.L.M. Hensen, Analysis of control strategies for thermally activated building systems under demand side management mechanisms, Energy Build. 80 (2014) 384–393. [8] S. Steinle, M. Zimmerlin, F. Mueller, L. Held, M.R. Suriyah, T. Leibfried, Time-dependent flexibility potential of heat pump systems for smart energy system operation, Energies 13 (2020) 4148. [9] N.J. Hewitt, Heat pumps and energy storage – the challenges of implementation, Appl. Energy 89 (1) (2012) 37–44. [10] M. Evens, A. Mugnini, A. Arteconi, Design energy flexibility characterisation of a heat pump and thermal energy storage in a comfort and climate box, Appl. Therm. Eng. 216 (2022) 119154. [11] Z. Marijanovic, P. Theile, B.H. Czock, Value of short-term heating system flexibility – a case study for residential heat pumps on the German intraday market, Energy 249 (2022) 123664. [12] Z. You, S.D. Lumpp, M. Doepfert, P. Tzscheutschler, C. Goebel, Leveraging flexibility of residential heat pumps through local energy markets, Appl. Energy 355 (2024) 122269. [13] C. Baumann, P. Kepplinger, Application of a flexibility estimation method for domestic heat pumps with reduced system information and data, Clean. Energy Syst. 6 (2023) 100081. [14] S. Kuboth, F. Heberle, T. Weith, M. Welzl, A. K¨ onig-Haagen, D. Brüggemann, Experimental short-term investigation of model predictive heat pump control in residential buildings, Energy Build. 204 (2019) 109444. [15] S. Kuboth, T. Weith, F. Heberle, M. Welzl, D. Brüggemann, Experimental long-term investigation of model predictive heat pump control in residential buildings with photovoltaic power generation, Energies 13 (2020) 3222. [16] C. Baumann, G. Huber, J. Alavanja, M. Preißinger, P. Kepplinger, Experimental validation of a state-of-the-art model predictive control approach for demand side management with a hot water heat pump, Energy Build. 285 (2023) 112923. [17] J.V.M. Walden, P. Stathopoulos, The impact of heat pump load flexibility on its process integration and economics, J. Clean. Prod. 462 (2024) 142643. [18] C. Schellenberg, L. Dimache, J. Lohan, Grid-edge technology - exploring the flexibility potential of a heat pump and thermal energy storage system, E3S Web Conf. 111 (2019). [19] J.V.M. Walden, M. B¨ ahr, A. Glade, J. Gollasch, A.P. Tran, T. Lorenz, Nonlinear operational optimization of an industrial power-to-heat system with a high temperature heat pump, a thermal energy storage and wind energy, Appl. Energy 344 (2023) 121247. [20] B. Li, Z. Liu, Y. Zheng, H. Xie, L. Zhang, Economy and energy flexibility optimization of the photovoltaic heat pump system with thermal energy storage, J. Energy Storage 100 (2024) 113526. G. Song et al. Journal of Building Engineering 115 (2025) 114501 16 [21] E. Gaucher-Loksts, A. Athienitis, M. Ouf, Design and energy flexibility analysis for building integrated photovoltaics-heat pump combinations in a house, Renew. Energy 195 (2022) 872–884. [22] Z. Wei, P.W. Tien, J. Calautit, J. Darkwa, M. Worall, R. Boukhanouf, Investigation of a model predictive control (MPC) strategy for seasonal thermochemical energy storage systems in district heating networks, Appl. Energy 376 (2024) 124164. [23] B. Yue, B. Su, F. Xiao, A. Li, K. Li, S. Li, R. Yan, Q. Lian, A. Li, Y. Li, X. Fang, X. Liang, Energy-oriented control retrofit for existing HVAC system adopting datadriven MPC – methodology, implementation and field test, Energy Build. 295 (2023) 113286. [24] J. Zhao, J. Li, Y. Shan, Research on a forecasted load-and time delay-based model predictive control (MPC) district energy system model, Energy Build. 231 (2021) 110631. [25] S. Wang, L. Kong, C. Liu, G. Cai, MPC-based energy optimization and regulation for zero-carbon energy supply building, Int. J. Hydrogen Energy 82 (2024) 1196–1210. [26] G. Fan, C. Peng, X. Wang, P. Wu, Y. Yang, H. Sun, Optimal scheduling of integrated energy system considering renewable energy uncertainties based on distributionally robust adaptive MPC, Renew. Energy 226 (2024) 120457. [27] C. Qian, N. He, Z. Cheng, R. Li, L. Yang, Double-layer optimal scheduling method for solar photovoltaic thermal system based on event-triggered MPC considering battery performance degradation, Energy 304 (2024) 132233. [28] J. Drgoˇ na, J. Arroyo, I. Cupeiro Figueroa, D. Blum, K. Arendt, D. Kim, E.P. Oll´ e, J. Oravec, M. Wetter, D.L. Vrabie, L. Helsen, All you need to know about model predictive control for buildings, Annu. Rev. Control 50 (2020) 190–232. [29] M. Wetter, W. Zuo, T.S. Nouidui, X. Pang, Modelica buildings library, J. Build. Perform. Simul. 7 (4) (2014) 253–270. [30] R. Baetens, R. De Coninck, F. Jorissen, D. Picard, L. Helsen, D. Saelens, Openideas-an open framework for integrated district energy simulations, in: Building Simulation, 2015, pp. 345–354. [31] A. Kumar, A. Narasimhan, T. Rajendran, S. Velut, Digital Twin Applications Using a Cloud Native Modelica Platform, 2022. [32] F. Delussu, D. Manzione, R. Meo, G. Ottino, M. Asare, Experiments and comparison of digital twinning of photovoltaic panels by machine learning models and a cyber-physical model in modelica, IEEE Trans. Ind. Inf. 18 (6) (2022) 4018–4028. [33] E. O’Dwyer, I. Pan, R. Charlesworth, S. Butler, N. Shah, Integration of an energy management tool and digital twin for coordination and control of multi-vector smart energy systems, Sustain. Cities Soc. 62 (2020) 102412. [34] C. Ates, D. Bicat, R. Yankov, J. Arweiler, R. Koch, H.-J. Bauer, Model predictive evolutionary temperature control via neural-network-based digital twins, Algorithms 16 (8) (2023) 387. [35] A. Clausen, K. Arendt, A. Johansen, F.C. Sangogboye, M.B. Kjærgaard, C.T. Veje, B.N. Jørgensen, A digital twin framework for improving energy efficiency and occupant comfort in public and commercial buildings, Energy Inf. 4 (2) (2021) 40. [36] A. Erfani, T. Jafarinejad, S. Roels, D. Saelens, In search of optimal building behavior models for model predictive control in the context of flexibility, Build. Simulat. 17 (1) (2024) 71–91. [37] A.G. Ashrae, Guideline 14-2014: Measurement of Energy, Demand, and Water Savings, American Society of Heating, Refrigerating, and Air Conditioning Engineers, 2014. Atlanta, Georgia. [38] F. Jorissen, G. Reynders, R. Baetens, D. Picard, D. Saelens, L. Helsen, Implementation and verification of the IDEAS building energy simulation library, J. Build. Perform. Simul. 11 (6) (2018) 669–688. [39] N. Standards Norway, Energy Performance of Buildings - Calculation of Energy and Power Demand. [40] A. Erfani, T. Jafarinejad, S. Roels, D. Saelens, Impact of dataset sampling period on building thermal models used for flexibility activation, Build. Environ. 262 (2024) 111775. G. Song et al. Journal of Building Engineering 115 (2025) 114501 17