""" Peak loads calculation workflow SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2022 Concordia CERC group Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ from pathlib import Path import helpers.constants as cte from loads_calculation import LoadsCalculation class PeakLoads: def __init__(self, city, path, weather_format, irradiance_format): self._city = city self._path = path self._weather_format = weather_format self._irradiance_format = irradiance_format self._results = [] self._sanity_check() self._workflow() def _sanity_check(self): levels_of_detail = self._city.level_of_detail if levels_of_detail.geometry is None: raise Exception(f'Level of detail of geometry not assigned') if levels_of_detail.geometry < 1: raise Exception(f'Level of detail of geometry = {levels_of_detail.geometry}. Required minimum level 1') if levels_of_detail.construction is None: raise Exception(f'Level of detail of construction not assigned') if levels_of_detail.construction < 1: raise Exception(f'Level of detail of construction = {levels_of_detail.construction}. Required minimum level 1') if levels_of_detail.usage is None: raise Exception(f'Level of detail of usage not assigned') if levels_of_detail.usage < 1: raise Exception(f'Level of detail of usage = {levels_of_detail.usage}. Required minimum level 1') for building in self._city.buildings: if cte.HOUR not in building.external_temperature: raise Exception(f'Building {building.name} does not have external temperature assigned') for surface in building.surfaces: if surface.type != cte.GROUND: if cte.HOUR not in surface.global_irradiance: raise Exception(f'Building {building.name} does not have global irradiance on surfaces assigned') def _workflow(self): for building in self._city.buildings: ambient_temperature = building.external_temperature[cte.HOUR][self._weather_format] ground_temperature = 0 heating_ambient_temperature = 100 cooling_ambient_temperature = -100 heating_calculation_hour = -1 cooling_calculation_hour = -1 for hour, temperature in enumerate(ambient_temperature): ground_temperature += temperature / 8760 if temperature < heating_ambient_temperature: heating_ambient_temperature = temperature heating_calculation_hour = hour if temperature > cooling_ambient_temperature: cooling_ambient_temperature = temperature cooling_calculation_hour = hour loads = LoadsCalculation(building) heating_load_transmitted = loads.get_heating_transmitted_load(heating_ambient_temperature, ground_temperature) heating_load_ventilation_sensible = loads.get_heating_ventilation_load_sensible(heating_ambient_temperature) heating_load_ventilation_latent = 0 heating_load = heating_load_transmitted + heating_load_ventilation_sensible + heating_load_ventilation_latent cooling_load_transmitted = loads.get_cooling_transmitted_load(cooling_ambient_temperature, ground_temperature) cooling_load_renovation_sensible = loads.get_cooling_ventilation_load_sensible(cooling_ambient_temperature) cooling_load_internal_gains_sensible = loads.get_internal_load_sensible() cooling_load_radiation = loads.get_radiation_load(self._irradiance_format, cooling_calculation_hour) cooling_load_sensible = cooling_load_transmitted + cooling_load_renovation_sensible - cooling_load_radiation \ - cooling_load_internal_gains_sensible cooling_load_latent = 0 cooling_load = cooling_load_sensible + cooling_load_latent self._results.append([building.name, heating_load, cooling_load]) self._print_results() def _print_results(self): print_results = 'Peak loads in W' for results in self._results: print_results += '\n' print_results += f'{results[0]}, {results[1]}, {results[2]}\n' file = 'city name: ' + self._city.name + '\n' for building in self._city.buildings: file += '\n' file += 'name: ' + building.name + '\n' file += 'year of construction: ' + str(building.year_of_construction) + '\n' file += 'function: ' + building.function + '\n' file += 'floor area: ' + str(building.internal_zones[0].area) + '\n' file += 'storeys: ' + str(building.storeys_above_ground) + '\n' file += 'heated_volume: ' + str(0.85 * building.volume) + '\n' file += 'volume: ' + str(building.volume) + '\n' full_path_results = Path(self._path / 'peak_loads.csv').resolve() with open(full_path_results, 'w') as results_file: results_file.write(print_results) full_path_metadata = Path(self._path / 'metadata.csv').resolve() with open(full_path_metadata, 'w') as metadata_file: metadata_file.write(file)