diff --git a/catalog_factories/construction/construction_helper.py b/catalog_factories/construction/construction_helper.py new file mode 100644 index 00000000..3708fbd0 --- /dev/null +++ b/catalog_factories/construction/construction_helper.py @@ -0,0 +1,59 @@ +from helpers import constants as cte + + +class ConstructionHelper: + """ + Construction helper class + """ + nrel_to_function = { + 'residential': cte.RESIDENTIAL, + 'midrise apartment': cte.MID_RISE_APARTMENT, + 'high-rise apartment': cte.HIGH_RISE_APARTMENT, + 'small office': cte.SMALL_OFFICE, + 'medium office': cte.MEDIUM_OFFICE, + 'large office': cte.LARGE_OFFICE, + 'primary school': cte.PRIMARY_SCHOOL, + 'secondary school': cte.SECONDARY_SCHOOL, + 'stand-alone retail': cte.STAND_ALONE_RETAIL, + 'hospital': cte.HOSPITAL, + 'outpatient healthcare': cte.OUT_PATIENT_HEALTH_CARE, + 'strip mall': cte.STRIP_MALL, + 'supermarket': cte.SUPERMARKET, + 'warehouse': cte.WAREHOUSE, + 'quick service restaurant': cte.QUICK_SERVICE_RESTAURANT, + 'full service restaurant': cte.FULL_SERVICE_RESTAURANT, + 'small hotel': cte.SMALL_HOTEL, + 'large hotel': cte.LARGE_HOTEL, + 'industry': cte.INDUSTRY + } + + nrcan_to_function = { + 'residential': cte.RESIDENTIAL, + } + + reference_standard_to_construction_period = { + 'non_standard_dompark': '1900 - 2004', + 'ASHRAE 90.1_2004': '2004 - 2009', + 'ASHRAE 189.1_2009': '2009 - PRESENT' + } + + nrel_surfaces_types_to_hub_types = { + 'exterior wall': cte.WALL, + 'interior wall': cte.INTERIOR_WALL, + 'ground wall': cte.GROUND_WALL, + 'exterior slab': cte.GROUND, + 'attic floor': cte.ATTIC_FLOOR, + 'interior slab': cte.INTERIOR_SLAB, + 'roof': cte.ROOF + } + nrcan_surfaces_types_to_hub_types = { + 'Wall_Outdoors': cte.WALL, + 'RoofCeiling_Outdoors': cte.ROOF, + 'Floor_Outdoors': cte.ATTIC_FLOOR, + 'Window_Outdoors': cte.WINDOW, + 'Skylight_Outdoors': cte.SKYLIGHT, + 'Door_Outdoors': cte.DOOR, + 'Wall_Ground': cte.GROUND_WALL, + 'RoofCeiling_Ground': cte.GROUND_WALL, + 'Floor_Ground': cte.GROUND + } diff --git a/catalog_factories/construction/construction_helpers.py b/catalog_factories/construction/construction_helpers.py deleted file mode 100644 index b19cfc3d..00000000 --- a/catalog_factories/construction/construction_helpers.py +++ /dev/null @@ -1,43 +0,0 @@ -from helpers import constants as cte - -nrel_to_function = { - 'residential': cte.RESIDENTIAL, - 'midrise apartment': cte.MID_RISE_APARTMENT, - 'high-rise apartment': cte.HIGH_RISE_APARTMENT, - 'small office': cte.SMALL_OFFICE, - 'medium office': cte.MEDIUM_OFFICE, - 'large office': cte.LARGE_OFFICE, - 'primary school': cte.PRIMARY_SCHOOL, - 'secondary school': cte.SECONDARY_SCHOOL, - 'stand-alone retail': cte.STAND_ALONE_RETAIL, - 'hospital': cte.HOSPITAL, - 'outpatient healthcare': cte.OUT_PATIENT_HEALTH_CARE, - 'strip mall': cte.STRIP_MALL, - 'supermarket': cte.SUPERMARKET, - 'warehouse': cte.WAREHOUSE, - 'quick service restaurant': cte.QUICK_SERVICE_RESTAURANT, - 'full service restaurant': cte.FULL_SERVICE_RESTAURANT, - 'small hotel': cte.SMALL_HOTEL, - 'large hotel': cte.LARGE_HOTEL, - 'industry': cte.INDUSTRY -} - -nrcan_to_function = { - 'residential': cte.RESIDENTIAL, -} - -reference_standard_to_construction_period = { - 'non_standard_dompark': '1900 - 2004', - 'ASHRAE 90.1_2004': '2004 - 2009', - 'ASHRAE 189.1_2009': '2009 - PRESENT' -} - -nrel_surfaces_types_to_hub_types = { - 'exterior wall': cte.WALL, - 'interior wall': cte.INTERIOR_WALL, - 'ground wall': cte.GROUND_WALL, - 'exterior slab': cte.GROUND, - 'attic floor': cte.ATTIC_FLOOR, - 'interior slab': cte.INTERIOR_SLAB, - 'roof': cte.ROOF -} \ No newline at end of file diff --git a/catalog_factories/construction/nrcan_catalog.py b/catalog_factories/construction/nrcan_catalog.py new file mode 100644 index 00000000..dafa0bdb --- /dev/null +++ b/catalog_factories/construction/nrcan_catalog.py @@ -0,0 +1,127 @@ +""" +NRCAN construction catalog +SPDX - License - Identifier: LGPL - 3.0 - or -later +Copyright © 2022 Concordia CERC group +Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca +""" + +import json +import urllib.request +import xmltodict +import string + +import helpers.constants as cte +from catalog_factories.catalog import Catalog +from catalog_factories.data_models.usages.content import Content +from catalog_factories.construction.construction_helper import ConstructionHelper +from catalog_factories.data_models.construction.construction import Construction +from catalog_factories.data_models.construction.archetype import Archetype + + +class NrcanCatalog(Catalog): + def __init__(self, path): + path = str(path / 'nrcan.xml') + self._content = None + self._g_value_per_hdd = [] + self._thermal_transmittance_per_hdd_and_surface = {} + self._window_ratios = {} + with open(path) as xml: + self._metadata = xmltodict.parse(xml.read()) + self._base_url_archetypes = self._metadata['nrcan']['@base_url_archetypes'] + self._base_url_construction = self._metadata['nrcan']['@base_url_construction'] + self._load_window_ratios() + self._load_construction_values() + self._content = Content(self._load_archetypes()) + + def _load_window_ratios(self): + for standard in self._metadata['nrcan']['standards_per_function']['standard']: + url = f'{self._base_url_archetypes}{standard["file_location"]}' + # todo: read from file + self._window_ratios = {'Mean': 0.2, 'North': 0.2, 'East': 0.2, 'South': 0.2, 'West': 0.2} + + def _load_construction_values(self): + for standard in self._metadata['nrcan']['standards_per_period']['standard']: + g_value_url = f'{self._base_url_construction}{standard["g_value_location"]}' + punc = '() Catalog: """ diff --git a/catalog_factories/usage/comnet_catalog.py b/catalog_factories/usage/comnet_catalog.py index a68ea03c..6edf316d 100644 --- a/catalog_factories/usage/comnet_catalog.py +++ b/catalog_factories/usage/comnet_catalog.py @@ -28,6 +28,7 @@ class ComnetCatalog(Catalog): self._archetypes = self._read_archetype_file() self._schedules = self._read_schedules_file() + # todo: comment with @Guille, this hypotheses should go in the import factory? sensible_convective = ch().comnet_occupancy_sensible_convective sensible_radiative = ch().comnet_occupancy_sensible_radiant lighting_convective = ch().comnet_lighting_convective @@ -41,7 +42,8 @@ class ComnetCatalog(Catalog): for schedule_key in self._archetypes['schedules_key']: comnet_usage = schedule_key schedule_name = self._archetypes['schedules_key'][schedule_key] - hours_day = self._calculate_hours_day(schedule_name) + hours_day = None + days_year = None occupancy_archetype = self._archetypes['occupancy'][comnet_usage] lighting_archetype = self._archetypes['lighting'][comnet_usage] appliances_archetype = self._archetypes['plug loads'][comnet_usage] @@ -86,29 +88,9 @@ class ComnetCatalog(Catalog): self._schedules[schedule_name]['Receptacle']) # get thermal control - max_heating_setpoint = cte.MIN_FLOAT - min_heating_setpoint = cte.MAX_FLOAT - - for schedule in self._schedules[schedule_name]['HtgSetPt']: - if schedule.values is None: - max_heating_setpoint = None - min_heating_setpoint = None - break - if max(schedule.values) > max_heating_setpoint: - max_heating_setpoint = max(schedule.values) - if min(schedule.values) < min_heating_setpoint: - min_heating_setpoint = min(schedule.values) - - min_cooling_setpoint = cte.MAX_FLOAT - for schedule in self._schedules[schedule_name]['ClgSetPt']: - if schedule.values is None: - min_cooling_setpoint = None - break - if min(schedule.values) < min_cooling_setpoint: - min_cooling_setpoint = min(schedule.values) - thermal_control = ThermalControl(max_heating_setpoint, - min_heating_setpoint, - min_cooling_setpoint, + thermal_control = ThermalControl(None, + None, + None, self._schedules[schedule_name]['HVAC Avail'], self._schedules[schedule_name]['HtgSetPt'], self._schedules[schedule_name]['ClgSetPt'] @@ -116,7 +98,7 @@ class ComnetCatalog(Catalog): usages.append(Usage(comnet_usage, hours_day, - 365, + days_year, mechanical_air_change, ventilation_rate, occupancy, @@ -202,16 +184,6 @@ class ComnetCatalog(Catalog): 'schedules_key': schedules_key } - def _calculate_hours_day(self, function): - days = [cte.MONDAY, cte.TUESDAY, cte.WEDNESDAY, cte.THURSDAY, cte.FRIDAY, cte.SATURDAY, cte.SUNDAY, cte.HOLIDAY] - number_of_days_per_type = [51, 50, 50, 50, 50, 52, 52, 10] - total = 0 - for schedule in self._schedules[function]['HVAC Avail']: - yearly_days = number_of_days_per_type[days.index(schedule.day_types[0])] - for value in schedule.values: - total += value * yearly_days - return total / 365 - def names(self, category=None): """ Get the catalog elements names diff --git a/catalog_factories/usage/nrcan_catalog.py b/catalog_factories/usage/nrcan_catalog.py index 5842bc3f..0e1e8882 100644 --- a/catalog_factories/usage/nrcan_catalog.py +++ b/catalog_factories/usage/nrcan_catalog.py @@ -3,6 +3,7 @@ NRCAN usage catalog SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2022 Concordia CERC group Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca +Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ import json @@ -50,59 +51,84 @@ class NrcanCatalog(Catalog): return Schedule(hub_type, raw['values'], data_type, time_step, time_range, day_types) def _load_schedules(self): - usage = self._metadata['nrcan']['standards']['usage'] + usage = self._metadata['nrcan'] url = f'{self._base_url}{usage["schedules_location"]}' + _schedule_types = [] with urllib.request.urlopen(url) as json_file: schedules_type = json.load(json_file) for schedule_type in schedules_type['tables']['schedules']['table']: schedule = NrcanCatalog._extract_schedule(schedule_type) - if schedule is not None: - self._schedules[schedule_type['name']] = schedule + if schedule_type['name'] not in _schedule_types: + _schedule_types.append(schedule_type['name']) + if schedule is not None: + self._schedules[schedule_type['name']] = [schedule] + else: + if schedule is not None: + _schedules = self._schedules[schedule_type['name']] + _schedules.append(schedule) + self._schedules[schedule_type['name']] = _schedules - def _get_schedule(self, name): + def _get_schedules(self, name): if name in self._schedules: return self._schedules[name] def _load_archetypes(self): usages = [] - name = self._metadata['nrcan']['standards']['usage'] + name = self._metadata['nrcan'] url = f'{self._base_url}{name["space_types_location"]}' with urllib.request.urlopen(url) as json_file: space_types = json.load(json_file)['tables']['space_types']['table'] - space_types = [st for st in space_types if st['building_type'] == 'Space Function'] +# space_types = [st for st in space_types if st['building_type'] == 'Space Function'] + space_types = [st for st in space_types if st['space_type'] == 'WholeBuilding'] for space_type in space_types: - usage_type = space_type['space_type'] - mechanical_air_change = space_type['ventilation_air_changes'] - ventilation_rate = space_type['ventilation_per_area'] - if ventilation_rate == 0: - ventilation_rate = space_type['ventilation_per_person'] +# usage_type = space_type['space_type'] + usage_type = space_type['building_type'] occupancy_schedule_name = space_type['occupancy_schedule'] lighting_schedule_name = space_type['lighting_schedule'] appliance_schedule_name = space_type['electric_equipment_schedule'] - # thermal control + hvac_schedule_name = space_type['exhaust_schedule'] + if 'FAN' in hvac_schedule_name: + hvac_schedule_name = hvac_schedule_name.replace('FAN', 'Fan') heating_setpoint_schedule_name = space_type['heating_setpoint_schedule'] cooling_setpoint_schedule_name = space_type['cooling_setpoint_schedule'] - occupancy_schedule = self._get_schedule(occupancy_schedule_name) - lighting_schedule = self._get_schedule(lighting_schedule_name) - appliance_schedule = self._get_schedule(appliance_schedule_name) - heating_schedule = self._get_schedule(heating_setpoint_schedule_name) - cooling_schedule = self._get_schedule(cooling_setpoint_schedule_name) + occupancy_schedule = self._get_schedules(occupancy_schedule_name) + lighting_schedule = self._get_schedules(lighting_schedule_name) + appliance_schedule = self._get_schedules(appliance_schedule_name) + heating_schedule = self._get_schedules(heating_setpoint_schedule_name) + cooling_schedule = self._get_schedules(cooling_setpoint_schedule_name) + hvac_availability = self._get_schedules(hvac_schedule_name) occupancy_density = space_type['occupancy_per_area'] - lighting_density = space_type['lighting_per_area'] + + # ACH + mechanical_air_change = space_type['ventilation_air_changes'] + # cfm/ft2 to m3/m2.s + ventilation_rate = space_type['ventilation_per_area'] / (cte.METERS_TO_FEET * cte.MINUTES_TO_SECONDS) + if ventilation_rate == 0: + # cfm/person to m3/m2.s + ventilation_rate = space_type['ventilation_per_person'] / occupancy_density\ + / (cte.METERS_TO_FEET * cte.MINUTES_TO_SECONDS) + + # W/sqft to W/m2 + lighting_density = space_type['lighting_per_area'] * cte.METERS_TO_FEET * cte.METERS_TO_FEET lighting_radiative_fraction = space_type['lighting_fraction_radiant'] lighting_convective_fraction = 0 if lighting_radiative_fraction is not None: lighting_convective_fraction = 1 - lighting_radiative_fraction lighting_latent_fraction = 0 - appliances_density = space_type['electric_equipment_per_area'] + # W/sqft to W/m2 + appliances_density = space_type['electric_equipment_per_area'] * cte.METERS_TO_FEET * cte.METERS_TO_FEET appliances_radiative_fraction = space_type['electric_equipment_fraction_radiant'] - appliances_convective_fraction = 0 - if appliances_radiative_fraction is not None: - appliances_convective_fraction = 1 - appliances_radiative_fraction appliances_latent_fraction = space_type['electric_equipment_fraction_latent'] + appliances_convective_fraction = 0 + if appliances_radiative_fraction is not None and appliances_latent_fraction is not None: + appliances_convective_fraction = 1 - appliances_radiative_fraction - appliances_latent_fraction - occupancy = Occupancy(occupancy_density, 0, 0, 0, occupancy_schedule) + occupancy = Occupancy(occupancy_density, + None, + None, + None, + occupancy_schedule) lighting = Lighting(lighting_density, lighting_convective_fraction, lighting_radiative_fraction, @@ -113,20 +139,12 @@ class NrcanCatalog(Catalog): appliances_radiative_fraction, appliances_latent_fraction, appliance_schedule) - if heating_schedule is not None: - thermal_control = ThermalControl(max(heating_schedule.values), - min(heating_schedule.values), - min(cooling_schedule.values), - None, - heating_schedule, - cooling_schedule) - else: - thermal_control = ThermalControl(None, - None, - None, - None, - None, - None) + thermal_control = ThermalControl(None, + None, + None, + hvac_availability, + heating_schedule, + cooling_schedule) hours_day = None days_year = None usages.append(Usage(usage_type, diff --git a/catalog_factories/usage/usage_helper.py b/catalog_factories/usage/usage_helper.py index 93c6fa04..d43af81f 100644 --- a/catalog_factories/usage/usage_helper.py +++ b/catalog_factories/usage/usage_helper.py @@ -19,6 +19,7 @@ class UsageHelper: 'Equipment': cte.APPLIANCES, 'Thermostat Setpoint Cooling': cte.COOLING_SET_POINT, # Compose 'Thermostat Setpoint' + 'Cooling' 'Thermostat Setpoint Heating': cte.HEATING_SET_POINT, # Compose 'Thermostat Setpoint' + 'Heating' + 'Fan': cte.HVAC_AVAILABILITY } _nrcan_data_type_to_hub_data_type = { 'FRACTION': cte.FRACTION, diff --git a/city_model_structure/building_demand/usage.py b/city_model_structure/building_demand/usage.py index 0a86b625..d6e4de77 100644 --- a/city_model_structure/building_demand/usage.py +++ b/city_model_structure/building_demand/usage.py @@ -26,7 +26,6 @@ class Usage: self._internal_gains = None self._hours_day = None self._days_year = None -# self._electrical_app_average_consumption_sqm_year = None self._mechanical_air_change = None self._occupancy = None self._lighting = None diff --git a/data/construction/nrcan.xml b/data/construction/nrcan.xml new file mode 100644 index 00000000..0a366273 --- /dev/null +++ b/data/construction/nrcan.xml @@ -0,0 +1,76 @@ + + + + + BTAPPRE1980/data/surface_thermal_transmittance.json + BTAPPRE1980/data/window_characteristics.json + + + BTAP1980TO2010/data/surface_thermal_transmittance.json + BTAP1980TO2010/data/window_characteristics.json + + + NECB2011/data/surface_thermal_transmittance.json + BTAP1980TO2010/data/window_characteristics.json + + + NECB2017/data/surface_thermal_transmittance.json + BTAP1980TO2010/data/window_characteristics.json + + + NECB2020/data/surface_thermal_transmittance.json + BTAP1980TO2010/data/window_characteristics.json + + + + + FullServiceRestaurant/CAN_PQ_Montreal.Intl.AP.716270_CWEC/os_report/8414706d-3ba9-4d70-ad3c-4db62d865e1b-os-report.html + + + HighriseApartment/CAN_PQ_Montreal.Intl.AP.716270_CWEC/os_report/83ab3764-046e-48a8-85cd-a3c0ac761efa-os-report.html + + + Hospital/CAN_PQ_Montreal.Intl.AP.716270_CWEC/os_report/210dac7e-2d51-40a9-bc78-ad0bc1c57a89-os-report.html + + + LargeHotel/CAN_PQ_Montreal.Intl.AP.716270_CWEC/os_report/d0185276-7fe0-4da9-bb5d-8c8a7c13c405-os-report.html + + + LargeOffice/CAN_PQ_Montreal.Intl.AP.716270_CWEC/os_report/2da33707-50a7-4554-91ed-c5fdbc1ce3b9-os-report.html + + + MediumOffice/CAN_PQ_Montreal.Intl.AP.716270_CWEC/os_report/65d97bf8-8749-410b-b53d-5a9c60e0227c-os-report.html + + + MidriseApartment/CAN_PQ_Montreal.Intl.AP.716270_CWEC/os_report/19518153-9c28-4e40-8bbd-98ef949c1bdb-os-report.html + + + Outpatient/CAN_PQ_Montreal.Intl.AP.716270_CWEC/os_report/deab93c7-d086-432d-bb90-33c8c4e1fab3-os-report.html + + + PrimarySchool/CAN_PQ_Montreal.Intl.AP.716270_CWEC/os_report/87f45397-5ef4-4df9-be41-d33c4b6d2fb7-os-report.html + + + QuickServiceRestaurant/CAN_PQ_Montreal.Intl.AP.716270_CWEC/ 0bc55858-a81b-4d07-9923-1d84e8a23194-os-report.html + + + RetailStandalone/CAN_PQ_Montreal.Intl.AP.716270_CWEC/os_report/a3643bcb-0eea-47d4-b6b9-253ed188ec0c-os-report.html + + + RetailStripmall/CAN_PQ_Montreal.Intl.AP.716270_CWEC/os_report/ebaf5a16-00af-49de-9672-6b373fc825be-os-report.html + + + SecondarySchool/CAN_PQ_Montreal.Intl.AP.716270_CWEC/os_report/3a4f105f-93ed-4b8b-9eb3-c8ca40c5de6e-os-report.html + + + SmallHotel/CAN_PQ_Montreal.Intl.AP.716270_CWEC/os_report/dff0a3fc-d9e5-4866-9e6a-dee9a0da60b2-os-report.html + + + SmallOffice/CAN_PQ_Montreal.Intl.AP.716270_CWEC/os_report/a9a3669d-beb8-4951-aa11-c27dbc61a344-os-report.html + + + Warehouse/CAN_PQ_Montreal.Intl.AP.716270_CWEC/os_report/569ec649-8017-4a3c-bd0a-337eba3ec488-os-report.html + + + diff --git a/data/usage/nrcan.xml b/data/usage/nrcan.xml index 5f160c9a..dfcbf90a 100644 --- a/data/usage/nrcan.xml +++ b/data/usage/nrcan.xml @@ -1,9 +1,5 @@ - - - NECB2020/data/space_types.json - NECB2015/data/schedules.json - - + NECB2020/data/space_types.json + NECB2015/data/schedules.json \ No newline at end of file diff --git a/imports/construction/helpers/construction_helper.py b/imports/construction/helpers/construction_helper.py index f29ba890..42709af7 100644 --- a/imports/construction/helpers/construction_helper.py +++ b/imports/construction/helpers/construction_helper.py @@ -23,6 +23,7 @@ class ConstructionHelper: cte.SMALL_OFFICE: 'small office', cte.MEDIUM_OFFICE: 'medium office', cte.LARGE_OFFICE: 'large office', + cte.EDUCATION: 'primary school', cte.PRIMARY_SCHOOL: 'primary school', cte.SECONDARY_SCHOOL: 'secondary school', cte.STAND_ALONE_RETAIL: 'stand-alone retail', diff --git a/imports/construction/nrcan_physics_parameters.py b/imports/construction/nrcan_physics_parameters.py new file mode 100644 index 00000000..258673db --- /dev/null +++ b/imports/construction/nrcan_physics_parameters.py @@ -0,0 +1,188 @@ +""" +NrcanPhysicsParameters import the construction and material information defined by NRCAN +SPDX - License - Identifier: LGPL - 3.0 - or -later +Copyright © 2022 Concordia CERC group +Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca +""" +import sys + +from catalog_factories.construction_catalog_factory import ConstructionCatalogFactory +from city_model_structure.building_demand.layer import Layer +from city_model_structure.building_demand.material import Material +from imports.construction.helpers.construction_helper import ConstructionHelper +from imports.construction.helpers.storeys_generation import StoreysGeneration + + +class NrcanPhysicsParameters: + """ + NrcanPhysicsParameters class + """ + def __init__(self, city, base_path, divide_in_storeys=False): + self._city = city + self._path = base_path + self._divide_in_storeys = divide_in_storeys + self._climate_zone = ConstructionHelper.city_to_nrel_climate_zone(city.name) + + def enrich_buildings(self): + """ + Returns the city with the construction parameters assigned to the buildings + """ + city = self._city + canel_catalog = ConstructionCatalogFactory('nrcan').catalog + for building in city.buildings: + try: + function = ConstructionHelper().nrel_from_libs_function(building.function) + archetype = self._search_archetype(canel_catalog, function, building.year_of_construction, + self._climate_zone) + except KeyError: + sys.stderr.write(f'Building {building.name} has unknown construction archetype for building function: ' + f'{building.function} and building year of construction: {building.year_of_construction} ' + f'and climate zone reference norm {self._climate_zone}\n') + return + + # if building has no thermal zones defined from geometry, and the building will be divided in storeys, + # one thermal zone per storey is assigned + if len(building.internal_zones) == 1: + if building.internal_zones[0].thermal_zones is None: + self._create_storeys(building, archetype, self._divide_in_storeys) + if self._divide_in_storeys: + for internal_zone in building.internal_zones: + for thermal_zone in internal_zone.thermal_zones: + thermal_zone.total_floor_area = thermal_zone.footprint_area + else: + number_of_storeys = int(float(building.eave_height) / float(building.average_storey_height)) + thermal_zone = building.internal_zones[0].thermal_zones[0] + thermal_zone.total_floor_area = thermal_zone.footprint_area * number_of_storeys + else: + for internal_zone in building.internal_zones: + for thermal_zone in internal_zone.thermal_zones: + thermal_zone.total_floor_area = thermal_zone.footprint_area + + for internal_zone in building.internal_zones: + self._assign_values(internal_zone.thermal_zones, archetype) + for thermal_zone in internal_zone.thermal_zones: + self._calculate_view_factors(thermal_zone) + + @staticmethod + def _search_archetype(nrel_catalog, function, year_of_construction, climate_zone): + nrel_archetypes = nrel_catalog.entries('archetypes') + for building_archetype in nrel_archetypes: + construction_period_limits = building_archetype.construction_period.split(' - ') + if construction_period_limits[1] == 'PRESENT': + construction_period_limits[1] = 3000 + if int(construction_period_limits[0]) <= int(year_of_construction) < int(construction_period_limits[1]): + if (str(function) == str(building_archetype.function)) and \ + (climate_zone == str(building_archetype.climate_zone)): + return building_archetype + raise KeyError('archetype not found') + + @staticmethod + def _search_construction_in_archetype(archetype, construction_type): + construction_archetypes = archetype.constructions + for construction_archetype in construction_archetypes: + if str(construction_type) == str(construction_archetype.type): + return construction_archetype + return None + + def _assign_values(self, thermal_zones, archetype): + for thermal_zone in thermal_zones: + thermal_zone.additional_thermal_bridge_u_value = archetype.extra_loses_due_to_thermal_bridges + thermal_zone.effective_thermal_capacity = archetype.thermal_capacity + thermal_zone.indirectly_heated_area_ratio = archetype.indirect_heated_ratio + thermal_zone.infiltration_rate_system_on = archetype.infiltration_rate_for_ventilation_system_on + thermal_zone.infiltration_rate_system_off = archetype.infiltration_rate_for_ventilation_system_off + for thermal_boundary in thermal_zone.thermal_boundaries: + construction_archetype = self._search_construction_in_archetype(archetype, thermal_boundary.type) + thermal_boundary.construction_name = construction_archetype.name + try: + thermal_boundary.window_ratio = construction_archetype.window_ratio + except ValueError: + # This is the normal operation way when the windows are defined in the geometry + continue + thermal_boundary.layers = [] + for layer_archetype in construction_archetype.layers: + layer = Layer() + layer.thickness = layer_archetype.thickness + material = Material() + archetype_material = layer_archetype.material + material.name = archetype_material.name + material.id = archetype_material.id + material.no_mass = archetype_material.no_mass + if archetype_material.no_mass: + material.thermal_resistance = archetype_material.thermal_resistance + else: + material.density = archetype_material.density + material.conductivity = archetype_material.conductivity + material.specific_heat = archetype_material.specific_heat + material.solar_absorptance = archetype_material.solar_absorptance + material.thermal_absorptance = archetype_material.thermal_absorptance + material.visible_absorptance = archetype_material.visible_absorptance + layer.material = material + thermal_boundary.layers.append(layer) + # The agreement is that the layers are defined from outside to inside + external_layer = construction_archetype.layers[0] + external_surface = thermal_boundary.parent_surface + external_surface.short_wave_reflectance = 1 - float(external_layer.material.solar_absorptance) + external_surface.long_wave_emittance = 1 - float(external_layer.material.solar_absorptance) + internal_layer = construction_archetype.layers[len(construction_archetype.layers) - 1] + internal_surface = thermal_boundary.internal_surface + internal_surface.short_wave_reflectance = 1 - float(internal_layer.material.solar_absorptance) + internal_surface.long_wave_emittance = 1 - float(internal_layer.material.solar_absorptance) + + for thermal_opening in thermal_boundary.thermal_openings: + if construction_archetype.window is not None: + window_archetype = construction_archetype.window + thermal_opening.construction_name = window_archetype.name + thermal_opening.frame_ratio = window_archetype.frame_ratio + thermal_opening.g_value = window_archetype.g_value + thermal_opening.overall_u_value = window_archetype.overall_u_value + + # todo: verify windows + @staticmethod + def _calculate_view_factors(thermal_zone): + """ + Get thermal zone view factors matrix + :return: [[float]] + """ + total_area = 0 + for thermal_boundary in thermal_zone.thermal_boundaries: + total_area += thermal_boundary.opaque_area + for thermal_opening in thermal_boundary.thermal_openings: + total_area += thermal_opening.area + + view_factors_matrix = [] + for thermal_boundary_1 in thermal_zone.thermal_boundaries: + values = [] + for thermal_boundary_2 in thermal_zone.thermal_boundaries: + value = 0 + if thermal_boundary_1.id != thermal_boundary_2.id: + value = thermal_boundary_2.opaque_area / (total_area - thermal_boundary_1.opaque_area) + values.append(value) + for thermal_boundary in thermal_zone.thermal_boundaries: + for thermal_opening in thermal_boundary.thermal_openings: + value = thermal_opening.area / (total_area - thermal_boundary_1.opaque_area) + values.append(value) + view_factors_matrix.append(values) + + for thermal_boundary_1 in thermal_zone.thermal_boundaries: + values = [] + for thermal_opening_1 in thermal_boundary_1.thermal_openings: + for thermal_boundary_2 in thermal_zone.thermal_boundaries: + value = thermal_boundary_2.opaque_area / (total_area - thermal_opening_1.area) + values.append(value) + for thermal_boundary in thermal_zone.thermal_boundaries: + for thermal_opening_2 in thermal_boundary.thermal_openings: + value = 0 + if thermal_opening_1.id != thermal_opening_2.id: + value = thermal_opening_2.area / (total_area - thermal_opening_1.area) + values.append(value) + view_factors_matrix.append(values) + thermal_zone.view_factors_matrix = view_factors_matrix + + @staticmethod + def _create_storeys(building, archetype, divide_in_storeys): + building.average_storey_height = archetype.average_storey_height + building.storeys_above_ground = 1 + thermal_zones = StoreysGeneration(building, building.internal_zones[0], + divide_in_storeys=divide_in_storeys).thermal_zones + building.internal_zones[0].thermal_zones = thermal_zones diff --git a/imports/construction/nrel_physics_parameters.py b/imports/construction/nrel_physics_parameters.py index 20576519..2ed1c097 100644 --- a/imports/construction/nrel_physics_parameters.py +++ b/imports/construction/nrel_physics_parameters.py @@ -32,7 +32,8 @@ class NrelPhysicsParameters: nrel_catalog = ConstructionCatalogFactory('nrel').catalog for building in city.buildings: try: - archetype = self._search_archetype(nrel_catalog, building.function, building.year_of_construction, + function = ConstructionHelper().nrel_from_libs_function(building.function) + archetype = self._search_archetype(nrel_catalog, function, building.year_of_construction, self._climate_zone) except KeyError: sys.stderr.write(f'Building {building.name} has unknown construction archetype for building function: ' diff --git a/imports/construction_factory.py b/imports/construction_factory.py index acf35988..4bf1110f 100644 --- a/imports/construction_factory.py +++ b/imports/construction_factory.py @@ -3,14 +3,17 @@ ConstructionFactory (before PhysicsFactory) retrieve the specific construction m SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2022 Concordia CERC group Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca +Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ + from pathlib import Path from imports.construction.nrel_physics_parameters import NrelPhysicsParameters +from imports.construction.nrcan_physics_parameters import NrcanPhysicsParameters class ConstructionFactory: """ - PhysicsFactor class + ConstructionFactory class """ def __init__(self, handler, city, base_path=None): if base_path is None: @@ -26,6 +29,13 @@ class ConstructionFactory: NrelPhysicsParameters(self._city, self._base_path).enrich_buildings() self._city.level_of_detail.construction = 2 + def _nrcan(self): + """ + Enrich the city by using NRCAN information + """ + NrcanPhysicsParameters(self._city, self._base_path).enrich_buildings() + self._city.level_of_detail.construction = 2 + def enrich(self): """ Enrich the city given to the class using the class given handler diff --git a/imports/usage/comnet_usage_parameters.py b/imports/usage/comnet_usage_parameters.py index c84e9c32..b5bfb8cc 100644 --- a/imports/usage/comnet_usage_parameters.py +++ b/imports/usage/comnet_usage_parameters.py @@ -120,6 +120,31 @@ class ComnetUsageParameters: usage_zone.hours_day = total / 365 usage_zone.days_year = 365 + max_heating_setpoint = cte.MIN_FLOAT + min_heating_setpoint = cte.MAX_FLOAT + + for schedule in archetype.thermal_control.heating_set_point_schedules: + if schedule.values is None: + max_heating_setpoint = None + min_heating_setpoint = None + break + if max(schedule.values) > max_heating_setpoint: + max_heating_setpoint = max(schedule.values) + if min(schedule.values) < min_heating_setpoint: + min_heating_setpoint = min(schedule.values) + + min_cooling_setpoint = cte.MAX_FLOAT + for schedule in archetype.thermal_control.cooling_set_point_schedules: + if schedule.values is None: + min_cooling_setpoint = None + break + if min(schedule.values) < min_cooling_setpoint: + min_cooling_setpoint = min(schedule.values) + + usage_zone.thermal_control.mean_heating_set_point = max_heating_setpoint + usage_zone.thermal_control.heating_set_back = min_heating_setpoint + usage_zone.thermal_control.mean_cooling_set_point = min_cooling_setpoint + @staticmethod def _calculate_internal_gains(archetype): diff --git a/imports/usage/helpers/usage_helper.py b/imports/usage/helpers/usage_helper.py index b1ae610a..eece9580 100644 --- a/imports/usage/helpers/usage_helper.py +++ b/imports/usage/helpers/usage_helper.py @@ -131,9 +131,9 @@ class UsageHelper: 'done changing the keywords.\n') _usage_to_nrcan = { - cte.RESIDENTIAL: 'Multi-unit residential', - cte.SINGLE_FAMILY_HOUSE: 'Multi-unit residential', - cte.MULTI_FAMILY_HOUSE: 'Multi-unit residential', + cte.RESIDENTIAL: 'Multi-unit residential building', + cte.SINGLE_FAMILY_HOUSE: 'Multi-unit residential building', + cte.MULTI_FAMILY_HOUSE: 'Multi-unit residential building', cte.EDUCATION: 'School/university', cte.SCHOOL_WITHOUT_SHOWER: 'School/university', cte.SCHOOL_WITH_SHOWER: 'School/university', @@ -145,7 +145,7 @@ class UsageHelper: cte.INDUSTRY: 'Manufacturing Facility', cte.RESTAURANT: 'Dining - family', cte.HEALTH_CARE: 'Hospital', - cte.RETIREMENT_HOME_OR_ORPHANAGE: 'Multi-unit residential', + cte.RETIREMENT_HOME_OR_ORPHANAGE: 'Multi-unit residential building', cte.OFFICE_AND_ADMINISTRATION: 'Office', cte.EVENT_LOCATION: 'Convention centre', cte.HALL: 'Convention centre', diff --git a/imports/usage/nrcan_usage_parameters.py b/imports/usage/nrcan_usage_parameters.py index ea2b1a4b..92acfb65 100644 --- a/imports/usage/nrcan_usage_parameters.py +++ b/imports/usage/nrcan_usage_parameters.py @@ -4,9 +4,8 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2022 Concordia CERC group Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ -import copy + import sys -import numpy import helpers.constants as cte from imports.usage.helpers.usage_helper import UsageHelper @@ -15,8 +14,6 @@ from city_model_structure.building_demand.lighting import Lighting from city_model_structure.building_demand.occupancy import Occupancy from city_model_structure.building_demand.appliances import Appliances from city_model_structure.building_demand.thermal_control import ThermalControl -from city_model_structure.attributes.schedule import Schedule -from city_model_structure.building_demand.internal_gain import InternalGain from catalog_factories.usage_catalog_factory import UsageCatalogFactory @@ -35,6 +32,7 @@ class NrcanUsageParameters: """ city = self._city nrcan_catalog = UsageCatalogFactory('nrcan').catalog + comnet_catalog = UsageCatalogFactory('comnet').catalog for building in city.buildings: usage_name = UsageHelper.nrcan_from_hub_usage(building.function) @@ -45,6 +43,14 @@ class NrcanUsageParameters: f' {building.function}') return + usage_name = UsageHelper.comnet_from_hub_usage(building.function) + try: + comnet_archetype_usage = self._search_archetypes(comnet_catalog, usage_name) + except KeyError: + sys.stderr.write(f'Building {building.name} has unknown usage archetype for building function:' + f' {building.function}') + return + for internal_zone in building.internal_zones: if internal_zone.area is None: raise Exception('Internal zone area not defined, ACH cannot be calculated') @@ -56,24 +62,22 @@ class NrcanUsageParameters: usage_zone = Usage() usage_zone.name = usage_name self._assign_values(usage_zone, archetype_usage, volume_per_area) + self._assign_comnet_extra_values(usage_zone, comnet_archetype_usage) usage_zone.percentage = 1 self._calculate_reduced_values_from_extended_library(usage_zone, archetype_usage) internal_zone.usages = [usage_zone] @staticmethod - def _search_archetypes(comnet_catalog, usage_name): - comnet_archetypes = comnet_catalog.entries('archetypes').usages - for building_archetype in comnet_archetypes: + def _search_archetypes(catalog, usage_name): + archetypes = catalog.entries('archetypes').usages + for building_archetype in archetypes: if str(usage_name) == str(building_archetype.name): return building_archetype raise KeyError('archetype not found') @staticmethod def _assign_values(usage_zone, archetype, volume_per_area): - # Due to the fact that python is not a typed language, the wrong object type is assigned to - # usage_zone.occupancy when writing usage_zone.occupancy = archetype.occupancy. - # Same happens for lighting and appliances. Therefore, this walk around has been done. if archetype.mechanical_air_change > 0: usage_zone.mechanical_air_change = archetype.mechanical_air_change elif archetype.ventilation_rate > 0: @@ -86,7 +90,7 @@ class NrcanUsageParameters: _occupancy.sensible_radiative_internal_gain = archetype.occupancy.sensible_radiative_internal_gain _occupancy.latent_internal_gain = archetype.occupancy.latent_internal_gain _occupancy.sensible_convective_internal_gain = archetype.occupancy.sensible_convective_internal_gain - _occupancy.occupancy_schedules = archetype.occupancy.occupancy_schedules + _occupancy.occupancy_schedules = archetype.occupancy.schedules usage_zone.occupancy = _occupancy _lighting = Lighting() _lighting.density = archetype.lighting.density @@ -108,6 +112,13 @@ class NrcanUsageParameters: _control.hvac_availability_schedules = archetype.thermal_control.hvac_availability_schedules usage_zone.thermal_control = _control + @staticmethod + def _assign_comnet_extra_values(usage_zone, archetype): + _occupancy = usage_zone.occupancy + _occupancy.sensible_radiative_internal_gain = archetype.occupancy.sensible_radiative_internal_gain + _occupancy.latent_internal_gain = archetype.occupancy.latent_internal_gain + _occupancy.sensible_convective_internal_gain = archetype.occupancy.sensible_convective_internal_gain + @staticmethod def _calculate_reduced_values_from_extended_library(usage_zone, archetype): number_of_days_per_type = {'WD': 251, 'Sat': 52, 'Sun': 62} @@ -126,66 +137,27 @@ class NrcanUsageParameters: usage_zone.hours_day = total / 365 usage_zone.days_year = 365 - @staticmethod - def _calculate_internal_gains(archetype): + max_heating_setpoint = cte.MIN_FLOAT + min_heating_setpoint = cte.MAX_FLOAT - _DAYS = [cte.MONDAY, cte.TUESDAY, cte.WEDNESDAY, cte.THURSDAY, cte.FRIDAY, cte.SATURDAY, cte.SUNDAY, cte.HOLIDAY] - _number_of_days_per_type = [51, 50, 50, 50, 50, 52, 52, 10] + for schedule in archetype.thermal_control.heating_set_point_schedules: + if schedule.values is None: + max_heating_setpoint = None + min_heating_setpoint = None + break + if max(schedule.values) > max_heating_setpoint: + max_heating_setpoint = max(schedule.values) + if min(schedule.values) < min_heating_setpoint: + min_heating_setpoint = min(schedule.values) - _mean_internal_gain = InternalGain() - _mean_internal_gain.type = 'mean_value_of_internal_gains' - _base_schedule = Schedule() - _base_schedule.type = cte.INTERNAL_GAINS - _base_schedule.time_range = cte.DAY - _base_schedule.time_step = cte.HOUR - _base_schedule.data_type = cte.FRACTION + min_cooling_setpoint = cte.MAX_FLOAT + for schedule in archetype.thermal_control.cooling_set_point_schedules: + if schedule.values is None: + min_cooling_setpoint = None + break + if min(schedule.values) < min_cooling_setpoint: + min_cooling_setpoint = min(schedule.values) - _latent_heat_gain = archetype.occupancy.latent_internal_gain - _convective_heat_gain = archetype.occupancy.sensible_convective_internal_gain - _radiative_heat_gain = archetype.occupancy.sensible_radiative_internal_gain - _total_heat_gain = (_latent_heat_gain + _convective_heat_gain + _radiative_heat_gain) - - _schedule_values = numpy.zeros([24, 8]) - _sum = 0 - for day, _schedule in enumerate(archetype.occupancy.schedules): - for v, value in enumerate(_schedule.values): - _schedule_values[v, day] = value * _total_heat_gain - _sum += value * _total_heat_gain * _number_of_days_per_type[day] - - _total_heat_gain += archetype.lighting.density + archetype.appliances.density - _latent_heat_gain += archetype.lighting.latent_fraction * archetype.lighting.density\ - + archetype.appliances.latent_fraction * archetype.appliances.density - _radiative_heat_gain = archetype.lighting.radiative_fraction * archetype.lighting.density \ - + archetype.appliances.radiative_fraction * archetype.appliances.density - _convective_heat_gain = archetype.lighting.convective_fraction * archetype.lighting.density \ - + archetype.appliances.convective_fraction * archetype.appliances.density - - for day, _schedule in enumerate(archetype.lighting.schedules): - for v, value in enumerate(_schedule.values): - _schedule_values[v, day] += value * archetype.lighting.density - _sum += value * archetype.lighting.density * _number_of_days_per_type[day] - - for day, _schedule in enumerate(archetype.appliances.schedules): - for v, value in enumerate(_schedule.values): - _schedule_values[v, day] += value * archetype.appliances.density - _sum += value * archetype.appliances.density * _number_of_days_per_type[day] - - _latent_fraction = _latent_heat_gain / _total_heat_gain - _radiative_fraction = _radiative_heat_gain / _total_heat_gain - _convective_fraction = _convective_heat_gain / _total_heat_gain - _average_internal_gain = _sum / _total_heat_gain - - _schedules = [] - for day in range(0, len(_DAYS)): - _schedule = copy.deepcopy(_base_schedule) - _schedule.day_types = [_DAYS[day]] - _schedule.values = _schedule_values[:day] - _schedules.append(_schedule) - - _mean_internal_gain.average_internal_gain = _average_internal_gain - _mean_internal_gain.latent_fraction = _latent_fraction - _mean_internal_gain.convective_fraction = _convective_fraction - _mean_internal_gain.radiative_fraction = _radiative_fraction - _mean_internal_gain.schedules = _schedules - - return [_mean_internal_gain] + usage_zone.thermal_control.mean_heating_set_point = max_heating_setpoint + usage_zone.thermal_control.heating_set_back = min_heating_setpoint + usage_zone.thermal_control.mean_cooling_set_point = min_cooling_setpoint diff --git a/unittests/test_enrichement.py b/unittests/test_enrichement.py index c63922f2..e9d3b9ca 100644 --- a/unittests/test_enrichement.py +++ b/unittests/test_enrichement.py @@ -86,11 +86,12 @@ class TestGeometryFactory(TestCase): elif input_key == 'hft': for building in city.buildings: building.function = GeometryHelper.libs_function_from_hft(building.function) + print(construction_key, usage_key) ConstructionFactory(construction_key, city).enrich() UsageFactory(usage_key, city).enrich() def _test_hft(self, file): - _construction_keys = ['nrel'] + _construction_keys = ['nrcan', 'nrel'] _usage_keys = ['comnet', 'nrcan'] for construction_key in _construction_keys: for usage_key in _usage_keys: @@ -121,7 +122,7 @@ class TestGeometryFactory(TestCase): def _test_pluto(self, file): _construction_keys = ['nrel'] - _usage_keys = ['comnet', 'hft'] + _usage_keys = ['comnet', 'nrcan'] for construction_key in _construction_keys: for usage_key in _usage_keys: # construction factory called first