This example shows how to create a simple Python script to write out a basic energy summary report after each simulation by accessing output variables reported in the EnergyPlus SQLite output file. The script could of course be extended to write more sophisticated reports depending on your model and your requirements.
The model is the same base model used in several other custom script tutorials.
The steps involved are as follows.
1. Create a new model located at London Gatwick.
2. Add a building using default settings and draw a rectangular block measuring 20m by 10m with block height of 3.5m as shown below.
3. Load the Generic Office Area Activity template at building level on the Activity Tab.
The next task is to write the script that will read the simulation results from the SQL output file and process and write them out as a summary report file. Steps are as follows.
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. Click on the Python-Script category and press the Add new item Info toolbar icon to open the Edit script dialog.
4. Copy and paste the script below into the script window. In summary, the script works as follows. Before the IDF is generated for the simulation the SQLite output option in each building in the model is forced to be on. Then after the simulation the key heating, cooling, equipment and lighting energy consumption outputs are loaded from the eplusout.sql simulation output file, summed to create a total and written to a text file in the DesignBuilder EnergyPlus folder.
from db_eplusout_reader import Variable, get_results
from db_eplusout_reader.constants import *
from datetime import datetime
# ensure that SQLite outputs are generated
def before_energy_idf_generation():
site = api_environment.Site
for building in site.Buildings:
building.SetAttribute("SSSQLiteOP", "1")
def after_energy_simulation():
variables = [
Variable("", "DistrictCooling:Facility", "J"),
Variable("", "DistrictHeating:Facility", "J"),
Variable("", "InteriorEquipment:Electricity", "J"),
Variable("", "InteriorLights:Electricity", "J")
]
file_path = api_environment.EnergyPlusFolder + r'eplusout.sql'
results = get_results(file_path, variables=variables, alike=True, frequency=RP)
convertJ_kWh = 3600000
cooling = results.arrays[0][0] / convertJ_kWh
heating = results. arrays[1][0] / convertJ_kWh
equipment = results.arrays[2][0] / convertJ_kWh
lighting = results.arrays [3][0] / convertJ_kWh
total = str(heating + cooling + equipment + lighting)
file_path = api_environment.EnergyPlusFolder + r'energy_report.txt'
with open(file_path, 'w') as file1:
line0 = "The following values have been retrieved from the .sql file."
line1 = "Cooling Energy: {0}{1}\n".format(cooling, " kWh")
line2 = "Heating Energy: {0}{1}\n".format(heating, " kWh")
line3 = "Equipment Energy: {0}{1}\n".format(equipment, " kWh")
line4 = "Lighting energy: {0}{1}\n".format(lighting, " kWh")
line5 = "Total Energy: {0}{1}\n".format(total, " kWh")
file1.write('{}\n\n{}\n{}\n{}\n{}\n{}'.format(line0,line1,line2,line3,line4,line5))
Tip: To save time you can copy the above script and paste it into the dialog. Note that Python requires the indentation as part of its syntax and when you paste the script the indents may become lost. In this case you must insert the indents manually after the paste. The easiest way to do that it by using the <Tab> key.
Now navigate to the Simulation tab and run an annual simulation, making sure that the Monthly and RunPeriod output option is checked under the Output Intervals for Reporting subheading.
Once the simulation is complete, navigate to the EnergyPlus folder (File > Folders > EnergyPlus folder menu command). A text file named "energy_report.txt" should be found there. The report should contain results like those below.
The following values have been retrieved from the .sql file.
Cooling Energy: 8783.43169749 kWh
Heating Energy: 8226.56484868 kWh
Equipment Energy: 7922.75824552 kWh
Lighting energy: 11450.1034080 kWh
Total Energy: 36382.8581997 kWh