hub/imports/physics_feeders/ca_physics_parameters.py

68 lines
3.4 KiB
Python

"""
CaPhysicsParameters import the construction and material information for Canada
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Pilar Monsalvete pilar_monsalvete@yahoo.es
"""
import sys
from imports.physics_feeders.nrel_physics_interface import NrelPhysicsInterface
from imports.physics_feeders.helpers.ca_to_library_types import CaToLibraryTypes
class CaPhysicsParameters(NrelPhysicsInterface):
"""
CaPhysicsParameters class
"""
def __init__(self, city, base_path):
super().__init__(base_path, 'ca_constructions_reduced.xml', 'ca_archetypes_reduced.xml')
self._city = city
def enrich_buildings(self):
"""
Returns the city with the physics parameters assigned to the buildings
:return:
"""
city = self._city
# it is assumed that all buildings have the same archetypes' keys
for building in city.buildings:
archetype = self._search_archetype(building.function, building.year_of_construction)
if archetype is None:
sys.stderr.write(f'Building {building.name} has unknown archetype for building function: {building.function} '
f'and building year of construction: {building.year_of_construction}\n')
continue
self._assign_values(building, archetype)
def _search_archetype(self, function, year_of_construction):
for building_archetype in self._building_archetypes:
a_ft = str(building_archetype.archetype_keys['@function'])
a_pc = str(building_archetype.archetype_keys['@periodOfConstruction'])
a_yc1 = int(a_pc.split(sep='-')[0])
a_yc2 = int(a_pc.split(sep='-')[1])
if a_ft == str(function):
if a_yc1 <= int(year_of_construction) <= a_yc2:
return building_archetype
return None
def _assign_values(self, building, archetype):
building.average_storey_height = archetype.average_storey_height
building.storeys_above_ground = archetype.storeys_above_ground
for thermal_zone in building.thermal_zones:
thermal_zone.additional_thermal_bridge_u_value = archetype.additional_thermal_bridge_u_value
thermal_zone.effective_thermal_capacity = archetype.effective_thermal_capacity
thermal_zone.indirectly_heated_area_ratio = archetype.indirectly_heated_area_ratio
thermal_zone.infiltration_rate_system_on = archetype.infiltration_rate_system_on
thermal_zone.infiltration_rate_system_off = archetype.infiltration_rate_system_off
for thermal_boundary in thermal_zone.bounded:
construction_type = CaToLibraryTypes.construction_types[thermal_boundary.type]
thermal_boundary_archetype = self._search_construction_in_archetype(archetype, construction_type)
thermal_boundary.u_value = thermal_boundary_archetype.overall_u_value
thermal_boundary.outside_solar_absorptance = thermal_boundary_archetype.outside_solar_absorptance
thermal_boundary.construction_name = thermal_boundary_archetype.construction_name
thermal_boundary.window_ratio = thermal_boundary_archetype.window_ratio
for thermal_opening in thermal_boundary.thermal_openings:
if thermal_boundary_archetype.thermal_opening is not None:
thermal_opening_archetype = thermal_boundary_archetype.thermal_opening
thermal_opening.frame_ratio = thermal_opening_archetype.frame_ratio
thermal_opening.g_value = thermal_opening_archetype.g_value
thermal_opening.overall_u_value = thermal_opening_archetype.overall_u_value