Optimisation Tutorial - Custom Script KPI Example 3 - Using EMS + Python Scripts to Optimise Controls for Comfort and Heating

This tutorial demonstrates how to find the optimum set of heating and natural ventilation system control set point temperatures that simultaneously minimise Fanger PPD discomfort and heating load across the whole building. Because EnergyPlus does not include a suitable whole building comfort PPD metric a Custom EMS script is written to generate a "Percentage Discomfort Area" output for each simulation to characterise the overall degree of discomfort for all zones in the building. When combined with a Custom Script KPI it can be used as a design objective in the optimisation.

 

The EMS script calculates the overall building "Percentage Discomfort Area" at each timestep of the simulation (during occupied periods only) by summing the floor area of uncomfortable zones having Fanger PPD < 20% and dividing by the total floor area. The % discomfort area is averaged over the year as a single value for the building which is read and processed in a Custom KPI script written in Python. The Python KPI script uses the db_eplusout_reader library provided with DesignBuilder to read and process the comfort EMS output from the SQL simulation output file and feeds the result back to DesignBuilder after each simulation to process.

 

Optimal settings for heating and natural ventilation setpoints are identified that provide the lowest heating loads while also minimising PPD discomfort levels.

 

The main learning point is to understand the process used to generate a custom output from an EnergyPlus simulation using EMS and use it as a KPI to identify optimum design parameters.

Step 1 - Create a base model

1. Create a new model located at London Gatwick.

 

2. Add a building using default settings and draw a rectangular block measuring 40m by 20m with block height of 3.5m as shown below.

 

 

3. Sub-divide the block into several zones as follows. The SE and SW-facing corner zones both have 10 x 10m floor area. For the purposes of this tutorial the objective is to create zones that will overheat to varying degrees over the course of hot days. The exact layout is not particularly important:

 

 

4. Open the Model options dialog:

 

5. On the Activity Tab at building level:

 

6. On the Openings tab at building level:

 

8. On the Lighting tab load the LED with linear control Lighting template.

 

9. On the HVAC tab:

 

Step 2 - Run a Simulation to Check the Base Model

Click on the Simulation tab and run a set of simulations to check the operation of the nat vent system to make sure you understand how it works in practice. You will probably want to run simulations for at least summer design, summer typical and winter design weeks looking at hourly or sub-hourly results to give the clearest picture of building behaviour. Does it maintain adequate comfort during the summer? Is the air change rate excessive at any point? Do you see any simultaneous heating and venting? Make any adjustments to the model and repeat this step until you are satisfied with the base model hourly results.

Step 3 - Make Optimisation Objective Settings

1. Open the Parametric, Optimisation and UA/SA Analysis Settings dialog by clicking on the toolbar icon and set the Analysis type on the Analysis tab to 2-Optimisation.

 

2. Go to the Objectives tab and add 2 new objectives for comfort and heating load. You can either edit the existing objectives or first delete those and create 2 new objectives. The steps involved are described below.

Minimise Discomfort > 20% PPD

To create the "Minimise Discomfort > 20% PPD" objective, a new Summary Output (aka KPI) must first be created. Click on the Objective KPI to open the list of existing Summary Outputs in the Info panel. Our custom KPI won't be listed there at first, so create it now by clicking on the existing Custom Script Summary Output on the list of KPIs, click on the Create copy of highlighted item Info toolbar icon and edit the clone. Make the following settings on the Summary Output dialog.

 

Note: The "PPD Discomfort > 20%" name entered here on the Summary Outputs dialog must match the name given in the custom KPI script described below. You may like to copy the name and paste it somewhere safe where you can easily access it later when writing the script.

Save the newly created KPI and select it on the Optimisation Objectives dialog.

 

Name the objective "Minimise Discomfort > 20% PPD". That name is for your own reference only and unlike the Summary Output name, does not need to match anything else. Select the 1-Min Min/Max option to say that you wish to minimise discomfort. The dialog should now look something like the screenshot below.

 

