130 lines
6.0 KiB
Python
130 lines
6.0 KiB
Python
"""
|
|
Peak loads calculation workflow
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
Copyright © 2022 Concordia CERC group
|
|
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
|
"""
|
|
|
|
from pathlib import Path
|
|
|
|
import hub.helpers.constants as cte
|
|
from loads_calculation import LoadsCalculation
|
|
|
|
_MONTH_STARTING_HOUR = [0, 744, 1416, 2160, 2880, 3624, 4344, 5088, 5832, 6552, 7296, 8016]
|
|
|
|
|
|
class PeakLoads:
|
|
def __init__(self, city, path, weather_format, irradiance_format):
|
|
self._city = city
|
|
self._path = path
|
|
self._weather_format = weather_format
|
|
self._irradiance_format = irradiance_format
|
|
self._results = {}
|
|
|
|
self._sanity_check()
|
|
self._workflow()
|
|
|
|
def _sanity_check(self):
|
|
levels_of_detail = self._city.level_of_detail
|
|
if levels_of_detail.geometry is None:
|
|
raise Exception(f'Level of detail of geometry not assigned')
|
|
if levels_of_detail.geometry < 1:
|
|
raise Exception(f'Level of detail of geometry = {levels_of_detail.geometry}. Required minimum level 1')
|
|
if levels_of_detail.construction is None:
|
|
raise Exception(f'Level of detail of construction not assigned')
|
|
if levels_of_detail.construction < 1:
|
|
raise Exception(f'Level of detail of construction = {levels_of_detail.construction}. Required minimum level 1')
|
|
if levels_of_detail.usage is None:
|
|
raise Exception(f'Level of detail of usage not assigned')
|
|
if levels_of_detail.usage < 1:
|
|
raise Exception(f'Level of detail of usage = {levels_of_detail.usage}. Required minimum level 1')
|
|
for building in self._city.buildings:
|
|
if cte.HOUR not in building.external_temperature:
|
|
raise Exception(f'Building {building.name} does not have external temperature assigned')
|
|
for surface in building.surfaces:
|
|
if surface.type != cte.GROUND:
|
|
if cte.HOUR not in surface.global_irradiance:
|
|
raise Exception(f'Building {building.name} does not have global irradiance on surfaces assigned')
|
|
|
|
def _workflow(self):
|
|
for building in self._city.buildings:
|
|
monthly_heating_loads = []
|
|
monthly_cooling_loads = []
|
|
ambient_temperature = building.external_temperature[cte.HOUR][self._weather_format]
|
|
for month in range(0, 12):
|
|
ground_temperature = building.ground_temperature[cte.MONTH]['2'][month]
|
|
heating_ambient_temperature = 100
|
|
cooling_ambient_temperature = -100
|
|
heating_calculation_hour = -1
|
|
cooling_calculation_hour = -1
|
|
start_hour = _MONTH_STARTING_HOUR[month]
|
|
end_hour = 8760
|
|
if month < 11:
|
|
end_hour = _MONTH_STARTING_HOUR[month + 1]
|
|
for hour in range(start_hour, end_hour):
|
|
temperature = ambient_temperature[hour]
|
|
if temperature < heating_ambient_temperature:
|
|
heating_ambient_temperature = temperature
|
|
heating_calculation_hour = hour
|
|
if temperature > cooling_ambient_temperature:
|
|
cooling_ambient_temperature = temperature
|
|
cooling_calculation_hour = hour
|
|
|
|
loads = LoadsCalculation(building)
|
|
heating_load_transmitted = loads.get_heating_transmitted_load(heating_ambient_temperature, ground_temperature)
|
|
heating_load_ventilation_sensible = loads.get_heating_ventilation_load_sensible(heating_ambient_temperature)
|
|
heating_load_ventilation_latent = 0
|
|
heating_load = heating_load_transmitted + heating_load_ventilation_sensible + heating_load_ventilation_latent
|
|
|
|
cooling_load_transmitted = loads.get_cooling_transmitted_load(cooling_ambient_temperature, ground_temperature)
|
|
cooling_load_renovation_sensible = loads.get_cooling_ventilation_load_sensible(cooling_ambient_temperature)
|
|
cooling_load_internal_gains_sensible = loads.get_internal_load_sensible()
|
|
cooling_load_radiation = loads.get_radiation_load(self._irradiance_format, cooling_calculation_hour)
|
|
cooling_load_sensible = cooling_load_transmitted + cooling_load_renovation_sensible - cooling_load_radiation \
|
|
- cooling_load_internal_gains_sensible
|
|
|
|
cooling_load_latent = 0
|
|
cooling_load = cooling_load_sensible + cooling_load_latent
|
|
if heating_load < 0:
|
|
heating_load = 0
|
|
if cooling_load > 0:
|
|
cooling_load = 0
|
|
monthly_heating_loads.append(heating_load)
|
|
monthly_cooling_loads.append(cooling_load)
|
|
|
|
self._results[building.name] = {'monthly heating peak load': monthly_heating_loads,
|
|
'monthly cooling peak load': monthly_cooling_loads}
|
|
self._print_results()
|
|
|
|
def _print_results(self):
|
|
print_results = f'Building name, monthly heating peak load W,,,,,,,,,,,, monthly cooling peak load W,,,,,,,,,,,'
|
|
for building in self._city.buildings:
|
|
results = self._results[building.name]
|
|
print_results += '\n'
|
|
print_results += f'{building.name}, '
|
|
for value in results["monthly heating peak load"]:
|
|
print_results += f'{value}, '
|
|
for value in results["monthly cooling peak load"]:
|
|
print_results += f'{value}, '
|
|
|
|
file = 'city name: ' + self._city.name + '\n'
|
|
for building in self._city.buildings:
|
|
file += '\n'
|
|
file += f'name: {building.name}\n'
|
|
file += f'year of construction: {building.year_of_construction}\n'
|
|
file += f'function: {building.function}\n'
|
|
file += f'floor area: {building.floor_area}\n'
|
|
if building.average_storey_height is not None and building.eave_height is not None:
|
|
file += f'storeys: {int(building.eave_height / building.average_storey_height)}\n'
|
|
else:
|
|
file += f'storeys: n/a\n'
|
|
file += f'heated_volume: {0.85 * building.volume}\n'
|
|
file += f'volume: {building.volume}\n'
|
|
|
|
full_path_results = Path(self._path / 'peak_loads.csv').resolve()
|
|
with open(full_path_results, 'w') as results_file:
|
|
results_file.write(print_results)
|
|
full_path_metadata = Path(self._path / 'metadata.csv').resolve()
|
|
with open(full_path_metadata, 'w') as metadata_file:
|
|
metadata_file.write(file)
|