2021-01-06 16:42:38 -05:00
|
|
|
"""
|
|
|
|
Hft-based interface, it reads format defined within the CERC team based on that one used in SimStadt and developed by
|
|
|
|
the IAF team at hft-Stuttgart and enriches the city with usage parameters
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
2021-05-27 17:20:06 -04:00
|
|
|
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
2021-01-06 16:42:38 -05:00
|
|
|
"""
|
|
|
|
import xmltodict
|
2021-03-02 18:57:09 -05:00
|
|
|
from imports.usage_feeders.data_classes.hft_usage_zone_archetype import HftUsageZoneArchetype as huza
|
|
|
|
from imports.usage_feeders.data_classes.hft_internal_gains_archetype import HftInternalGainsArchetype as higa
|
2021-01-06 16:42:38 -05:00
|
|
|
|
|
|
|
|
|
|
|
class HftUsageInterface:
|
|
|
|
"""
|
|
|
|
HftUsageInterface abstract class
|
|
|
|
"""
|
|
|
|
def __init__(self, base_path, usage_file='ca_library_reduced.xml'):
|
|
|
|
path = str(base_path / usage_file)
|
|
|
|
self._usage_archetypes = []
|
|
|
|
with open(path) as xml:
|
2021-01-07 18:12:13 -05:00
|
|
|
self._archetypes = xmltodict.parse(xml.read(), force_list=('zoneUsageVariant', 'zoneUsageType'))
|
|
|
|
for zone_usage_type in self._archetypes['buildingUsageLibrary']['zoneUsageType']:
|
|
|
|
usage = zone_usage_type['id']
|
|
|
|
usage_archetype = self._parse_zone_usage_type(usage, zone_usage_type)
|
|
|
|
self._usage_archetypes.append(usage_archetype)
|
|
|
|
if 'zoneUsageVariant' in zone_usage_type:
|
|
|
|
for usage_zone_variant in zone_usage_type['zoneUsageVariant']:
|
|
|
|
usage = usage_zone_variant['id']
|
2021-01-07 18:53:26 -05:00
|
|
|
usage_archetype_variant = self._parse_zone_usage_variant(usage, usage_archetype, usage_zone_variant)
|
2021-01-07 18:12:13 -05:00
|
|
|
self._usage_archetypes.append(usage_archetype_variant)
|
2021-01-06 16:42:38 -05:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _parse_zone_usage_type(usage, zone_usage_type):
|
2021-05-27 18:23:39 -04:00
|
|
|
occupancy_density = zone_usage_type['occupancy']['occupancyDensity']
|
|
|
|
hours_day = zone_usage_type['occupancy']['usageHoursPerDay']
|
|
|
|
days_year = zone_usage_type['occupancy']['usageDaysPerYear']
|
2021-01-06 16:42:38 -05:00
|
|
|
cooling_setpoint = zone_usage_type['endUses']['space_cooling']['coolingSetPointTemperature']
|
|
|
|
heating_setpoint = zone_usage_type['endUses']['space_heating']['heatingSetPointTemperature']
|
|
|
|
heating_setback = zone_usage_type['endUses']['space_heating']['heatingSetBackTemperature']
|
|
|
|
mechanical_air_change = None
|
|
|
|
if 'ventilation' in zone_usage_type['endUses'] and zone_usage_type['endUses']['ventilation'] is not None:
|
|
|
|
mechanical_air_change = zone_usage_type['endUses']['ventilation']['mechanicalAirChangeRate']
|
|
|
|
dhw_average_volume_pers_day = None
|
|
|
|
dhw_preparation_temperature = None
|
|
|
|
if 'domestic_hot_water' in zone_usage_type['endUses']:
|
2021-01-08 16:08:29 -05:00
|
|
|
# liters to cubic meters
|
|
|
|
dhw_average_volume_pers_day = float(
|
|
|
|
zone_usage_type['endUses']['domestic_hot_water']['averageVolumePerPersAndDay'])/1000
|
2021-01-06 16:42:38 -05:00
|
|
|
dhw_preparation_temperature = zone_usage_type['endUses']['domestic_hot_water']['preparationTemperature']
|
|
|
|
electrical_app_average_consumption_sqm_year = None
|
|
|
|
if 'all_electrical_appliances' in zone_usage_type['endUses']:
|
|
|
|
if 'averageConsumptionPerSqmAndYear' in zone_usage_type['endUses']['all_electrical_appliances']:
|
2021-01-08 16:08:29 -05:00
|
|
|
# kWh to J
|
2021-01-06 16:42:38 -05:00
|
|
|
electrical_app_average_consumption_sqm_year = \
|
2021-01-08 16:08:29 -05:00
|
|
|
float(zone_usage_type['endUses']['all_electrical_appliances']['averageConsumptionPerSqmAndYear'])/3.6
|
2021-01-06 16:42:38 -05:00
|
|
|
|
2021-05-26 18:17:23 -04:00
|
|
|
# todo: for internal_gain in usage_zone_variant['schedules']['internGains']:????????????????
|
2021-01-06 16:42:38 -05:00
|
|
|
# There are no more internal gains? How is it saved when more than one???
|
|
|
|
internal_gains = []
|
2021-05-27 18:23:39 -04:00
|
|
|
if 'internGains' in zone_usage_type['occupancy']:
|
|
|
|
latent_fraction = zone_usage_type['occupancy']['internGains']['latentFraction']
|
|
|
|
convective_fraction = zone_usage_type['occupancy']['internGains']['convectiveFraction']
|
|
|
|
average_internal_gain = zone_usage_type['occupancy']['internGains']['averageInternGainPerSqm']
|
|
|
|
radiative_fraction = zone_usage_type['occupancy']['internGains']['radiantFraction']
|
2021-01-07 18:53:26 -05:00
|
|
|
else:
|
|
|
|
latent_fraction = 0
|
|
|
|
convective_fraction = 0
|
|
|
|
average_internal_gain = 0
|
|
|
|
radiative_fraction = 0
|
|
|
|
|
2021-01-07 18:12:13 -05:00
|
|
|
internal_gains.append(higa(average_internal_gain, convective_fraction, radiative_fraction, latent_fraction))
|
|
|
|
usage_zone_archetype = huza(usage=usage, internal_gains=internal_gains, heating_set_point=heating_setpoint,
|
|
|
|
heating_set_back=heating_setback, cooling_set_point=cooling_setpoint,
|
|
|
|
occupancy_density=occupancy_density, hours_day=hours_day, days_year=days_year,
|
|
|
|
dhw_average_volume_pers_day=dhw_average_volume_pers_day,
|
|
|
|
dhw_preparation_temperature=dhw_preparation_temperature,
|
|
|
|
electrical_app_average_consumption_sqm_year=electrical_app_average_consumption_sqm_year,
|
|
|
|
mechanical_air_change=mechanical_air_change)
|
2021-01-06 16:42:38 -05:00
|
|
|
return usage_zone_archetype
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _parse_zone_usage_variant(usage, usage_zone, usage_zone_variant):
|
|
|
|
# for the variants all is optional because it mimics the inheritance concept from OOP
|
|
|
|
occupancy_density = usage_zone.occupancy_density
|
|
|
|
hours_day = usage_zone.hours_day
|
|
|
|
days_year = usage_zone.days_year
|
|
|
|
cooling_setpoint = usage_zone.cooling_setpoint
|
|
|
|
heating_setpoint = usage_zone.heating_setpoint
|
|
|
|
heating_setback = usage_zone.heating_setback
|
|
|
|
mechanical_air_change = usage_zone.mechanical_air_change
|
|
|
|
dhw_average_volume_pers_day = usage_zone.dhw_average_volume_pers_day
|
|
|
|
dhw_preparation_temperature = usage_zone.dhw_preparation_temperature
|
|
|
|
electrical_app_average_consumption_sqm_year = usage_zone.electrical_app_average_consumption_sqm_year
|
|
|
|
|
2021-05-26 18:17:23 -04:00
|
|
|
# todo: for internal_gain in usage_zone_variant['schedules']['internGains']:????????????????
|
2021-01-06 16:42:38 -05:00
|
|
|
# There are no more internal gains? How is it saved when more than one???
|
|
|
|
# for internal_gain in usage_zone.internal_gains:
|
2021-01-07 18:53:26 -05:00
|
|
|
internal_gains = usage_zone.internal_gains[0]
|
|
|
|
latent_fraction = internal_gains.latent_fraction
|
|
|
|
convective_fraction = internal_gains.convective_fraction
|
|
|
|
average_internal_gain = internal_gains.average_internal_gain
|
|
|
|
radiative_fraction = internal_gains.radiative_fraction
|
2021-01-06 16:42:38 -05:00
|
|
|
|
2021-05-26 18:17:23 -04:00
|
|
|
if 'usageHoursPerDay' in usage_zone_variant['schedules']:
|
|
|
|
hours_day = usage_zone_variant['schedules']['usageHoursPerDay']
|
|
|
|
if 'usageDaysPerYear' in usage_zone_variant['schedules']:
|
|
|
|
days_year = usage_zone_variant['schedules']['usageDaysPerYear']
|
2021-01-07 18:53:26 -05:00
|
|
|
if 'space_cooling' in usage_zone_variant['endUses'] and usage_zone_variant['endUses']['space_cooling'] is not None:
|
|
|
|
if 'coolingSetPointTemperature' in usage_zone_variant['endUses']['space_cooling']:
|
|
|
|
cooling_setpoint = usage_zone_variant['endUses']['space_cooling']['coolingSetPointTemperature']
|
|
|
|
if 'space_heating' in usage_zone_variant['endUses'] and usage_zone_variant['endUses']['space_heating'] is not None:
|
|
|
|
if 'heatingSetPointTemperature' in usage_zone_variant['endUses']['space_heating']:
|
|
|
|
heating_setpoint = usage_zone_variant['endUses']['space_heating']['heatingSetPointTemperature']
|
|
|
|
if 'heatingSetBackTemperature' in usage_zone_variant['endUses']['space_heating']:
|
|
|
|
heating_setback = usage_zone_variant['endUses']['space_heating']['heatingSetBackTemperature']
|
2021-01-06 16:42:38 -05:00
|
|
|
if 'ventilation' in usage_zone_variant['endUses'] and usage_zone_variant['endUses']['ventilation'] is not None:
|
2021-01-07 18:53:26 -05:00
|
|
|
if 'mechanicalAirChangeRate' in usage_zone_variant['endUses']['ventilation']:
|
|
|
|
mechanical_air_change = usage_zone_variant['endUses']['ventilation']['mechanicalAirChangeRate']
|
2021-05-26 18:17:23 -04:00
|
|
|
# todo: for internal_gain in usage_zone_variant['schedules']['internGains']:????????????????
|
2021-01-06 16:42:38 -05:00
|
|
|
# There are no more internal gains? How is it saved when more than one???
|
2021-05-26 18:17:23 -04:00
|
|
|
if 'internalGains' in usage_zone_variant['schedules'] and usage_zone_variant['schedules']['internGains'] is not None:
|
2021-01-07 18:53:26 -05:00
|
|
|
internal_gains = []
|
2021-05-26 18:17:23 -04:00
|
|
|
if 'latentFraction' in usage_zone_variant['schedules']['internGains']:
|
|
|
|
latent_fraction = usage_zone_variant['schedules']['internGains']['latentFraction']
|
|
|
|
if 'convectiveFraction' in usage_zone_variant['schedules']['internGains']:
|
|
|
|
convective_fraction = usage_zone_variant['schedules']['internGains']['convectiveFraction']
|
|
|
|
if 'averageInternGainPerSqm' in usage_zone_variant['schedules']['internGains']:
|
|
|
|
average_internal_gain = usage_zone_variant['schedules']['internGains']['averageInternGainPerSqm']
|
|
|
|
if 'radiantFraction' in usage_zone_variant['schedules']['internGains']:
|
|
|
|
radiative_fraction = usage_zone_variant['schedules']['internGains']['radiantFraction']
|
2021-01-07 18:53:26 -05:00
|
|
|
internal_gains.append(higa(average_internal_gain, convective_fraction, radiative_fraction, latent_fraction))
|
2021-01-07 18:12:13 -05:00
|
|
|
usage_zone_archetype = huza(usage=usage, internal_gains=internal_gains, heating_set_point=heating_setpoint,
|
|
|
|
heating_set_back=heating_setback, cooling_set_point=cooling_setpoint,
|
|
|
|
occupancy_density=occupancy_density, hours_day=hours_day, days_year=days_year,
|
|
|
|
dhw_average_volume_pers_day=dhw_average_volume_pers_day,
|
|
|
|
dhw_preparation_temperature=dhw_preparation_temperature,
|
|
|
|
electrical_app_average_consumption_sqm_year=electrical_app_average_consumption_sqm_year,
|
|
|
|
mechanical_air_change=mechanical_air_change)
|
2021-01-06 16:42:38 -05:00
|
|
|
return usage_zone_archetype
|
|
|
|
|
2021-01-07 18:12:13 -05:00
|
|
|
def enrich_buildings(self):
|
2021-01-06 16:42:38 -05:00
|
|
|
raise NotImplementedError
|