From c8c4a681e34f801f50df151e31bf8120f8d56782 Mon Sep 17 00:00:00 2001 From: guille Date: Wed, 16 Mar 2022 13:21:51 -0400 Subject: [PATCH] Fixing bugs in idf export --- exports/formats/idf.py | 156 +++++++++++++----- exports/formats/idf_files/Minimal.idf | 5 +- .../one_building_in_kelowna_alkis.gml | 2 +- 3 files changed, 116 insertions(+), 47 deletions(-) diff --git a/exports/formats/idf.py b/exports/formats/idf.py index b956367e..54e899d3 100644 --- a/exports/formats/idf.py +++ b/exports/formats/idf.py @@ -3,6 +3,7 @@ TestOccupancyFactory test and validate the city model structure schedules parame SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Soroush Samareh Abolhassani - soroush.samarehabolhassani@mail.concordia.ca """ + from geomeppy import IDF @@ -18,6 +19,7 @@ class Idf: _MATERIAL_NOMASS = 'MATERIAL:NOMASS' _ROUGHNESS = 'MediumRough' _HOURLY_SCHEDULE = 'SCHEDULE:DAY:HOURLY' + _COMPACT_SCHEDULE = 'SCHEDULE:COMPACT' _ZONE = 'ZONE' _LIGHTS = 'LIGHTS' _PEOPLE = 'PEOPLE' @@ -28,8 +30,8 @@ class Idf: _ON_OFF = 'On/Off' _FRACTION = 'Fraction' _ANY_NUMBER = 'Any Number' - _CONTINUOUS = 'CONTINUOUS' - _DISCRETE = 'DISCRETE' + _CONTINUOUS = 'Continuous' + _DISCRETE = 'Discrete' idf_surfaces = { # todo: make an enum for all the surface types @@ -42,9 +44,18 @@ class Idf: 'residential': 'residential_building' } + idf_type_limits = { + 'on_off': 'on/off', + 'fraction': 'Fraction', + 'any_number': 'Any Number', + 'continuous': 'Continuous', + 'discrete': 'Discrete' + } + def __init__(self, city, output_path, idf_file_path, idd_file_path, epw_file_path, export_type="Surfaces"): self._city = city - self._output_path = str((output_path / f'{city.name}.idf').resolve()) + self._output_path = str(output_path.resolve()) + self._output_file = str((output_path / f'{city.name}.idf').resolve()) self._export_type = export_type self._idd_file_path = str(idd_file_path) self._idf_file_path = str(idf_file_path) @@ -59,10 +70,13 @@ class Idf: self._export() @staticmethod - def _matrix_to_list(points): + def _matrix_to_list(points, lower_corner): + lower_x = lower_corner[0] + lower_y = lower_corner[1] + lower_z = lower_corner[2] points_list = [] for point in points: - point_tuple = (point[0], point[1], point[2]) + point_tuple = (point[0]-lower_x, point[1]-lower_y, point[2]-lower_z) points_list.append(point_tuple) return points_list @@ -103,41 +117,71 @@ class Idf: Visible_Absorptance=layer.material.visible_absorptance ) - def _add_schedule(self, usage_zone, schedule_type, limit_name='Any Number'): + def _add_daily_schedule(self, usage_zone, schedule): + _schedule = self._idf.newidfobject(self._COMPACT_SCHEDULE, Name=f'{schedule.type} schedules {usage_zone.usage}') + _val = schedule.values + _schedule.Schedule_Type_Limits_Name = self.idf_type_limits[schedule.data_type.lower()] + _schedule.Field_1 = "Through: 12/31" + _schedule.Field_2 = "For: AllDays" + _schedule.Field_3 = "Until: 01:00" + _schedule.Field_4 = _val[0] + _schedule.Field_5 = "Until: 02:00" + _schedule.Field_6 = _val[1] + _schedule.Field_7 = "Until: 03:00" + _schedule.Field_8 = _val[2] + _schedule.Field_9 = "Until: 04:00" + _schedule.Field_10 = _val[3] + _schedule.Field_11 = "Until: 05:00" + _schedule.Field_12 = _val[4] + _schedule.Field_13 = "Until: 06:00" + _schedule.Field_14 = _val[5] + _schedule.Field_15 = "Until: 07:00" + _schedule.Field_16 = _val[6] + _schedule.Field_17 = "Until: 08:00" + _schedule.Field_18 = _val[7] + _schedule.Field_19 = "Until: 09:00" + _schedule.Field_20 = _val[8] + _schedule.Field_21 = "Until: 10:00" + _schedule.Field_22 = _val[9] + _schedule.Field_23 = "Until: 11:00" + _schedule.Field_24 = _val[10] + _schedule.Field_25 = "Until: 12:00" + _schedule.Field_26 = _val[11] + _schedule.Field_27 = "Until: 13:00" + _schedule.Field_28 = _val[12] + _schedule.Field_29 = "Until: 14:00" + _schedule.Field_30 = _val[13] + _schedule.Field_31 = "Until: 15:00" + _schedule.Field_32 = _val[14] + _schedule.Field_33 = "Until: 16:00" + _schedule.Field_34 = _val[15] + _schedule.Field_35 = "Until: 17:00" + _schedule.Field_36 = _val[16] + _schedule.Field_37 = "Until: 18:00" + _schedule.Field_38 = _val[17] + _schedule.Field_39 = "Until: 19:00" + _schedule.Field_40 = _val[18] + _schedule.Field_41 = "Until: 20:00" + _schedule.Field_42 = _val[19] + _schedule.Field_43 = "Until: 21:00" + _schedule.Field_44 = _val[20] + _schedule.Field_45 = "Until: 22:00" + _schedule.Field_46 = _val[21] + _schedule.Field_47 = "Until: 23:00" + _schedule.Field_48 = _val[22] + _schedule.Field_49 = "Until: 24:00" + _schedule.Field_50 = _val[23] + + def _add_schedule(self, usage_zone, schedule_type): for schedule in self._idf.idfobjects[self._HOURLY_SCHEDULE]: if schedule.Name == f'{schedule_type} schedules {usage_zone.usage}': return - if usage_zone.schedules is None or schedule_type not in usage_zone.schedules: - # there are no schedule for this type - return - schedule = self._idf.newidfobject(self._HOURLY_SCHEDULE, Name=f'{schedule_type} schedules {usage_zone.usage}') - schedule.Schedule_Type_Limits_Name = limit_name - - schedule.Hour_1 = usage_zone.schedules[schedule_type]["WD"][0] - schedule.Hour_2 = usage_zone.schedules[schedule_type]["WD"][1] - schedule.Hour_3 = usage_zone.schedules[schedule_type]["WD"][2] - schedule.Hour_4 = usage_zone.schedules[schedule_type]["WD"][3] - schedule.Hour_5 = usage_zone.schedules[schedule_type]["WD"][4] - schedule.Hour_6 = usage_zone.schedules[schedule_type]["WD"][5] - schedule.Hour_7 = usage_zone.schedules[schedule_type]["WD"][6] - schedule.Hour_8 = usage_zone.schedules[schedule_type]["WD"][7] - schedule.Hour_9 = usage_zone.schedules[schedule_type]["WD"][8] - schedule.Hour_10 = usage_zone.schedules[schedule_type]["WD"][9] - schedule.Hour_11 = usage_zone.schedules[schedule_type]["WD"][10] - schedule.Hour_12 = usage_zone.schedules[schedule_type]["WD"][11] - schedule.Hour_13 = usage_zone.schedules[schedule_type]["WD"][12] - schedule.Hour_14 = usage_zone.schedules[schedule_type]["WD"][13] - schedule.Hour_15 = usage_zone.schedules[schedule_type]["WD"][14] - schedule.Hour_16 = usage_zone.schedules[schedule_type]["WD"][15] - schedule.Hour_17 = usage_zone.schedules[schedule_type]["WD"][16] - schedule.Hour_18 = usage_zone.schedules[schedule_type]["WD"][17] - schedule.Hour_19 = usage_zone.schedules[schedule_type]["WD"][18] - schedule.Hour_20 = usage_zone.schedules[schedule_type]["WD"][19] - schedule.Hour_21 = usage_zone.schedules[schedule_type]["WD"][20] - schedule.Hour_22 = usage_zone.schedules[schedule_type]["WD"][21] - schedule.Hour_23 = usage_zone.schedules[schedule_type]["WD"][22] - schedule.Hour_24 = usage_zone.schedules[schedule_type]["WD"][23] - + for schedule in usage_zone.schedules: + if schedule.type == schedule_type: + if schedule.time_range == "day": + return self._add_daily_schedule(usage_zone, schedule) + return + def _add_construction(self, thermal_boundary): for construction in self._idf.idfobjects[self._CONSTRUCTION]: if construction.Name == thermal_boundary.construction_name: @@ -183,7 +227,9 @@ class Idf: thermostat = self._add_thermostat(usage_zone) self._idf.newidfobject(self._IDEAL_LOAD_AIR_SYSTEM, Zone_Name=usage_zone.id, - Cooling_Availability_Schedule_Name=f'Refrigeration schedules {usage_zone.usage}', + System_Availability_Schedule_Name=f'HVAC AVAIL SCHEDULES {usage_zone.usage}', + Heating_Availability_Schedule_Name=f'HVAC AVAIL SCHEDULES {usage_zone.usage}', + Cooling_Availability_Schedule_Name=f'HVAC AVAIL SCHEDULES {usage_zone.usage}', Template_Thermostat_Name=thermostat.Name) def _add_occupancy(self, usage_zone): @@ -194,7 +240,7 @@ class Idf: Number_of_People_Calculation_Method="People", Number_of_People=500, # todo: get people from where? Fraction_Radiant=0.3, # todo: howto get this from InternalGains - Activity_Level_Schedule_Name='occupant schedules' + Activity_Level_Schedule_Name=f'Occupancy schedules {usage_zone.usage}' ) def _add_equipment(self, usage_zone): @@ -227,17 +273,19 @@ class Idf: Export the idf file into the given path export type = "Surfaces|Block" """ + for building in self._city.buildings: for usage_zone in building.usage_zones: self._add_schedule(usage_zone, "Infiltration") self._add_schedule(usage_zone, "Lights") self._add_schedule(usage_zone, "Occupancy") - self._add_schedule(usage_zone, "Refrigeration", self._ON_OFF) + self._add_schedule(usage_zone, "Refrigeration") + self._add_schedule(usage_zone, "HVAC Avail") self._add_zone(usage_zone) self._add_heating_system(usage_zone) - # self._add_infiltration(usage_zone) - # self._add_occupancy(usage_zone) + self._add_infiltration(usage_zone) + self._add_occupancy(usage_zone) for thermal_zone in building.thermal_zones: for thermal_boundary in thermal_zone.thermal_boundaries: self._add_construction(thermal_boundary) @@ -246,8 +294,27 @@ class Idf: self._add_surfaces(building) else: self._add_block(building) + self._idf.newidfobject( + "OUTPUT:VARIABLE", + Variable_Name="Zone Ideal Loads Supply Air Total Heating Energy", + Reporting_Frequency="Hourly", + ) + self._idf.newidfobject( + "OUTPUT:VARIABLE", + Variable_Name="Zone Ideal Loads Supply Air Total Cooling Energy", + Reporting_Frequency="Hourly", + ) self._idf.match() - self._idf.saveas(str(self._output_path)) + self._idf.intersect_match() + self._idf.saveas(str(self._output_file)) + return self._idf + + def run(self): + """ + Start the energy plus simulation + """ + self._idf.run(expandobjects=True, readvars=True, output_directory=self._output_path, + output_prefix=f'{self._city.name}_') def _add_block(self, building): _points = self._matrix_to_2d_list(building.foot_print.coordinates) @@ -267,6 +334,7 @@ class Idf: self._idf.intersect_match() def _add_surfaces(self, building): + for thermal_zone in building.thermal_zones: for boundary in thermal_zone.thermal_boundaries: idf_surface_type = self.idf_surfaces[boundary.surface.type] @@ -274,5 +342,5 @@ class Idf: surface = self._idf.newidfobject(self._SURFACE, Name=f'{boundary.surface.name}', Surface_Type=idf_surface_type, Zone_Name=usage_zone.id, Construction_Name=boundary.construction_name) - coordinates = self._matrix_to_list(boundary.surface.solid_polygon.coordinates) + coordinates = self._matrix_to_list(boundary.surface.solid_polygon.coordinates, self._city.lower_corner) surface.setcoords(coordinates) diff --git a/exports/formats/idf_files/Minimal.idf b/exports/formats/idf_files/Minimal.idf index c56db8eb..67846cf4 100644 --- a/exports/formats/idf_files/Minimal.idf +++ b/exports/formats/idf_files/Minimal.idf @@ -122,8 +122,8 @@ No, !- Do Zone Sizing Calculation No, !- Do System Sizing Calculation No, !- Do Plant Sizing Calculation - Yes, !- Run Simulation for Sizing Periods - No, !- Run Simulation for Weather File Run Periods + No, !- Run Simulation for Sizing Periods + Yes, !- Run Simulation for Weather File Run Periods No, !- Do HVAC Sizing Simulation for Sizing Periods 1; !- Maximum Number of HVAC Sizing Simulation Passes @@ -149,3 +149,4 @@ Output:Table:SummaryReports, AllSummary; !- Report 1 Name + Output:Diagnostics,DisplayUnusedSchedules; \ No newline at end of file diff --git a/unittests/tests_data/one_building_in_kelowna_alkis.gml b/unittests/tests_data/one_building_in_kelowna_alkis.gml index ee239b38..05926e5e 100644 --- a/unittests/tests_data/one_building_in_kelowna_alkis.gml +++ b/unittests/tests_data/one_building_in_kelowna_alkis.gml @@ -14,8 +14,8 @@ m2 -1010 1996 +residential 5.3 1