2020-10-21 15:23:06 -04:00
|
|
|
"""
|
|
|
|
TestOccupancyFactory test and validate the city model structure occupancy parameters
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
2020-10-22 07:30:34 -04:00
|
|
|
Copyright © 2020 Project Author Soroush Samareh Abolhassani - soroush.samarehabolhassani@mail.concordia.ca
|
2020-10-21 15:23:06 -04:00
|
|
|
"""
|
2020-10-21 14:38:19 -04:00
|
|
|
from geomeppy import IDF
|
2020-11-04 11:56:57 -05:00
|
|
|
import os
|
2020-10-21 14:38:19 -04:00
|
|
|
import esoreader
|
2020-10-21 15:23:06 -04:00
|
|
|
from pathlib import Path
|
2020-11-11 19:39:51 -05:00
|
|
|
import helpers
|
2020-10-21 14:38:19 -04:00
|
|
|
|
2020-10-22 07:30:34 -04:00
|
|
|
class IdfHelper:
|
2020-10-27 13:19:50 -04:00
|
|
|
_THERMOSTAT = 'HVACTEMPLATE:THERMOSTAT'
|
|
|
|
_IDEAL_LOAD_AIR_SYSTEM = 'HVACTEMPLATE:ZONE:IDEALLOADSAIRSYSTEM'
|
|
|
|
_SURFACE = 'BUILDINGSURFACE:DETAILED'
|
|
|
|
|
2020-10-26 10:00:42 -04:00
|
|
|
idf_surfaces = {
|
|
|
|
'Wall': 'wall',
|
|
|
|
'Ground': 'floor',
|
|
|
|
'Roof': 'roof'
|
|
|
|
}
|
2020-11-05 11:45:39 -05:00
|
|
|
idf_usage = {
|
|
|
|
'residential': 'residential_building'
|
|
|
|
}
|
2020-10-21 14:38:19 -04:00
|
|
|
|
2020-10-26 13:47:10 -04:00
|
|
|
def __init__(self, idf_file_path, idd_file_path, epw_file_path):
|
2020-10-22 07:55:40 -04:00
|
|
|
self._idd_file_path = str(idd_file_path)
|
|
|
|
self._idf_file_path = str(idf_file_path)
|
|
|
|
self._epw_file_path = str(epw_file_path)
|
2020-10-26 13:47:10 -04:00
|
|
|
IDF.setiddname(self._idd_file_path)
|
2020-10-26 13:33:03 -04:00
|
|
|
self._idf = IDF(self._idf_file_path, self._epw_file_path)
|
2020-10-26 10:00:42 -04:00
|
|
|
self._idf.epw = self._epw_file_path
|
2020-10-22 07:55:40 -04:00
|
|
|
|
2020-11-13 01:37:53 -05:00
|
|
|
def add_schedule(self,occupancy):
|
|
|
|
schedule_occupancy =self._idf.newidfobject("SCHEDULE:DAY:HOURLY".upper())
|
|
|
|
schedule_occupancy.Name='occupant schedule'
|
|
|
|
schedule_occupancy.Hour_1=occupancy.occupant_schedule[0]
|
|
|
|
schedule_occupancy.Hour_2=occupancy.occupant_schedule[1]
|
|
|
|
schedule_occupancy.Hour_3=occupancy.occupant_schedule[2]
|
|
|
|
schedule_occupancy.Hour_4=occupancy.occupant_schedule[3]
|
|
|
|
schedule_occupancy.Hour_5=occupancy.occupant_schedule[4]
|
|
|
|
schedule_occupancy.Hour_6=occupancy.occupant_schedule[5]
|
|
|
|
schedule_occupancy.Hour_7=occupancy.occupant_schedule[6]
|
|
|
|
schedule_occupancy.Hour_8=occupancy.occupant_schedule[7]
|
|
|
|
schedule_occupancy.Hour_9=occupancy.occupant_schedule[8]
|
|
|
|
schedule_occupancy.Hour_10=occupancy.occupant_schedule[9]
|
|
|
|
schedule_occupancy.Hour_11=occupancy.occupant_schedule[10]
|
|
|
|
schedule_occupancy.Hour_12=occupancy.occupant_schedule[11]
|
|
|
|
schedule_occupancy.Hour_13=occupancy.occupant_schedule[12]
|
|
|
|
schedule_occupancy.Hour_14=occupancy.occupant_schedule[13]
|
|
|
|
schedule_occupancy.Hour_15=occupancy.occupant_schedule[14]
|
|
|
|
schedule_occupancy.Hour_16=occupancy.occupant_schedule[15]
|
|
|
|
schedule_occupancy.Hour_17=occupancy.occupant_schedule[16]
|
|
|
|
schedule_occupancy.Hour_18=occupancy.occupant_schedule[17]
|
|
|
|
schedule_occupancy.Hour_19=occupancy.occupant_schedule[18]
|
|
|
|
schedule_occupancy.Hour_20=occupancy.occupant_schedule[19]
|
|
|
|
schedule_occupancy.Hour_21=occupancy.occupant_schedule[20]
|
|
|
|
schedule_occupancy.Hour_22=occupancy.occupant_schedule[21]
|
|
|
|
schedule_occupancy.Hour_23=occupancy.occupant_schedule[22]
|
|
|
|
schedule_occupancy.Hour_24=occupancy.occupant_schedule[23]
|
|
|
|
|
|
|
|
|
2020-11-11 19:39:51 -05:00
|
|
|
def add_material(self, layer):
|
|
|
|
materials = self._idf.newidfobject("MATERIAL".upper())
|
|
|
|
materials.Name = layer.material.name
|
|
|
|
materials.Roughness = helpers.roughness
|
|
|
|
materials.Thickness = layer.thickness
|
|
|
|
materials.Conductivity = layer.material.conductivity
|
|
|
|
materials.Density = layer.material.density
|
|
|
|
materials.Specific_Heat = layer.material.specific_heat
|
|
|
|
materials.Thermal_Absorptance = layer.material.thermal_absorptance
|
|
|
|
materials.Solar_Absorptance = layer.material.solar_absorptance
|
|
|
|
materials.Visible_Absorptance = layer.material.visible_absorptance
|
|
|
|
|
|
|
|
def add_construction(self, thermal_boundary):
|
|
|
|
for boundary in thermal_boundary:
|
|
|
|
for layer in boundary:
|
|
|
|
if len(layer) == 2:
|
|
|
|
self._idf.newidfobject("CONSTRUCTION", Name=boundary.construction_name,
|
|
|
|
Outside_Layer=layer[0].material.name, Layer_2=layer[1].material.name)
|
|
|
|
elif len(layer) == 3:
|
|
|
|
self._idf.newidfobject("CONSTRUCTION", Name=boundary.construction_name,
|
|
|
|
Outside_Layer=layer[0].material.name, Layer_2=layer[1].material.name, Layer_3=layer[2].material.name)
|
|
|
|
elif len(layer) == 4:
|
|
|
|
self._idf.newidfobject("CONSTRUCTION", Name=boundary.construction_name,
|
|
|
|
Outside_Layer=layer[0].material.name, Layer_2=layer[1].material.name, Layer_3=layer[2].material.name, Layer_4=layer[3].material.name)
|
|
|
|
else:
|
|
|
|
print("Could not find the true construction")
|
|
|
|
|
2020-11-04 08:54:10 -05:00
|
|
|
def add_heating_system(self, building):
|
2020-10-27 13:19:50 -04:00
|
|
|
for usage_zone in building.usage_zones:
|
|
|
|
thermostat_name = f'Thermostat {building.name}'
|
|
|
|
# todo: this will fail for more than one usage zone
|
|
|
|
static_thermostat = self._idf.newidfobject(self._THERMOSTAT,
|
|
|
|
Name=thermostat_name,
|
|
|
|
Constant_Heating_Setpoint=usage_zone.heating_setpoint,
|
2020-11-04 08:54:10 -05:00
|
|
|
Constant_Cooling_Setpoint=usage_zone.cooling_setpoint,
|
2020-10-27 13:19:50 -04:00
|
|
|
)
|
2020-11-04 08:54:10 -05:00
|
|
|
for zone in self._idf.idfobjects['ZONE']:
|
|
|
|
if zone.Name.find(building.name) != -1:
|
|
|
|
self._idf.newidfobject(self._IDEAL_LOAD_AIR_SYSTEM,
|
|
|
|
Zone_Name=zone.Name,
|
|
|
|
Template_Thermostat_Name=static_thermostat.Name,)
|
2020-10-22 07:55:40 -04:00
|
|
|
|
2020-10-23 15:49:04 -04:00
|
|
|
@staticmethod
|
|
|
|
def _matrix_to_list(points):
|
|
|
|
points_list = []
|
|
|
|
for point in points:
|
|
|
|
point_tuple = (point[0], point[1], point[2])
|
|
|
|
points_list.append(point_tuple)
|
|
|
|
return points_list
|
|
|
|
|
2020-10-26 10:00:42 -04:00
|
|
|
@staticmethod
|
|
|
|
def _matrix_to_2d_list(points):
|
|
|
|
points_list = []
|
|
|
|
for point in points:
|
|
|
|
point_tuple = (point[0], point[1])
|
|
|
|
points_list.append(point_tuple)
|
|
|
|
return points_list
|
|
|
|
|
|
|
|
def add_block(self, building):
|
|
|
|
_points = IdfHelper._matrix_to_2d_list(building.foot_print.points)
|
2020-11-04 08:54:10 -05:00
|
|
|
self._idf.add_block(name=building.name, coordinates=_points, height=building.max_height,
|
|
|
|
num_stories=int(building.storeys_above_ground))
|
|
|
|
self.add_heating_system(building)
|
2020-11-04 11:56:57 -05:00
|
|
|
self._idf.intersect_match()
|
2020-10-26 10:00:42 -04:00
|
|
|
|
|
|
|
def add_surfaces(self, building):
|
2020-11-05 11:11:43 -05:00
|
|
|
index = 0
|
|
|
|
for zone in building.thermal_zones:
|
|
|
|
zone_name = f'Building {building.name} usage zone {index}'
|
|
|
|
self._idf.newidfobject('ZONE', Name=zone_name)
|
|
|
|
for surface in zone.surfaces:
|
|
|
|
idf_surface = self.idf_surfaces[surface.type]
|
|
|
|
wall = self._idf.newidfobject(self._SURFACE, Name=f'{building.name}-{surface.name}', Surface_Type=idf_surface,
|
|
|
|
Zone_Name=zone_name)
|
|
|
|
coordinates = IdfHelper._matrix_to_list(surface.points)
|
|
|
|
wall.setcoords(coordinates)
|
|
|
|
index += 1
|
|
|
|
self.add_heating_system(building)
|
|
|
|
self._idf.intersect_match()
|
2020-11-04 11:56:57 -05:00
|
|
|
|
2020-11-13 01:37:53 -05:00
|
|
|
def add_lighting (self):
|
|
|
|
for zone in self._idf.idfobjects["ZONE"]:
|
|
|
|
self._idf.newidfobject("LIGHTS",
|
|
|
|
Name = zone.Name+"_"+"lighting",
|
|
|
|
Zone_or_ZoneList_Name = zone.Name,
|
|
|
|
Schedule_Name = "Lighting_Weekday",
|
|
|
|
Design_Level_Calculation_Method = 'Watts/Area',
|
|
|
|
Watts_per_Zone_Floor_Area = 15,
|
|
|
|
Return_Air_Fraction = 0,
|
|
|
|
Fraction_Radiant = 0.7,
|
|
|
|
Fraction_Visible = 0.2,
|
|
|
|
Fraction_Replaceable = 1,
|
|
|
|
# Lights.End-Use_Subcategory='LightsWired',
|
|
|
|
Return_Air_Fraction_Calculated_from_Plenum_Temperature = 'No'
|
|
|
|
)
|
|
|
|
|
|
|
|
def add_occupancy(self,occupancy):
|
|
|
|
for zone in self._idf.idfobjects["ZONE"]:
|
|
|
|
self._idf.newidfobject("PEOPLE",
|
|
|
|
Name = zone.Name+"_"+"occupancy",
|
|
|
|
Zone_or_ZoneList_Name = zone.Name,
|
|
|
|
Number_of_People_Schedule_Name = 'occupant schedule',
|
|
|
|
Number_of_People_Calculation_Method = "People",
|
|
|
|
Number_of_People = occupancy.number_of_occupants,
|
|
|
|
# Zone_Floor_Area_per_Person=31.41,
|
|
|
|
# People_per_Zone_Floor_Area=17*0.05,
|
|
|
|
# Zone_Floor_Area_per_Person=1.65880764E+01,
|
|
|
|
Fraction_Radiant = 0.3,
|
|
|
|
Activity_Level_Schedule_Name = "People_Weekday_ActivityLevel"
|
|
|
|
)
|
|
|
|
|
|
|
|
def add_equipment(self):
|
|
|
|
for zone in self._idf.idfobjects["ZONE"]:
|
|
|
|
self._idf.newidfobject("ELECTRICEQUIPMENT",
|
|
|
|
Name = zone.Name+"_"+'electricload',
|
|
|
|
Zone_or_ZoneList_Name = zone.Name,
|
|
|
|
Schedule_Name = 'ElectricalEquipment',
|
|
|
|
Design_Level_Calculation_Method = 'EquipmentLevel',
|
|
|
|
Design_Level = 566000
|
|
|
|
)
|
|
|
|
|
|
|
|
def add_infiltration(self):
|
|
|
|
for zone in self._idf.idfobjects["ZONE"]:
|
|
|
|
self._idf.newidfobject("ZONEINFILTRATION:DESIGNFLOWRATE",
|
|
|
|
Name=zone.Name+"_"+"infiltration",
|
|
|
|
Zone_or_ZoneList_Name=zone.Name,
|
|
|
|
Schedule_Name='Infiltration_schedule',
|
|
|
|
Design_Flow_Rate_Calculation_Method='AirChanges/Hour',
|
|
|
|
Air_Changes_per_Hour=0.35,
|
|
|
|
Constant_Term_Coefficient=0.606,
|
|
|
|
Temperature_Term_Coefficient=3.6359996E-02,
|
|
|
|
Velocity_Term_Coefficient=0.1177165,
|
|
|
|
Velocity_Squared_Term_Coefficient=0.0000000E+00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-11-04 11:56:57 -05:00
|
|
|
def run(self, output_directory, window_ratio=0.35, display_render=False, output_prefix=None, keep_file=None):
|
2020-10-26 13:33:03 -04:00
|
|
|
self._idf.set_default_constructions()
|
2020-10-27 13:19:50 -04:00
|
|
|
self._idf.set_wwr(window_ratio, construction="Project External Window")
|
2020-10-26 13:33:03 -04:00
|
|
|
self._idf.translate_to_origin()
|
2020-10-23 15:49:04 -04:00
|
|
|
if display_render:
|
|
|
|
self._idf.view_model()
|
2020-10-28 12:20:13 -04:00
|
|
|
# Run
|
2020-11-04 11:56:57 -05:00
|
|
|
self._idf.newidfobject("OUTPUT:METER", Key_Name="Heating:DistrictHeating", Reporting_Frequency="hourly")
|
|
|
|
self._idf.newidfobject("OUTPUT:METER", Key_Name="Cooling:DistrictCooling", Reporting_Frequency="hourly")
|
|
|
|
idf_path = None
|
2020-11-04 08:54:10 -05:00
|
|
|
if keep_file is not None:
|
|
|
|
idf_path = (keep_file / 'in.idf').resolve()
|
|
|
|
self._idf.saveas(str(idf_path))
|
2020-11-04 11:56:57 -05:00
|
|
|
if idf_path is None:
|
|
|
|
idf_path = (Path(__file__).parent / 'in.idf').resolve()
|
|
|
|
|
|
|
|
# There is a bug in the IDF class, when called, it return an error, as a work around we call call energy+ directly
|
|
|
|
run_command = f"energyplus --weather {self._epw_file_path} --output-directory {output_directory} --idd " \
|
|
|
|
f"{self._idd_file_path} --expandobjects --output-prefix {output_prefix} {idf_path}"
|
|
|
|
os.system(run_command)
|
|
|
|
|
|
|
|
if keep_file is None:
|
|
|
|
os.remove(idf_path)
|
2020-10-28 12:20:13 -04:00
|
|
|
return
|
2020-10-26 13:47:10 -04:00
|
|
|
|
|
|
|
@staticmethod
|
2020-11-04 11:56:57 -05:00
|
|
|
def read_eso(eso_file_path):
|
|
|
|
dd, data = esoreader.read(eso_file_path)
|
|
|
|
list_values = [v for v in data.values()]
|
2020-10-22 07:55:40 -04:00
|
|
|
heating = [(float(x)) / 3600000.0 for x in list_values[0]]
|
|
|
|
cooling = [(float(x)) / 3600000.0 for x in list_values[1]]
|
2020-10-27 13:19:50 -04:00
|
|
|
return heating, cooling
|