Update data/calculation.py
Browse files- data/calculation.py +24 -19
data/calculation.py
CHANGED
|
@@ -23,21 +23,21 @@ class ComponentType(Enum):
|
|
| 23 |
SKYLIGHT = "Skylight"
|
| 24 |
|
| 25 |
class TFMCalculations:
|
| 26 |
-
|
| 27 |
def calculate_conduction_load(component, outdoor_temp: float, indoor_temp: float, hour: int, mode: str = "none") -> tuple[float, float]:
|
| 28 |
"""Calculate conduction load for heating and cooling in kW based on mode."""
|
| 29 |
if mode == "none":
|
| 30 |
return 0, 0
|
| 31 |
delta_t = outdoor_temp - indoor_temp
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
load = component.u_value * component.area * delta_t
|
| 33 |
for i, ctf in enumerate(component.ctf):
|
| 34 |
load += ctf * (outdoor_temp - indoor_temp) * np.exp(-i * 3600 / 3600)
|
| 35 |
-
if mode == "cooling"
|
| 36 |
-
|
| 37 |
-
heating_load = 0
|
| 38 |
-
elif mode == "heating":
|
| 39 |
-
cooling_load = 0
|
| 40 |
-
heating_load = max(-load, 0) / 1000 # Positive for heating (kW)
|
| 41 |
return cooling_load, heating_load
|
| 42 |
|
| 43 |
@staticmethod
|
|
@@ -91,13 +91,13 @@ class TFMCalculations:
|
|
| 91 |
air_density = 1.2 # kg/m鲁
|
| 92 |
specific_heat = 1000 # J/kg路K
|
| 93 |
delta_t = outdoor_temp - indoor_temp
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
load = ventilation_flow * air_density * specific_heat * delta_t / 1000 # kW
|
| 95 |
-
if mode == "cooling"
|
| 96 |
-
|
| 97 |
-
heating_load = 0
|
| 98 |
-
elif mode == "heating":
|
| 99 |
-
cooling_load = 0
|
| 100 |
-
heating_load = max(-load, 0)
|
| 101 |
return cooling_load, heating_load
|
| 102 |
|
| 103 |
@staticmethod
|
|
@@ -115,6 +115,10 @@ class TFMCalculations:
|
|
| 115 |
air_density = 1.2 # kg/m鲁
|
| 116 |
specific_heat = 1000 # J/kg路K
|
| 117 |
delta_t = outdoor_temp - indoor_temp
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
if method == "ACH":
|
| 119 |
ach = settings.get("rate", 0.5)
|
| 120 |
infiltration_flow = ach * volume / 3600 # m鲁/s
|
|
@@ -128,12 +132,8 @@ class TFMCalculations:
|
|
| 128 |
delta_t_abs = abs(delta_t)
|
| 129 |
infiltration_flow = c * (delta_t_abs ** n) * area / 3600 # m鲁/s
|
| 130 |
load = infiltration_flow * air_density * specific_heat * delta_t / 1000 # kW
|
| 131 |
-
if mode == "cooling"
|
| 132 |
-
|
| 133 |
-
heating_load = 0
|
| 134 |
-
elif mode == "heating":
|
| 135 |
-
cooling_load = 0
|
| 136 |
-
heating_load = max(-load, 0)
|
| 137 |
return cooling_load, heating_load
|
| 138 |
|
| 139 |
@staticmethod
|
|
@@ -247,6 +247,11 @@ class TFMCalculations:
|
|
| 247 |
# Calculate total loads, subtracting internal load for heating
|
| 248 |
total_cooling = conduction_cooling + solar + internal + ventilation_cooling + infiltration_cooling
|
| 249 |
total_heating = max(conduction_heating + ventilation_heating + infiltration_heating - internal, 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
loads.append({
|
| 251 |
"hour": hour,
|
| 252 |
"month": hour_data["month"],
|
|
|
|
| 23 |
SKYLIGHT = "Skylight"
|
| 24 |
|
| 25 |
class TFMCalculations:
|
| 26 |
+
@staticmethod
|
| 27 |
def calculate_conduction_load(component, outdoor_temp: float, indoor_temp: float, hour: int, mode: str = "none") -> tuple[float, float]:
|
| 28 |
"""Calculate conduction load for heating and cooling in kW based on mode."""
|
| 29 |
if mode == "none":
|
| 30 |
return 0, 0
|
| 31 |
delta_t = outdoor_temp - indoor_temp
|
| 32 |
+
if mode == "cooling" and delta_t <= 0:
|
| 33 |
+
return 0, 0
|
| 34 |
+
if mode == "heating" and delta_t >= 0:
|
| 35 |
+
return 0, 0
|
| 36 |
load = component.u_value * component.area * delta_t
|
| 37 |
for i, ctf in enumerate(component.ctf):
|
| 38 |
load += ctf * (outdoor_temp - indoor_temp) * np.exp(-i * 3600 / 3600)
|
| 39 |
+
cooling_load = load / 1000 if mode == "cooling" else 0
|
| 40 |
+
heating_load = -load / 1000 if mode == "heating" else 0
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
return cooling_load, heating_load
|
| 42 |
|
| 43 |
@staticmethod
|
|
|
|
| 91 |
air_density = 1.2 # kg/m鲁
|
| 92 |
specific_heat = 1000 # J/kg路K
|
| 93 |
delta_t = outdoor_temp - indoor_temp
|
| 94 |
+
if mode == "cooling" and delta_t <= 0:
|
| 95 |
+
return 0, 0
|
| 96 |
+
if mode == "heating" and delta_t >= 0:
|
| 97 |
+
return 0, 0
|
| 98 |
load = ventilation_flow * air_density * specific_heat * delta_t / 1000 # kW
|
| 99 |
+
cooling_load = load if mode == "cooling" else 0
|
| 100 |
+
heating_load = -load if mode == "heating" else 0
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
return cooling_load, heating_load
|
| 102 |
|
| 103 |
@staticmethod
|
|
|
|
| 115 |
air_density = 1.2 # kg/m鲁
|
| 116 |
specific_heat = 1000 # J/kg路K
|
| 117 |
delta_t = outdoor_temp - indoor_temp
|
| 118 |
+
if mode == "cooling" and delta_t <= 0:
|
| 119 |
+
return 0, 0
|
| 120 |
+
if mode == "heating" and delta_t >= 0:
|
| 121 |
+
return 0, 0
|
| 122 |
if method == "ACH":
|
| 123 |
ach = settings.get("rate", 0.5)
|
| 124 |
infiltration_flow = ach * volume / 3600 # m鲁/s
|
|
|
|
| 132 |
delta_t_abs = abs(delta_t)
|
| 133 |
infiltration_flow = c * (delta_t_abs ** n) * area / 3600 # m鲁/s
|
| 134 |
load = infiltration_flow * air_density * specific_heat * delta_t / 1000 # kW
|
| 135 |
+
cooling_load = load if mode == "cooling" else 0
|
| 136 |
+
heating_load = -load if mode == "heating" else 0
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
return cooling_load, heating_load
|
| 138 |
|
| 139 |
@staticmethod
|
|
|
|
| 247 |
# Calculate total loads, subtracting internal load for heating
|
| 248 |
total_cooling = conduction_cooling + solar + internal + ventilation_cooling + infiltration_cooling
|
| 249 |
total_heating = max(conduction_heating + ventilation_heating + infiltration_heating - internal, 0)
|
| 250 |
+
# Enforce mutual exclusivity
|
| 251 |
+
if mode == "cooling":
|
| 252 |
+
total_heating = 0
|
| 253 |
+
elif mode == "heating":
|
| 254 |
+
total_cooling = 0
|
| 255 |
loads.append({
|
| 256 |
"hour": hour,
|
| 257 |
"month": hour_data["month"],
|