solved a bug in income.py and added creation of energy systems in buildings in importer

This commit is contained in:
Pilar Monsalvete 2023-06-01 11:06:16 -04:00
parent 3cdad733b3
commit 22c4f362fe
3 changed files with 103 additions and 51 deletions

View File

@ -51,7 +51,7 @@ class Income:
Get electricity export incomes in currency per J Get electricity export incomes in currency per J
:return: None or float :return: None or float
""" """
return self._construction_subsidy return self._electricity_export
@property @property
def reductions_tax(self) -> Union[None, float]: def reductions_tax(self) -> Union[None, float]:

View File

@ -605,6 +605,7 @@ class Building(CityObject):
def _calculate_working_hours(self): def _calculate_working_hours(self):
_working_hours = {} _working_hours = {}
print('working hours')
for internal_zone in self.internal_zones: for internal_zone in self.internal_zones:
for thermal_zone in internal_zone.thermal_zones: for thermal_zone in internal_zone.thermal_zones:
_working_hours_per_thermal_zone = {} _working_hours_per_thermal_zone = {}
@ -625,7 +626,8 @@ class Building(CityObject):
_working_hours[key][i] = 1 _working_hours[key][i] = 1
_total_hours = 0 _total_hours = 0
for key in _working_hours: for key in _working_hours:
_total_hours += _working_hours[key] * cte.DAYS_A_YEAR[key] hours = sum(_working_hours[key])
_total_hours += hours * cte.DAYS_A_YEAR[key]
return _total_hours return _total_hours
@property @property
@ -641,6 +643,7 @@ class Building(CityObject):
_peak_load = self.cooling_peak_load[cte.YEAR][cte.COOLING_PEAK_LOAD][0] _peak_load = self.cooling_peak_load[cte.YEAR][cte.COOLING_PEAK_LOAD][0]
_peak_load_type = cte.COOLING _peak_load_type = cte.COOLING
_working_hours = self._calculate_working_hours()
_consumption_fix_flow = 0 _consumption_fix_flow = 0
if self.energy_systems is None: if self.energy_systems is None:
return self._distribution_systems_electrical_consumption return self._distribution_systems_electrical_consumption
@ -652,29 +655,32 @@ class Building(CityObject):
distribution_system = energy_system.distribution_system.generic_distribution_system distribution_system = energy_system.distribution_system.generic_distribution_system
consumption_variable_flow = distribution_system.distribution_consumption_variable_flow consumption_variable_flow = distribution_system.distribution_consumption_variable_flow
for demand_type in energy_system.demand_types: for demand_type in energy_system.demand_types:
if demand_type.lower() == cte.HEATING: if demand_type.lower() == cte.HEATING.lower():
if _peak_load_type == cte.HEATING: if _peak_load_type == cte.HEATING.lower():
_consumption_fix_flow = distribution_system.distribution_consumption_fix_flow _consumption_fix_flow = distribution_system.distribution_consumption_fix_flow
for heating_demand_key in self.heating: for heating_demand_key in self.heating:
_consumption = [0]*len(self.heating) _consumption = [0]*len(self.heating[heating_demand_key][cte.INSEL_MEB])
_demand = self.heating[heating_demand_key][cte.INSEL_MEB] _demand = self.heating[heating_demand_key][cte.INSEL_MEB]
for i in range(0, len(_consumption)): for i in range(0, len(_consumption)):
_consumption[i] += (parasitic_energy_consumption + consumption_variable_flow) * _demand[i] _consumption[i] += (parasitic_energy_consumption + consumption_variable_flow) * _demand[i]
self._distribution_systems_electrical_consumption[heating_demand_key] = _consumption self._distribution_systems_electrical_consumption[heating_demand_key] = _consumption
if demand_type.lower() == cte.COOLING: if demand_type.lower() == cte.COOLING.lower():
if _peak_load_type == cte.COOLING: print('works')
if _peak_load_type == cte.COOLING.lower():
_consumption_fix_flow = distribution_system.distribution_consumption_fix_flow _consumption_fix_flow = distribution_system.distribution_consumption_fix_flow
for demand_key in self.cooling: for demand_key in self.cooling:
_consumption = self._distribution_systems_electrical_consumption[demand_key] _consumption = self._distribution_systems_electrical_consumption[demand_key]
print('cooling', _consumption)
_demand = self.cooling[demand_key][cte.INSEL_MEB] _demand = self.cooling[demand_key][cte.INSEL_MEB]
for i in range(0, len(_consumption)): for i in range(0, len(_consumption)):
_consumption[i] += (parasitic_energy_consumption + consumption_variable_flow) * _demand[i] _consumption[i] += (parasitic_energy_consumption + consumption_variable_flow) * _demand[i]
self._distribution_systems_electrical_consumption[demand_key] = _consumption self._distribution_systems_electrical_consumption[demand_key] = _consumption
print(_consumption)
for key in self._distribution_systems_electrical_consumption: for key in self._distribution_systems_electrical_consumption:
for i in range(0, len(self._distribution_systems_electrical_consumption[key])): for i in range(0, len(self._distribution_systems_electrical_consumption[key])):
self._distribution_systems_electrical_consumption[key][i] += _peak_load * _consumption_fix_flow \ self._distribution_systems_electrical_consumption[key][i] += _peak_load * _consumption_fix_flow \
* self._calculate_working_hours() * _working_hours
return self._distribution_systems_electrical_consumption return self._distribution_systems_electrical_consumption
def _calculate_consumption(self, consumption_type, demand): def _calculate_consumption(self, consumption_type, demand):

View File

@ -4,7 +4,9 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2023 Concordia CERC group Copyright © 2023 Concordia CERC group
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
""" """
import logging import logging
import copy
from pandas import DataFrame from pandas import DataFrame
@ -12,6 +14,10 @@ from hub.catalog_factories.energy_systems_catalog_factory import EnergySystemsCa
from hub.city_model_structure.energy_systems.generic_distribution_system import GenericDistributionSystem from hub.city_model_structure.energy_systems.generic_distribution_system import GenericDistributionSystem
from hub.city_model_structure.energy_systems.generic_energy_system import GenericEnergySystem from hub.city_model_structure.energy_systems.generic_energy_system import GenericEnergySystem
from hub.city_model_structure.energy_systems.generic_generation_system import GenericGenerationSystem from hub.city_model_structure.energy_systems.generic_generation_system import GenericGenerationSystem
from hub.city_model_structure.energy_systems.energy_system import EnergySystem
from hub.city_model_structure.energy_systems.generation_system import GenerationSystem
from hub.city_model_structure.energy_systems.distribution_system import DistributionSystem
from hub.city_model_structure.energy_systems.emission_system import EmissionSystem
from hub.helpers.dictionaries import Dictionaries from hub.helpers.dictionaries import Dictionaries
@ -46,6 +52,25 @@ class MontrealCustomEnergySystemParameters:
logging.error(f'Building {building.name} has unknown energy system archetype for system name: {archetype_name}') logging.error(f'Building {building.name} has unknown energy system archetype for system name: {archetype_name}')
continue continue
_energy_systems_connection_table, _generic_energy_systems \
= self._create_generic_systems(archetype, building, archetype_name,
_energy_systems_connection_table, _generic_energy_systems)
city.energy_systems_connection_table = _energy_systems_connection_table
city.generic_energy_systems = _generic_energy_systems
self._associate_energy_systems(city)
@staticmethod
def _search_archetypes(catalog, name):
archetypes = catalog.entries('archetypes')
for building_archetype in archetypes:
if str(name) == str(building_archetype.name):
return building_archetype
raise KeyError('archetype not found')
@staticmethod
def _create_generic_systems(archetype, building, archetype_name,
_energy_systems_connection_table, _generic_energy_systems):
building_systems = [] building_systems = []
data = [archetype_name, building.name] data = [archetype_name, building.name]
_energy_systems_connection_table.loc[len(_energy_systems_connection_table)] = data _energy_systems_connection_table.loc[len(_energy_systems_connection_table)] = data
@ -89,13 +114,34 @@ class MontrealCustomEnergySystemParameters:
if archetype_name not in _generic_energy_systems: if archetype_name not in _generic_energy_systems:
_generic_energy_systems[archetype_name] = building_systems _generic_energy_systems[archetype_name] = building_systems
city.energy_systems_connection_table = _energy_systems_connection_table return _energy_systems_connection_table, _generic_energy_systems
city.generic_energy_systems = _generic_energy_systems
@staticmethod @staticmethod
def _search_archetypes(catalog, name): def _associate_energy_systems(city):
archetypes = catalog.entries('archetypes') energy_systems_connection = city.energy_systems_connection_table
for building_archetype in archetypes: for building in city.buildings:
if str(name) == str(building_archetype.name): _building_energy_systems = []
return building_archetype energy_systems = energy_systems_connection['Energy System Type'] \
raise KeyError('archetype not found') .where(energy_systems_connection['Building'] == building.name)
for energy_system in energy_systems:
_generic_building_energy_systems = city.generic_energy_systems[energy_system]
for _generic_building_energy_system in _generic_building_energy_systems:
_building_energy_equipment = EnergySystem()
_building_energy_equipment.demand_types = _generic_building_energy_system.demand_types
_building_distribution_system = DistributionSystem()
_building_distribution_system.generic_distribution_system = \
copy.deepcopy(_generic_building_energy_system.distribution_system)
_building_emission_system = EmissionSystem()
_building_emission_system.generic_emission_system = \
copy.deepcopy(_generic_building_energy_system.emission_system)
_building_generation_system = GenerationSystem()
_building_generation_system.generic_generation_system = \
copy.deepcopy(_generic_building_energy_system.generation_system)
_building_energy_equipment.generation_system = _building_generation_system
_building_energy_equipment.distribution_system = _building_distribution_system
_building_energy_equipment.emission_system = _building_emission_system
_building_energy_systems.append(_building_energy_equipment)
building.energy_systems = _building_energy_systems