mabuseif commited on
Commit
1043d9b
·
verified ·
1 Parent(s): 16e2fd4

Update app/hvac_loads.py

Browse files
Files changed (1) hide show
  1. app/hvac_loads.py +118 -1
app/hvac_loads.py CHANGED
@@ -1099,7 +1099,7 @@ def display_hvac_loads_page():
1099
  index=["Fixed Setpoints", "ASHRAE 55 Adaptive Comfort"].index(st.session_state.project_data["indoor_conditions"]["type"])
1100
  )
1101
  st.session_state.project_data["indoor_conditions"]["type"] = indoor_type
1102
-
1103
  if indoor_type == "Fixed Setpoints":
1104
  col1, col2 = st.columns(2)
1105
  with col1:
@@ -1152,6 +1152,123 @@ def display_hvac_loads_page():
1152
  key="adaptive_acceptability"
1153
  )
1154
  st.session_state.project_data["indoor_conditions"]["adaptive_acceptability"] = acceptability
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1155
 
1156
  # Calculate HVAC Loads
1157
  if st.button("Calculate HVAC Loads"):
 
1099
  index=["Fixed Setpoints", "ASHRAE 55 Adaptive Comfort"].index(st.session_state.project_data["indoor_conditions"]["type"])
1100
  )
1101
  st.session_state.project_data["indoor_conditions"]["type"] = indoor_type
1102
+
1103
  if indoor_type == "Fixed Setpoints":
1104
  col1, col2 = st.columns(2)
1105
  with col1:
 
1152
  key="adaptive_acceptability"
1153
  )
1154
  st.session_state.project_data["indoor_conditions"]["adaptive_acceptability"] = acceptability
