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
|
|
|
|
import esoreader
|
2020-10-21 15:23:06 -04:00
|
|
|
from pathlib import Path
|
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-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-10-28 12:20:13 -04:00
|
|
|
def add_heating_system(self, building, zone = None):
|
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,
|
|
|
|
Constant_Cooling_Setpoint=usage_zone.cooling_setpoint
|
|
|
|
)
|
2020-10-28 12:20:13 -04:00
|
|
|
if zone is None:
|
|
|
|
for zone in self._idf.idfobjects['ZONE']:
|
|
|
|
if zone.Name.find(building.name) != -1:
|
|
|
|
break
|
|
|
|
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-10-27 13:19:50 -04:00
|
|
|
self._idf.add_block(name=building.name, coordinates=_points, height=building.max_height)
|
|
|
|
# self.add_heating_system(building)
|
2020-10-26 10:00:42 -04:00
|
|
|
|
|
|
|
def add_surfaces(self, building):
|
2020-10-28 12:20:13 -04:00
|
|
|
self.add_block(building)
|
|
|
|
for zone in self._idf.idfobjects['ZONE']:
|
|
|
|
if zone.Name.find(building.name) != -1:
|
|
|
|
for surface in building.surfaces:
|
|
|
|
idf_surface = self.idf_surfaces[surface.type]
|
|
|
|
wall = self._idf.newidfobject(self._SURFACE, Name=surface.name, Surface_Type=idf_surface, Zone_Name=zone.Name)
|
|
|
|
coordinates = IdfHelper._matrix_to_list(surface.points)
|
|
|
|
if len(coordinates) > 2:
|
|
|
|
wall.setcoords(coordinates)
|
|
|
|
# self.add_heating_system(building, zone)
|
2020-10-26 10:00:42 -04:00
|
|
|
|
2020-10-27 13:19:50 -04:00
|
|
|
def run(self, window_ratio=0.35, display_render=False, output_prefix=None, output_directory='tests'):
|
2020-10-26 13:33:03 -04:00
|
|
|
self._idf.intersect_match()
|
|
|
|
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-27 13:19:50 -04:00
|
|
|
else:
|
2020-10-28 12:20:13 -04:00
|
|
|
# self._idf.to_obj('ep_outputs/city.obj')
|
|
|
|
print("match")
|
|
|
|
# Run
|
|
|
|
self._idf.newidfobject("OUTPUT:METER", Key_Name="Heating:DistrictHeating", Reporting_Frequency="hourly")
|
|
|
|
self._idf.newidfobject("OUTPUT:METER", Key_Name="Cooling:DistrictCooling", Reporting_Frequency="hourly")
|
|
|
|
try:
|
|
|
|
self._idf.run(output_prefix=output_prefix, output_directory=output_directory)
|
|
|
|
except:
|
|
|
|
print("exception launched")
|
|
|
|
print("completed!")
|
|
|
|
return
|
2020-10-26 13:47:10 -04:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def read_eso(eso_path):
|
2020-10-27 13:19:50 -04:00
|
|
|
print("read_eso")
|
|
|
|
return [], []
|
|
|
|
"""
|
|
|
|
eso = esoreader.read(str(eso_path))
|
|
|
|
list_values = [v for v in df.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-26 13:47:10 -04:00
|
|
|
|
2020-10-27 13:19:50 -04:00
|
|
|
return heating, cooling
|
|
|
|
"""
|