mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
427 lines
16 KiB
Python
427 lines
16 KiB
Python
import pint
|
|
import re
|
|
import itertools
|
|
|
|
from model_data.Property import Property
|
|
import pandas as pd
|
|
from copy import deepcopy
|
|
|
|
external_wall_insulation_parts = [
|
|
{
|
|
# Example product
|
|
# https://insulationgo.co.uk/100mm-rockwool-external-wall-insulation-dual-density-slabs-a1-non-combustible
|
|
# -slab-ewi-render-fire/
|
|
"type": "external_wall_insulation",
|
|
"description": "Mineral Wool External Wall Insulation",
|
|
"depths": [30, 50, 70, 80, 90, 100, 150, 200],
|
|
"depth_unit": "mm",
|
|
"cost": None,
|
|
"cost_unit": None,
|
|
"r_value_per_mm": 0.0278,
|
|
"r_value_unit": "square_meter_kelvin_per_watt",
|
|
"thermal_conductivity": 0.036,
|
|
"thermal_conductivity_unit": "watt_per_meter_kelvin"
|
|
},
|
|
{
|
|
# Example product
|
|
# https://www.insulationking.co.uk/products/polystyrene-eps70?variant=44156186558759
|
|
"type": "external_wall_insulation",
|
|
"description": "Expanded Polystyrene External Wall Insulation",
|
|
"depths": [25, 50, 100, 125],
|
|
"depth_unit": "mm",
|
|
"cost": None,
|
|
"cost_unit": None,
|
|
"r_value_per_mm": 0.02703,
|
|
"r_value_unit": "square_meter_kelvin_per_watt",
|
|
"thermal_conductivity": 0.037,
|
|
"thermal_conductivity_unit": "watt_per_meter_kelvin"
|
|
},
|
|
{
|
|
# Example product
|
|
# https://www.insulationshop.co/20mm_kooltherm_k5_external_wall_kingspan.html
|
|
"type": "external_wall_insulation",
|
|
"description": "Phenolic Foam External Wall Insulation",
|
|
"depths": [20, 50, 100],
|
|
"depth_unit": "mm",
|
|
"cost": None,
|
|
"cost_unit": None,
|
|
"r_value_per_mm": 0.043478260869565216,
|
|
"r_value_unit": "square_meter_kelvin_per_watt",
|
|
"thermal_conductivity": 0.023,
|
|
"thermal_conductivity_unit": "watt_per_meter_kelvin"
|
|
|
|
},
|
|
{
|
|
"type": "external_wall_insulation",
|
|
"description": "Polyisocyanurate/Polyurethane Foam External Wall Insulation",
|
|
"depths": [],
|
|
"depth_unit": "mm",
|
|
"cost": None,
|
|
"cost_unit": None,
|
|
"r_value_per_mm": None,
|
|
"r_value_unit": "square_meter_kelvin_per_watt",
|
|
"thermal_conductivity": None,
|
|
"thermal_conductivity_unit": "watt_per_meter_kelvin"
|
|
},
|
|
{
|
|
# Example product
|
|
# https://www.mikewye.co.uk/product/steico-duo-dry/
|
|
"type": "external_wall_insulation",
|
|
"description": "Wood Fiber External Wall Insulation",
|
|
"depths": [40, 60],
|
|
"depth_unit": "mm",
|
|
"cost": None,
|
|
"cost_unit": None,
|
|
"r_value_per_mm": 0.023255813953488375,
|
|
"r_value_unit": "square_meter_kelvin_per_watt",
|
|
"thermal_conductivity": 0.043,
|
|
"thermal_conductivity_unit": "watt_per_meter_kelvin"
|
|
},
|
|
{
|
|
# Example product
|
|
# https://www.thermablok.co.uk/site/wp-content/uploads/2022/09/Thermablok-Aerogel-Insulation-Blanket-TDS-AIS
|
|
# -and-Steel-Related-Details.pdf
|
|
"type": "external_wall_insulation",
|
|
"description": "Aerogel External Wall Insulation",
|
|
"depths": [10, 20, 30, 40, 50, 60, 70],
|
|
"depth_unit": "mm",
|
|
"cost": None,
|
|
"cost_unit": None,
|
|
"r_value_per_mm": 0.06666666666666667,
|
|
"r_value_unit": "square_meter_kelvin_per_watt",
|
|
"thermal_conductivity": 0.015,
|
|
"thermal_conductivity_unit": "watt_per_meter_kelvin"
|
|
},
|
|
{
|
|
"type": "external_wall_insulation",
|
|
"description": "Vacuum Insulation Panels External Wall Insulation",
|
|
"depths": [45, 60],
|
|
"depth_unit": "mm",
|
|
"cost": None,
|
|
"cost_unit": None,
|
|
"r_value_per_mm": 0.16666666666666666,
|
|
"r_value_unit": "square_meter_kelvin_per_watt",
|
|
"thermal_conductivity": 0.006,
|
|
"thermal_conductivity_unit": "watt_per_meter_kelvin"
|
|
}
|
|
]
|
|
|
|
internal_wall_insulation_parts = [
|
|
{
|
|
# Example product
|
|
# https://www.insulationshop.co/25mm_polystyrene_insulation_eps_70jablite.html
|
|
"type": "internal_wall_insulation",
|
|
"description": "Rigid Insulation Boards Internal Wall Insulation",
|
|
"depths": [25, 40, 50, 75, 100],
|
|
"depth_unit": "mm",
|
|
"cost": None,
|
|
"cost_unit": None,
|
|
"r_value_per_mm": 0.026315789473684213,
|
|
"r_value_unit": "square_meter_kelvin_per_watt",
|
|
"thermal_conductivity": 0.038,
|
|
"thermal_conductivity_unit": "watt_per_meter_kelvin"
|
|
},
|
|
{
|
|
# Example product
|
|
# https://www.rockwool.com/siteassets/rw-uk/downloads/datasheets/flexi.pdf
|
|
"type": "internal_wall_insulation",
|
|
"description": "Mineral Wool Internal Wall Insulation",
|
|
"depths": [140],
|
|
"depth_unit": "mm",
|
|
"cost": None,
|
|
"cost_unit": None,
|
|
"r_value_per_mm": 0.02857142857142857,
|
|
"r_value_unit": "square_meter_kelvin_per_watt",
|
|
"thermal_conductivity": 0.035,
|
|
"thermal_conductivity_unit": "watt_per_meter_kelvin"
|
|
},
|
|
{
|
|
# Example product
|
|
# https://www.kingspan.com/gb/en/products/insulation-boards/wall-insulation-boards/kooltherm-k118-insulated
|
|
# -plasterboard/
|
|
"type": "internal_wall_insulation",
|
|
"description": "Insulated Plasterboard Internal Wall Insulation",
|
|
"depths": [25, 80],
|
|
"depth_unit": "mm",
|
|
"cost": None,
|
|
"cost_unit": None,
|
|
"r_value_per_mm": 0.02857142857142857,
|
|
"r_value_unit": "square_meter_kelvin_per_watt",
|
|
"thermal_conductivity": 0.019,
|
|
"thermal_conductivity_unit": "watt_per_meter_kelvin"
|
|
},
|
|
{
|
|
"type": "internal_wall_insulation",
|
|
"description": "Reflective Internal Wall Insulation",
|
|
"depths": [],
|
|
"depth_unit": "mm",
|
|
"cost": None,
|
|
"cost_unit": None,
|
|
"r_value_per_mm": None,
|
|
"r_value_unit": "square_meter_kelvin_per_watt",
|
|
"thermal_conductivity": None,
|
|
"thermal_conductivity_unit": "watt_per_meter_kelvin"
|
|
},
|
|
{
|
|
# Example product
|
|
# https://www.insulationsuperstore.co.uk/product/vacutherm-vacupor-nt-b2-vacuum-insulated-panel-1m-x-600mm-x
|
|
# -30mm.html
|
|
"type": "internal_wall_insulation",
|
|
"description": "Vacuum Insulation Panels Wall Insulation",
|
|
"depths": [20, 30],
|
|
"depth_unit": "mm",
|
|
"cost": None,
|
|
"cost_unit": None,
|
|
"r_value_per_mm": 0.125,
|
|
"r_value_unit": "square_meter_kelvin_per_watt",
|
|
"thermal_conductivity": 0.008,
|
|
"thermal_conductivity_unit": "watt_per_meter_kelvin"
|
|
},
|
|
]
|
|
|
|
wall_parts = external_wall_insulation_parts + internal_wall_insulation_parts
|
|
|
|
|
|
class WallRecommendations:
|
|
YEAR_WALLS_BUILT_WITH_INSULATION = 1990
|
|
U_VALUE_UNIT = 'w/m-¦k'
|
|
BUILDING_REGULATIONS_PART_L_MAX_U_VALUE = 0.18
|
|
# Often cited minimum practical u-value
|
|
DIMINISHING_RETURNS_U_VALUE = 0.15
|
|
|
|
# Add some error so that if, for example, a new part we recommend provides a u-value of 0.19,
|
|
# we still consider it as an option
|
|
U_VALUE_ERROR = 0.01
|
|
|
|
DEFAULT_U_VALUES = {
|
|
"solid_brick": 2,
|
|
}
|
|
|
|
def __init__(self, property_instance: Property):
|
|
self.property = property_instance
|
|
self.year_built = self._year_property_was_built()
|
|
# TODO: Need to properly implement this
|
|
self.in_converation_area = False
|
|
|
|
# Will contains a list of recommended measures
|
|
self.recommendations = []
|
|
|
|
def _year_property_was_built(self):
|
|
"""
|
|
Estimates when the property was built based on as much available data as possible.
|
|
|
|
"""
|
|
|
|
if self.property.full_sap_epc:
|
|
return pd.to_datetime(self.property.full_sap_epc["lodgement-date"]).year
|
|
|
|
if self.property.data["construction-age-band"]:
|
|
# Take the lower limit. If we're pessimistic about the age of the property, that at least means we have
|
|
# more options for recommendations if that age falls before the year that insulation in walls became
|
|
# common practice
|
|
band = [int(x) for x in re.findall(r'\b\d{4}\b', self.property.data["construction-age-band"])]
|
|
return band[0]
|
|
|
|
raise NotImplementedError("Implement me!")
|
|
|
|
def recommend(self):
|
|
# if building built after 1990 + we're able to identify U-value +
|
|
# U-value less than 0.18 and if in or close to a conversation area,
|
|
# recommend internal wall insulation as a possible measure
|
|
|
|
u_value = self.property.walls["thermal_transmittance"]
|
|
|
|
is_cavity_wall = self.property.walls["is_cavity_wall"]
|
|
is_solid_brick = self.property.walls["is_solid_brick"]
|
|
insulation_thickness = self.property.walls["insulation_thickness"]
|
|
|
|
if u_value:
|
|
if self.property.walls["thermal_transmittance_unit"] != self.U_VALUE_UNIT:
|
|
raise NotImplementedError("Haven't handled the case of other u value units yet")
|
|
|
|
if (not is_cavity_wall) and (self.year_built >= self.YEAR_WALLS_BUILT_WITH_INSULATION) and (
|
|
u_value >= self.BUILDING_REGULATIONS_PART_L_MAX_U_VALUE
|
|
):
|
|
# Recommend internal wall insulation
|
|
iwi_parts = [part for part in wall_parts if part["type"] == "internal_wall_insulation"]
|
|
for part in iwi_parts:
|
|
_, new_u_value = self.calculate_u_value_uplift(u_value, part["u_value"])
|
|
new_u_value = round(new_u_value, 2)
|
|
|
|
# We allow a small tolerance for error so we don't discount the recommendation entirely
|
|
# if it's close, since this is an estimated new u-value
|
|
if new_u_value - self.U_VALUE_ERROR <= self.BUILDING_REGULATIONS_PART_L_MAX_U_VALUE:
|
|
self.recommendations.append(
|
|
{
|
|
**part, "new_u_value": new_u_value,
|
|
}
|
|
)
|
|
|
|
if is_solid_brick and insulation_thickness == "none":
|
|
|
|
# TODO: what if we recommend both internal and external wall insulation? Individually, they might not
|
|
# get the wall to the required u-value, but together they might. We need to handle this case
|
|
|
|
# This is an estimated figure based on industry standards
|
|
u_value = self.DEFAULT_U_VALUES["solid_brick"]
|
|
|
|
ewi_parts = [
|
|
part for part in wall_parts if part["type"] == "external_wall_insulation"
|
|
] if not self.in_converation_area else []
|
|
|
|
iwi_parts = [part for part in wall_parts if part["type"] == "internal_wall_insulation"]
|
|
|
|
# Recommend external and internal wall insulation separately
|
|
for part in ewi_parts + iwi_parts:
|
|
|
|
for depth in part["depths"]:
|
|
part_u_value = self.r_value_per_mm_to_u_value(depth, part["r_value_per_mm"])
|
|
|
|
_, new_u_value = self.calculate_u_value_uplift(u_value, part_u_value)
|
|
new_u_value = round(new_u_value, 2)
|
|
|
|
if new_u_value < self.DIMINISHING_RETURNS_U_VALUE:
|
|
# We don't recommend an overkill solution
|
|
continue
|
|
|
|
# We allow a small tolerance for error so we don't discount the recommendation entirely
|
|
# if it's close, since this is an estimated new u-value
|
|
if new_u_value - self.U_VALUE_ERROR <= self.BUILDING_REGULATIONS_PART_L_MAX_U_VALUE:
|
|
self.recommendations.append(
|
|
self._get_recommended_part(part, depth, new_u_value)
|
|
)
|
|
|
|
# We also can recommend both internal and external wall insulation together
|
|
for ewi_part in ewi_parts:
|
|
for iwi_part in iwi_parts:
|
|
for ewi_depth, iwi_depth in itertools.product(ewi_part["depths"], iwi_part["depths"]):
|
|
ewi_part_u_value = self.r_value_per_mm_to_u_value(ewi_depth, ewi_part["r_value_per_mm"])
|
|
iwi_part_u_value = self.r_value_per_mm_to_u_value(iwi_depth, iwi_part["r_value_per_mm"])
|
|
|
|
# First calculate the new U-value after applying external wall insulation
|
|
_, ewi_new_u_value = self.calculate_u_value_uplift(u_value, ewi_part_u_value)
|
|
# Then calculate the new U-value after applying internal wall insulation
|
|
_, combined_new_u_value = self.calculate_u_value_uplift(ewi_new_u_value, iwi_part_u_value)
|
|
combined_new_u_value = round(combined_new_u_value, 2)
|
|
|
|
if combined_new_u_value < self.DIMINISHING_RETURNS_U_VALUE:
|
|
# We don't recommend an overkill solution
|
|
continue
|
|
|
|
# Check if the combined new U-value meets the requirement
|
|
if combined_new_u_value - self.U_VALUE_ERROR <= self.BUILDING_REGULATIONS_PART_L_MAX_U_VALUE:
|
|
# Here you might want to define a way to add both recommendations together.
|
|
# For now, I'm adding them as separate items in the list
|
|
|
|
recommendation = [
|
|
self._get_recommended_part(ewi_part, ewi_depth, combined_new_u_value),
|
|
self._get_recommended_part(iwi_part, iwi_depth, combined_new_u_value)
|
|
]
|
|
self.recommendations.append(recommendation)
|
|
|
|
raise NotImplementedError("Not implemented yet")
|
|
|
|
@staticmethod
|
|
def _get_recommended_part(part, selected_depth, new_u_value):
|
|
"""
|
|
Utility function to return a recommended part with the selected depth.
|
|
:param part:
|
|
:param selected_depth:
|
|
:param new_u_value:
|
|
:return:
|
|
"""
|
|
recommended_part = deepcopy(part)
|
|
recommended_part["depths"] = [selected_depth]
|
|
|
|
return {
|
|
**recommended_part, "new_u_value": new_u_value,
|
|
}
|
|
|
|
@staticmethod
|
|
def calculate_u_value_uplift(u_value, insulation_u_value):
|
|
"""
|
|
Calculates the U-value uplift (improvement) when applying internal wall insulation to a wall.
|
|
|
|
|
|
:param u_value: Float, Starting U-value of the wall (without insulation) in W/m²K.
|
|
:param insulation_u_value: Float, U-value of the internal wall insulation in W/m²K.
|
|
|
|
Returns:
|
|
float: U-value uplift (improvement) achieved by applying internal wall insulation in W/m²K.
|
|
|
|
Raises:
|
|
ZeroDivisionError: If either u_value or iwi_u_value is zero.
|
|
|
|
Notes:
|
|
This function assumes 100% coverage of the internal wall insulation and does not account for other factors
|
|
such as thermal bridging or the specific configuration of the wall.
|
|
"""
|
|
|
|
inverse_u_value = 1 / u_value
|
|
inverse_insulation_u_value = 1 / insulation_u_value
|
|
|
|
inverse_u_total = inverse_u_value + inverse_insulation_u_value
|
|
new_u_value = 1 / inverse_u_total
|
|
|
|
u_value_uplift = u_value - new_u_value
|
|
|
|
return u_value_uplift, new_u_value
|
|
|
|
@staticmethod
|
|
def rvalue_per_mm(total_r_value: float, thickness_mm: float) -> float:
|
|
"""Return R-value per mm.
|
|
|
|
Parameters
|
|
----------
|
|
total_r_value : float
|
|
Total R-value (in m2K/W).
|
|
thickness_mm : float
|
|
Thickness of the material in mm.
|
|
|
|
Returns
|
|
-------
|
|
float
|
|
R-value per mm.
|
|
"""
|
|
return total_r_value / thickness_mm
|
|
|
|
@staticmethod
|
|
def r_value_per_mm_to_u_value(depth_mm: int, r_value_per_mm: float):
|
|
"""
|
|
Converts R-value per mm to U-value in W/m²K.
|
|
|
|
Parameters
|
|
----------
|
|
depth_mm : int
|
|
Depth of the material in mm.
|
|
r_value_per_mm : float
|
|
R-value per mm.
|
|
|
|
Returns
|
|
-------
|
|
float
|
|
U-value in W/m²K.
|
|
"""
|
|
return 1 / (depth_mm * r_value_per_mm)
|
|
|
|
@staticmethod
|
|
def thermal_conductivity_to_r_value_per_mm(thermal_conductivity: float) -> float:
|
|
"""Convert thermal conductivity to R-value per mm.
|
|
|
|
Parameters
|
|
----------
|
|
thermal_conductivity : float
|
|
Thermal conductivity (in W/mK).
|
|
|
|
Returns
|
|
-------
|
|
float
|
|
R-value per mm.
|
|
"""
|
|
# Calculate R-value in m²K/W for 1 meter of the material
|
|
r_value_per_meter = 1 / thermal_conductivity
|
|
|
|
# Convert R-value to R-value per mm
|
|
r_value_per_mm = r_value_per_meter / 1000
|
|
|
|
return r_value_per_mm
|