Skip to content

Carleton-DBOM-Research-Group/MPC-for-EnergyPlus-Python-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

MPC-in-Python-API-for-EnergyPlus

This code integrates a model predictive controller into an EnergyPlus simulation using the Python API for EnergyPlus

You will need:

  • Jupyter notebook and EnergyPlus
  • An idf file (for training)
  • The same idf file but with an energy management system that controls the "sensible load request" of the HVAC system (the HVAC output) by modifying a constant schedule value called HVACoutSch (for implementation)
  • A csv containing weather data used for training and implemetation (I used cloud cover and outdoor temperature at hourly resolution for 2018 and 2019)
  • An epw file (I used one from 2018 for testing, and one from 2019 for implementation)

The first part of the code runs an initial simulation to get training data Next, that training data is used to Calculate C and U in this equation:

C dTia/dt = U(Toa - Tia) + Qhvac + Qmisc

where Tis is the indoor temperature (oC), t is time (seconds), C is the thermal capacitance (kJ/oC), U is the thermal transmittance (kW/oC), Qhvac is the energy output by the hvac system (kW), and Qmisc is any other heat gains/disturbances (kW)

Once we have C and U, we can calculate Qmisc for every hour of the initial simulation. These hourly Qmisc values get clustered using K-means clustering, and each cluster is assigned an average Qmisc profile to provide disturbance estimates for each day type. Then a decision tree is trained to figure out with day type we should expect based on the day of the week, the month of the year in a cyclical format, and cloud cover forecasts. Finally we calculate the heating and cooling capacity of the HVAC system by taking the 99th and 1st percentile of the HVAC output, these will be used by our MPC

Once we have C, U, our decision tree, our Qmisc profiles, and our heating and cooling capacities we're ready to run our simulation

  • Warning: it may take several hours to run depending on your prediction horizon length and choice of optimizer. This code uses an 8 hour prediciton horizon which may take up to 12 hours to run, but this can be shortened by modifying the hyperparameters in the section called "Define callback function". This code also uses the SLSQP optimizer which is much faster than other methods like differential evolution

To run the simulation, first we get our day type classifications and Qmisc profiles in advance by collecting cloud cover values from the weather file (see "Get day types, setpoints, and forecasts"), and using our decision tree for each control timestep (20 minutes) for the whole simulation. In the same loop we also collect heating and cooling setpoints, outdoor temperature forecasts, and days of the week which will all be used by our MPC.

The we define our cost/objective function.

Then we define our callback function, which is iteratively activated throughout the simulation to control the HVAC output directly

  • Note: your idf file should have an energy mangement system that controls the HVAC "sensible load request" by modifying a constant schedule value called HVACoutSch. This is the value that the MPC changes to control the HVAC system.

The callback function uses our pre-determined setpoints, Toa forecasts, and Qmisc forecasts in the cost function to predict indoor temperatures, and the cost associated with different potential control decision chosen by the optimizer

In the callback function we also record information that's not recorded by energyplus, like the predicted temepratures, the chosen control sequences, the cost of the chosen control sequence, plus some extra stuff that is recorded by energyplus in case we want to look at it right away instead of creating a separate data analysis script

Then we run our simulation!

  • Note: the callback function is set to run at different times using this command: api.runtime.callback_begin_system_timestep_before_predictor(state,callback_mpc). This makes it so it runs before the MPC makes any decisions about HVAC operation, because we want to make those decisions ourselves

Useful documentation:

This is documentation for the Python API for EnergyPlus: https://energyplus.readthedocs.io/en/latest/api.html

Once it is published, I will also link a paper describing how the MPC works and its implementation in EnergyPlus

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published