2023-09-06 14:55:14 -04:00
|
|
|
"""
|
|
|
|
Insel monthly energy balance
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2022 Concordia CERC group
|
|
|
|
Project Coder Saeed Ranjbar saeed.ranjbar@concordia.ca
|
|
|
|
Project collaborator Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
|
|
|
"""
|
|
|
|
from pathlib import Path
|
|
|
|
import csv
|
|
|
|
|
2023-10-05 05:30:20 -04:00
|
|
|
from hub.helpers.monthly_values import MonthlyValues
|
2023-09-06 14:55:14 -04:00
|
|
|
import hub.helpers.constants as cte
|
|
|
|
|
|
|
|
|
2023-10-05 05:30:20 -04:00
|
|
|
class EnergyPlus:
|
|
|
|
"""
|
|
|
|
Energy plus class
|
|
|
|
"""
|
2023-09-07 18:16:07 -04:00
|
|
|
def __init__(self, city, base_path):
|
|
|
|
self._city = city
|
2023-09-06 14:55:14 -04:00
|
|
|
self._base_path = base_path
|
|
|
|
|
|
|
|
@staticmethod
|
2023-09-07 18:16:07 -04:00
|
|
|
def _building_energy_demands(energy_plus_output_file_path):
|
2023-09-06 14:55:14 -04:00
|
|
|
with open(Path(energy_plus_output_file_path).resolve(), 'r', encoding='utf8') as csv_file:
|
|
|
|
csv_output = csv.reader(csv_file)
|
2023-09-07 18:16:07 -04:00
|
|
|
headers = next(csv_output)
|
|
|
|
building_energy_demands = {
|
|
|
|
'Heating (J)': [],
|
|
|
|
'Cooling (J)': [],
|
|
|
|
'DHW (J)': [],
|
|
|
|
'Appliances (J)': [],
|
|
|
|
'Lighting (J)': []
|
|
|
|
}
|
|
|
|
heating_column_index = []
|
|
|
|
cooling_column_index = []
|
|
|
|
dhw_column_index = []
|
|
|
|
appliance_column_index = []
|
|
|
|
lighting_column_index = []
|
|
|
|
for index, header in enumerate(headers):
|
|
|
|
if "Total Heating" in header:
|
|
|
|
heating_column_index.append(index)
|
|
|
|
elif "Total Cooling" in header:
|
|
|
|
cooling_column_index.append(index)
|
|
|
|
elif "DHW" in header:
|
|
|
|
dhw_column_index.append(index)
|
|
|
|
elif "InteriorEquipment" in header:
|
|
|
|
appliance_column_index.append(index)
|
|
|
|
elif "InteriorLights" in header:
|
|
|
|
lighting_column_index.append(index)
|
2023-09-06 14:55:14 -04:00
|
|
|
|
2023-09-07 18:16:07 -04:00
|
|
|
for line in csv_output:
|
|
|
|
total_heating_demand = 0
|
|
|
|
total_cooling_demand = 0
|
|
|
|
total_dhw_demand = 0
|
|
|
|
total_appliance_demand = 0
|
|
|
|
total_lighting_demand = 0
|
|
|
|
for heating_index in heating_column_index:
|
|
|
|
total_heating_demand += float(line[heating_index])
|
|
|
|
building_energy_demands['Heating (J)'].append(total_heating_demand)
|
|
|
|
for cooling_index in cooling_column_index:
|
|
|
|
total_cooling_demand += float(line[cooling_index])
|
|
|
|
building_energy_demands['Cooling (J)'].append(total_cooling_demand)
|
|
|
|
for dhw_index in dhw_column_index:
|
|
|
|
total_dhw_demand += float(line[dhw_index]) * 3600
|
|
|
|
building_energy_demands['DHW (J)'].append(total_dhw_demand)
|
|
|
|
for appliance_index in appliance_column_index:
|
|
|
|
total_appliance_demand += float(line[appliance_index])
|
|
|
|
building_energy_demands['Appliances (J)'].append(total_appliance_demand)
|
|
|
|
for lighting_index in lighting_column_index:
|
|
|
|
total_lighting_demand += float(line[lighting_index])
|
|
|
|
building_energy_demands['Lighting (J)'].append(total_lighting_demand)
|
2023-09-06 14:55:14 -04:00
|
|
|
|
2023-09-07 18:16:07 -04:00
|
|
|
return building_energy_demands
|
2023-09-06 14:55:14 -04:00
|
|
|
|
2023-09-07 18:16:07 -04:00
|
|
|
def enrich(self):
|
|
|
|
"""
|
|
|
|
Enrich the city by using the energy plus workflow output files (J)
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
for building in self._city.buildings:
|
2023-09-08 05:05:58 -04:00
|
|
|
file_name = f'{building.name}_out.csv'
|
2023-09-07 18:16:07 -04:00
|
|
|
energy_plus_output_file_path = Path(self._base_path / file_name).resolve()
|
|
|
|
if energy_plus_output_file_path.is_file():
|
2023-09-08 05:05:58 -04:00
|
|
|
building_energy_demands = self._building_energy_demands(energy_plus_output_file_path)
|
|
|
|
building.heating_demand[cte.HOUR] = building_energy_demands['Heating (J)']
|
|
|
|
building.cooling_demand[cte.HOUR] = building_energy_demands['Cooling (J)']
|
|
|
|
building.domestic_hot_water_heat_demand[cte.HOUR] = building_energy_demands['DHW (J)']
|
|
|
|
building.appliances_electrical_demand[cte.HOUR] = building_energy_demands['Appliances (J)']
|
|
|
|
building.lighting_electrical_demand[cte.HOUR] = building_energy_demands['Lighting (J)']
|
|
|
|
# todo: @Saeed, this a list of ONE value with the total energy of the year, exactly the same as cte.YEAR.
|
|
|
|
# You have to use the method to add hourly values from helpers/monthly_values
|
2023-09-08 11:50:20 -04:00
|
|
|
building.heating_demand[cte.MONTH] = MonthlyValues.get_total_month(building.heating_demand[cte.HOUR])
|
|
|
|
building.cooling_demand[cte.MONTH] = MonthlyValues.get_total_month(building.cooling_demand[cte.HOUR])
|
|
|
|
building.domestic_hot_water_heat_demand[cte.MONTH] = (
|
|
|
|
MonthlyValues.get_total_month(building.domestic_hot_water_heat_demand[cte.HOUR]))
|
|
|
|
building.appliances_electrical_demand[cte.MONTH] = (
|
|
|
|
MonthlyValues.get_total_month(building.appliances_electrical_demand[cte.HOUR]))
|
|
|
|
building.lighting_electrical_demand[cte.MONTH] = (
|
|
|
|
MonthlyValues.get_total_month(building.lighting_electrical_demand[cte.HOUR]))
|
2023-09-07 18:16:07 -04:00
|
|
|
building.heating_demand[cte.YEAR] = [sum(building.heating_demand[cte.MONTH])]
|
|
|
|
building.cooling_demand[cte.YEAR] = [sum(building.cooling_demand[cte.MONTH])]
|
|
|
|
building.domestic_hot_water_heat_demand[cte.YEAR] = [sum(building.domestic_hot_water_heat_demand[cte.MONTH])]
|
|
|
|
building.appliances_electrical_demand[cte.YEAR] = [sum(building.appliances_electrical_demand[cte.MONTH])]
|
|
|
|
building.lighting_electrical_demand[cte.YEAR] = [sum(building.lighting_electrical_demand[cte.MONTH])]
|