hub/physics/physics_feeders/us_base_physics_parameters.py
pilar 0bdcf9b139 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	physics/physics_feeders/us_base_physics_parameters.py
2020-06-10 11:11:35 -04:00

114 lines
6.3 KiB
Python

"""
UsBasePhysicParameters, model the us archetypes and material, used by UsNewYorkCityPhysicsParameters and
UsPhysicsParameters as base class
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
"""
import xmltodict
from city_model_structure.layer import Layer
from city_model_structure.material import Material
from pathlib import Path
from physics.physics_feeders.helpers.us_to_library_types import UsToLibraryTypes
class UsBasePhysicsParameters:
def __init__(self, climate_zone, city_objects, function_to_type, base_path):
self._climate_zone = climate_zone
self._city_objects = city_objects
# load US Library
path = str(Path.cwd() / base_path / 'us_constructions.xml')
with open(path) as xml:
self._library = xmltodict.parse(xml.read(), force_list='layer')
# load US Archetypes
path = str(Path.cwd() / base_path / 'us_archetypes.xml')
with open(path) as xml:
self._archetypes = xmltodict.parse(xml.read(), force_list='layer')
for city_object in self._city_objects:
building_type = function_to_type(city_object.function)
if building_type is None:
return
archetype = self.search_archetype(building_type,
UsToLibraryTypes.yoc_to_standard(city_object.year_of_construction),
self._climate_zone)
# ToDo:remove this in the future
# ToDo: Raise WrongArchetype if not all the surface types are defined for the given city_object
if archetype is None:
print(building_type, UsToLibraryTypes.yoc_to_standard(city_object.year_of_construction),
self._climate_zone)
raise Exception('Archetype not found for building')
city_object.average_storey_height = archetype['average_storey_height']['#text']
city_object.storeys_above_ground = archetype['number_of_storeys']['#text']
for thermal_zone in city_object.thermal_zones:
thermal_zone.effective_thermal_capacity = archetype['thermal_capacity']['#text']
thermal_zone.additional_thermal_bridge_u_value = archetype['extra_loses_due_to_thermal_bridges']['#text']
thermal_zone.indirectly_heated_area_ratio = archetype['indirect_heated_ratio']['#text']
thermal_zone.infiltration_rate_system_off = archetype['infiltration_rate_for_ventilation_system_off']['#text']
thermal_zone.infiltration_rate_system_on = archetype['infiltration_rate_for_ventilation_system_on']['#text']
for thermal_boundary in thermal_zone.bounded:
construction_type = UsToLibraryTypes.construction_types[thermal_boundary.type]
construction = UsBasePhysicsParameters.search_construction_in_archetype(archetype, construction_type)
construction_id = construction['@id']
c_lib = self.search_construction_type('construction', construction_id)
if 'outside_solar_absorptance' in c_lib:
thermal_boundary.outside_solar_absorptance = c_lib['outside_solar_absorptance']['#text']
thermal_boundary.outside_thermal_absorptance = c_lib['outside_thermal_absorptance']['#text']
thermal_boundary.outside_visible_absorptance = c_lib['outside_visible_absorptance']['#text']
thermal_boundary.window_ratio = construction['window_ratio']['#text']
thermal_boundary.layers = []
for current_layer in c_lib['layers']['layer']:
layer = Layer()
if 'thickness' in current_layer:
layer.thickness = current_layer['thickness']['#text']
material_lib = self.search_construction_type('material', current_layer['material'])
material = Material()
if 'conductivity' in material_lib:
material.conductivity = material_lib['conductivity']['#text']
material.specific_heat = material_lib['specific_heat']['#text']
material.density = material_lib['density']['#text']
material.solar_absorptance = material_lib['solar_absorptance']['#text']
material.thermal_absorptance = material_lib['thermal_absorptance']['#text']
material.visible_absorptance = material_lib['visible_absorptance']['#text']
material.no_mass = 'no_mass' in material_lib
if 'thermal_resistance' in material_lib:
material.thermal_resistance = material_lib['thermal_resistance']['#text']
layer.material = material
thermal_boundary.layers.append(layer)
for opening in thermal_boundary.thermal_openings:
if construction['window'] is None:
continue
w_lib = self.search_construction_type('window', construction['window'])
opening.conductivity_w_mk = w_lib['conductivity']['#text']
opening.frame_ratio = w_lib['frame_ratio']['#text']
opening.g_value = w_lib['solar_transmittance_at_normal_incidence']['#text']
opening.thickness = w_lib['thickness']['#text']
opening.back_side_solar_transmittance_at_normal_incidence = \
w_lib['back_side_solar_transmittance_at_normal_incidence']['#text']
opening.front_side_solar_transmittance_at_normal_incidence = \
w_lib['front_side_solar_transmittance_at_normal_incidence']['#text']
def search_archetype(self, building_type, standard, climate_zone):
for archetype in self._archetypes['archetypes']['archetype']:
a_yc = str(archetype['@reference_standard'])
a_bt = str(archetype['@building_type'])
a_cz = str(archetype['@climate_zone'])
if (a_yc == str(standard)) and (a_bt == str(building_type)) and (a_cz == str(climate_zone)):
return archetype
return None
def search_construction_type(self, construction_type, construction_id):
for c_lib in self._library['library'][construction_type + 's'][construction_type]:
if construction_id == c_lib['@id']:
return c_lib
raise Exception('Archetype definition contains elements that does not exist in the library')
@staticmethod
def search_construction_in_archetype(archetype, construction_type):
for construction in archetype['constructions']['construction']:
if construction['@type'] == construction_type:
return construction
raise Exception('Construction type not found')