Spaces:
Sleeping
Sleeping
Update utils/cooling_load.py
Browse files- utils/cooling_load.py +50 -33
utils/cooling_load.py
CHANGED
|
@@ -29,7 +29,7 @@ class CoolingLoadCalculator:
|
|
| 29 |
self.hours = list(range(24))
|
| 30 |
self.valid_latitudes = ['24N', '36N', '48N']
|
| 31 |
self.valid_months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
|
| 32 |
-
self.valid_wall_groups = [
|
| 33 |
self.valid_roof_groups = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
|
| 34 |
|
| 35 |
def validate_latitude(self, latitude: Any) -> str:
|
|
@@ -382,21 +382,32 @@ class CoolingLoadCalculator:
|
|
| 382 |
logger.debug(f"calculate_wall_cooling_load: latitude={latitude}, month={month}, wall_group={wall.wall_group}, orientation={wall.orientation.value}")
|
| 383 |
|
| 384 |
# Validate wall_group
|
| 385 |
-
wall_group = str(wall.wall_group)
|
| 386 |
if wall_group not in self.valid_wall_groups:
|
| 387 |
-
|
| 388 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 400 |
|
| 401 |
load = wall.u_value * wall.area * cltd
|
| 402 |
logger.debug(f"Wall load: u_value={wall.u_value}, area={wall.area}, cltd={cltd}, load={load}")
|
|
@@ -440,15 +451,20 @@ class CoolingLoadCalculator:
|
|
| 440 |
logger.warning(f"Invalid roof group: {roof_group}. Defaulting to 'A'")
|
| 441 |
roof_group = 'A'
|
| 442 |
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
|
| 453 |
load = roof.u_value * roof.area * cltd
|
| 454 |
logger.debug(f"Roof load: u_value={roof.u_value}, area={roof.area}, cltd={cltd}, load={load}")
|
|
@@ -697,7 +713,7 @@ class CoolingLoadCalculator:
|
|
| 697 |
return {
|
| 698 |
'sensible': max(sensible_load, 0.0),
|
| 699 |
'latent': max(latent_load, 0.0),
|
| 700 |
-
'
|
| 701 |
}
|
| 702 |
|
| 703 |
except Exception as e:
|
|
@@ -839,7 +855,7 @@ if __name__ == "__main__":
|
|
| 839 |
orientation=Orientation.NORTH,
|
| 840 |
area=20.0,
|
| 841 |
u_value=0.5,
|
| 842 |
-
wall_group="1"
|
| 843 |
)],
|
| 844 |
'roofs': [Roof(
|
| 845 |
name="Main Roof",
|
|
@@ -889,18 +905,19 @@ if __name__ == "__main__":
|
|
| 889 |
|
| 890 |
building_volume = 300.0
|
| 891 |
|
| 892 |
-
# Test with multiple latitudes and
|
| 893 |
test_cases = [
|
| 894 |
-
{'latitude': '24N', 'month': 'Jul'},
|
| 895 |
-
{'latitude': '36N', 'month': 'Jul'},
|
| 896 |
-
{'latitude': '48N', 'month': 'Jan'},
|
| 897 |
-
{'latitude': '1_31.973N', 'month': 'Jul'}, #
|
| 898 |
-
{'latitude': 'invalid', 'month': 'invalid'} #
|
| 899 |
]
|
| 900 |
|
| 901 |
for case in test_cases:
|
| 902 |
outdoor_conditions['latitude'] = case['latitude']
|
| 903 |
outdoor_conditions['month'] = case['month']
|
|
|
|
| 904 |
try:
|
| 905 |
hourly_loads = calculator.calculate_hourly_cooling_loads(
|
| 906 |
building_components,
|
|
@@ -909,6 +926,6 @@ if __name__ == "__main__":
|
|
| 909 |
internal_loads,
|
| 910 |
building_volume
|
| 911 |
)
|
| 912 |
-
print(f"Success for latitude={case['latitude']}, month={case['month']}: Hourly Loads calculated")
|
| 913 |
except Exception as e:
|
| 914 |
-
print(f"Error for latitude={case['latitude']}, month={case['month']}: {str(e)}")
|
|
|
|
| 29 |
self.hours = list(range(24))
|
| 30 |
self.valid_latitudes = ['24N', '36N', '48N']
|
| 31 |
self.valid_months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
|
| 32 |
+
self.valid_wall_groups = ['A', 'B', 'C', 'D'] # Adjusted to common ASHRAE groups
|
| 33 |
self.valid_roof_groups = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
|
| 34 |
|
| 35 |
def validate_latitude(self, latitude: Any) -> str:
|
|
|
|
| 382 |
logger.debug(f"calculate_wall_cooling_load: latitude={latitude}, month={month}, wall_group={wall.wall_group}, orientation={wall.orientation.value}")
|
| 383 |
|
| 384 |
# Validate wall_group
|
| 385 |
+
wall_group = str(wall.wall_group).upper()
|
| 386 |
if wall_group not in self.valid_wall_groups:
|
| 387 |
+
# Map numeric groups to letters (e.g., '1' -> 'A')
|
| 388 |
+
numeric_map = {'1': 'A', '2': 'B', '3': 'C', '4': 'D'}
|
| 389 |
+
if wall_group in numeric_map:
|
| 390 |
+
wall_group = numeric_map[wall_group]
|
| 391 |
+
logger.info(f"Mapped wall_group {wall.wall_group} to {wall_group}")
|
| 392 |
+
else:
|
| 393 |
+
logger.warning(f"Invalid wall group: {wall_group}. Defaulting to 'A'")
|
| 394 |
+
wall_group = 'A'
|
| 395 |
|
| 396 |
+
try:
|
| 397 |
+
cltd = self.ashrae_tables.calculate_corrected_cltd_wall(
|
| 398 |
+
wall_group=wall_group,
|
| 399 |
+
orientation=wall.orientation.value,
|
| 400 |
+
hour=hour,
|
| 401 |
+
color='Dark',
|
| 402 |
+
month=month,
|
| 403 |
+
latitude=latitude,
|
| 404 |
+
indoor_temp=indoor_temp,
|
| 405 |
+
outdoor_temp=outdoor_temp
|
| 406 |
+
)
|
| 407 |
+
except Exception as e:
|
| 408 |
+
logger.error(f"calculate_corrected_cltd_wall failed for wall_group={wall_group}: {str(e)}")
|
| 409 |
+
logger.warning("Using default CLTD=10.0°C")
|
| 410 |
+
cltd = 10.0 # Conservative fallback
|
| 411 |
|
| 412 |
load = wall.u_value * wall.area * cltd
|
| 413 |
logger.debug(f"Wall load: u_value={wall.u_value}, area={wall.area}, cltd={cltd}, load={load}")
|
|
|
|
| 451 |
logger.warning(f"Invalid roof group: {roof_group}. Defaulting to 'A'")
|
| 452 |
roof_group = 'A'
|
| 453 |
|
| 454 |
+
try:
|
| 455 |
+
cltd = self.ashrae_tables.calculate_corrected_cltd_roof(
|
| 456 |
+
roof_group=roof_group,
|
| 457 |
+
hour=hour,
|
| 458 |
+
color='Dark',
|
| 459 |
+
month=month,
|
| 460 |
+
latitude=latitude,
|
| 461 |
+
indoor_temp=indoor_temp,
|
| 462 |
+
outdoor_temp=outdoor_temp
|
| 463 |
+
)
|
| 464 |
+
except Exception as e:
|
| 465 |
+
logger.error(f"calculate_corrected_cltd_roof failed for roof_group={roof_group}: {str(e)}")
|
| 466 |
+
logger.warning("Using default CLTD=10.0°C")
|
| 467 |
+
cltd = 10.0 # Conservative fallback
|
| 468 |
|
| 469 |
load = roof.u_value * roof.area * cltd
|
| 470 |
logger.debug(f"Roof load: u_value={roof.u_value}, area={roof.area}, cltd={cltd}, load={load}")
|
|
|
|
| 713 |
return {
|
| 714 |
'sensible': max(sensible_load, 0.0),
|
| 715 |
'latent': max(latent_load, 0.0),
|
| 716 |
+
EXAMtotal': max(sensible_load + latent_load, 0.0)
|
| 717 |
}
|
| 718 |
|
| 719 |
except Exception as e:
|
|
|
|
| 855 |
orientation=Orientation.NORTH,
|
| 856 |
area=20.0,
|
| 857 |
u_value=0.5,
|
| 858 |
+
wall_group="1" # Will be mapped to 'A'
|
| 859 |
)],
|
| 860 |
'roofs': [Roof(
|
| 861 |
name="Main Roof",
|
|
|
|
| 905 |
|
| 906 |
building_volume = 300.0
|
| 907 |
|
| 908 |
+
# Test with multiple latitudes, months, and wall groups
|
| 909 |
test_cases = [
|
| 910 |
+
{'latitude': '24N', 'month': 'Jul', 'wall_group': 'A'},
|
| 911 |
+
{'latitude': '36N', 'month': 'Jul', 'wall_group': 'B'},
|
| 912 |
+
{'latitude': '48N', 'month': 'Jan', 'wall_group': '1'}, # Should map to 'A'
|
| 913 |
+
{'latitude': '1_31.973N', 'month': 'Jul', 'wall_group': 'invalid'}, # Should default to 'A'
|
| 914 |
+
{'latitude': 'invalid', 'month': 'invalid', 'wall_group': '2'} # Should map to 'B'
|
| 915 |
]
|
| 916 |
|
| 917 |
for case in test_cases:
|
| 918 |
outdoor_conditions['latitude'] = case['latitude']
|
| 919 |
outdoor_conditions['month'] = case['month']
|
| 920 |
+
building_components['walls'][0].wall_group = case['wall_group']
|
| 921 |
try:
|
| 922 |
hourly_loads = calculator.calculate_hourly_cooling_loads(
|
| 923 |
building_components,
|
|
|
|
| 926 |
internal_loads,
|
| 927 |
building_volume
|
| 928 |
)
|
| 929 |
+
print(f"Success for latitude={case['latitude']}, month={case['month']}, wall_group={case['wall_group']}: Hourly Loads calculated")
|
| 930 |
except Exception as e:
|
| 931 |
+
print(f"Error for latitude={case['latitude']}, month={case['month']}, wall_group={case['wall_group']}: {str(e)}")
|