EnergyPlus with Python
EnergyPlus is the US Department of Energy’s flagship program for building energy modeling. Developed by a team of researchers, engineers, it is freely available under an open source license at this website
The EnergyPlus program models heating, cooling, lighting, ventilation, other energy flows, by using a collection of many program modules that work together to calculate the energy required for heating and cooling a building using a variety of systems and energy sources. It does this by simulating the building and associated energy systems when they are exposed to different environmental and operating conditions. The core of the simulation is a model of the building that is based on fundamental heat balance principles.
In the following, we focus on how we can extract energy Plus model from design builder and run it using python in customized approach with Energy plus core engine. The Notebook used is available on this link on Github
Exporting IDF Files
- Open your DesignBuilder dsb model file (let’s take the Atrium model proposed by design builder).
- Click on the File > Export > Export EnergyPlus or DBSim input file > Simulation menu option.
- Open the file with text editor in order to check the Energy Plus version, note that the energy plus version is that is embedded in design builder
Download Energy Plus and IDF conversion
The next step is to download the desired energy plus engine from this link, let’s assume that the energy plus Engine downloaded and installed is the v8.9.0 The next step is to convert you IDF file from the 8.6 version to the 8.9 version, in order to be compatible with the installed Energy plus Engine.
To do that:
1-Navigate to IDFVersionUpdated which is located at C:\EnergyPlusV8-9-0\PreProcess\IDFVersionUpdater (if we assume that the energy plus was installed at the C:\ folder)
2- Click on Choose File to update and browse to the IDF file and choose the new version as 8.9.0
3-Once the conversion process is finished, a new IDF file is created
Installing and using EPPY (Python Package)
Eppy is a scripting language for EnergyPlus idf files, and EnergyPlus output files. Eppy is written in the programming language Python. As a result it takes full advantage of the rich data structure and idioms that are avaliable in python. You can programmatically navigate, search, and modify EnergyPlus idf files using eppy. The power of using a scripting language allows you to do the following:
- Make a large number of changes in an idf file with a few lines of eppy code.
- Use conditions and filters when making changes to an idf file
- Make changes to multiple idf files.
- Read data from the output files of an E+ simulation run.
- Based to the results of an E+ simulation run, generate the input file for the next simulation run.
To install Eppy package, run in your cmd window pip install eppy
In order to use this python package, we need essentially 3 files:
1- The IDF file as done above.
2- The IDD file is located in the folder of the Energy Plus
3- The EPW file is the weather file used for the simulation
We propose to put each file in a folder
First of all, let’s create an IDF class using the package:
from eppy import modeleditor
from eppy.modeleditor import IDF
iddfile = "Example\Resources\iddfiles\Energy+.idd"
fname1 = "Example\Resources\idffiles\Model_Design_builder.idf"
Weather= "Example\Resources\WeatherDATA\FRA_Paris.epw"
IDF.setiddname(iddfile)
idf1 = IDF(fname1,Weather)
idf1.printidf()
The IDF class is constructed with different objects, we can iterate over the IDF class in order to Know name of the different objects.
for x in idf1.idfobjects:
print (x)
Among these objects, the most important that can be modified during energy simulation studies are:
- idf1.idfobjects[‘LIGHTS’] in order to control the light load in each zone.
- idf1.idfobjects[‘PEOPLE’] in order to control the people load in each zone.
- idf1.idfobjects[‘ELECTRICEQUIPMENT’] in order to control the equipment load in each zone.
- idf1.idfobjects[‘ZONEINFILTRATION:DESIGNFLOWRATE’] in order to control the infiltration rate in each zone.
- idf1.idfobjects[“MATERIAL”] in order to control the defined material.
- idf1.idfobjects[“CONSTRUCTION”] in order to control the layer used to construct each wall on the building.
- idf1.idfobjects[“WINDOWMATERIAL:GLAZING”] in order to control the proprieties of the glazed material used.
- idf1.idfobjects[‘BUILDINGSURFACE:DETAILED’] in order to control coordinate and the assigned material for each wall.
Modify the IDF file
Let’s assume that we want that:
- The density of people equals 5 peoples in each zone.
The density of light equals 6W/m². +The thickness of the concrete material equal 0.25 m.
peoples=idf1.idfobjects['PEOPLE'] for people in peoples: people.Number_of_People_Calculation_Method='People' people.Number_of_People=5 print (idf1.idfobjects['PEOPLE'])
LIGHTS=idf1.idfobjects['LIGHTS'] for LIGHT in LIGHTS: LIGHT.Design_Level_Calculation_Method='Watts/Area' LIGHT.Watts_per_Zone_Floor_Area=6 print (idf1.idfobjects['LIGHTS'])
for material in idf1.idfobjects["MATERIAL"]:
if material.Name.find('Concrete')>0:
material.Thickness=0.25
Run E+ simulation
In order to run a simulation with energy plus, we use only a simple command as EnergyPlus can be called on the cmd Windows.
Import subprocess
idf1.saveas(r"out.idf")
fname1 = "out.idf"
subprocess.call("C:\EnergyPlusV8-9-0\energyplus.exe -w "+Weather +" -r " +fname1, shell=True)
All the EnergyPlus output files are located in the folder