city_retrofit/hub/imports/retrofit_factory.py
2024-09-19 21:10:26 -04:00

49 lines
2.5 KiB
Python

from hub.city_model_structure.building import Building
from hub.city_model_structure.city import City
import hub.helpers.constants as cte
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:
print("building", building.name)
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 and thermal_boundary.type == cte.WALL:
print("old_u_value", thermal_boundary.u_value)
self._change_thermal_resistance(thermal_boundary, wall_u_value)
thermal_boundary.u_value = wall_u_value
elif roof_u_value 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 and thermal_boundary.type == cte.GROUND:
self._change_thermal_resistance(thermal_boundary, ground_u_value)
thermal_boundary.u_value = ground_u_value
def _change_thermal_resistance(self, thermal_boundary, u_value):
old_u_value =thermal_boundary.u_value
new_u_value = u_value
if new_u_value < old_u_value:
delta_r = 1/(old_u_value - new_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:
pass
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.15, roof_u_value=0.08, ground_u_value=0.1)