""" CaUsageParameters model the usage properties 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 imports.geometry.helpers.geometry_helper import GeometryHelper from imports.usage.hft_usage_interface import HftUsageInterface from imports.usage.helpers.usage_helper import UsageHelper from city_model_structure.building_demand.usage_zone import UsageZone from city_model_structure.building_demand.internal_gains import InternalGains 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 class CaUsageParameters(HftUsageInterface): """ CaUsageParameters class """ def __init__(self, city, base_path): super().__init__(base_path, 'ca_archetypes_reduced.xml') self._city = city def enrich_buildings(self): """ Returns the city with the usage parameters assigned to the buildings :return: """ city = self._city for building in city.buildings: usage = GeometryHelper().libs_usage_from_libs_function(building.function) try: archetype = self._search_archetype(usage) except KeyError: sys.stderr.write(f'Building {building.name} has unknown archetype for building function:' f' {building.function}\n') return for internal_zone in building.internal_zones: usage_zone = UsageZone() usage_zone.usage = building.function usage_zone.percentage = 1 self._assign_values_usage_zone(usage_zone, archetype) internal_zone.usage_zones = [usage_zone] def _search_archetype(self, libs_usage): building_usage = UsageHelper().hft_from_libs_usage(libs_usage) for building_archetype in self._usage_archetypes: if building_archetype.usage == building_usage: return building_archetype return None @staticmethod def _assign_values_usage_zone(usage_zone, archetype): # Due to the fact that python is not a typed language, the wrong object type is assigned to # usage_zone.internal_gains when writing usage_zone.internal_gains = archetype.internal_gains. # Therefore, this walk around has been done. usage_zone.mechanical_air_change = archetype.mechanical_air_change _occupancy = Occupancy() _occupancy.occupancy_density = archetype.occupancy.occupancy_density usage_zone.occupancy = _occupancy usage_zone.hours_day = archetype.hours_day usage_zone.days_year = archetype.days_year _appliances = Appliances() _appliances.appliances_density = archetype.appliances.appliances_density usage_zone.appliances = _appliances _control = ThermalControl() _control.mean_heating_set_point = archetype.thermal_control.mean_heating_set_point _control.heating_set_back = archetype.thermal_control.heating_set_back _control.mean_cooling_set_point = archetype.thermal_control.mean_cooling_set_point usage_zone.thermal_control = _control _internal_gains = [] for archetype_internal_gain in archetype.not_detailed_source_mean_annual_internal_gains: _internal_gain = InternalGains() _internal_gain.average_internal_gain = archetype_internal_gain.average_internal_gain _internal_gain.convective_fraction = archetype_internal_gain.convective_fraction _internal_gain.radiative_fraction = archetype_internal_gain.radiative_fraction _internal_gain.latent_fraction = archetype_internal_gain.latent_fraction _internal_gains.append(_internal_gain) usage_zone.not_detailed_source_mean_annual_internal_gains = _internal_gains