""" Nrel-based interface, it reads format defined within the CERC team based on NREL structure and enriches the city with archetypes and materials SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Pilar Monsalvete pilar_monsalvete@yahoo.es """ import xmltodict from factories.physics_feeders.data_classes.nrel_building_achetype import NrelBuildingArchetype from factories.physics_feeders.data_classes.nrel_thermal_boundary_archetype import NrelThermalBoundaryArchetype from factories.physics_feeders.data_classes.nrel_thermal_opening_archetype import NrelThermalOpeningArchetype from factories.physics_feeders.data_classes.nrel_layer_archetype import NrelLayerArchetype class NrelPhysicsInterface: """ NrelPhysicsInterface abstract class """ def __init__(self, base_path, constructions_file='us_constructions.xml', archetypes_file='us_archetypes.xml'): self._building_archetypes = [] # load construction Library, CERC-NREL format path = str(base_path / constructions_file) with open(path) as xml: self._library = xmltodict.parse(xml.read(), force_list='layer') # load archetypes Library, CERC-NREL format path = str(base_path / archetypes_file) with open(path) as xml: self._archetypes = xmltodict.parse(xml.read(), force_list='layer') for archetype in self._archetypes['archetypes']['archetype']: archetype_keys = {} for key, value in archetype.items(): if key[0] == '@': archetype_keys[key] = value average_storey_height = archetype['average_storey_height']['#text'] storeys_above_ground = archetype['number_of_storeys']['#text'] effective_thermal_capacity = archetype['thermal_capacity']['#text'] additional_thermal_bridge_u_value = archetype['extra_loses_due_to_thermal_bridges']['#text'] indirectly_heated_area_ratio = archetype['indirect_heated_ratio']['#text'] infiltration_rate_system_off = archetype['infiltration_rate_for_ventilation_system_off']['#text'] infiltration_rate_system_on = archetype['infiltration_rate_for_ventilation_system_on']['#text'] thermal_boundary_archetypes = [] for construction in archetype['constructions']['construction']: construction_type = construction['@type'] construction_id = construction['@id'] c_lib = self._search_construction_type('construction', construction_id) construction_name = c_lib['@name'] layers = [] if 'layers' in c_lib: for current_layer in c_lib['layers']['layer']: material_lib = self._search_construction_type('material', current_layer['material']) name = material_lib['@name'] solar_absorptance = material_lib['solar_absorptance']['#text'] thermal_absorptance = material_lib['thermal_absorptance']['#text'] visible_absorptance = material_lib['visible_absorptance']['#text'] no_mass = 'no_mass' in material_lib if no_mass: thermal_resistance = material_lib['thermal_resistance']['#text'] layer = NrelLayerArchetype(name, solar_absorptance, thermal_absorptance, visible_absorptance, no_mass=no_mass, thermal_resistance=thermal_resistance) else: thickness = current_layer['thickness']['#text'] conductivity = material_lib['conductivity']['#text'] specific_heat = material_lib['specific_heat']['#text'] density = material_lib['density']['#text'] layer = NrelLayerArchetype(name, solar_absorptance, thermal_absorptance, visible_absorptance, thickness=thickness, conductivity=conductivity, specific_heat=specific_heat, density=density) layers.append(layer) thermal_opening = None window_ratio = 0 if 'window' in construction and construction['window'] is not None: window_ratio = construction['window_ratio']['#text'] w_lib = self._search_construction_type('window', construction['window']) frame_ratio = w_lib['frame_ratio']['#text'] if 'conductivity' in w_lib: conductivity = w_lib['conductivity']['#text'] thickness = w_lib['thickness']['#text'] g_value = w_lib['solar_transmittance_at_normal_incidence']['#text'] back_side_solar_transmittance_at_normal_incidence = \ w_lib['back_side_solar_transmittance_at_normal_incidence']['#text'] front_side_solar_transmittance_at_normal_incidence = \ w_lib['front_side_solar_transmittance_at_normal_incidence']['#text'] thermal_opening = NrelThermalOpeningArchetype(conductivity=conductivity, frame_ratio=frame_ratio, g_value=g_value, thickness=thickness, back_side_solar_transmittance_at_normal_incidence= back_side_solar_transmittance_at_normal_incidence, front_side_solar_transmittance_at_normal_incidence= front_side_solar_transmittance_at_normal_incidence) else: overall_u_value = w_lib['overall_u_value']['#text'] g_value = w_lib['g_value'] thermal_opening = NrelThermalOpeningArchetype(frame_ratio=frame_ratio, g_value=g_value, overall_u_value=overall_u_value) if 'outside_thermal_absorptance' in c_lib: outside_solar_absorptance = c_lib['outside_solar_absorptance']['#text'] outside_thermal_absorptance = c_lib['outside_thermal_absorptance']['#text'] outside_visible_absorptance = c_lib['outside_visible_absorptance']['#text'] thermal_boundary_archetype = NrelThermalBoundaryArchetype(construction_type, window_ratio, construction_name, layers, thermal_opening, outside_solar_absorptance, outside_thermal_absorptance, outside_visible_absorptance) else: if 'overall_u_value' in c_lib: overall_u_value = c_lib['overall_u_value']['#text'] outside_solar_absorptance = c_lib['outside_solar_absorptance']['#text'] thermal_boundary_archetype = NrelThermalBoundaryArchetype(construction_type, window_ratio, construction_name, layers, thermal_opening, outside_solar_absorptance= outside_solar_absorptance, overall_u_value=overall_u_value) else: thermal_boundary_archetype = NrelThermalBoundaryArchetype(construction_type, window_ratio, construction_name, layers, thermal_opening) thermal_boundary_archetypes.append(thermal_boundary_archetype) building_archetype = NrelBuildingArchetype(archetype_keys, average_storey_height, storeys_above_ground, effective_thermal_capacity, additional_thermal_bridge_u_value, indirectly_heated_area_ratio, infiltration_rate_system_off, infiltration_rate_system_on, thermal_boundary_archetypes) self._building_archetypes.append(building_archetype) 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(building_archetype, construction_type): for thermal_boundary in building_archetype.thermal_boundary_archetypes: if thermal_boundary.boundary_type == construction_type: return thermal_boundary raise Exception('Construction type not found') def fill_buildings(self): raise NotImplementedError def _search_archetype(self, keys): raise NotImplementedError def _assign_values(self, building, archetype): raise NotImplementedError