From 323d3577bd9d7f7eea50479739e7f901f79d65ec Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Fri, 22 May 2026 21:35:47 +0000 Subject: [PATCH] Cohort residual slice 16b: LINE_31 gable_wall fix + 000477 door cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calculator fix in heat_transmission.py: Detailed §3.10 RR gable_wall surfaces are routed to `party` at U=0.25 per Table 4, so their area sits on worksheet line (32) — NOT on (26)-(30). The slice 13 loop summed every detailed surface (including gable_wall) into `rr_detailed_area`, overcounting LINE_31 by Σ A_gable and inflating (36) thermal bridging by `y × A_gable`. Pinned by a new unit test `test_room_in_roof_detailed_gable_wall_ excluded_from_line_31_external_area` — synthetic dwelling with one RR detailed surface of each kind asserts LINE_31 matches the worksheet's (26)-(30) sum, excluding the gable_wall area. 000477 fixture cleanup (cohort consistency per [[feedback-no-misleading-insulation-type]]): - door_count 1 → 2. Worksheet line 42 lodges total door area 3.70 m² = 2 × _DEFAULT_DOOR_AREA_M2 (1.85). "Doors uninsulated 1" in the worksheet is a single entry but the area resolves to 2 physical doors (front + back, typical mid-terrace). The slice-14 door_count=1 closure was a workaround that masked the gable_wall LINE_31 bug — now closed properly. - `insulation_type="mineral_wool"` stripped from the 2 uninsulated slope panels. Per the no-misleading-insulation convention, uninsulated surfaces (thickness=0) leave `insulation_type` unset. Impact (e2e): 000477 SAP integer 65 = PDF (Δ=0 maintained); continuous 64.526 vs PDF 65.005 = 0.479 (within the existing <=0.5 ceiling, tightens in S19). The two corrections (door_count +5.55 W/K, bridging fix −2.27 W/K) nearly cancel; the residual ~0.9 W/K LINE_33 undershoot is the per-window mixed-U-value lodgement gap (Ticket 3 windows). Remaining for 000480 closure (separate ticket): §3 LINE_33/LINE_37 now match PDF exactly (223.61 / 243.41 vs 223.62 / 243.42). But SAP=66 vs PDF=61 because downstream residuals — lighting kWh +165% (565 vs 213), hot_water kWh +38% (3345 vs 2424), main_heating fuel kWh +23% (15472 vs 12580) — cascade into a -13% total-fuel-cost gap that the prior gable_wall bug was masking. Investigation deferred to a new follow-up. Co-Authored-By: Claude Opus 4.7 --- .../domain/sap/worksheet/heat_transmission.py | 11 ++- .../tests/_elmhurst_worksheet_000477.py | 11 ++- .../worksheet/tests/test_heat_transmission.py | 75 +++++++++++++++++++ 3 files changed, 90 insertions(+), 7 deletions(-) diff --git a/packages/domain/src/domain/sap/worksheet/heat_transmission.py b/packages/domain/src/domain/sap/worksheet/heat_transmission.py index 43d6bef1..06abcde3 100644 --- a/packages/domain/src/domain/sap/worksheet/heat_transmission.py +++ b/packages/domain/src/domain/sap/worksheet/heat_transmission.py @@ -420,29 +420,32 @@ def heat_transmission_from_cert( for surf in rir.detailed_surfaces: kind = surf.kind area = surf.area_m2 - rr_detailed_area += area + # Only (26)-(30) elements contribute to the external area + # aggregate (LINE_31) — gable_wall sits on (32) alongside + # the regular party walls, so its area is bookkept under + # `party` and excluded from `rr_detailed_area`. if kind == "slope": + rr_detailed_area += area roof += area * u_rr_slope( country=country, age_band=rir.construction_age_band, insulation_thickness_mm=surf.insulation_thickness_mm, insulation_type=surf.insulation_type, ) elif kind == "flat_ceiling": + rr_detailed_area += area roof += area * u_rr_flat_ceiling( country=country, age_band=rir.construction_age_band, insulation_thickness_mm=surf.insulation_thickness_mm, insulation_type=surf.insulation_type, ) elif kind == "stud_wall": + rr_detailed_area += area roof += area * u_rr_stud_wall( country=country, age_band=rir.construction_age_band, insulation_thickness_mm=surf.insulation_thickness_mm, insulation_type=surf.insulation_type, ) elif kind == "gable_wall": - # Treated as party-style at U=0.25 per Table 4. Lines - # 196-197 of the U985 worksheet for 000477 confirm - # this — RR gable walls land under (32) with U=0.25. party += 0.25 * area floor += uf * floor_area_total party += upw * party_area diff --git a/packages/domain/src/domain/sap/worksheet/tests/_elmhurst_worksheet_000477.py b/packages/domain/src/domain/sap/worksheet/tests/_elmhurst_worksheet_000477.py index fc3d1290..7666ebd3 100644 --- a/packages/domain/src/domain/sap/worksheet/tests/_elmhurst_worksheet_000477.py +++ b/packages/domain/src/domain/sap/worksheet/tests/_elmhurst_worksheet_000477.py @@ -85,11 +85,11 @@ def build_epc() -> EpcPropertyData: ), SapRoomInRoofSurface( kind="slope", area_m2=5.71, - insulation_thickness_mm=0, insulation_type="mineral_wool", + insulation_thickness_mm=0, ), SapRoomInRoofSurface( kind="slope", area_m2=7.02, - insulation_thickness_mm=0, insulation_type="mineral_wool", + insulation_thickness_mm=0, ), SapRoomInRoofSurface(kind="gable_wall", area_m2=7.55), SapRoomInRoofSurface(kind="gable_wall", area_m2=7.55), @@ -106,7 +106,12 @@ def build_epc() -> EpcPropertyData: sap_building_parts=[main], habitable_rooms_count=4, heated_rooms_count=4, - door_count=1, # U985 line 42: single "Doors uninsulated" entry @ 3.70 + # 000477 line 42 lodges total door area 3.70 m² = 2 × _DEFAULT_DOOR_ + # AREA_M2 (1.85). Worksheet vocabulary calls it one "Doors + # uninsulated 1" entry but the area resolves to 2 physical doors + # (front + back, typical mid-terrace). U=3.0 (Table 26 age B + # uninsulated) × 3.70 m² = 11.10 W/K matches LINE_26 exactly. + door_count=2, percent_draughtproofed=100, low_energy_fixed_lighting_bulbs_count=SECTION_5_BULB_COUNT_LEL, sap_windows=list(SECTION_6_VERTICAL_WINDOWS), diff --git a/packages/domain/src/domain/sap/worksheet/tests/test_heat_transmission.py b/packages/domain/src/domain/sap/worksheet/tests/test_heat_transmission.py index 2aa26947..732e51d2 100644 --- a/packages/domain/src/domain/sap/worksheet/tests/test_heat_transmission.py +++ b/packages/domain/src/domain/sap/worksheet/tests/test_heat_transmission.py @@ -1530,3 +1530,78 @@ def test_room_in_roof_detailed_per_surface_lodgement_routes_each_to_correct_line assert result.roof_w_per_k == pytest.approx(expected_roof, abs=0.001) assert result.party_walls_w_per_k == pytest.approx(expected_party, abs=0.001) assert result.walls_w_per_k == pytest.approx(expected_walls, abs=0.001) + + +def test_room_in_roof_detailed_gable_wall_excluded_from_line_31_external_area() -> None: + """LINE_31 = Σ(26)-(30) net areas — the external-elements aggregate + that drives (36) thermal-bridging. Per the U985 worksheet, RR gable + walls sit on line (32) alongside party walls (Table 4 "as common + wall"), so their area must NOT contribute to LINE_31. Pre-fix the + detailed-RR loop summed every surface (including gable_wall) into + the external-area accumulator, overcounting LINE_31 by the gable + area and inflating (36) bridging by `y × A_gable`. + + Synthetic dwelling (mirrors the routing test above; LINE_31 is + now the assertion): + - 1 storey × 40 m², 24 m perim, 2.5 m height → gross_wall 60, + net_wall 60 (no openings). + - Roof = ground_floor − RR_floor = 40 − 10 = 30 m². + - Ground floor = 40 m². + - RR detailed surfaces: slope 10 + stud_wall 5 + flat_ceiling 8 + (on (30)) + gable_wall 7 (on (32)). + + Expected LINE_31 = net_wall 60 + roof 30 + floor 40 + windows 0 + + doors 0 + rr_external(slope+stud+flat) 23 + = 153 m². Pre-fix this would have been 153 + 7 + = 160 m² (gable double-counted). + """ + # Arrange + main = make_building_part( + identifier=BuildingPartIdentifier.MAIN, + construction_age_band="B", + wall_construction=4, + wall_insulation_type=4, + party_wall_construction=1, + roof_construction=4, + floor_dimensions=[ + make_floor_dimension( + total_floor_area_m2=40.0, room_height_m=2.5, + heat_loss_perimeter_m=24.0, party_wall_length_m=0.0, floor=0, + ), + ], + sap_room_in_roof=SapRoomInRoof( + floor_area=10.0, construction_age_band="B", + detailed_surfaces=[ + SapRoomInRoofSurface( + kind="slope", area_m2=10.0, + insulation_thickness_mm=100, insulation_type="mineral_wool", + ), + SapRoomInRoofSurface( + kind="stud_wall", area_m2=5.0, + insulation_thickness_mm=100, insulation_type="mineral_wool", + ), + SapRoomInRoofSurface( + kind="flat_ceiling", area_m2=8.0, + insulation_thickness_mm=200, insulation_type="mineral_wool", + ), + SapRoomInRoofSurface(kind="gable_wall", area_m2=7.0), + ], + ), + ) + epc = make_minimal_sap10_epc( + total_floor_area_m2=50.0, + habitable_rooms_count=3, + country_code="ENG", + sap_building_parts=[main], + ) + + # Act + result = heat_transmission_from_cert( + epc, window_total_area_m2=0.0, window_avg_u_value=None, door_count=0, + ) + + # Assert + expected_line_31 = 60.0 + 30.0 + 40.0 + 0.0 + 0.0 + (10.0 + 5.0 + 8.0) + assert result.total_external_element_area_m2 == pytest.approx( + expected_line_31, abs=0.001 + )