2021-11-11 17:25:53 -05:00
|
|
|
"""
|
2022-12-07 10:54:28 -05:00
|
|
|
ComnetUsageParameters extracts the usage properties from Comnet catalog and assigns to each building
|
2021-11-11 17:25:53 -05:00
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
2022-04-08 09:35:33 -04:00
|
|
|
Copyright © 2022 Concordia CERC group
|
|
|
|
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
2021-11-11 17:25:53 -05:00
|
|
|
"""
|
2022-05-18 14:52:41 -04:00
|
|
|
import copy
|
2021-11-11 17:25:53 -05:00
|
|
|
import sys
|
2022-05-18 14:52:41 -04:00
|
|
|
import numpy
|
2021-11-11 17:25:53 -05:00
|
|
|
|
|
|
|
import helpers.constants as cte
|
2022-12-16 07:21:33 -05:00
|
|
|
from helpers.dictionaries import Dictionaries
|
2022-12-06 15:28:59 -05:00
|
|
|
from city_model_structure.building_demand.usage import Usage
|
2022-03-08 19:19:52 -05:00
|
|
|
from city_model_structure.building_demand.lighting import Lighting
|
|
|
|
from city_model_structure.building_demand.occupancy import Occupancy
|
|
|
|
from city_model_structure.building_demand.appliances import Appliances
|
2022-03-17 18:49:44 -04:00
|
|
|
from city_model_structure.building_demand.thermal_control import ThermalControl
|
|
|
|
from city_model_structure.attributes.schedule import Schedule
|
2022-05-18 14:52:41 -04:00
|
|
|
from city_model_structure.building_demand.internal_gain import InternalGain
|
2022-12-07 10:54:28 -05:00
|
|
|
from catalog_factories.usage_catalog_factory import UsageCatalogFactory
|
2021-11-11 17:25:53 -05:00
|
|
|
|
|
|
|
|
|
|
|
class ComnetUsageParameters:
|
|
|
|
"""
|
|
|
|
ComnetUsageParameters class
|
|
|
|
"""
|
|
|
|
def __init__(self, city, base_path):
|
|
|
|
self._city = city
|
2022-12-07 10:54:28 -05:00
|
|
|
self._path = base_path
|
2022-03-17 18:49:44 -04:00
|
|
|
|
2021-11-11 17:25:53 -05:00
|
|
|
def enrich_buildings(self):
|
|
|
|
"""
|
|
|
|
Returns the city with the usage parameters assigned to the buildings
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
city = self._city
|
2022-12-07 10:54:28 -05:00
|
|
|
comnet_catalog = UsageCatalogFactory('comnet').catalog
|
2021-11-11 17:25:53 -05:00
|
|
|
for building in city.buildings:
|
2022-12-16 07:21:33 -05:00
|
|
|
usage_name = Dictionaries().hub_usage_to_comnet_usage[building.function]
|
2022-03-17 18:49:44 -04:00
|
|
|
try:
|
2022-12-07 10:54:28 -05:00
|
|
|
archetype_usage = self._search_archetypes(comnet_catalog, usage_name)
|
2022-03-17 18:49:44 -04:00
|
|
|
except KeyError:
|
2022-12-07 10:54:28 -05:00
|
|
|
sys.stderr.write(f'Building {building.name} has unknown usage archetype for building function:'
|
|
|
|
f' {building.function}')
|
2022-03-17 18:49:44 -04:00
|
|
|
return
|
2021-11-11 17:25:53 -05:00
|
|
|
|
2022-03-08 20:08:03 -05:00
|
|
|
for internal_zone in building.internal_zones:
|
2022-03-17 18:49:44 -04:00
|
|
|
if internal_zone.area is None:
|
|
|
|
raise Exception('Internal zone area not defined, ACH cannot be calculated')
|
|
|
|
if internal_zone.volume is None:
|
|
|
|
raise Exception('Internal zone volume not defined, ACH cannot be calculated')
|
|
|
|
if internal_zone.area <= 0:
|
|
|
|
raise Exception('Internal zone area is zero, ACH cannot be calculated')
|
|
|
|
volume_per_area = internal_zone.volume / internal_zone.area
|
2022-12-06 15:28:59 -05:00
|
|
|
usage_zone = Usage()
|
2022-12-07 10:54:28 -05:00
|
|
|
usage_zone.name = usage_name
|
|
|
|
self._assign_values(usage_zone, archetype_usage, volume_per_area)
|
2022-03-08 20:08:03 -05:00
|
|
|
usage_zone.percentage = 1
|
2022-03-17 18:49:44 -04:00
|
|
|
self._calculate_reduced_values_from_extended_library(usage_zone, archetype_usage)
|
2021-11-11 17:25:53 -05:00
|
|
|
|
2022-12-06 15:28:59 -05:00
|
|
|
internal_zone.usages = [usage_zone]
|
2021-11-11 17:25:53 -05:00
|
|
|
|
|
|
|
@staticmethod
|
2022-12-07 10:54:28 -05:00
|
|
|
def _search_archetypes(comnet_catalog, usage_name):
|
|
|
|
comnet_archetypes = comnet_catalog.entries('archetypes').usages
|
|
|
|
for building_archetype in comnet_archetypes:
|
|
|
|
if str(usage_name) == str(building_archetype.name):
|
|
|
|
return building_archetype
|
|
|
|
raise KeyError('archetype not found')
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _assign_values(usage_zone, archetype, volume_per_area):
|
2021-11-11 17:25:53 -05:00
|
|
|
# Due to the fact that python is not a typed language, the wrong object type is assigned to
|
2022-03-17 18:49:44 -04:00
|
|
|
# usage_zone.occupancy when writing usage_zone.occupancy = archetype.occupancy.
|
|
|
|
# Same happens for lighting and appliances. Therefore, this walk around has been done.
|
2022-12-07 10:54:28 -05:00
|
|
|
usage_zone.mechanical_air_change = archetype.ventilation_rate / volume_per_area \
|
|
|
|
* cte.HOUR_TO_MINUTES * cte.MINUTES_TO_SECONDS
|
2022-03-17 18:49:44 -04:00
|
|
|
_occupancy = Occupancy()
|
2022-12-07 10:54:28 -05:00
|
|
|
_occupancy.occupancy_density = archetype.occupancy.occupancy_density
|
|
|
|
_occupancy.sensible_radiative_internal_gain = archetype.occupancy.sensible_radiative_internal_gain
|
|
|
|
_occupancy.latent_internal_gain = archetype.occupancy.latent_internal_gain
|
|
|
|
_occupancy.sensible_convective_internal_gain = archetype.occupancy.sensible_convective_internal_gain
|
|
|
|
_occupancy.occupancy_schedules = archetype.occupancy.schedules
|
2022-03-17 18:49:44 -04:00
|
|
|
usage_zone.occupancy = _occupancy
|
|
|
|
_lighting = Lighting()
|
2022-12-07 10:54:28 -05:00
|
|
|
_lighting.density = archetype.lighting.density
|
2022-03-17 18:49:44 -04:00
|
|
|
_lighting.convective_fraction = archetype.lighting.convective_fraction
|
|
|
|
_lighting.radiative_fraction = archetype.lighting.radiative_fraction
|
|
|
|
_lighting.latent_fraction = archetype.lighting.latent_fraction
|
|
|
|
_lighting.schedules = archetype.lighting.schedules
|
|
|
|
usage_zone.lighting = _lighting
|
|
|
|
_appliances = Appliances()
|
2022-12-07 10:54:28 -05:00
|
|
|
_appliances.density = archetype.appliances.density
|
2022-03-17 18:49:44 -04:00
|
|
|
_appliances.convective_fraction = archetype.appliances.convective_fraction
|
|
|
|
_appliances.radiative_fraction = archetype.appliances.radiative_fraction
|
|
|
|
_appliances.latent_fraction = archetype.appliances.latent_fraction
|
|
|
|
_appliances.schedules = archetype.appliances.schedules
|
|
|
|
usage_zone.appliances = _appliances
|
|
|
|
_control = ThermalControl()
|
|
|
|
_control.cooling_set_point_schedules = archetype.thermal_control.cooling_set_point_schedules
|
|
|
|
_control.heating_set_point_schedules = archetype.thermal_control.heating_set_point_schedules
|
|
|
|
_control.hvac_availability_schedules = archetype.thermal_control.hvac_availability_schedules
|
|
|
|
usage_zone.thermal_control = _control
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _calculate_reduced_values_from_extended_library(usage_zone, archetype):
|
|
|
|
number_of_days_per_type = {'WD': 251, 'Sat': 52, 'Sun': 62}
|
|
|
|
total = 0
|
|
|
|
for schedule in archetype.thermal_control.hvac_availability_schedules:
|
|
|
|
if schedule.day_types[0] == cte.SATURDAY:
|
|
|
|
for value in schedule.values:
|
|
|
|
total += value * number_of_days_per_type['Sat']
|
|
|
|
elif schedule.day_types[0] == cte.SUNDAY:
|
|
|
|
for value in schedule.values:
|
|
|
|
total += value * number_of_days_per_type['Sun']
|
|
|
|
else:
|
|
|
|
for value in schedule.values:
|
|
|
|
total += value * number_of_days_per_type['WD']
|
|
|
|
|
|
|
|
usage_zone.hours_day = total / 365
|
|
|
|
usage_zone.days_year = 365
|
2022-05-18 14:52:41 -04:00
|
|
|
|
2022-12-15 07:42:59 -05:00
|
|
|
max_heating_setpoint = cte.MIN_FLOAT
|
|
|
|
min_heating_setpoint = cte.MAX_FLOAT
|
|
|
|
|
|
|
|
for schedule in archetype.thermal_control.heating_set_point_schedules:
|
|
|
|
if schedule.values is None:
|
|
|
|
max_heating_setpoint = None
|
|
|
|
min_heating_setpoint = None
|
|
|
|
break
|
|
|
|
if max(schedule.values) > max_heating_setpoint:
|
|
|
|
max_heating_setpoint = max(schedule.values)
|
|
|
|
if min(schedule.values) < min_heating_setpoint:
|
|
|
|
min_heating_setpoint = min(schedule.values)
|
|
|
|
|
|
|
|
min_cooling_setpoint = cte.MAX_FLOAT
|
|
|
|
for schedule in archetype.thermal_control.cooling_set_point_schedules:
|
|
|
|
if schedule.values is None:
|
|
|
|
min_cooling_setpoint = None
|
|
|
|
break
|
|
|
|
if min(schedule.values) < min_cooling_setpoint:
|
|
|
|
min_cooling_setpoint = min(schedule.values)
|
|
|
|
|
|
|
|
usage_zone.thermal_control.mean_heating_set_point = max_heating_setpoint
|
|
|
|
usage_zone.thermal_control.heating_set_back = min_heating_setpoint
|
|
|
|
usage_zone.thermal_control.mean_cooling_set_point = min_cooling_setpoint
|
|
|
|
|
2022-05-18 14:52:41 -04:00
|
|
|
@staticmethod
|
|
|
|
def _calculate_internal_gains(archetype):
|
|
|
|
|
|
|
|
_DAYS = [cte.MONDAY, cte.TUESDAY, cte.WEDNESDAY, cte.THURSDAY, cte.FRIDAY, cte.SATURDAY, cte.SUNDAY, cte.HOLIDAY]
|
|
|
|
_number_of_days_per_type = [51, 50, 50, 50, 50, 52, 52, 10]
|
|
|
|
|
|
|
|
_mean_internal_gain = InternalGain()
|
|
|
|
_mean_internal_gain.type = 'mean_value_of_internal_gains'
|
|
|
|
_base_schedule = Schedule()
|
|
|
|
_base_schedule.type = cte.INTERNAL_GAINS
|
|
|
|
_base_schedule.time_range = cte.DAY
|
|
|
|
_base_schedule.time_step = cte.HOUR
|
|
|
|
_base_schedule.data_type = cte.FRACTION
|
|
|
|
|
|
|
|
_latent_heat_gain = archetype.occupancy.latent_internal_gain
|
|
|
|
_convective_heat_gain = archetype.occupancy.sensible_convective_internal_gain
|
|
|
|
_radiative_heat_gain = archetype.occupancy.sensible_radiative_internal_gain
|
|
|
|
_total_heat_gain = (_latent_heat_gain + _convective_heat_gain + _radiative_heat_gain)
|
|
|
|
|
2022-06-08 16:22:12 -04:00
|
|
|
_schedule_values = numpy.zeros([24, 8])
|
2022-05-18 14:52:41 -04:00
|
|
|
_sum = 0
|
|
|
|
for day, _schedule in enumerate(archetype.occupancy.schedules):
|
|
|
|
for v, value in enumerate(_schedule.values):
|
|
|
|
_schedule_values[v, day] = value * _total_heat_gain
|
|
|
|
_sum += value * _total_heat_gain * _number_of_days_per_type[day]
|
|
|
|
|
|
|
|
_total_heat_gain += archetype.lighting.density + archetype.appliances.density
|
|
|
|
_latent_heat_gain += archetype.lighting.latent_fraction * archetype.lighting.density\
|
|
|
|
+ archetype.appliances.latent_fraction * archetype.appliances.density
|
|
|
|
_radiative_heat_gain = archetype.lighting.radiative_fraction * archetype.lighting.density \
|
|
|
|
+ archetype.appliances.radiative_fraction * archetype.appliances.density
|
|
|
|
_convective_heat_gain = archetype.lighting.convective_fraction * archetype.lighting.density \
|
|
|
|
+ archetype.appliances.convective_fraction * archetype.appliances.density
|
|
|
|
|
|
|
|
for day, _schedule in enumerate(archetype.lighting.schedules):
|
|
|
|
for v, value in enumerate(_schedule.values):
|
|
|
|
_schedule_values[v, day] += value * archetype.lighting.density
|
|
|
|
_sum += value * archetype.lighting.density * _number_of_days_per_type[day]
|
|
|
|
|
|
|
|
for day, _schedule in enumerate(archetype.appliances.schedules):
|
|
|
|
for v, value in enumerate(_schedule.values):
|
|
|
|
_schedule_values[v, day] += value * archetype.appliances.density
|
|
|
|
_sum += value * archetype.appliances.density * _number_of_days_per_type[day]
|
|
|
|
|
|
|
|
_latent_fraction = _latent_heat_gain / _total_heat_gain
|
|
|
|
_radiative_fraction = _radiative_heat_gain / _total_heat_gain
|
|
|
|
_convective_fraction = _convective_heat_gain / _total_heat_gain
|
|
|
|
_average_internal_gain = _sum / _total_heat_gain
|
|
|
|
|
|
|
|
_schedules = []
|
|
|
|
for day in range(0, len(_DAYS)):
|
|
|
|
_schedule = copy.deepcopy(_base_schedule)
|
|
|
|
_schedule.day_types = [_DAYS[day]]
|
|
|
|
_schedule.values = _schedule_values[:day]
|
|
|
|
_schedules.append(_schedule)
|
|
|
|
|
|
|
|
_mean_internal_gain.average_internal_gain = _average_internal_gain
|
|
|
|
_mean_internal_gain.latent_fraction = _latent_fraction
|
|
|
|
_mean_internal_gain.convective_fraction = _convective_fraction
|
|
|
|
_mean_internal_gain.radiative_fraction = _radiative_fraction
|
|
|
|
_mean_internal_gain.schedules = _schedules
|
|
|
|
|
|
|
|
return [_mean_internal_gain]
|