hub/imports/construction/ca_physics_parameters.py

83 lines
4.3 KiB
Python
Raw Normal View History

2021-01-05 15:01:36 -05:00
"""
CaPhysicsParameters import the construction and material information for Canada
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
2021-01-05 15:01:36 -05:00
"""
2021-01-07 17:33:55 -05:00
import sys
from imports.construction.helpers.construction_helper import ConstructionHelper
2021-08-26 13:27:43 -04:00
from imports.construction.nrel_physics_interface import NrelPhysicsInterface
2021-01-05 15:01:36 -05:00
2021-01-06 16:42:38 -05:00
class CaPhysicsParameters(NrelPhysicsInterface):
2021-01-05 15:01:36 -05:00
"""
CaPhysicsParameters class
"""
def __init__(self, city, base_path):
2021-01-06 16:42:38 -05:00
super().__init__(base_path, 'ca_constructions_reduced.xml', 'ca_archetypes_reduced.xml')
2021-01-05 15:01:36 -05:00
self._city = city
2021-01-06 16:42:38 -05:00
def enrich_buildings(self):
2021-01-06 16:42:38 -05:00
"""
Returns the city with the construction parameters assigned to the buildings
:return: None
2021-01-06 16:42:38 -05:00
"""
city = self._city
# it is assumed that all buildings have the same archetypes' keys
for building in city.buildings:
try:
archetype = self._search_archetype(ConstructionHelper.nrcan_from_libs_function(building.function),
building.year_of_construction)
except KeyError:
sys.stderr.write(f'Building {building.name} has unknown archetype for building function: '
f'{ConstructionHelper.nrcan_from_libs_function(building.function)} '
f'and building year of construction: {building.year_of_construction}\n')
return
2022-03-08 19:19:52 -05:00
# if building has no thermal zones defined from geometry, 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)
2022-03-08 19:19:52 -05:00
self._assign_values(building.internal_zones, archetype)
for internal_zone in building.internal_zones:
for thermal_zone in internal_zone.thermal_zones:
self._calculate_view_factors(thermal_zone)
2021-01-06 16:42:38 -05:00
def _search_archetype(self, function, year_of_construction):
2021-01-06 16:42:38 -05:00
for building_archetype in self._building_archetypes:
a_ft = str(building_archetype.archetype_keys['@function'])
a_pc = str(building_archetype.archetype_keys['@periodOfConstruction'])
2021-01-06 16:42:38 -05:00
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:
2021-01-06 16:42:38 -05:00
return building_archetype
return None
def _assign_values(self, internal_zones, archetype):
for internal_zone in internal_zones:
for thermal_zone in internal_zone.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.thermal_boundaries:
construction_type = ConstructionHelper.nrcan_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
try:
thermal_boundary.window_ratio = thermal_boundary_archetype.window_ratio
except ValueError:
# This is the normal operation way when the windows are defined in the geometry
continue
if thermal_boundary.thermal_openings is not None:
for thermal_opening in thermal_boundary.thermal_openings:
if thermal_boundary_archetype.thermal_opening_archetype is not None:
thermal_opening_archetype = thermal_boundary_archetype.thermal_opening_archetype
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