1155
+
1156
+ # Internal Loads Conditions Configuration
1157
+ st.subheader("Internal Loads Conditions")
1158
+ col1, col2, col3, col4, col5 = st.columns(5)
1159
+
1160
+ # Initialize internal_loads_conditions if not present
1161
+ if "internal_loads_conditions" not in st.session_state.project_data:
1162
+ st.session_state.project_data["internal_loads_conditions"] = {
1163
+ "air_velocity": 0.1,
1164
+ "lighting_convective_fraction": 0.5,
1165
+ "lighting_radiative_fraction": 0.5,
1166
+ "equipment_convective_fraction": 0.5,
1167
+ "equipment_radiative_fraction": 0.5
1168
+ }
1169
+
1170
+ # Retrieve internal loads data
1171
+ internal_loads = st.session_state.project_data.get("internal_loads", {})
1172
+ lighting_systems = internal_loads.get("lighting", [])
1173
+ equipment_systems = internal_loads.get("equipment", [])
1174
+
1175
+ # Calculate average fractions from lighting systems
1176
+ lighting_convective_total = 0.0
1177
+ lighting_radiative_total = 0.0
1178
+ lighting_count = len(lighting_systems) or 1 # Avoid division by zero
1179
+ for system in lighting_systems:
1180
+ lighting_convective_total += system.get("convective_fraction", 0.5)
1181
+ lighting_radiative_total += system.get("radiative_fraction", 0.5)
1182
+ default_lighting_convective = lighting_convective_total / lighting_count
1183
+ default_lighting_radiative = lighting_radiative_total / lighting_count
1184
+
1185
+ # Calculate average fractions from equipment systems
1186
+ equipment_convective_total = 0.0
1187
+ equipment_radiative_total = 0.0
1188
+ equipment_count = len(equipment_systems) or 1 # Avoid division by zero
1189
+ for system in equipment_systems:
1190
+ equipment_convective_total += system.get("convective_fraction", 0.5)
1191
+ equipment_radiative_total += system.get("radiative_fraction", 0.5)
1192
+ default_equipment_convective = equipment_convective_total / equipment_count
1193
+ default_equipment_radiative = equipment_radiative_total / equipment_count
1194
+
1195
+ with col1:
1196
+ air_velocity = st.number_input(
1197
+ "Air Velocity (m/s)",
1198
+ min_value=0.0,
1199
+ max_value=2.0,
1200
+ value=st.session_state.project_data["internal_loads_conditions"].get("air_velocity", 0.1),
1201
+ step=0.01,
1202
+ key="hvac_air_velocity"
1203
+ )
1204
+ if air_velocity < 0.0 or air_velocity > 2.0:
1205
+ st.error("Air velocity must be between 0 and 2 m/s.")
1206
+ air_velocity = max(0.0, min(2.0, air_velocity))
1207
+
1208
+ with col2:
1209
+ lighting_convective_fraction = st.number_input(
1210
+ "Lighting Convective Fraction",
1211
+ min_value=0.0,
1212
+ max_value=1.0,
1213
+ value=st.session_state.project_data["internal_loads_conditions"].get("lighting_convective_fraction", default_lighting_convective),
1214
+ step=0.01,
1215
+ key="hvac_lighting_convective"
1216
+ )
1217
+
1218
+ with col3:
1219
+ lighting_radiative_fraction = st.number_input(
1220
+ "Lighting Radiative Fraction",
1221
+ min_value=0.0,
1222
+ max_value=1.0,
1223
+ value=st.session_state.project_data["internal_loads_conditions"].get("lighting_radiative_fraction", default_lighting_radiative),
1224
+ step=0.01,
1225
+ key="hvac_lighting_radiative"
1226
+ )
1227
+ # Validate lighting fractions sum to 1.0
1228
+ if abs(lighting_convective_fraction + lighting_radiative_fraction - 1.0) > 0.01:
1229
+ st.error("Lighting convective and radiative fractions must sum to 1.0.")
1230
+
1231
+ with col4:
1232
+ equipment_convective_fraction = st.number_input(
1233
+ "Equipment Convective Fraction",
1234
+ min_value=0.0,
1235
+ max_value=1.0,
1236
+ value=st.session_state.project_data["internal_loads_conditions"].get("equipment_convective_fraction", default_equipment_convective),
1237
+ step=0.01,
1238
+ key="hvac_equipment_convective"
1239
+ )
1240
+
1241
+ with col5:
1242
+ equipment_radiative_fraction = st.number_input(
1243
+ "Equipment Radiative Fraction",
1244
+ min_value=0.0,
1245
+ max_value=1.0,
1246
+ value=st.session_state.project_data["internal_loads_conditions"].get("equipment_radiative_fraction", default_equipment_radiative),
1247
+ step=0.01,
1248
+ key="hvac_equipment_radiative"
1249
+ )
1250
+ # Validate equipment fractions sum to 1.0
1251
+ if abs(equipment_convective_fraction + equipment_radiative_fraction - 1.0) > 0.01:
1252
+ st.error("Equipment convective and radiative fractions must sum to 1.0.")
1253
+
1254
+ if st.button("Save Internal Loads Conditions"):
1255
+ st.session_state.project_data["internal_loads_conditions"].update({
1256
+ "air_velocity": air_velocity,
1257
+ "lighting_convective_fraction": lighting_convective_fraction,
1258
+ "lighting_radiative_fraction": lighting_radiative_fraction,
1259
+ "equipment_convective_fraction": equipment_convective_fraction,
1260
+ "equipment_radiative_fraction": equipment_radiative_fraction
1261
+ })
1262
+ # Update lighting systems with new fractions
1263
+ for system in lighting_systems:
1264
+ system["convective_fraction"] = lighting_convective_fraction
1265
+ system["radiative_fraction"] = lighting_radiative_fraction
1266
+ # Update equipment systems with new fractions
1267
+ for system in equipment_systems:
1268
+ system["convective_fraction"] = equipment_convective_fraction
1269
+ system["radiative_fraction"] = equipment_radiative_fraction
1270
+ st.success("Internal loads conditions saved successfully.")
1271
+ logger.info("Internal loads conditions updated in session state")
1272
 
1273
  # Calculate HVAC Loads
1274
  if st.button("Calculate HVAC Loads"):