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
:return: None or float
"""
return self._construction_subsidy
return self._electricity_export
@property
def reductions_tax(self) -> Union[None, float]:

View File

@ -605,6 +605,7 @@ class Building(CityObject):
def _calculate_working_hours(self):
_working_hours = {}
print('working hours')
for internal_zone in self.internal_zones:
for thermal_zone in internal_zone.thermal_zones:
_working_hours_per_thermal_zone = {}
@ -625,7 +626,8 @@ class Building(CityObject):
_working_hours[key][i] = 1
_total_hours = 0
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
@property
@ -641,6 +643,7 @@ class Building(CityObject):
_peak_load = self.cooling_peak_load[cte.YEAR][cte.COOLING_PEAK_LOAD][0]
_peak_load_type = cte.COOLING
_working_hours = self._calculate_working_hours()
_consumption_fix_flow = 0
if self.energy_systems is None:
return self._distribution_systems_electrical_consumption
@ -652,29 +655,32 @@ class Building(CityObject):
distribution_system = energy_system.distribution_system.generic_distribution_system
consumption_variable_flow = distribution_system.distribution_consumption_variable_flow
for demand_type in energy_system.demand_types:
if demand_type.lower() == cte.HEATING:
if _peak_load_type == cte.HEATING:
if demand_type.lower() == cte.HEATING.lower():
if _peak_load_type == cte.HEATING.lower():
_consumption_fix_flow = distribution_system.distribution_consumption_fix_flow
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]
for i in range(0, len(_consumption)):
_consumption[i] += (parasitic_energy_consumption + consumption_variable_flow) * _demand[i]
self._distribution_systems_electrical_consumption[heating_demand_key] = _consumption
if demand_type.lower() == cte.COOLING:
if _peak_load_type == cte.COOLING:
if demand_type.lower() == cte.COOLING.lower():
print('works')
if _peak_load_type == cte.COOLING.lower():
_consumption_fix_flow = distribution_system.distribution_consumption_fix_flow
for demand_key in self.cooling:
_consumption = self._distribution_systems_electrical_consumption[demand_key]
print('cooling', _consumption)
_demand = self.cooling[demand_key][cte.INSEL_MEB]
for i in range(0, len(_consumption)):
_consumption[i] += (parasitic_energy_consumption + consumption_variable_flow) * _demand[i]
self._distribution_systems_electrical_consumption[demand_key] = _consumption
print(_consumption)
for key in self._distribution_systems_electrical_consumption:
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._calculate_working_hours()
* _working_hours
return self._distribution_systems_electrical_consumption
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
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
import logging
import copy
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_energy_system import GenericEnergySystem
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
@ -46,52 +52,14 @@ class MontrealCustomEnergySystemParameters:
logging.error(f'Building {building.name} has unknown energy system archetype for system name: {archetype_name}')
continue
building_systems = []
data = [archetype_name, building.name]
_energy_systems_connection_table.loc[len(_energy_systems_connection_table)] = data
for equipment in archetype.systems:
energy_system = GenericEnergySystem()
_hub_demand_types = []
for demand_type in equipment.demand_types:
_hub_demand_types.append(Dictionaries().montreal_demand_type_to_hub_energy_demand_type[demand_type])
energy_system.name = archetype_name
energy_system.demand_types = _hub_demand_types
_generation_system = GenericGenerationSystem()
archetype_generation_equipment = equipment.generation_system
_type = str(equipment.name).split('_')[0]
_generation_system.type = Dictionaries().montreal_system_to_hub_energy_generation_system[
_type]
_generation_system.fuel_type = archetype_generation_equipment.fuel_type
_generation_system.source_types = archetype_generation_equipment.source_types
_generation_system.heat_efficiency = archetype_generation_equipment.heat_efficiency
_generation_system.cooling_efficiency = archetype_generation_equipment.cooling_efficiency
_generation_system.electricity_efficiency = archetype_generation_equipment.electricity_efficiency
_generation_system.source_temperature = archetype_generation_equipment.source_temperature
_generation_system.source_mass_flow = archetype_generation_equipment.source_mass_flow
_generation_system.storage = archetype_generation_equipment.storage
_generation_system.auxiliary_equipment = None
energy_system.generation_system = _generation_system
_distribution_system = GenericDistributionSystem()
archetype_distribution_equipment = equipment.distribution_system
_distribution_system.type = archetype_distribution_equipment.type
_distribution_system.supply_temperature = archetype_distribution_equipment.supply_temperature
_distribution_system.distribution_consumption_fix_flow = \
archetype_distribution_equipment.distribution_consumption_fix_flow
_distribution_system.distribution_consumption_variable_flow = \
archetype_distribution_equipment.distribution_consumption_variable_flow
_distribution_system.heat_losses = archetype_distribution_equipment.heat_losses
energy_system.distribution_system = _distribution_system
building_systems.append(energy_system)
if archetype_name not in _generic_energy_systems:
_generic_energy_systems[archetype_name] = building_systems
_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')
@ -99,3 +67,81 @@ class MontrealCustomEnergySystemParameters:
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 = []
data = [archetype_name, building.name]
_energy_systems_connection_table.loc[len(_energy_systems_connection_table)] = data
for equipment in archetype.systems:
energy_system = GenericEnergySystem()
_hub_demand_types = []
for demand_type in equipment.demand_types:
_hub_demand_types.append(Dictionaries().montreal_demand_type_to_hub_energy_demand_type[demand_type])
energy_system.name = archetype_name
energy_system.demand_types = _hub_demand_types
_generation_system = GenericGenerationSystem()
archetype_generation_equipment = equipment.generation_system
_type = str(equipment.name).split('_')[0]
_generation_system.type = Dictionaries().montreal_system_to_hub_energy_generation_system[
_type]
_generation_system.fuel_type = archetype_generation_equipment.fuel_type
_generation_system.source_types = archetype_generation_equipment.source_types
_generation_system.heat_efficiency = archetype_generation_equipment.heat_efficiency
_generation_system.cooling_efficiency = archetype_generation_equipment.cooling_efficiency
_generation_system.electricity_efficiency = archetype_generation_equipment.electricity_efficiency
_generation_system.source_temperature = archetype_generation_equipment.source_temperature
_generation_system.source_mass_flow = archetype_generation_equipment.source_mass_flow
_generation_system.storage = archetype_generation_equipment.storage
_generation_system.auxiliary_equipment = None
energy_system.generation_system = _generation_system
_distribution_system = GenericDistributionSystem()
archetype_distribution_equipment = equipment.distribution_system
_distribution_system.type = archetype_distribution_equipment.type
_distribution_system.supply_temperature = archetype_distribution_equipment.supply_temperature
_distribution_system.distribution_consumption_fix_flow = \
archetype_distribution_equipment.distribution_consumption_fix_flow
_distribution_system.distribution_consumption_variable_flow = \
archetype_distribution_equipment.distribution_consumption_variable_flow
_distribution_system.heat_losses = archetype_distribution_equipment.heat_losses
energy_system.distribution_system = _distribution_system
building_systems.append(energy_system)
if archetype_name not in _generic_energy_systems:
_generic_energy_systems[archetype_name] = building_systems
return _energy_systems_connection_table, _generic_energy_systems
@staticmethod
def _associate_energy_systems(city):
energy_systems_connection = city.energy_systems_connection_table
for building in city.buildings:
_building_energy_systems = []
energy_systems = energy_systems_connection['Energy System Type'] \
.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