Heating load

Now create the Heating load objective. This is straightforward as we can use a standard built-in KPI.

 

Select the Heating load KPI and call the objective "Heating load". Select the 1-Min Min/Max option to say that you wish to minimise it. The objectives dialog should now look like the screenshot below.

 

 

With both objectives defined, the Objectives tab should now be set up like this:

 

Step 4 - Make Optimisation Variable Settings

Now set up the design variables. The variables to be included are:

 

 

With the above variables defined, the Variables tab should now look like this:

 

Step 5 - Write Custom EMS Script to Calculate Fanger % Discomfort Area

The EMS script to be used in this example is provided below. Follow the steps below to set it up for the analysis.

1. Click on the Scripts toolbar icon to open the Script Manager dialog and click on the Enable scripts checkbox.

 

2. Click on the Script browse item. A list of the existing scripts appears in the Info panel to the right.

 

3. Open the EMS category and click on the Add new item toolbar icon to create a new script.

 

4. Enter the name as "Fanger % Discomfort Area",

 

5. Enable the program

 

6.Copy the script below and paste it in the script text area.

 

Now check you understand how the EMS script works.

 

The script sets up a sensor for each occupied zone in the model to get a reading for the Fanger PPD. This is checked at the end of each zone timestep during occupied periods and compared against the threshold of 20%. If the % PPD is higher than the comfort threshold the whole zone is considered to be uncomfortable and its floor area is added to the total. The total uncomfortable floor area is divided by the total floor area of all occupied zones to give the floor-area-weighted % discomfort for the building. The timestep % discomfort outputs are averaged over the whole simulation to create a single discomfort metric which is reported as "Percentage Discomfort Area" in the SQL output file.

 

Step 6 - Write Python Script for the Custom Script KPI

The next task is to write the script that will read the EMS "Percentage Discomfort Area" simulation outputs from the SQL output file, process them and pass back to DesignBuilder as a Custom KPI. Steps are as follows.

1. Click on the Scripts toolbar icon to open the Script Manager dialog. The Enable scripts checkbox should already be checked.

 

2. Click on the Script browse item. A list of the existing scripts appears in the Info panel to the right.

 

3. Click on an existing script within the Python-Script category and press the Add new item Info toolbar icon to open the Edit script dialog.

 

4. Enter the name as "Python Script: PPD Discomfort > 20%", enable the program and copy and paste the script below into the script text area.

 

In summary, the script works as follows. After each simulation the SQL output file is opened and the building "Percentage Discomfort Area" EMS output is read for the RunPeriod. This floor-area-weighted % discomfort value indicates the % of time that the building was uncomfortable over the year. This value is converted to hours by dividing by 100 (converting a % to a fraction) and multiplying by 8760 (hours in the year). The value for the simulation is then written to the special "ParamResultsTmp" table together with the name of the Objective to be picked up by DesignBuilder when it processes the simulation results.

 

Tip: To save time you can copy the above script and paste it into the dialog.

Step 6 - Re-Run a standard simulation

Click on the Simulation tab and press update to re-run a base annual simulation with the Monthly and RunPeriod results option checked.

Important Note: Make sure to switch off Daily, Hourly and Sub-hourly results for this simulation to ensure that the upcoming optimisation simulations and results processing are kept as efficient as possible.

Step 7 - Run the Optimisation

Navigate to the Optimisation + UA/SA tab on the Simulation screen and press the Update toolbar icon to open the Optimisation Calculation Options dialog. You can accept the default optimisation settings for the purposes of this tutorial.

 

Press the Start button to run the optimisation simulations.

 

After the optimisation has converged and you have closed the Calculation Options dialog, you should see results similar to those below on the main screen. Depending on the speed of your machine and the number or cores available, it will some time before all the simulations required for the optimisation are completed.

 

 

The results show that to minimise both heating energy and PPD discomfort over the year, the following optimal variable settings are indicated: