mabuseif commited on
Commit
f5a16fc
·
verified ·
1 Parent(s): 38e42ff

Update utils/cooling_load.py

Browse files
Files changed (1) hide show
  1. utils/cooling_load.py +140 -140
utils/cooling_load.py CHANGED
@@ -25,152 +25,152 @@ class CoolingLoadCalculator:
25
  self.hours = list(range(24))
26
 
27
  def calculate_hourly_cooling_loads(
28
- self,
29
- building_components: Dict[str, List[Any]],
30
- outdoor_conditions: Dict[str, Any],
31
- indoor_conditions: Dict[str, Any],
32
- internal_loads: Dict[str, Any],
33
- building_volume: float
34
- ) -> Dict[str, Any]:
35
- """
36
- Calculate hourly cooling loads for all components.
37
-
38
- Args:
39
- building_components: Dictionary of building components
40
- outdoor_conditions: Outdoor weather conditions
41
- indoor_conditions: Indoor design conditions
42
- internal_loads: Internal heat gains
43
- building_volume: Building volume in cubic meters
44
 
45
- Returns:
46
- Dictionary containing hourly cooling loads
47
- """
48
- hourly_loads = {
49
- 'walls': {h: 0.0 for h in range(1, 25)},
50
- 'roofs': {h: 0.0 for h in range(1, 25)},
51
- 'windows_conduction': {h: 0.0 for h in range(1, 25)},
52
- 'windows_solar': {h: 0.0 for h in range(1, 25)},
53
- 'doors': {h: 0.0 for h in range(1, 25)},
54
- 'people_sensible': {h: 0.0 for h in range(1, 25)},
55
- 'people_latent': {h: 0.0 for h in range(1, 25)},
56
- 'lights': {h: 0.0 for h in range(1, 25)},
57
- 'equipment_sensible': {h: 0.0 for h in range(1, 25)},
58
- 'equipment_latent': {h: 0.0 for h in range(1, 25)},
59
- 'infiltration_sensible': {h: 0.0 for h in range(1, 25)},
60
- 'infiltration_latent': {h: 0.0 for h in range(1, 25)},
61
- 'ventilation_sensible': {h: 0.0 for h in range(1, 25)},
62
- 'ventilation_latent': {h: 0.0 for h in range(1, 25)}
63
- }
64
-
65
- try:
66
- # Calculate loads for walls
67
- for wall in building_components.get('walls', []):
68
- for hour in range(24):
69
- load = self.calculate_wall_cooling_load(
70
- wall=wall,
71
- outdoor_temp=outdoor_conditions['temperature'],
72
- indoor_temp=indoor_conditions['temperature'],
73
- month=outdoor_conditions['month'],
74
- hour=hour,
75
- latitude=outdoor_conditions['latitude']
76
- )
77
- hourly_loads['walls'][hour + 1] += load
78
 
79
- # Calculate loads for roofs
80
- for roof in building_components.get('roofs', []):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  for hour in range(24):
82
- load = self.calculate_roof_cooling_load(
83
- roof=roof,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  outdoor_temp=outdoor_conditions['temperature'],
 
85
  indoor_temp=indoor_conditions['temperature'],
86
- month=outdoor_conditions['month'],
87
- hour=hour,
88
- latitude=outdoor_conditions['latitude']
89
  )
90
- hourly_loads['roofs'][hour + 1] += load
91
-
92
- # Calculate loads for windows
93
- for window in building_components.get('windows', []):
94
- for hour in range(24):
95
- load_dict = self.calculate_window_cooling_load(
96
- window=window,
97
  outdoor_temp=outdoor_conditions['temperature'],
 
98
  indoor_temp=indoor_conditions['temperature'],
99
- month=outdoor_conditions['month'],
100
- hour=hour,
101
- latitude=outdoor_conditions['latitude'],
102
- shading_coefficient=window.shading_coefficient
103
  )
104
- hourly_loads['windows_conduction'][hour + 1] += load_dict['conduction']
105
- hourly_loads['windows_solar'][hour + 1] += load_dict['solar']
106
 
107
- # Calculate loads for doors
108
- for door in building_components.get('doors', []):
109
- for hour in range(24):
110
- load = self.calculate_door_cooling_load(
111
- door=door,
112
- outdoor_temp=outdoor_conditions['temperature'],
113
- indoor_temp=indoor_conditions['temperature']
114
- )
115
- hourly_loads['doors'][hour + 1] += load
116
 
117
- # Calculate internal loads
118
- for hour in range(24):
119
- # People loads
120
- people_load = self.calculate_people_cooling_load(
121
- num_people=internal_loads['people']['number'],
122
- activity_level=internal_loads['people']['activity_level'],
123
- hour=hour
124
- )
125
- hourly_loads['people_sensible'][hour + 1] += people_load['sensible']
126
- hourly_loads['people_latent'][hour + 1] += people_load['latent']
127
-
128
- # Lighting loads
129
- lights_load = self.calculate_lights_cooling_load(
130
- power=internal_loads['lights']['power'],
131
- use_factor=internal_loads['lights']['use_factor'],
132
- special_allowance=internal_loads['lights']['special_allowance'],
133
- hour=hour
134
- )
135
- hourly_loads['lights'][hour + 1] += lights_load
136
-
137
- # Equipment loads
138
- equipment_load = self.calculate_equipment_cooling_load(
139
- power=internal_loads['equipment']['power'],
140
- use_factor=internal_loads['equipment']['use_factor'],
141
- radiation_factor=internal_loads['equipment']['radiation_factor'],
142
- hour=hour
143
- )
144
- hourly_loads['equipment_sensible'][hour + 1] += equipment_load['sensible']
145
- hourly_loads['equipment_latent'][hour + 1] += equipment_load['latent']
146
-
147
- # Infiltration loads
148
- infiltration_load = self.calculate_infiltration_cooling_load(
149
- flow_rate=internal_loads['infiltration']['flow_rate'],
150
- building_volume=building_volume,
151
- outdoor_temp=outdoor_conditions['temperature'],
152
- outdoor_rh=outdoor_conditions['relative_humidity'],
153
- indoor_temp=indoor_conditions['temperature'],
154
- indoor_rh=indoor_conditions['relative_humidity']
155
- )
156
- hourly_loads['infiltration_sensible'][hour + 1] += infiltration_load['sensible']
157
- hourly_loads['infiltration_latent'][hour + 1] += infiltration_load['latent']
158
-
159
- # Ventilation loads
160
- ventilation_load = self.calculate_ventilation_cooling_load(
161
- flow_rate=internal_loads['ventilation']['flow_rate'],
162
- outdoor_temp=outdoor_conditions['temperature'],
163
- outdoor_rh=outdoor_conditions['relative_humidity'],
164
- indoor_temp=indoor_conditions['temperature'],
165
- indoor_rh=indoor_conditions['relative_humidity']
166
- )
167
- hourly_loads['ventilation_sensible'][hour + 1] += ventilation_load['sensible']
168
- hourly_loads['ventilation_latent'][hour + 1] += ventilation_load['latent']
169
-
170
- return hourly_loads
171
-
172
- except Exception as e:
173
- raise Exception(f"Error in calculate_hourly_cooling_loads: {str(e)}")
174
 
175
  def calculate_design_cooling_load(self, hourly_loads: Dict[str, Any]) -> Dict[str, Any]:
176
  """
@@ -186,7 +186,7 @@ class CoolingLoadCalculator:
186
  design_loads = {}
187
  total_loads = []
188
 
189
- for hour in self.hours:
190
  total_load = sum([
191
  hourly_loads['walls'][hour],
192
  hourly_loads['roofs'][hour],
@@ -205,7 +205,7 @@ class CoolingLoadCalculator:
205
  ])
206
  total_loads.append(total_load)
207
 
208
- design_hour = self.hours[np.argmax(total_loads)]
209
 
210
  design_loads = {
211
  'design_hour': design_hour,
@@ -632,7 +632,7 @@ if __name__ == "__main__":
632
  orientation=Orientation.HORIZONTAL,
633
  area=100.0,
634
  u_value=0.3,
635
- roof_group="1"
636
  )],
637
  'windows': [Window(
638
  name="South Window",
@@ -656,7 +656,7 @@ if __name__ == "__main__":
656
  'relative_humidity': 50.0,
657
  'ground_temperature': 20.0,
658
  'month': 'Jul',
659
- 'latitude': '31.973N',
660
  'wind_speed': 4.0,
661
  'day_of_year': 204
662
  }
@@ -701,7 +701,7 @@ if __name__ == "__main__":
701
  hourly_loads = calculator.calculate_hourly_cooling_loads(
702
  building_components=building_components,
703
  outdoor_conditions=outdoor_conditions,
704
- indoor_conditions=indoor_conditions,
705
  internal_loads=internal_loads,
706
  building_volume=building_volume
707
  )
 
25
  self.hours = list(range(24))
26
 
27
  def calculate_hourly_cooling_loads(
28
+ self,
29
+ building_components: Dict[str, List[Any]],
30
+ outdoor_conditions: Dict[str, Any],
31
+ indoor_conditions: Dict[str, Any],
32
+ internal_loads: Dict[str, Any],
33
+ building_volume: float
34
+ ) -> Dict[str, Any]:
35
+ """
36
+ Calculate hourly cooling loads for all components.
 
 
 
 
 
 
 
37
 
38
+ Args:
39
+ building_components: Dictionary of building components
40
+ outdoor_conditions: Outdoor weather conditions
41
+ indoor_conditions: Indoor design conditions
42
+ internal_loads: Internal heat gains
43
+ building_volume: Building volume in cubic meters
44
+
45
+ Returns:
46
+ Dictionary containing hourly cooling loads
47
+ """
48
+ hourly_loads = {
49
+ 'walls': {h: 0.0 for h in range(1, 25)},
50
+ 'roofs': {h: 0.0 for h in range(1, 25)},
51
+ 'windows_conduction': {h: 0.0 for h in range(1, 25)},
52
+ 'windows_solar': {h: 0.0 for h in range(1, 25)},
53
+ 'doors': {h: 0.0 for h in range(1, 25)},
54
+ 'people_sensible': {h: 0.0 for h in range(1, 25)},
55
+ 'people_latent': {h: 0.0 for h in range(1, 25)},
56
+ 'lights': {h: 0.0 for h in range(1, 25)},
57
+ 'equipment_sensible': {h: 0.0 for h in range(1, 25)},
58
+ 'equipment_latent': {h: 0.0 for h in range(1, 25)},
59
+ 'infiltration_sensible': {h: 0.0 for h in range(1, 25)},
60
+ 'infiltration_latent': {h: 0.0 for h in range(1, 25)},
61
+ 'ventilation_sensible': {h: 0.0 for h in range(1, 25)},
62
+ 'ventilation_latent': {h: 0.0 for h in range(1, 25)}
63
+ }
 
 
 
 
 
 
 
64
 
65
+ try:
66
+ # Calculate loads for walls
67
+ for wall in building_components.get('walls', []):
68
+ for hour in range(24):
69
+ load = self.calculate_wall_cooling_load(
70
+ wall=wall,
71
+ outdoor_temp=outdoor_conditions['temperature'],
72
+ indoor_temp=indoor_conditions['temperature'],
73
+ month=outdoor_conditions['month'],
74
+ hour=hour,
75
+ latitude=outdoor_conditions['latitude']
76
+ )
77
+ hourly_loads['walls'][hour + 1] += load
78
+
79
+ # Calculate loads for roofs
80
+ for roof in building_components.get('roofs', []):
81
+ for hour in range(24):
82
+ load = self.calculate_roof_cooling_load(
83
+ roof=roof,
84
+ outdoor_temp=outdoor_conditions['temperature'],
85
+ indoor_temp=indoor_conditions['temperature'],
86
+ month=outdoor_conditions['month'],
87
+ hour=hour,
88
+ latitude=outdoor_conditions['latitude']
89
+ )
90
+ hourly_loads['roofs'][hour + 1] += load
91
+
92
+ # Calculate loads for windows
93
+ for window in building_components.get('windows', []):
94
+ for hour in range(24):
95
+ load_dict = self.calculate_window_cooling_load(
96
+ window=window,
97
+ outdoor_temp=outdoor_conditions['temperature'],
98
+ indoor_temp=indoor_conditions['temperature'],
99
+ month=outdoor_conditions['month'],
100
+ hour=hour,
101
+ latitude=outdoor_conditions['latitude'],
102
+ shading_coefficient=window.shading_coefficient
103
+ )
104
+ hourly_loads['windows_conduction'][hour + 1] += load_dict['conduction']
105
+ hourly_loads['windows_solar'][hour + 1] += load_dict['solar']
106
+
107
+ # Calculate loads for doors
108
+ for door in building_components.get('doors', []):
109
+ for hour in range(24):
110
+ load = self.calculate_door_cooling_load(
111
+ door=door,
112
+ outdoor_temp=outdoor_conditions['temperature'],
113
+ indoor_temp=indoor_conditions['temperature']
114
+ )
115
+ hourly_loads['doors'][hour + 1] += load
116
+
117
+ # Calculate internal loads
118
  for hour in range(24):
119
+ # People loads
120
+ people_load = self.calculate_people_cooling_load(
121
+ num_people=internal_loads['people']['number'],
122
+ activity_level=internal_loads['people']['activity_level'],
123
+ hour=hour
124
+ )
125
+ hourly_loads['people_sensible'][hour + 1] += people_load['sensible']
126
+ hourly_loads['people_latent'][hour + 1] += people_load['latent']
127
+
128
+ # Lighting loads
129
+ lights_load = self.calculate_lights_cooling_load(
130
+ power=internal_loads['lights']['power'],
131
+ use_factor=internal_loads['lights']['use_factor'],
132
+ special_allowance=internal_loads['lights']['special_allowance'],
133
+ hour=hour
134
+ )
135
+ hourly_loads['lights'][hour + 1] += lights_load
136
+
137
+ # Equipment loads
138
+ equipment_load = self.calculate_equipment_cooling_load(
139
+ power=internal_loads['equipment']['power'],
140
+ use_factor=internal_loads['equipment']['use_factor'],
141
+ radiation_factor=internal_loads['equipment']['radiation_factor'],
142
+ hour=hour
143
+ )
144
+ hourly_loads['equipment_sensible'][hour + 1] += equipment_load['sensible']
145
+ hourly_loads['equipment_latent'][hour + 1] += equipment_load['latent']
146
+
147
+ # Infiltration loads
148
+ infiltration_load = self.calculate_infiltration_cooling_load(
149
+ flow_rate=internal_loads['infiltration']['flow_rate'],
150
+ building_volume=building_volume,
151
  outdoor_temp=outdoor_conditions['temperature'],
152
+ outdoor_rh=outdoor_conditions['relative_humidity'],
153
  indoor_temp=indoor_conditions['temperature'],
154
+ indoor_rh=indoor_conditions['relative_humidity']
 
 
155
  )
156
+ hourly_loads['infiltration_sensible'][hour + 1] += infiltration_load['sensible']
157
+ hourly_loads['infiltration_latent'][hour + 1] += infiltration_load['latent']
158
+
159
+ # Ventilation loads
160
+ ventilation_load = self.calculate_ventilation_cooling_load(
161
+ flow_rate=internal_loads['ventilation']['flow_rate'],
 
162
  outdoor_temp=outdoor_conditions['temperature'],
163
+ outdoor_rh=outdoor_conditions['relative_humidity'],
164
  indoor_temp=indoor_conditions['temperature'],
165
+ indoor_rh=indoor_conditions['relative_humidity']
 
 
 
166
  )
167
+ hourly_loads['ventilation_sensible'][hour + 1] += ventilation_load['sensible']
168
+ hourly_loads['ventilation_latent'][hour + 1] += ventilation_load['latent']
169
 
170
+ return hourly_loads
 
 
 
 
 
 
 
 
171
 
172
+ except Exception as e:
173
+ raise Exception(f"Error in calculate_hourly_cooling_loads: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
 
175
  def calculate_design_cooling_load(self, hourly_loads: Dict[str, Any]) -> Dict[str, Any]:
176
  """
 
186
  design_loads = {}
187
  total_loads = []
188
 
189
+ for hour in range(1, 25):
190
  total_load = sum([
191
  hourly_loads['walls'][hour],
192
  hourly_loads['roofs'][hour],
 
205
  ])
206
  total_loads.append(total_load)
207
 
208
+ design_hour = range(1, 25)[np.argmax(total_loads)]
209
 
210
  design_loads = {
211
  'design_hour': design_hour,
 
632
  orientation=Orientation.HORIZONTAL,
633
  area=100.0,
634
  u_value=0.3,
635
+ roof_group="A"
636
  )],
637
  'windows': [Window(
638
  name="South Window",
 
656
  'relative_humidity': 50.0,
657
  'ground_temperature': 20.0,
658
  'month': 'Jul',
659
+ 'latitude': '24N',
660
  'wind_speed': 4.0,
661
  'day_of_year': 204
662
  }
 
701
  hourly_loads = calculator.calculate_hourly_cooling_loads(
702
  building_components=building_components,
703
  outdoor_conditions=outdoor_conditions,
704
+ indoor_conditions=indoors_conditions,
705
  internal_loads=internal_loads,
706
  building_volume=building_volume
707
  )