from hub.city_model_structure.building import Building from hub.city_model_structure.city import City import hub.helpers.constants as cte import copy class RetrofitFactory: def __init__(self, retrofit_type, city): self._retrofit_type = retrofit_type self._city = city def apply_retrofit(self, wall_u_value=None, roof_u_value=None, ground_u_value=None): for building in self._city.buildings: self._apply_retrofit_to_building(building, wall_u_value, roof_u_value, ground_u_value) def _apply_retrofit_to_building(self, building: Building, wall_u_value, roof_u_value, ground_u_value): for thermal_zone in building.thermal_zones_from_internal_zones: for thermal_boundary in thermal_zone.thermal_boundaries: if wall_u_value is not None and thermal_boundary.type == cte.WALL and thermal_boundary.u_value > wall_u_value: self._change_thermal_resistance(thermal_boundary, wall_u_value) print("u_value",thermal_boundary.u_value) thermal_boundary.u_value = wall_u_value elif roof_u_value is not None and thermal_boundary.type == cte.ROOF: self._change_thermal_resistance(thermal_boundary, roof_u_value) thermal_boundary.u_value = roof_u_value elif ground_u_value is not None and thermal_boundary.type == cte.GROUND: self._change_thermal_resistance(thermal_boundary, ground_u_value) thermal_boundary.u_value = ground_u_value print("thermal_boundary.u_value",thermal_boundary.u_value, thermal_boundary.type) def _change_thermal_resistance(self, thermal_boundary, new_u_value): old_u_value = thermal_boundary.u_value new_u_value = new_u_value if new_u_value < old_u_value: delta_r = (1 / new_u_value) - (1 / old_u_value) for layer in thermal_boundary.layers: if "virtual_no_mass" in layer.material_name.lower(): new_thermal_resistance = layer.thermal_resistance + delta_r layer.thermal_resistance = new_thermal_resistance else: print("New U-value:", new_u_value, "is not less than old U-value:", old_u_value, "for thermal boundary type:", thermal_boundary.type) def enrich(self): # This method can be expanded to include different retrofit strategies if self._retrofit_type == 'basic': self.apply_retrofit(wall_u_value=0.247, roof_u_value=0.138, ground_u_value=0.156) elif self._retrofit_type == 'advanced': self.apply_retrofit(wall_u_value=0.11, roof_u_value=0.08, ground_u_value=0.1)